chat.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view class="container">
  3. <view class="search-box">
  4. <u-search
  5. v-model="searchForm.keyword"
  6. :clearabled="true"
  7. bg-color="#E5E5E5"
  8. :input-style="searchInputStyle"
  9. placeholder="请输入搜索内容"
  10. ></u-search>
  11. </view>
  12. <view class="list-box">
  13. <view class="list-item-box" v-for="item in list" :key="item.id" @click="onChatClick(item)">
  14. <view class="main-box">
  15. <!-- <view class="icon-box">
  16. <cover-image class="icon" :src="`https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/chat-icon/${item.type}.png`"></cover-image>
  17. <view class="tag" v-show="item.isRead"></view>
  18. </view> -->
  19. <view class="content-box">
  20. <view class="title">
  21. {{item.title}}
  22. </view>
  23. <view class="text">
  24. {{item.content}}
  25. </view>
  26. <view class="tag" v-show="item.isRead"></view>
  27. </view>
  28. <view class="other-box">
  29. <view class="date">
  30. {{item.time}}
  31. </view>
  32. </view>
  33. </view>
  34. <view class="line-box"></view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script setup>
  40. import { ref } from 'vue'
  41. import { onLoad, onReachBottom } from '@dcloudio/uni-app'
  42. import { query, count } from '@/api/chat.js'
  43. const uToast = ref()
  44. const searchInputStyle = {
  45. backgroundColor: '#E5E5E5'
  46. }
  47. const pageNum = ref(1)
  48. const pageSize = ref(10)
  49. const visualLoadMore = ref(false)
  50. const loadMoreStatus = ref('more')
  51. const searchForm = ref({
  52. keyword: '',
  53. pageNumber: 1,
  54. pageSize: 10
  55. })
  56. const list = ref([
  57. {
  58. id: '1',
  59. title: '会费缴交成功通知',
  60. content: '尊敬的用户,您在2023年8月16日15:00成交缴交会费……',
  61. type: 'zhifu',
  62. time: '8/21',
  63. isRead: true
  64. },
  65. {
  66. id: '2',
  67. title: '继续教育通知',
  68. content: '尊敬的用户,您预约2023年8月16日《广州市存量房网……',
  69. type: 'jiaoyu',
  70. time: '8/20',
  71. isRead: true
  72. },
  73. {
  74. id: '3',
  75. title: '课程购买成功通知',
  76. content: '尊敬的用户,您在成功购买2023年8月16日《广州市存……',
  77. type: 'goumai',
  78. time: '8/19',
  79. isRead: true
  80. },
  81. {
  82. id: '4',
  83. title: '个人会员生日祝福',
  84. content: '尊敬的用户,今日是您的生日,协会祝你在……',
  85. type: 'shengri',
  86. time: '8/16',
  87. isRead: false
  88. },
  89. ])
  90. function onSearch() {
  91. loadMoreStatus.value = 'more'
  92. query(searchForm.value).then(res => {
  93. if (res && res.message === 'success') {
  94. list.value = res.data
  95. if (res.count === 0) {
  96. visualLoadMore.value = false
  97. }
  98. }
  99. })
  100. }
  101. function onChatClick(chat) {
  102. uni.navigateTo({
  103. url: `/pages/chatDetail/chatDetail?id=${chat.id}&title=${chat.title}`
  104. })
  105. }
  106. onReachBottom(async () => {
  107. if (loadMoreStatus.value === 'noMore') {
  108. uni.showToast({
  109. title: '没有更多啦>﹏<',
  110. icon: 'none'
  111. })
  112. return
  113. }
  114. visualLoadMore.value = true
  115. loadMoreStatus.value = 'loading'
  116. searchForm.value.pageNum++
  117. query(searchForm.value).then(res => {
  118. if (res && res.message === 'success') {
  119. if (res.data) {
  120. if (res.count >= list.value.length) {
  121. if (list.value.length === res.count) {
  122. loadMoreStatus.value = 'noMore'
  123. visualLoadMore.value = true
  124. } else {
  125. list.value.push(...res.data)
  126. loadMoreStatus.value = 'more'
  127. visualLoadMore.value = false
  128. }
  129. } else {
  130. loadMoreStatus.value = 'noMore'
  131. visualLoadMore.value = true
  132. }
  133. } else {
  134. loadMoreStatus.value = 'noMore'
  135. visualLoadMore.value = true
  136. }
  137. }
  138. })
  139. })
  140. onLoad(() => {
  141. onSearch()
  142. count().then(res => {
  143. if (res && res.message === 'success') {
  144. uni.setTabBarBadge({ //显示数字
  145. index: 1, //tabbar下标
  146. text: `${res.data.amount}` ?? '0' //数字
  147. })
  148. }
  149. })
  150. })
  151. </script>
  152. <style lang="scss" scoped>
  153. .container {
  154. height: 100vh;
  155. width: 100vw;
  156. background-color: $uni-bg-color;
  157. padding: 0 20rpx;
  158. .search-box {
  159. margin-bottom: 20rpx;
  160. @include topMagnet();
  161. ::v-deep(.u-search) {
  162. background-color: #e5e5e5;
  163. border-radius: 50rpx;
  164. .u-action {
  165. width: 18%;
  166. background-color: $uni-color-primary;
  167. border-radius: 50rpx;
  168. color: $uni-text-color-inverse;
  169. margin-right: 8rpx;
  170. font-size: 28rpx;
  171. line-height: 50rpx;
  172. letter-spacing: 3rpx;
  173. text-align: center;
  174. }
  175. }
  176. }
  177. .list-box {
  178. padding: 0 20rpx;
  179. .list-item-box {
  180. .main-box {
  181. display: flex;
  182. justify-content: space-between;
  183. align-items: center;
  184. padding: 30rpx 0;
  185. &:active {
  186. background-color: $uni-bg-color-hover;
  187. }
  188. // .icon-box {
  189. // width: 15%;
  190. // display: flex;
  191. // justify-content: center;
  192. // align-items: center;
  193. // position: relative;
  194. // .icon {
  195. // width: 70rpx;
  196. // height: 70rpx;
  197. // }
  198. // .tag {
  199. // position: absolute;
  200. // right: 5rpx;
  201. // top: -3rpx;
  202. // width: 15rpx;
  203. // height: 15rpx;
  204. // background-color: $uni-color-error;
  205. // border-radius: 50%;
  206. // }
  207. // }
  208. .content-box {
  209. width: 85%;
  210. display: flex;
  211. flex-direction: column;
  212. justify-content: space-around;
  213. gap: 10rpx;
  214. position: relative;
  215. .title {
  216. height: calc(70% - 5rpx);
  217. font-size: $uni-title-font-size-2;
  218. font-weight: bold;
  219. }
  220. .text {
  221. height: calc(30% - 5rpx);
  222. font-size: $uni-font-size-2;
  223. color: $uni-text-color-grey;
  224. @include text-overflow();
  225. }
  226. .tag {
  227. position: absolute;
  228. left: -14rpx;
  229. top: -3rpx;
  230. width: 15rpx;
  231. height: 15rpx;
  232. background-color: $uni-color-error;
  233. border-radius: 50%;
  234. }
  235. }
  236. .other-box {
  237. width: 15%;
  238. display: flex;
  239. flex-direction: column;
  240. justify-content: flex-end;
  241. align-items: center;
  242. gap: 10rpx;
  243. .date {
  244. font-size: $uni-font-size-2;
  245. color: $uni-text-color-grey;
  246. }
  247. }
  248. }
  249. .line-box {
  250. height: 1rpx;
  251. width: 80%;
  252. background-color: #E5E5E5;
  253. margin: 0 auto;
  254. }
  255. }
  256. }
  257. }
  258. </style>