chat.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view class="chat-container">
  3. <scroll-view refresher-enabled :refresher-triggered="isRefreshing" @refresherrefresh="onCustomRefresh"
  4. class="scroll-view-class" @scrolltolower="scrolltolower" scroll-y>
  5. <view class="chat-main">
  6. <view v-if="list && list.length > 0">
  7. <view class="chat-item" v-for="item in list" :key="item.code" @click="onClick(item)">
  8. <img v-if="item.conversationAvatar" :src="item.conversationAvatar" alt="" class="chat-img" />
  9. <img src="/static/serverImg/mine/user.png" alt="" class="chat-img" v-else/>
  10. <view class="chat-box">
  11. <view class="chat-top">
  12. <text class="chat-name">{{ item.conversationType === '1'? '系统消息': type?item.volunteerName: item.userName }}</text>
  13. <text class="chat-time">{{ handlerData(item.newestMsgTime || item.createTime) }}</text>
  14. </view>
  15. <view class="chat-bottom">
  16. <text class="chat-text">
  17. {{ item.newestMsgContent }}
  18. </text>
  19. <!-- <view class="chat-num">
  20. 2
  21. </view> -->
  22. </view>
  23. </view>
  24. </view>
  25. <!-- <up-loadmore style="margin-top: 40rpx;" :status="loadmoreInfo.status"
  26. :loadmoreText="loadmoreInfo.loadingText" :loadingText="loadmoreInfo.loadmoreText"
  27. :nomoreText="loadmoreInfo.nomoreText" @loadmore="handleLoadmore" /> -->
  28. </view>
  29. <view v-else>
  30. <NoneView value="您还没有相关消息" />
  31. </view>
  32. </view>
  33. </scroll-view>
  34. <custom-tab-bar page="chat" />
  35. </view>
  36. </template>
  37. <script setup>
  38. import CustomTabBar from '@/components/CustomTabBar/index.vue'
  39. import { ref, computed } from 'vue'
  40. import { getAccountChangeList, getVolunteerChangeList } from "@/api/mine";
  41. import { onShow } from '@dcloudio/uni-app';
  42. import { useDict } from '@/utils/dict.js';
  43. import NoneView from '@/components/NoneView/index.vue'
  44. import dayjs from 'dayjs/esm/index'
  45. import { getList } from '@/api/conversation.js';
  46. const { } = useDict();
  47. const userType = uni.getStorageSync('userType') //读取本地存储
  48. console.log("TCL: userType", userType)
  49. const list = ref([])
  50. const type = computed(() =>{
  51. return userType === 1
  52. })
  53. const isRefreshing = ref(false)
  54. const loadmoreInfo = ref({
  55. status: 'loadmore',
  56. loadingText: '努力加载中...',
  57. loadmoreText: '点击加载更多~',
  58. nomoreText: '您没有更多消息~'
  59. })
  60. const pages = ref({
  61. current: 1,
  62. pageSize: 10,
  63. total: 0,
  64. })
  65. const isToday = (date) => {
  66. return dayjs(date).isSame(dayjs(), 'day');
  67. };
  68. const isYesterday = (date) => {
  69. return dayjs(date).isSame(dayjs().subtract(1, 'day'), 'day');
  70. };
  71. const handlerData = (dates) => {
  72. const date = dayjs(dates);
  73. if (isToday(dates)) {
  74. return date.format('HH:MM');;
  75. } else if (isYesterday(dates)) {
  76. return '昨天';
  77. } else {
  78. return date.format('YY/MM/DD'); // 或者其他格式如 'YYYY年MM月DD日'
  79. }
  80. }
  81. const onClick = (record) => {
  82. console.log("TCL: onClick -> record", record)
  83. uni.navigateTo({
  84. url: `/pages_orderuser/pages/talk/pages/index/index?conversationRecordId=${record.conversationRecordId}`
  85. });
  86. }
  87. const scrolltolower = () => {
  88. init('bottom')
  89. };
  90. const onCustomRefresh = () => {
  91. isRefreshing.value = true;
  92. pages.value.current = 1;
  93. init('top')
  94. };
  95. const init = async (type) => {
  96. try {
  97. if (type === 'bottom') {
  98. if (list.value.length < pages.value.total) {
  99. loadmoreInfo.value.status = 'loading';
  100. pages.value.current++;
  101. } else {
  102. loadmoreInfo.value.status = 'nomore';
  103. return;
  104. }
  105. } else {
  106. uni.showLoading({
  107. title: '数据加载中...',
  108. })
  109. }
  110. const res = await getList({
  111. // pageNum: pages.value.current,
  112. // pageSize: pages.value.pageSize,
  113. system: userType===1?'1':'2'
  114. });
  115. list.value = type === 'top' ? res.rows : [...list.value, ...res.rows];
  116. pages.value.total = res.total;
  117. } catch (error) {
  118. console.log('error', error);
  119. uni.showToast({
  120. title: error.msg,
  121. icon: 'error',
  122. });
  123. } finally {
  124. if (type === 'top') {
  125. isRefreshing.value = false;
  126. uni.hideLoading();
  127. }
  128. if (list.value.length === pages.value.total) {
  129. loadmoreInfo.value.status = 'nomore';
  130. }
  131. }
  132. }
  133. const totalInit = async () => {
  134. // try {
  135. // const listApi = userType === 1 ? getTotalMoney : getVolunteerTotalMoney;
  136. // const res = await listApi({});
  137. // data.value.totalEarning = res.data.totalEarning;
  138. // data.value.totalExpend = res.data.totalExpend;
  139. // } catch (error) {
  140. // console.log('error', error);
  141. // uni.showToast({
  142. // title: error.msg,
  143. // icon: 'error',
  144. // });
  145. // }
  146. }
  147. onShow(() => {
  148. init('top');
  149. // totalInit();
  150. })
  151. </script>
  152. <style lang="scss" scoped>
  153. .chat-container {
  154. height: 100vh;
  155. .scroll-view-class {
  156. height: 100vh;
  157. // background: rgba(245, 245, 245, 1);
  158. }
  159. .chat-item {
  160. padding: 16rpx;
  161. display: flex;
  162. .chat-img {
  163. width: 96rpx;
  164. height: 96rpx;
  165. border-radius: 16rpx;
  166. margin-right: 12rpx;
  167. }
  168. .chat-box {
  169. border-bottom: 1px solid rgba(238, 238, 238, 1);
  170. flex: 1;
  171. padding-bottom: 16rpx;
  172. .chat-top {
  173. display: flex;
  174. align-items: center;
  175. justify-content: space-between;
  176. .chat-name {
  177. font-size: 32rpx;
  178. font-weight: 400;
  179. line-height: 48rpx;
  180. color: rgba(0, 0, 0, 1);
  181. }
  182. .chat-time {
  183. font-size: 28rpx;
  184. font-weight: 400;
  185. line-height: 40rpx;
  186. color: rgba(75, 85, 99, 1);
  187. }
  188. }
  189. .chat-bottom {
  190. display: flex;
  191. justify-content: space-between;
  192. .chat-text {
  193. font-size: 28rpx;
  194. font-weight: 400;
  195. line-height: 40rpx;
  196. color: rgba(102, 102, 102, 1);
  197. width: 250px;
  198. white-space: nowrap; /* 禁止换行 */
  199. overflow: hidden; /* 隐藏溢出内容 */
  200. text-overflow: ellipsis; /* 溢出部分显示省略号 */
  201. }
  202. .chat-num {
  203. background: rgba(239, 68, 68, 1);
  204. color: #fff;
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. width: 20px;
  209. height: 20px;
  210. border-radius: 20px;
  211. line-height: 20px;
  212. }
  213. }
  214. }
  215. }
  216. }
  217. </style>