chat.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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,onMounted } 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') || 1;//读取本地存储
  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&conversationType=3`
  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}&conversationType=${record.conversationType}`
  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. onMounted(() =>{
  233. getNav()
  234. })
  235. </script>
  236. <style lang="scss" scoped>
  237. .chat-container {
  238. position: fixed;
  239. top: 0px;
  240. bottom: 0;
  241. left: 0px;
  242. right: 0px;
  243. padding-bottom: 190rpx;
  244. background: #FAF8F7;
  245. .scroll-view-class {
  246. height: 100%;
  247. padding-bottom: 200rpx;
  248. }
  249. .chat-main {
  250. height: 100%;
  251. display: flex;
  252. flex-direction: column;
  253. }
  254. .chat-list {
  255. padding: 16rpx 0 16rpx 32rpx;
  256. }
  257. .chat-item {
  258. display: flex;
  259. flex: 1;
  260. .chat-img {
  261. width: 84rpx;
  262. height: 84rpx;
  263. border-radius: 84rpx;
  264. margin-right: 26rpx;
  265. }
  266. .chat-box {
  267. flex: 1;
  268. border-bottom: 1rpx solid rgba(216, 216, 216, 0.8);
  269. height: 100%;
  270. padding-bottom: 30rpx;
  271. padding-right: 53rpx;
  272. .chat-top {
  273. display: flex;
  274. align-items: center;
  275. justify-content: space-between;
  276. .chat-name {
  277. font-family: PingFang SC;
  278. font-size: 32rpx;
  279. font-weight: normal;
  280. line-height: 40rpx;
  281. letter-spacing: normal;
  282. color: rgba(0, 0, 0, 0.8);
  283. }
  284. .chat-time {
  285. font-family: PingFang SC;
  286. font-size: 28rpx;
  287. font-weight: normal;
  288. line-height: 40rpx;
  289. text-align: right;
  290. letter-spacing: normal;
  291. color: rgba(0, 0, 0, 0.5);
  292. }
  293. }
  294. .chat-bottom {
  295. display: flex;
  296. justify-content: space-between;
  297. .chat-text {
  298. font-family: PingFang SC;
  299. font-size: 28rpx;
  300. font-weight: normal;
  301. line-height: 40rpx;
  302. letter-spacing: normal;
  303. color: rgba(109, 121, 141, 0.8);
  304. width: 250px;
  305. white-space: nowrap;
  306. /* 禁止换行 */
  307. overflow: hidden;
  308. /* 隐藏溢出内容 */
  309. text-overflow: ellipsis;
  310. /* 溢出部分显示省略号 */
  311. }
  312. // .chat-num {
  313. // background: rgba(239, 68, 68, 1);
  314. // color: #fff;
  315. // display: flex;
  316. // align-items: center;
  317. // justify-content: center;
  318. // width: 40rpx;
  319. // height: 40rpx;
  320. // border-radius: 40rpx;
  321. // line-height: 40rpx;
  322. // font-size: 24rpx;
  323. // }
  324. }
  325. }
  326. .chat-box:last-child {
  327. border-bottom:none;
  328. }
  329. }
  330. }
  331. .chat-item {
  332. transition: transform 0.2s ease;
  333. }
  334. .container-banner {
  335. display: flex;
  336. align-items: flex-end;
  337. background: #fff;
  338. .container-banner-box {
  339. display: flex;
  340. align-items: center;
  341. justify-content: space-between;
  342. padding: 0 45rpx;
  343. .container-banner-btn {
  344. font-size: 30rpx;
  345. font-weight: 500;
  346. line-height: 44rpx;
  347. display: flex;
  348. align-items: center;
  349. color: #3D3D3D;
  350. margin-left: 13rpx;
  351. }
  352. }
  353. }
  354. .chat-sys-box {
  355. padding: 24rpx 32rpx 46rpx;
  356. display: flex;
  357. gap: 32rpx;
  358. .chat-sys-item {
  359. flex: 1;
  360. padding: 32rpx;
  361. border-radius: 18rpx;
  362. background: #FFFFFF;
  363. box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(0, 0, 0, 0.06);
  364. .chat-sys-title {
  365. font-size: 32rpx;
  366. font-weight: 600;
  367. color: rgba(0, 0, 0, 0.8);
  368. margin-bottom: 16rpx;
  369. position: relative;
  370. }
  371. .chat-sys-btn {
  372. border-radius: 24rpx;
  373. background: #F7F7F7;
  374. width: 128rpx;
  375. height: 48rpx;
  376. font-size: 26rpx;
  377. font-weight: 600;
  378. line-height: 40rpx;
  379. color: #757474;
  380. display: flex;
  381. align-items: center;
  382. justify-content: center;
  383. }
  384. }
  385. }
  386. .sys-ab {
  387. position: absolute;
  388. right: -14rpx;
  389. top: -22rpx;
  390. }
  391. .chat-num {
  392. width: 32rpx;
  393. height: 32rpx;
  394. border-radius: 32rpx;
  395. font-family: PingFang SC;
  396. font-size: 24rpx;
  397. font-weight: 600;
  398. line-height: 44rpx;
  399. text-align: center;
  400. display: flex;
  401. align-items: center;
  402. justify-content: center;
  403. color: #FFFFFF;
  404. background: #FF1818;
  405. }
  406. </style>