chat.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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">{{ type?item.userName:item.volunteerName }}</text>
  13. <text class="chat-time">{{ item.createTime }}</text>
  14. </view>
  15. <view class="chat-bottom">
  16. <text class="chat-text">
  17. {{ item.msgContent }}
  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 { getList } from '@/api/conversation.js';
  45. const { } = useDict();
  46. const userType = uni.getStorageSync('userType') //读取本地存储
  47. const list = ref([])
  48. const type = computed(() =>{
  49. return userType === 1
  50. })
  51. const isRefreshing = ref(false)
  52. const loadmoreInfo = ref({
  53. status: 'loadmore',
  54. loadingText: '努力加载中...',
  55. loadmoreText: '点击加载更多~',
  56. nomoreText: '您没有更多消息~'
  57. })
  58. const pages = ref({
  59. current: 1,
  60. pageSize: 10,
  61. total: 0,
  62. })
  63. const onClick = (record) => {
  64. console.log("TCL: onClick -> record", record)
  65. uni.navigateTo({
  66. url: `/pages_orderuser/pages/talk/pages/index/index?conversationRecordId=${record.conversationRecordId}`
  67. });
  68. }
  69. const scrolltolower = () => {
  70. init('bottom')
  71. };
  72. const onCustomRefresh = () => {
  73. isRefreshing.value = true;
  74. pages.value.current = 1;
  75. init('top')
  76. };
  77. const init = async (type) => {
  78. try {
  79. if (type === 'bottom') {
  80. if (list.value.length < pages.value.total) {
  81. loadmoreInfo.value.status = 'loading';
  82. pages.value.current++;
  83. } else {
  84. loadmoreInfo.value.status = 'nomore';
  85. return;
  86. }
  87. } else {
  88. uni.showLoading({
  89. title: '数据加载中...',
  90. })
  91. }
  92. const res = await getList({
  93. // pageNum: pages.value.current,
  94. // pageSize: pages.value.pageSize,
  95. system: userType===1?'1':'2'
  96. });
  97. list.value = type === 'top' ? res.rows : [...list.value, ...res.rows];
  98. pages.value.total = res.total;
  99. } catch (error) {
  100. console.log('error', error);
  101. uni.showToast({
  102. title: error.msg,
  103. icon: 'error',
  104. });
  105. } finally {
  106. if (type === 'top') {
  107. isRefreshing.value = false;
  108. uni.hideLoading();
  109. }
  110. if (list.value.length === pages.value.total) {
  111. loadmoreInfo.value.status = 'nomore';
  112. }
  113. }
  114. }
  115. const totalInit = async () => {
  116. // try {
  117. // const listApi = userType === 1 ? getTotalMoney : getVolunteerTotalMoney;
  118. // const res = await listApi({});
  119. // data.value.totalEarning = res.data.totalEarning;
  120. // data.value.totalExpend = res.data.totalExpend;
  121. // } catch (error) {
  122. // console.log('error', error);
  123. // uni.showToast({
  124. // title: error.msg,
  125. // icon: 'error',
  126. // });
  127. // }
  128. }
  129. onShow(() => {
  130. init('top');
  131. // totalInit();
  132. })
  133. </script>
  134. <style lang="scss" scoped>
  135. .chat-container {
  136. height: 100vh;
  137. .scroll-view-class {
  138. height: 100vh;
  139. // background: rgba(245, 245, 245, 1);
  140. }
  141. .chat-item {
  142. padding: 16rpx;
  143. display: flex;
  144. .chat-img {
  145. width: 96rpx;
  146. height: 96rpx;
  147. border-radius: 16rpx;
  148. margin-right: 12rpx;
  149. }
  150. .chat-box {
  151. border-bottom: 1px solid rgba(238, 238, 238, 1);
  152. flex: 1;
  153. padding-bottom: 16rpx;
  154. .chat-top {
  155. display: flex;
  156. align-items: center;
  157. justify-content: space-between;
  158. .chat-name {
  159. font-size: 32rpx;
  160. font-weight: 400;
  161. line-height: 48rpx;
  162. color: rgba(0, 0, 0, 1);
  163. }
  164. .chat-time {
  165. font-size: 28rpx;
  166. font-weight: 400;
  167. line-height: 40rpx;
  168. color: rgba(75, 85, 99, 1);
  169. }
  170. }
  171. .chat-bottom {
  172. display: flex;
  173. justify-content: space-between;
  174. .chat-text {
  175. font-size: 28rpx;
  176. font-weight: 400;
  177. line-height: 40rpx;
  178. color: rgba(102, 102, 102, 1);
  179. width: 250px;
  180. white-space: nowrap; /* 禁止换行 */
  181. overflow: hidden; /* 隐藏溢出内容 */
  182. text-overflow: ellipsis; /* 溢出部分显示省略号 */
  183. }
  184. .chat-num {
  185. background: rgba(239, 68, 68, 1);
  186. color: #fff;
  187. display: flex;
  188. align-items: center;
  189. justify-content: center;
  190. width: 20px;
  191. height: 20px;
  192. border-radius: 20px;
  193. line-height: 20px;
  194. }
  195. }
  196. }
  197. }
  198. }
  199. </style>