chat.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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">{{ 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 goSys =()=>{
  112. const count = list.value.filter(item => item.conversationType === '3')
  113. if(count && count.length >0){
  114. const data = count[0];
  115. onClick(data);
  116. }
  117. }
  118. const onKf = () => {
  119. uni.navigateTo({
  120. url: `/pages_orderuser/pages/talk/pages/index/index?customerService=true`
  121. })
  122. }
  123. const loadmoreInfo = ref({
  124. status: 'loadmore',
  125. loadingText: '努力加载中...',
  126. loadmoreText: '点击加载更多~',
  127. nomoreText: '您没有更多消息~'
  128. })
  129. const pages = ref({
  130. current: 1,
  131. pageSize: 10,
  132. total: 0,
  133. })
  134. const isToday = (date) => {
  135. return dayjs(date).isSame(dayjs(), 'day');
  136. };
  137. const isYesterday = (date) => {
  138. return dayjs(date).isSame(dayjs().subtract(1, 'day'), 'day');
  139. };
  140. const handlerData = (dates) => {
  141. const date = dayjs(dates);
  142. if (isToday(dates)) {
  143. return date.format('HH:MM');;
  144. } else if (isYesterday(dates)) {
  145. return '昨天';
  146. } else {
  147. return date.format('YY/MM/DD'); // 或者其他格式如 'YYYY年MM月DD日'
  148. }
  149. }
  150. const onClick = (record) => {
  151. console.log("TCL: onClick -> record", record)
  152. uni.navigateTo({
  153. url: `/pages_orderuser/pages/talk/pages/index/index?conversationRecordId=${record.conversationRecordId}`
  154. });
  155. }
  156. const scrolltolower = () => {
  157. init('bottom')
  158. };
  159. const onCustomRefresh = () => {
  160. isRefreshing.value = true;
  161. pages.value.current = 1;
  162. init('top')
  163. };
  164. const handleDelete = (item) => {
  165. uni.showModal({
  166. title: '提示',
  167. content: '确定要删除该聊天吗?',
  168. success: async (res) => {
  169. if (res.confirm) {
  170. // 调用删除接口
  171. try {
  172. await conversationRemove({
  173. conversationRecordId: item.conversationRecordId,
  174. system: userType === 1 ? '1' : '2'
  175. }); // 替换为实际接口
  176. uni.showToast({ title: '删除成功' });
  177. init('top'); // 刷新列表
  178. } catch (err) {
  179. uni.showToast({ title: '删除失败', icon: 'none' });
  180. }
  181. }
  182. }
  183. });
  184. };
  185. const init = async (type) => {
  186. try {
  187. if (type === 'bottom') {
  188. if (list.value.length < pages.value.total) {
  189. loadmoreInfo.value.status = 'loading';
  190. pages.value.current++;
  191. } else {
  192. loadmoreInfo.value.status = 'nomore';
  193. return;
  194. }
  195. } else {
  196. uni.showLoading({
  197. title: '数据加载中...',
  198. })
  199. }
  200. const res = await getList({
  201. // pageNum: pages.value.current,
  202. // pageSize: pages.value.pageSize,
  203. system: userType === 1 ? '1' : '2'
  204. });
  205. list.value = type === 'top' ? res.rows : [...list.value, ...res.rows];
  206. pages.value.total = res.total;
  207. } catch (error) {
  208. console.log('error', error);
  209. uni.showToast({
  210. title: error.msg,
  211. icon: 'error',
  212. });
  213. } finally {
  214. if (type === 'top') {
  215. isRefreshing.value = false;
  216. uni.hideLoading();
  217. }
  218. if (list.value.length === pages.value.total) {
  219. loadmoreInfo.value.status = 'nomore';
  220. }
  221. }
  222. }
  223. const getNav = async () => {
  224. try {
  225. const res = await getNavBarHeight();
  226. globalData.value = res;
  227. console.log("TCL: getNav -> res", res)
  228. } catch (error) {
  229. }
  230. }
  231. onShow(() => {
  232. init('top');
  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: 150rpx;
  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>