octopus-effects-list.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view class="container">
  3. <view class="page-header">
  4. <text class="page-title">感恩记录</text>
  5. <text class="page-sub">管理你的感恩时刻与成效记录</text>
  6. </view>
  7. <!-- 记录列表 -->
  8. <view class="record-list" v-if="records && records.length > 0">
  9. <view class="record-item" v-for="r in records" :key="r.id">
  10. <view class="record-main">
  11. <view class="record-amount">{{ formatAmount(r.effectAmount) }} 元</view>
  12. <view class="record-tags">
  13. <text class="tag" v-for="t in (r.effectTypeList || [])" :key="t">{{ t }}</text>
  14. </view>
  15. </view>
  16. <view class="record-date">{{ formatTime(r.createdAt) }}</view>
  17. <view class="record-desc" v-if="r.effectDesc">{{ r.effectDesc }}</view>
  18. <view class="record-actions">
  19. <text class="action-btn-del" @tap="onDelete(r.id)">删除</text>
  20. </view>
  21. </view>
  22. </view>
  23. <!-- 空状态 -->
  24. <view class="empty-state" v-else>
  25. <text class="empty-icon">🙏</text>
  26. <text class="empty-text">暂无感恩记录</text>
  27. <text class="empty-hint">记录你的感恩时刻,画出章鱼图</text>
  28. </view>
  29. <!-- 添加按钮 -->
  30. <view class="fab" @tap="goAddEffect">
  31. <text class="fab-icon">+</text>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import { getOctopusEffects, deleteOctopusEffect } from '../../utils/api.js'
  37. export default {
  38. data() {
  39. return {
  40. records: [],
  41. _onLoadFired: false
  42. }
  43. },
  44. onLoad() {
  45. this.loadRecords()
  46. this._onLoadFired = true
  47. },
  48. onShow() {
  49. if (this._onLoadFired) {
  50. this._onLoadFired = false
  51. } else {
  52. this.loadRecords()
  53. }
  54. },
  55. methods: {
  56. async loadRecords() {
  57. try {
  58. var res = await getOctopusEffects()
  59. if (res.code === 200 && res.data && res.data.list) {
  60. this.records = res.data.list
  61. } else {
  62. this.records = []
  63. }
  64. } catch (e) { /* 静默 */ }
  65. },
  66. formatAmount: function(val) {
  67. if (val == null) return '0'
  68. return String(val)
  69. },
  70. formatTime: function(ts) {
  71. if (!ts) return ''
  72. return String(ts).substring(0, 10)
  73. },
  74. onDelete: function(id) {
  75. var self = this
  76. uni.showModal({
  77. title: '提示',
  78. content: '确定删除这条感恩记录吗?',
  79. success: function(res) {
  80. if (!res.confirm) return
  81. deleteOctopusEffect({ effectId: id }).then(function(r) {
  82. if (r.code === 200) {
  83. uni.showToast({ title: '已删除', icon: 'success' })
  84. self.loadRecords()
  85. } else {
  86. uni.showToast({ title: r.message || '删除失败', icon: 'none' })
  87. }
  88. }).catch(function(e) {
  89. uni.showToast({ title: '删除失败', icon: 'none' })
  90. })
  91. }
  92. })
  93. },
  94. goAddEffect: function() {
  95. uni.navigateTo({ url: '/pages/action-detail/octopus-add-effect' })
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped>
  101. .container {
  102. min-height: 100vh;
  103. background: #f5f7fa;
  104. padding: 24rpx;
  105. padding-bottom: 120rpx;
  106. }
  107. .page-header {
  108. padding: 20rpx 0 30rpx;
  109. }
  110. .page-title {
  111. font-size: 36rpx;
  112. font-weight: bold;
  113. color: #333;
  114. display: block;
  115. }
  116. .page-sub {
  117. font-size: 24rpx;
  118. color: #999;
  119. margin-top: 4rpx;
  120. display: block;
  121. }
  122. .record-list {
  123. display: flex;
  124. flex-direction: column;
  125. gap: 20rpx;
  126. }
  127. .record-item {
  128. background: #fff;
  129. border-radius: 16rpx;
  130. padding: 24rpx;
  131. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  132. position: relative;
  133. }
  134. .record-main {
  135. display: flex;
  136. justify-content: space-between;
  137. align-items: center;
  138. }
  139. .record-amount {
  140. font-size: 32rpx;
  141. font-weight: bold;
  142. color: #F97316;
  143. }
  144. .record-tags {
  145. display: flex;
  146. gap: 8rpx;
  147. }
  148. .tag {
  149. font-size: 20rpx;
  150. padding: 4rpx 12rpx;
  151. background: #FFF7ED;
  152. color: #F97316;
  153. border-radius: 8rpx;
  154. }
  155. .record-date {
  156. font-size: 24rpx;
  157. color: #94A3B8;
  158. margin-top: 12rpx;
  159. }
  160. .record-desc {
  161. font-size: 26rpx;
  162. color: #666;
  163. margin-top: 8rpx;
  164. }
  165. .record-actions {
  166. position: absolute;
  167. top: 24rpx;
  168. right: 24rpx;
  169. }
  170. .action-btn-del {
  171. font-size: 24rpx;
  172. color: #CBD5E1;
  173. padding: 4rpx 12rpx;
  174. border-radius: 8rpx;
  175. }
  176. .action-btn-del:active {
  177. color: #EF4444;
  178. background: #FEF2F2;
  179. }
  180. .empty-state {
  181. display: flex;
  182. flex-direction: column;
  183. align-items: center;
  184. padding: 80rpx 20rpx;
  185. }
  186. .empty-icon {
  187. font-size: 80rpx;
  188. margin-bottom: 16rpx;
  189. }
  190. .empty-text {
  191. font-size: 28rpx;
  192. color: #333;
  193. font-weight: 500;
  194. margin-bottom: 8rpx;
  195. }
  196. .empty-hint {
  197. font-size: 24rpx;
  198. color: #999;
  199. }
  200. .fab {
  201. position: fixed;
  202. bottom: 80rpx;
  203. right: 40rpx;
  204. width: 100rpx;
  205. height: 100rpx;
  206. border-radius: 50%;
  207. background: linear-gradient(135deg, #F97316, #FB923C);
  208. box-shadow: 0 4rpx 20rpx rgba(249,115,22,0.35);
  209. display: flex;
  210. align-items: center;
  211. justify-content: center;
  212. }
  213. .fab-icon {
  214. font-size: 48rpx;
  215. color: #fff;
  216. font-weight: 300;
  217. }
  218. </style>