chat.vue 7.0 KB

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