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" @click="onKf">去查看</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 src="/static/serverImg/mine/system.png" alt="" class="chat-img" v-if="item.conversationType === '1'" />
  41. <img src="/static/serverImg/mine/customer.png" alt="" class="chat-img" v-else-if="item.conversationType === '3'" />
  42. <img v-else :src="item.conversationAvatar" alt=""
  43. class="chat-img" />
  44. <view class="chat-box">
  45. <view class="chat-top">
  46. <text class="chat-name">{{['1','3'].includes(item.conversationType) ?
  47. item.conversationType ==='1'?'系统消息' :'客服消息'
  48. :
  49. type ? item.volunteerName : item.userName }}</text>
  50. <text class="chat-time">{{ handlerData(item.newestMsgTime ||
  51. item.createTime) }}</text>
  52. </view>
  53. <view class="chat-bottom">
  54. <text class="chat-text">
  55. {{ item.msgType === '2' ? '[图片]' : item.newestMsgContent || '[暂无消息]' }}
  56. </text>
  57. <view class="chat-num"
  58. v-if="item.msgUnreadCount && item.msgUnreadCount > 0">
  59. {{ item.msgUnreadCount }}
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. </uni-swipe-action-item>
  66. </uni-swipe-action>
  67. </view>
  68. <view v-else>
  69. <NoneView value="暂无消息" icon="/static/serverImg/chat/null.png" />
  70. </view>
  71. </view>
  72. </scroll-view>
  73. <custom-tab-bar page="chat" />
  74. </view>
  75. </template>
  76. <script setup>
  77. import CustomTabBar from '@/components/CustomTabBar/index.vue'
  78. import { ref, computed } from 'vue'
  79. import { onShow } from '@dcloudio/uni-app';
  80. import NoneView from '@/components/NoneView/index.vue'
  81. import dayjs from 'dayjs/esm/index'
  82. import { getList, conversationRemove } from '@/api/conversation.js';
  83. import { getNavBarHeight } from '@/utils/index.js'
  84. const userType = uni.getStorageSync('userType') //读取本地存储
  85. const list = ref([])
  86. const globalData = ref({
  87. statusBarHeight: 47,
  88. navBarHeight: 91,
  89. })
  90. const type = computed(() => {
  91. return userType === 1
  92. })
  93. const isRefreshing = ref(false)
  94. // 客服数量
  95. const kf_count = computed(() =>{
  96. const count = list.value.filter(item => item.conversationType === '3')
  97. if(count && count.length >0){
  98. return count[0].msgUnreadCount
  99. }
  100. return 0
  101. })
  102. //系统消息数量
  103. const xt_count = computed(() =>{
  104. const count = list.value.filter(item => item.conversationType === '1')
  105. if(count && count.length >0){
  106. return count[0].msgUnreadCount
  107. }
  108. return 0
  109. })
  110. const goSys =()=>{
  111. const count = list.value.filter(item => item.conversationType === '3')
  112. if(count && count.length >0){
  113. const data = count[0];
  114. onClick(data);
  115. }
  116. }
  117. const onKf = () => {
  118. uni.navigateTo({
  119. url: `/pages_orderuser/pages/talk/pages/index/index?customerService=true`
  120. })
  121. }
  122. const loadmoreInfo = ref({
  123. status: 'loadmore',
  124. loadingText: '努力加载中...',
  125. loadmoreText: '点击加载更多~',
  126. nomoreText: '您没有更多消息~'
  127. })
  128. const pages = ref({
  129. current: 1,
  130. pageSize: 10,
  131. total: 0,
  132. })
  133. const isToday = (date) => {
  134. return dayjs(date).isSame(dayjs(), 'day');
  135. };
  136. const isYesterday = (date) => {
  137. return dayjs(date).isSame(dayjs().subtract(1, 'day'), 'day');
  138. };
  139. const handlerData = (dates) => {
  140. const date = dayjs(dates);
  141. if (isToday(dates)) {
  142. return date.format('HH:MM');;
  143. } else if (isYesterday(dates)) {
  144. return '昨天';
  145. } else {
  146. return date.format('YY/MM/DD'); // 或者其他格式如 'YYYY年MM月DD日'
  147. }
  148. }
  149. const onClick = (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. } catch (error) {
  226. }
  227. }
  228. onShow(() => {
  229. init('top');
  230. getNav()
  231. })
  232. </script>
  233. <style lang="scss" scoped>
  234. .chat-container {
  235. position: fixed;
  236. top: 0px;
  237. bottom: 0;
  238. left: 0px;
  239. right: 0px;
  240. padding-bottom: 150rpx;
  241. background: #FAF8F7;
  242. .scroll-view-class {
  243. height: 100%;
  244. padding-bottom: 200rpx;
  245. }
  246. .chat-main {
  247. height: 100%;
  248. display: flex;
  249. flex-direction: column;
  250. }
  251. .chat-list {
  252. padding: 16rpx 0 16rpx 32rpx;
  253. }
  254. .chat-item {
  255. display: flex;
  256. flex: 1;
  257. .chat-img {
  258. width: 84rpx;
  259. height: 84rpx;
  260. border-radius: 84rpx;
  261. margin-right: 26rpx;
  262. }
  263. .chat-box {
  264. flex: 1;
  265. border-bottom: 1rpx solid rgba(216, 216, 216, 0.8);
  266. height: 100%;
  267. padding-bottom: 30rpx;
  268. padding-right: 53rpx;
  269. .chat-top {
  270. display: flex;
  271. align-items: center;
  272. justify-content: space-between;
  273. .chat-name {
  274. font-family: PingFang SC;
  275. font-size: 32rpx;
  276. font-weight: normal;
  277. line-height: 40rpx;
  278. letter-spacing: normal;
  279. color: rgba(0, 0, 0, 0.8);
  280. }
  281. .chat-time {
  282. font-family: PingFang SC;
  283. font-size: 28rpx;
  284. font-weight: normal;
  285. line-height: 40rpx;
  286. text-align: right;
  287. letter-spacing: normal;
  288. color: rgba(0, 0, 0, 0.5);
  289. }
  290. }
  291. .chat-bottom {
  292. display: flex;
  293. justify-content: space-between;
  294. .chat-text {
  295. font-family: PingFang SC;
  296. font-size: 28rpx;
  297. font-weight: normal;
  298. line-height: 40rpx;
  299. letter-spacing: normal;
  300. color: rgba(109, 121, 141, 0.8);
  301. width: 250px;
  302. white-space: nowrap;
  303. /* 禁止换行 */
  304. overflow: hidden;
  305. /* 隐藏溢出内容 */
  306. text-overflow: ellipsis;
  307. /* 溢出部分显示省略号 */
  308. }
  309. // .chat-num {
  310. // background: rgba(239, 68, 68, 1);
  311. // color: #fff;
  312. // display: flex;
  313. // align-items: center;
  314. // justify-content: center;
  315. // width: 40rpx;
  316. // height: 40rpx;
  317. // border-radius: 40rpx;
  318. // line-height: 40rpx;
  319. // font-size: 24rpx;
  320. // }
  321. }
  322. }
  323. .chat-box:last-child {
  324. border-bottom:none;
  325. }
  326. }
  327. }
  328. .chat-item {
  329. transition: transform 0.2s ease;
  330. }
  331. .container-banner {
  332. display: flex;
  333. align-items: flex-end;
  334. background: #fff;
  335. .container-banner-box {
  336. display: flex;
  337. align-items: center;
  338. justify-content: space-between;
  339. padding: 0 45rpx;
  340. .container-banner-btn {
  341. font-size: 30rpx;
  342. font-weight: 500;
  343. line-height: 44rpx;
  344. display: flex;
  345. align-items: center;
  346. color: #3D3D3D;
  347. margin-left: 13rpx;
  348. }
  349. }
  350. }
  351. .chat-sys-box {
  352. padding: 24rpx 32rpx 46rpx;
  353. display: flex;
  354. gap: 32rpx;
  355. .chat-sys-item {
  356. flex: 1;
  357. padding: 32rpx;
  358. border-radius: 18rpx;
  359. background: #FFFFFF;
  360. box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(0, 0, 0, 0.06);
  361. .chat-sys-title {
  362. font-size: 32rpx;
  363. font-weight: 600;
  364. color: rgba(0, 0, 0, 0.8);
  365. margin-bottom: 16rpx;
  366. position: relative;
  367. }
  368. .chat-sys-btn {
  369. border-radius: 24rpx;
  370. background: #F7F7F7;
  371. width: 128rpx;
  372. height: 48rpx;
  373. font-size: 26rpx;
  374. font-weight: 600;
  375. line-height: 40rpx;
  376. color: #757474;
  377. display: flex;
  378. align-items: center;
  379. justify-content: center;
  380. }
  381. }
  382. }
  383. .sys-ab {
  384. position: absolute;
  385. right: -14rpx;
  386. top: -22rpx;
  387. }
  388. .chat-num {
  389. width: 32rpx;
  390. height: 32rpx;
  391. border-radius: 32rpx;
  392. font-family: PingFang SC;
  393. font-size: 24rpx;
  394. font-weight: 600;
  395. line-height: 44rpx;
  396. text-align: center;
  397. display: flex;
  398. align-items: center;
  399. justify-content: center;
  400. color: #FFFFFF;
  401. background: #FF1818;
  402. }
  403. </style>