chat.vue 7.7 KB

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