You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

224 lines
4.3 KiB

  1. <template>
  2. <view class="page">
  3. <view v-if="list.length" class="msg-list">
  4. <view class="msg-item" v-for="item in list" :key="item.id" @tap="goDetail(item.id)">
  5. <view class="msg-icon" :class="getMsgClass(item)">
  6. <u-icon :name="getMsgIcon(item)" size="22" :color="getMsgColor(item)" />
  7. </view>
  8. <view class="msg-body">
  9. <view class="msg-title-row">
  10. <text class="msg-title">{{ item.title }}</text>
  11. <view v-if="!item.is_read" class="unread-dot"></view>
  12. </view>
  13. <text class="msg-desc">{{ item.content }}</text>
  14. <text class="msg-time">{{ item.create_time }}</text>
  15. </view>
  16. <text class="arrow">›</text>
  17. </view>
  18. </view>
  19. <view v-if="!loading && !list.length" class="empty">
  20. <u-icon name="bell" size="60" color="#ccc" />
  21. <text class="empty-text">暂无消息</text>
  22. </view>
  23. <view v-if="loading" class="loading-tip">
  24. <u-loading-icon size="24" />
  25. </view>
  26. <view v-if="!loading && finished && list.length" class="no-more">没有更多了</view>
  27. </view>
  28. </template>
  29. <script setup>
  30. import { ref } from 'vue'
  31. import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
  32. import { get } from '@/utils/request.js'
  33. const list = ref([])
  34. const page = ref(1)
  35. const loading = ref(false)
  36. const finished = ref(false)
  37. onLoad(() => {
  38. loadMessages()
  39. })
  40. onPullDownRefresh(() => {
  41. page.value = 1
  42. finished.value = false
  43. list.value = []
  44. loadMessages().then(() => uni.stopPullDownRefresh())
  45. })
  46. onReachBottom(() => {
  47. if (!finished.value && !loading.value) loadMessages()
  48. })
  49. const loadMessages = async () => {
  50. if (loading.value) return
  51. loading.value = true
  52. try {
  53. const res = await get('/api/mp/messages', { page: page.value, pageSize: 20 })
  54. const data = res.data || {}
  55. const items = data.data || []
  56. if (page.value === 1) {
  57. list.value = items
  58. } else {
  59. list.value.push(...items)
  60. }
  61. if (page.value >= (data.totalPages || 1)) {
  62. finished.value = true
  63. } else {
  64. page.value++
  65. }
  66. } catch (e) {}
  67. loading.value = false
  68. }
  69. const getMsgClass = (item) => {
  70. if (item.type === 1) return 'success'
  71. if (item.type === 3) return 'return'
  72. if (item.type === 4) return item.reason ? 'fail' : 'sample'
  73. return 'fail'
  74. }
  75. const getMsgIcon = (item) => {
  76. if (item.type === 1) return 'checkmark-circle-fill'
  77. if (item.type === 3) return 'order'
  78. if (item.type === 4) return item.reason ? 'close-circle-fill' : 'checkmark-circle-fill'
  79. return 'close-circle-fill'
  80. }
  81. const getMsgColor = (item) => {
  82. if (item.type === 1) return '#52c41a'
  83. if (item.type === 3) return '#0e63e3'
  84. if (item.type === 4) return item.reason ? '#f5222d' : '#52c41a'
  85. return '#f5222d'
  86. }
  87. const goDetail = (id) => {
  88. const item = list.value.find(m => m.id === id)
  89. if (item) item.is_read = 1
  90. uni.navigateTo({ url: `/pages/message/detail?id=${id}` })
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .page {
  95. min-height: 100vh;
  96. background: #f4f4f5;
  97. padding: 24rpx;
  98. }
  99. .msg-item {
  100. display: flex;
  101. align-items: flex-start;
  102. background: #fff;
  103. border-radius: 10rpx;
  104. padding: 28rpx 24rpx;
  105. margin-bottom: 20rpx;
  106. border: 1rpx solid #ebeef5;
  107. }
  108. .msg-icon {
  109. width: 56rpx;
  110. height: 56rpx;
  111. border-radius: 50%;
  112. display: flex;
  113. align-items: center;
  114. justify-content: center;
  115. flex-shrink: 0;
  116. margin-right: 20rpx;
  117. margin-top: 4rpx;
  118. &.success {
  119. background: #f6ffed;
  120. }
  121. &.fail {
  122. background: #fff2f0;
  123. }
  124. &.return {
  125. background: #f0f5ff;
  126. }
  127. &.sample {
  128. background: #f6ffed;
  129. }
  130. }
  131. .msg-body {
  132. flex: 1;
  133. min-width: 0;
  134. }
  135. .msg-title-row {
  136. display: flex;
  137. align-items: center;
  138. gap: 12rpx;
  139. }
  140. .msg-title {
  141. font-size: 30rpx;
  142. font-weight: 600;
  143. color: #333;
  144. }
  145. .unread-dot {
  146. width: 14rpx;
  147. height: 14rpx;
  148. border-radius: 50%;
  149. background: #f5222d;
  150. flex-shrink: 0;
  151. }
  152. .msg-desc {
  153. font-size: 26rpx;
  154. color: #888;
  155. margin-top: 8rpx;
  156. display: -webkit-box;
  157. -webkit-line-clamp: 1;
  158. -webkit-box-orient: vertical;
  159. overflow: hidden;
  160. }
  161. .msg-time {
  162. font-size: 24rpx;
  163. color: #bbb;
  164. margin-top: 8rpx;
  165. }
  166. .arrow {
  167. color: #c0c4cc;
  168. font-size: 28rpx;
  169. flex-shrink: 0;
  170. margin-left: 12rpx;
  171. margin-top: 8rpx;
  172. }
  173. .empty {
  174. display: flex;
  175. flex-direction: column;
  176. align-items: center;
  177. padding-top: 200rpx;
  178. }
  179. .empty-text {
  180. font-size: 28rpx;
  181. color: #ccc;
  182. margin-top: 20rpx;
  183. }
  184. .loading-tip {
  185. display: flex;
  186. justify-content: center;
  187. padding: 40rpx 0;
  188. }
  189. .no-more {
  190. text-align: center;
  191. font-size: 24rpx;
  192. color: #ccc;
  193. padding: 30rpx 0;
  194. }
  195. </style>