chat.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <view class="chat-container">
  3. <view class="container-banner" :style="{ height: globalData.navBarHeight + 'px' }">
  4. <view class="container-banner-box" :style="{ height: globalData.statusBarHeight + 'px' }">
  5. <img src="/static/serverImg/chat/msg.png" alt="" style="width: 34rpx;height: 34rpx;">
  6. <view class="container-banner-btn">咨询客服</view>
  7. </view>
  8. </view>
  9. <scroll-view refresher-enabled :refresher-triggered="isRefreshing" @refresherrefresh="onCustomRefresh"
  10. class="scroll-view-class" @scrolltolower="scrolltolower" scroll-y>
  11. <view class="chat-main">
  12. <view class="chat-sys-box">
  13. <view class="chat-sys-item">
  14. <view class="chat-sys-title">
  15. 收到{{kf_count}}条客服对话
  16. <view class="chat-num sys-ab" v-if="kf_count > 0">{{ kf_count }}</view>
  17. </view>
  18. <view class="chat-sys-btn">去查看</view>
  19. </view>
  20. <view class="chat-sys-item">
  21. <view class="chat-sys-title">收到{{xt_count}}条系统提醒
  22. <view class="chat-num sys-ab" v-if="xt_count > 0">{{ xt_count }}</view>
  23. </view>
  24. <view class="chat-sys-btn">去查看</view>
  25. </view>
  26. </view>
  27. <view v-if="list && list.length > 0" class="chat-list">
  28. <uni-swipe-action>
  29. <uni-swipe-action-item v-for="item in list" :key="item.code" :right-options="[
  30. {
  31. text: '删除',
  32. style: {
  33. backgroundColor: '#ff4949',
  34. width: '80px'
  35. }
  36. }
  37. ]" @click="handleDelete(item)">
  38. <template #default>
  39. <view class="chat-item" @click="onClick(item)">
  40. <img v-if="item.conversationAvatar" :src="item.conversationAvatar" alt=""
  41. class="chat-img" />
  42. <img src="/static/serverImg/mine/user.png" alt="" class="chat-img" v-else />
  43. <view class="chat-box">
  44. <view class="chat-top">
  45. <text class="chat-name">{{ item.conversationType === '1' ? '系统消息' :
  46. type ? item.volunteerName : item.userName }}</text>
  47. <text class="chat-time">{{ handlerData(item.newestMsgTime ||
  48. item.createTime) }}</text>
  49. </view>
  50. <view class="chat-bottom">
  51. <text class="chat-text">
  52. {{ item.msgType === '2' ? '[图片]' : item.newestMsgContent || '[暂无消息]' }}
  53. </text>
  54. <view class="chat-num"
  55. v-if="item.msgUnreadCount && item.msgUnreadCount > 0">
  56. {{ item.msgUnreadCount }}
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. </template>
  62. </uni-swipe-action-item>
  63. </uni-swipe-action>
  64. </view>
  65. <view v-else>
  66. <NoneView value="暂无消息" icon="/static/serverImg/chat/null.png" />
  67. </view>
  68. </view>
  69. </scroll-view>
  70. <custom-tab-bar page="chat" />
  71. </view>
  72. </template>
  73. <script setup>
  74. import CustomTabBar from '@/components/CustomTabBar/index.vue'
  75. import { ref, computed, reactive } from 'vue'
  76. import { getAccountChangeList, getVolunteerChangeList } from "@/api/mine";
  77. import { onShow } from '@dcloudio/uni-app';
  78. import { useDict } from '@/utils/dict.js';
  79. import NoneView from '@/components/NoneView/index.vue'
  80. import dayjs from 'dayjs/esm/index'
  81. import { getList, conversationRemove } from '@/api/conversation.js';
  82. import { getNavBarHeight } from '@/utils/index.js'
  83. const { } = useDict();
  84. const userType = uni.getStorageSync('userType') //读取本地存储
  85. console.log("TCL: userType", userType)
  86. const list = ref([])
  87. const globalData = ref({
  88. statusBarHeight: 47,
  89. navBarHeight: 91,
  90. })
  91. const type = computed(() => {
  92. return userType === 1
  93. })
  94. const isRefreshing = ref(false)
  95. // 客服数量
  96. const kf_count = computed(() =>{
  97. const count = list.value.filter(item => item.conversationType === '3')
  98. if(count && count.length >0){
  99. return count[0].msgUnreadCount
  100. }
  101. return 0
  102. })
  103. //系统消息数量
  104. const xt_count = computed(() =>{
  105. const count = list.value.filter(item => item.conversationType === '1')
  106. if(count && count.length >0){
  107. return count[0].msgUnreadCount
  108. }
  109. return 0
  110. })
  111. const loadmoreInfo = ref({
  112. status: 'loadmore',
  113. loadingText: '努力加载中...',
  114. loadmoreText: '点击加载更多~',
  115. nomoreText: '您没有更多消息~'
  116. })
  117. const pages = ref({
  118. current: 1,
  119. pageSize: 10,
  120. total: 0,
  121. })
  122. const isToday = (date) => {
  123. return dayjs(date).isSame(dayjs(), 'day');
  124. };
  125. const isYesterday = (date) => {
  126. return dayjs(date).isSame(dayjs().subtract(1, 'day'), 'day');
  127. };
  128. const handlerData = (dates) => {
  129. const date = dayjs(dates);
  130. if (isToday(dates)) {
  131. return date.format('HH:MM');;
  132. } else if (isYesterday(dates)) {
  133. return '昨天';
  134. } else {
  135. return date.format('YY/MM/DD'); // 或者其他格式如 'YYYY年MM月DD日'
  136. }
  137. }
  138. const onClick = (record) => {
  139. console.log("TCL: onClick -> record", record)
  140. uni.navigateTo({
  141. url: `/pages_orderuser/pages/talk/pages/index/index?conversationRecordId=${record.conversationRecordId}`
  142. });
  143. }
  144. const scrolltolower = () => {
  145. init('bottom')
  146. };
  147. const onCustomRefresh = () => {
  148. isRefreshing.value = true;
  149. pages.value.current = 1;
  150. init('top')
  151. };
  152. const handleDelete = (item) => {
  153. uni.showModal({
  154. title: '提示',
  155. content: '确定要删除该聊天吗?',
  156. success: async (res) => {
  157. if (res.confirm) {
  158. // 调用删除接口
  159. try {
  160. await conversationRemove({
  161. conversationRecordId: item.conversationRecordId,
  162. system: userType === 1 ? '1' : '2'
  163. }); // 替换为实际接口
  164. uni.showToast({ title: '删除成功' });
  165. init('top'); // 刷新列表
  166. } catch (err) {
  167. uni.showToast({ title: '删除失败', icon: 'none' });
  168. }
  169. }
  170. }
  171. });
  172. };
  173. const init = async (type) => {
  174. try {
  175. if (type === 'bottom') {
  176. if (list.value.length < pages.value.total) {
  177. loadmoreInfo.value.status = 'loading';
  178. pages.value.current++;
  179. } else {
  180. loadmoreInfo.value.status = 'nomore';
  181. return;
  182. }
  183. } else {
  184. uni.showLoading({
  185. title: '数据加载中...',
  186. })
  187. }
  188. const res = await getList({
  189. // pageNum: pages.value.current,
  190. // pageSize: pages.value.pageSize,
  191. system: userType === 1 ? '1' : '2'
  192. });
  193. list.value = type === 'top' ? res.rows : [...list.value, ...res.rows];
  194. pages.value.total = res.total;
  195. } catch (error) {
  196. console.log('error', error);
  197. uni.showToast({
  198. title: error.msg,
  199. icon: 'error',
  200. });
  201. } finally {
  202. if (type === 'top') {
  203. isRefreshing.value = false;
  204. uni.hideLoading();
  205. }
  206. if (list.value.length === pages.value.total) {
  207. loadmoreInfo.value.status = 'nomore';
  208. }
  209. }
  210. }
  211. const getNav = async () => {
  212. try {
  213. const res = await getNavBarHeight();
  214. globalData.value = res;
  215. console.log("TCL: getNav -> res", res)
  216. } catch (error) {
  217. }
  218. }
  219. onShow(() => {
  220. init('top');
  221. getNav()
  222. })
  223. </script>
  224. <style lang="scss" scoped>
  225. .chat-container {
  226. position: fixed;
  227. top: 0px;
  228. bottom: 0;
  229. left: 0px;
  230. right: 0px;
  231. padding-bottom: 150rpx;
  232. background: #FAF8F7;
  233. .scroll-view-class {
  234. height: 100%;
  235. padding-bottom: 200rpx;
  236. }
  237. .chat-main {
  238. height: 100%;
  239. display: flex;
  240. flex-direction: column;
  241. }
  242. .chat-list {
  243. padding: 16rpx 0 16rpx 32rpx;
  244. }
  245. .chat-item {
  246. display: flex;
  247. flex: 1;
  248. .chat-img {
  249. width: 84rpx;
  250. height: 84rpx;
  251. border-radius: 84rpx;
  252. margin-right: 26rpx;
  253. }
  254. .chat-box {
  255. flex: 1;
  256. border-bottom: 1rpx solid rgba(216, 216, 216, 0.8);
  257. height: 100%;
  258. padding-bottom: 30rpx;
  259. padding-right: 53rpx;
  260. .chat-top {
  261. display: flex;
  262. align-items: center;
  263. justify-content: space-between;
  264. .chat-name {
  265. font-family: PingFang SC;
  266. font-size: 32rpx;
  267. font-weight: normal;
  268. line-height: 40rpx;
  269. letter-spacing: normal;
  270. color: rgba(0, 0, 0, 0.8);
  271. }
  272. .chat-time {
  273. font-family: PingFang SC;
  274. font-size: 28rpx;
  275. font-weight: normal;
  276. line-height: 40rpx;
  277. text-align: right;
  278. letter-spacing: normal;
  279. color: rgba(0, 0, 0, 0.5);
  280. }
  281. }
  282. .chat-bottom {
  283. display: flex;
  284. justify-content: space-between;
  285. .chat-text {
  286. font-family: PingFang SC;
  287. font-size: 28rpx;
  288. font-weight: normal;
  289. line-height: 40rpx;
  290. letter-spacing: normal;
  291. color: rgba(109, 121, 141, 0.8);
  292. width: 250px;
  293. white-space: nowrap;
  294. /* 禁止换行 */
  295. overflow: hidden;
  296. /* 隐藏溢出内容 */
  297. text-overflow: ellipsis;
  298. /* 溢出部分显示省略号 */
  299. }
  300. // .chat-num {
  301. // background: rgba(239, 68, 68, 1);
  302. // color: #fff;
  303. // display: flex;
  304. // align-items: center;
  305. // justify-content: center;
  306. // width: 40rpx;
  307. // height: 40rpx;
  308. // border-radius: 40rpx;
  309. // line-height: 40rpx;
  310. // font-size: 24rpx;
  311. // }
  312. }
  313. }
  314. .chat-box:last-child {
  315. border-bottom:none;
  316. }
  317. }
  318. }
  319. .chat-item {
  320. transition: transform 0.2s ease;
  321. }
  322. .container-banner {
  323. display: flex;
  324. align-items: flex-end;
  325. background: #fff;
  326. .container-banner-box {
  327. display: flex;
  328. align-items: center;
  329. justify-content: space-between;
  330. padding: 0 45rpx;
  331. .container-banner-btn {
  332. font-size: 30rpx;
  333. font-weight: 500;
  334. line-height: 44rpx;
  335. display: flex;
  336. align-items: center;
  337. color: #3D3D3D;
  338. margin-left: 13rpx;
  339. }
  340. }
  341. }
  342. .chat-sys-box {
  343. padding: 24rpx 32rpx 46rpx;
  344. display: flex;
  345. gap: 32rpx;
  346. .chat-sys-item {
  347. flex: 1;
  348. padding: 32rpx;
  349. border-radius: 18rpx;
  350. background: #FFFFFF;
  351. box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(0, 0, 0, 0.06);
  352. .chat-sys-title {
  353. font-size: 32rpx;
  354. font-weight: 600;
  355. color: rgba(0, 0, 0, 0.8);
  356. margin-bottom: 16rpx;
  357. position: relative;
  358. }
  359. .chat-sys-btn {
  360. border-radius: 24rpx;
  361. background: #F7F7F7;
  362. width: 128rpx;
  363. height: 48rpx;
  364. font-size: 26rpx;
  365. font-weight: 600;
  366. line-height: 40rpx;
  367. color: #757474;
  368. display: flex;
  369. align-items: center;
  370. justify-content: center;
  371. }
  372. }
  373. }
  374. .sys-ab {
  375. position: absolute;
  376. right: -14rpx;
  377. top: -22rpx;
  378. }
  379. .chat-num {
  380. width: 32rpx;
  381. height: 32rpx;
  382. border-radius: 32rpx;
  383. font-family: PingFang SC;
  384. font-size: 24rpx;
  385. font-weight: 600;
  386. line-height: 44rpx;
  387. text-align: center;
  388. display: flex;
  389. align-items: center;
  390. justify-content: center;
  391. color: #FFFFFF;
  392. background: #FF1818;
  393. }
  394. </style>