chat.vue 6.7 KB

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