chat.vue 14 KB

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