chat.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. uni.navigateTo({
  150. url: `/pages_orderuser/pages/talk/pages/index/index?conversationRecordId=${record.conversationRecordId}`
  151. });
  152. }
  153. const scrolltolower = () => {
  154. init('bottom')
  155. };
  156. const onCustomRefresh = () => {
  157. isRefreshing.value = true;
  158. pages.value.current = 1;
  159. init('top')
  160. };
  161. const handleDelete = (item) => {
  162. uni.showModal({
  163. title: '提示',
  164. content: '确定要删除该聊天吗?',
  165. success: async (res) => {
  166. if (res.confirm) {
  167. // 调用删除接口
  168. try {
  169. await conversationRemove({
  170. conversationRecordId: item.conversationRecordId,
  171. system: userType === 1 ? '1' : '2'
  172. }); // 替换为实际接口
  173. uni.showToast({ title: '删除成功' });
  174. init('top'); // 刷新列表
  175. } catch (err) {
  176. uni.showToast({ title: '删除失败', icon: 'none' });
  177. }
  178. }
  179. }
  180. });
  181. };
  182. const init = async (type) => {
  183. try {
  184. if (type === 'bottom') {
  185. if (list.value.length < pages.value.total) {
  186. loadmoreInfo.value.status = 'loading';
  187. pages.value.current++;
  188. } else {
  189. loadmoreInfo.value.status = 'nomore';
  190. return;
  191. }
  192. } else {
  193. uni.showLoading({
  194. title: '数据加载中...',
  195. })
  196. }
  197. const res = await getList({
  198. // pageNum: pages.value.current,
  199. // pageSize: pages.value.pageSize,
  200. system: userType === 1 ? '1' : '2'
  201. });
  202. list.value = type === 'top' ? res.rows : [...list.value, ...res.rows];
  203. pages.value.total = res.total;
  204. } catch (error) {
  205. console.log('error', error);
  206. uni.showToast({
  207. title: error.msg,
  208. icon: 'error',
  209. });
  210. } finally {
  211. if (type === 'top') {
  212. isRefreshing.value = false;
  213. uni.hideLoading();
  214. }
  215. if (list.value.length === pages.value.total) {
  216. loadmoreInfo.value.status = 'nomore';
  217. }
  218. }
  219. }
  220. const getNav = async () => {
  221. try {
  222. const res = await getNavBarHeight();
  223. globalData.value = res;
  224. } catch (error) {
  225. }
  226. }
  227. onShow(() => {
  228. init('top');
  229. getNav()
  230. })
  231. </script>
  232. <style lang="scss" scoped>
  233. .chat-container {
  234. position: fixed;
  235. top: 0px;
  236. bottom: 0;
  237. left: 0px;
  238. right: 0px;
  239. padding-bottom: 150rpx;
  240. background: #FAF8F7;
  241. .scroll-view-class {
  242. height: 100%;
  243. padding-bottom: 200rpx;
  244. }
  245. .chat-main {
  246. height: 100%;
  247. display: flex;
  248. flex-direction: column;
  249. }
  250. .chat-list {
  251. padding: 16rpx 0 16rpx 32rpx;
  252. }
  253. .chat-item {
  254. display: flex;
  255. flex: 1;
  256. .chat-img {
  257. width: 84rpx;
  258. height: 84rpx;
  259. border-radius: 84rpx;
  260. margin-right: 26rpx;
  261. }
  262. .chat-box {
  263. flex: 1;
  264. border-bottom: 1rpx solid rgba(216, 216, 216, 0.8);
  265. height: 100%;
  266. padding-bottom: 30rpx;
  267. padding-right: 53rpx;
  268. .chat-top {
  269. display: flex;
  270. align-items: center;
  271. justify-content: space-between;
  272. .chat-name {
  273. font-family: PingFang SC;
  274. font-size: 32rpx;
  275. font-weight: normal;
  276. line-height: 40rpx;
  277. letter-spacing: normal;
  278. color: rgba(0, 0, 0, 0.8);
  279. }
  280. .chat-time {
  281. font-family: PingFang SC;
  282. font-size: 28rpx;
  283. font-weight: normal;
  284. line-height: 40rpx;
  285. text-align: right;
  286. letter-spacing: normal;
  287. color: rgba(0, 0, 0, 0.5);
  288. }
  289. }
  290. .chat-bottom {
  291. display: flex;
  292. justify-content: space-between;
  293. .chat-text {
  294. font-family: PingFang SC;
  295. font-size: 28rpx;
  296. font-weight: normal;
  297. line-height: 40rpx;
  298. letter-spacing: normal;
  299. color: rgba(109, 121, 141, 0.8);
  300. width: 250px;
  301. white-space: nowrap;
  302. /* 禁止换行 */
  303. overflow: hidden;
  304. /* 隐藏溢出内容 */
  305. text-overflow: ellipsis;
  306. /* 溢出部分显示省略号 */
  307. }
  308. // .chat-num {
  309. // background: rgba(239, 68, 68, 1);
  310. // color: #fff;
  311. // display: flex;
  312. // align-items: center;
  313. // justify-content: center;
  314. // width: 40rpx;
  315. // height: 40rpx;
  316. // border-radius: 40rpx;
  317. // line-height: 40rpx;
  318. // font-size: 24rpx;
  319. // }
  320. }
  321. }
  322. .chat-box:last-child {
  323. border-bottom:none;
  324. }
  325. }
  326. }
  327. .chat-item {
  328. transition: transform 0.2s ease;
  329. }
  330. .container-banner {
  331. display: flex;
  332. align-items: flex-end;
  333. background: #fff;
  334. .container-banner-box {
  335. display: flex;
  336. align-items: center;
  337. justify-content: space-between;
  338. padding: 0 45rpx;
  339. .container-banner-btn {
  340. font-size: 30rpx;
  341. font-weight: 500;
  342. line-height: 44rpx;
  343. display: flex;
  344. align-items: center;
  345. color: #3D3D3D;
  346. margin-left: 13rpx;
  347. }
  348. }
  349. }
  350. .chat-sys-box {
  351. padding: 24rpx 32rpx 46rpx;
  352. display: flex;
  353. gap: 32rpx;
  354. .chat-sys-item {
  355. flex: 1;
  356. padding: 32rpx;
  357. border-radius: 18rpx;
  358. background: #FFFFFF;
  359. box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(0, 0, 0, 0.06);
  360. .chat-sys-title {
  361. font-size: 32rpx;
  362. font-weight: 600;
  363. color: rgba(0, 0, 0, 0.8);
  364. margin-bottom: 16rpx;
  365. position: relative;
  366. }
  367. .chat-sys-btn {
  368. border-radius: 24rpx;
  369. background: #F7F7F7;
  370. width: 128rpx;
  371. height: 48rpx;
  372. font-size: 26rpx;
  373. font-weight: 600;
  374. line-height: 40rpx;
  375. color: #757474;
  376. display: flex;
  377. align-items: center;
  378. justify-content: center;
  379. }
  380. }
  381. }
  382. .sys-ab {
  383. position: absolute;
  384. right: -14rpx;
  385. top: -22rpx;
  386. }
  387. .chat-num {
  388. width: 32rpx;
  389. height: 32rpx;
  390. border-radius: 32rpx;
  391. font-family: PingFang SC;
  392. font-size: 24rpx;
  393. font-weight: 600;
  394. line-height: 44rpx;
  395. text-align: center;
  396. display: flex;
  397. align-items: center;
  398. justify-content: center;
  399. color: #FFFFFF;
  400. background: #FF1818;
  401. }
  402. </style>