index.vue 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. <template>
  2. <view>
  3. <view class="msg-box" :style="{ paddingTop: BarHeight + 'px' }">
  4. <!-- <view class="msg-box"> -->
  5. <!-- 顶部导航栏 -->
  6. <view class="nav-header">
  7. <view class="nav-left">
  8. <!-- <u-icon name="search" color="rgba(56, 58, 63, 1)" size="40"></u-icon> -->
  9. </view>
  10. <view class="nav-center">
  11. <text class="nav-title">消息</text>
  12. </view>
  13. <view class="nav-right">
  14. <!-- <u-icon name="bell" color="rgba(56, 58, 63, 1)" size="40" style="margin-right: 20rpx;"></u-icon> -->
  15. <!-- <u-icon name="setting" color="rgba(56, 58, 63, 1)" size="40" v-if="isLogin" @click="showSettingsModal"></u-icon> -->
  16. </view>
  17. </view>
  18. <!-- 系统通知 -->
  19. <view class="system-message-wrapper flex align-center" @click="goMsg">
  20. <view class="system-message-image flex align-center justify-center">
  21. <image src="/static/im/letter.svg" class="letter-icon"></image>
  22. </view>
  23. <view class="system-message-wrapper-r flex align-center justify-between">
  24. <view class="flex align-center">
  25. <text class="message-text">系统消息</text>
  26. <text class="message-count" v-if="systemCount">{{ systemCount }}</text>
  27. </view>
  28. <view class="system-message-time" v-if="systemCount">{{ systemMessageTime || '' }}</view>
  29. </view>
  30. </view>
  31. <!-- 搜索栏 -->
  32. <view class="search-bar flex align-center" v-if="isLogin" @click="goSearch">
  33. <image src="@/static/images/svg/search.svg" class="search-icon"></image>
  34. 搜索聊天记录
  35. </view>
  36. <!-- tabs -->
  37. <view class="tabs-wrapper flex align-center justify-between" v-if="isLogin">
  38. <view
  39. class="tab"
  40. v-for="(tab, index) in prevTabs"
  41. :class="{ 'active-tab': selectedTab == tab.type }"
  42. :key="tab.type + index"
  43. @click="changeTab(tab.type, 'fixed')">
  44. {{ tab.name }}
  45. <template v-if="userType == 1 && unreadCount && tab.type == 'unread'">
  46. ({{ unreadCount }})
  47. <view class="red-dot"></view>
  48. </template>
  49. </view>
  50. <view
  51. class="tab"
  52. v-for="(tab, index) in midTabs"
  53. :class="{ 'active-tab': selectedTab == tab.type }"
  54. :key="tab.type + index"
  55. @click="changeTab(tab.type)">{{ tab.name }}</view>
  56. <view class="icon-wrapper">
  57. <image src="/static/im/more.svg" class="more-icon" @click="showTabModal = true"></image>
  58. <u-mask :show="showTabModal" @click="showTabModal = false">
  59. <view class="tabs-list" :style="{ top: `calc(${BarHeight}px + 370rpx)` }">
  60. <view class="tab-item" v-for="(tab, index) in endTabs" :key="tab.type + index" @click.stop="changeTab(tab.type)">{{ tab.name }}</view>
  61. </view>
  62. </u-mask>
  63. </view>
  64. </view>
  65. <!-- 聊天列表 -->
  66. <template v-if="chatList.length">
  67. <scroll-view
  68. class="scroll-view"
  69. :style="{ height: `calc(100vh - 380rpx - ${BarHeight}px)` }"
  70. :scroll-y="true"
  71. :refresher-threshold="100"
  72. :refresher-enabled="true"
  73. :refresher-triggered="isRefreshing"
  74. scroll-with-animation="true"
  75. @refresherrefresh="handleRefresh">
  76. <view class="list">
  77. <view
  78. class="chat-item flex justify-between"
  79. v-for="item in chatList"
  80. :key="item.chatConversationId"
  81. @click="goIM(item)"
  82. @longpress="confirmDelete(item)">
  83. <view class="avatar-wrapper">
  84. <image :src="item.avatar || '/static/logo.png'" mode="aspectFill" class="avatar"></image>
  85. <view class="dot online-dot" v-if="item.onlineStatus == 'ONLINE'"></view>
  86. <view class="dot offline-dot" v-else></view>
  87. </view>
  88. <view class="chat-info-wrapper flex justify-between">
  89. <view class="chat-info-wrapper-l">
  90. <view class="chat-info-wrapper-l-t flex align-center">
  91. <view class="user-name">{{ item.userName }}</view>
  92. <view class="tip-wrapper">
  93. <text class="text-tip" v-if="item.companyName">{{ item.companyName }}</text>
  94. <text class="text-tip" style="margin: 0 6rpx;" v-if="item.companyName && item.stationName"> | </text>
  95. <text class="text-tip" v-if="item.stationName">{{ item.stationName }}</text>
  96. </view>
  97. </view>
  98. <view class="chat-info-wrapper-l-b">
  99. <template v-if="item.messageType == 1">{{item.content}}</template>
  100. <template v-else-if="item.messageType == 10">简历已发送</template>
  101. <template v-else-if="item.messageType == 18">位置</template>
  102. <template v-else-if="item.messageType == 9">简历请求</template>
  103. <template v-else-if="item.messageType == 6">微信请求</template>
  104. <template v-else-if="item.messageType == 5">手机号请求</template>
  105. <template v-else-if="item.messageType == 2">[图片]</template>
  106. <template v-else-if="item.messageType == 3">[语音]</template>
  107. <template v-else-if="item.messageType == 7">[交换手机]</template>
  108. <template v-else-if="item.messageType == 8">[交换微信]</template>
  109. <template v-else-if="item.messageType == 12">{{item.content}}已拒绝</template>
  110. <template v-else-if="item.messageType == 4">
  111. <image
  112. class="chat-listitem-text"
  113. v-if="item.content && item.messageType === 4"
  114. :src="ossUrl +item.content"
  115. style="height: 40rpx;width: 40rpx;"
  116. ></image>
  117. </template>
  118. <template v-else-if="item.messageType == 20">[视频通话]</template>
  119. <template v-else-if="item.messageType == 21">[语音通话]</template>
  120. <template v-else-if="item.messageType == 99">[面试邀约]</template>
  121. <template v-else-if="item.messageType == 98">[{{item.content}}]</template>
  122. <template v-else-if="item.messageType == 96 || item.messageType == 97">[{{item.content}}]</template>
  123. <template v-else>[其他消息类型]</template>
  124. </view>
  125. </view>
  126. <view class="chat-info-wrapper-r">
  127. <view class="chat-info-wrapper-r-t">
  128. <image src="/static/im/toUp.svg" class="up-icon" v-if="showIsTop(item)"></image>
  129. </view>
  130. <view class="chat-time" v-if="item.messageTime">{{ getMonthOrDay(item.messageTime) }}</view>
  131. <view class="count-wrapper">
  132. <view class="count" v-if="item.contentCount">{{ item.contentCount }}</view>
  133. </view>
  134. </view>
  135. </view>
  136. </view>
  137. </view>
  138. </scroll-view>
  139. </template>
  140. <empty v-if="!chatList.length" content='暂无消息'></empty>
  141. </view>
  142. <!-- <view class="chat-title">聊天</view> -->
  143. <!-- <view v-if="msgList.length" class="margin-topW">
  144. <view class="flex padding-tb radius padding-lr-sm bg" @click="goMsg" v-for="(item,index) in msgList"
  145. :key='index'>
  146. <view>
  147. <image style="width: 80rpx;height: 80rpx;border-radius: 80rpx;"
  148. src="../../static/images/msg/msg.png"></image>
  149. </view>
  150. <view class="flex-sub margin-left-sm">
  151. <view class="flex justify-between">
  152. <view class="text-white">{{item.title?item.title: '系统消息'}}</view>
  153. <view v-if="messageCount>0"
  154. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  155. {{messageCount}}
  156. </view>
  157. </view>
  158. <view>
  159. <view class="text-grey">{{item.content}}</view>
  160. </view>
  161. </view>
  162. </view>
  163. </view> -->
  164. <!-- <view v-if="chatList.length" class="margin-top-sm content ">
  165. <view class="radius padding-lr-sm bg" style="margin-top: 4rpx;" @click="goIM(item)" @longpress="confirmDelete(item)"
  166. v-for="(item,index) in chatList" :key='index'>
  167. <view class="flex padding-tb ">
  168. <view class="avatar-container">
  169. <u-image shape="circle" width='80rpx' height="80rpx" :src="item.avatar"></u-image>
  170. </view>
  171. <view class="flex-sub margin-left-sm" style="overflow: hidden;">
  172. <view class="flex justify-between align-center">
  173. <view class="text-white flex align-center" style="flex: 1;overflow: hidden;">
  174. <view class="text-white" style="font-size: 30rpx;">
  175. {{item.userName}}
  176. </view>
  177. <text class="text-grey userNameleng" style="font-size: 26rpx;margin-left: 10rpx;">
  178. <text v-if="item.companyName">{{item.companyName}} |</text>
  179. {{item.stationName}}
  180. </text>
  181. </view>
  182. <view class="text-grey" style="flex-shrink: 0;margin-left: 10rpx;">
  183. {{item.messageTime?getMonthOrDay(item.messageTime):''}}</view>
  184. </view>
  185. <view class="flex justify-between" style="margin-top: 10rpx;">
  186. <view class="text-grey" v-if="item.messageType == 1">{{item.content}}</view>
  187. <view class="text-grey" v-else-if="item.messageType == 10">简历已发送</view>
  188. <view class="text-grey" v-else-if="item.messageType == 18">位置</view>
  189. <view class="text-grey" v-else-if="item.messageType == 9">简历请求</view>
  190. <view class="text-grey" v-else-if="item.messageType == 6">微信请求</view>
  191. <view class="text-grey" v-else-if="item.messageType == 5">手机号请求</view>
  192. <view class="text-grey" v-else-if="item.messageType == 2">[图片]</view>
  193. <view class="text-grey" v-else-if="item.messageType == 3">[语音]</view>
  194. <view class="text-grey" v-else-if="item.messageType == 7">[交换手机]</view>
  195. <view class="text-grey" v-else-if="item.messageType == 8">[交换微信]</view>
  196. <view class="text-grey" v-else-if="item.messageType == 12">{{item.content}}已拒绝</view>
  197. <view class="text-grey" v-else-if="item.messageType == 4"><image class="chat-listitem-text"
  198. v-if="item.content && item.messageType === 4"
  199. :src="ossUrl +item.content"
  200. style="height: 40rpx;width: 40rpx;"></image></view>
  201. <view class="text-grey" v-else-if="item.messageType == 20">[视频通话]</view>
  202. <view class="text-grey" v-else-if="item.messageType == 21">[语音通话]</view>
  203. <view class="text-grey" v-else-if="item.messageType == 99">[面试邀约]</view>
  204. <view class="text-grey" v-else-if="item.messageType == 98">[{{item.content}}]</view>
  205. <view class="text-grey" v-else-if="item.messageType == 96 || item.messageType == 97">[{{item.content}}]</view>
  206. <view class="text-grey" v-else>[其他消息类型]</view>
  207. <view v-if="item.contentCount"
  208. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  209. {{item.contentCount}}
  210. </view>
  211. </view>
  212. </view>
  213. </view>
  214. </view>
  215. </view> -->
  216. <!-- <empty v-if="!chatList.length" content='暂无消息'></empty> -->
  217. <!-- 消息设置弹窗 -->
  218. <u-popup v-model="showSettings" mode="bottom" :mask-close-able="true" border-radius="20">
  219. <view class="settings-modal">
  220. <view class="modal-drag-bar"></view>
  221. <view class="modal-title">消息设置</view>
  222. <!-- 消息通知开关 -->
  223. <view class="setting-item setting-item-first">
  224. <view class="setting-left">
  225. <view class="setting-title-row">
  226. <view class="setting-label">消息通知开关</view>
  227. <view class="setting-desc">关闭后将不再向你推送消息通知</view>
  228. </view>
  229. <view class="switch-status" :class="{ 'status-on': notificationEnabled, 'status-off': !notificationEnabled }">
  230. {{ notificationEnabled ? 'On' : 'Off' }}
  231. </view>
  232. </view>
  233. <view class="setting-right">
  234. <u-switch v-model="notificationEnabled" active-color="#007AFF" @change="toggleNotification"></u-switch>
  235. </view>
  236. </view>
  237. <!-- 招呼语设置 -->
  238. <view class="setting-item" @click="goGreetingSettings">
  239. <view class="setting-left">
  240. <view class="setting-label">招呼语设置</view>
  241. </view>
  242. <view class="setting-right">
  243. <view class="setting-desc">设置后,沟通时可自动发送设置的招呼语</view>
  244. <u-icon name="arrow-right" color="rgba(29, 33, 41, 1)" size="24"></u-icon>
  245. </view>
  246. </view>
  247. <!-- 常用语设置 -->
  248. <view class="setting-item" @click="goCommonPhrases">
  249. <view class="setting-left">
  250. <view class="setting-label">常用语设置</view>
  251. </view>
  252. <view class="setting-right">
  253. <u-icon name="arrow-right" color="rgba(29, 33, 41, 1)" size="24"></u-icon>
  254. </view>
  255. </view>
  256. </view>
  257. </u-popup>
  258. </view>
  259. </template>
  260. <script>
  261. import empty from '../../components/empty.vue'
  262. import configData from '../../common/config.js'
  263. import { debounce } from '../../utils/util'
  264. // 求职端tabs
  265. // 显示:全部(固定)、未读(固定)、新招呼、仅沟通、有交换、有面试
  266. const JobApplicationTab = [
  267. {
  268. type: '',
  269. name: '全部'
  270. },
  271. {
  272. type: 'unread',
  273. name: '未读'
  274. },
  275. {
  276. type: 'new',
  277. name: '新招呼'
  278. },
  279. {
  280. type: 'communicating',
  281. name: '仅沟通'
  282. },
  283. {
  284. type: 'exchanged',
  285. name: '有交换'
  286. },
  287. {
  288. type: 'interview',
  289. name: '有面试'
  290. },
  291. ]
  292. // 招聘端tabs
  293. // 显示:全部(固定)、新招呼(固定)、沟通中、已约面、已获取简历、已交换电话、已交换微信、收藏
  294. const RecruitmentTab = [
  295. {
  296. type: '',
  297. name: '全部'
  298. },
  299. {
  300. type: 'new',
  301. name: '新招呼'
  302. },
  303. {
  304. type: 'communicating',
  305. name: '沟通中'
  306. },
  307. {
  308. type: 'interview',
  309. name: '已约面'
  310. },
  311. {
  312. type: 'gotResume',
  313. name: '已获取简历'
  314. },
  315. {
  316. type: 'gotPhone',
  317. name: '已交换电话'
  318. },
  319. {
  320. type: 'gotWx',
  321. name: '已交换微信'
  322. },
  323. {
  324. type: 'collected',
  325. name: '收藏'
  326. },
  327. ]
  328. export default {
  329. components: {
  330. empty
  331. },
  332. data() {
  333. return {
  334. BarHeight: 0,
  335. page: 1,
  336. limit: 100,
  337. chatList: [],
  338. msgList: [],
  339. time: '',
  340. messageCount: 0,
  341. // userCount: 0,
  342. arr: [],
  343. showModal: true,
  344. showSettings: false, // 控制设置弹窗显示
  345. notificationEnabled: true, // 消息通知开关状态
  346. ossUrl:configData.ossUrl,
  347. tabs: [],
  348. selectedTab: '',
  349. isRefreshing: false,
  350. total: 0,
  351. userType: null,
  352. showTabModal: false,
  353. systemCount: 0, // 系统消息数量
  354. systemMessageTime: '', // 系统消息时间
  355. refreshTime: '', // 更新时间戳
  356. isLogin: false,
  357. unreadCount: 0
  358. }
  359. },
  360. computed: {
  361. prevTabs() {
  362. return this.tabs.slice(0, 2)
  363. },
  364. midTabs() {
  365. return this.tabs.slice(2, 4)
  366. },
  367. endTabs() {
  368. return this.tabs.slice(4)
  369. }
  370. },
  371. onLoad() {
  372. // #ifdef APP-PLUS
  373. let systemInfo = uni.getSystemInfoSync();
  374. this.BarHeight = systemInfo.statusBarHeight;
  375. // #endif
  376. uni.$on('chatUnreadCount', (data) => {
  377. if (this.userType === 1) {
  378. this.unreadCount = data
  379. }
  380. })
  381. },
  382. onUnload() {
  383. uni.$off('chatUnreadCount')
  384. if (this.time) clearInterval(this.time)
  385. },
  386. // //下拉刷新
  387. // onPullDownRefresh() {
  388. // let that = this
  389. // if (uni.getStorageSync('token')) {
  390. // that.getweiduMsg();
  391. // that.getChatList()
  392. // that.getMsgList()
  393. // that.$nextTick(function() {
  394. // that.messageCount = uni.getStorageSync('messageCount')
  395. // })
  396. // }
  397. // },
  398. onShow() {
  399. if (uni.getStorageSync('token')) {
  400. const userType = uni.getStorageSync('userType') || null
  401. if (this.userType != userType) {
  402. this.userType = userType
  403. this.init()
  404. } else {
  405. // if (this.userType == 1) {
  406. // this.getUnreadCount()
  407. // }
  408. this.getChatList()
  409. this.getMsgList()
  410. }
  411. this.isLogin = true
  412. this.time = setInterval(() => {
  413. const newTime = (new Date()).getTime()
  414. // 判断上一次请求是否大于3s
  415. if (this.refreshTime + 3000 < newTime) {
  416. // this.getweiduMsg();
  417. // if (this.userType == 1) {
  418. // this.getUnreadCount()
  419. // }
  420. this.getChatList()
  421. this.getMsgList()
  422. this.$nextTick(() => {
  423. this.messageCount = uni.getStorageSync('messageCount')
  424. })
  425. }
  426. }, 3000)
  427. this.$Request.getT('/app/common/type/310').then(res => { //消息未读提醒
  428. if (res.code == 0) {
  429. if (res.data && res.data.value) {
  430. this.arr.push(res.data.value)
  431. }
  432. }
  433. })
  434. this.$Request.getT('/app/common/type/337').then(res => { //预约成功通知(通用)
  435. if (res.code == 0) {
  436. if (res.data && res.data.value) {
  437. this.arr.push(res.data.value)
  438. }
  439. }
  440. })
  441. this.$Request.getT('/app/common/type/338').then(res => { //订单状态通知
  442. if (res.code == 0) {
  443. if (res.data && res.data.value) {
  444. this.arr.push(res.data.value)
  445. }
  446. }
  447. })
  448. // // #ifdef MP-WEIXIN
  449. // if (this.showModal) {
  450. // this.openMsg()
  451. // }
  452. // // #endif
  453. } else {
  454. this.isLogin = false
  455. this.chatList = []
  456. this.msgList = []
  457. }
  458. },
  459. onHide() {
  460. clearInterval(this.time)
  461. },
  462. methods: {
  463. // 初始化
  464. init() {
  465. // if (this.userType == 1) {
  466. // this.getUnreadCount()
  467. // }
  468. this.setTabs()
  469. this.getChatList()
  470. this.getMsgList()
  471. },
  472. // 设置tabs
  473. setTabs() {
  474. const userType = this.$queue.getData('userType')
  475. if (userType == 1) {
  476. this.tabs = JobApplicationTab
  477. } else if (userType == 2) {
  478. this.tabs = RecruitmentTab
  479. }
  480. },
  481. changeTab(type, isFixed = '') {
  482. if (!isFixed) {
  483. const index = this.tabs.findIndex(tab => tab.type == type)
  484. if (index > -1) {
  485. const tabItem = this.tabs.splice(index, 1)
  486. this.tabs.splice(2, 0, ...tabItem)
  487. }
  488. }
  489. if (this.showTabModal) {
  490. this.showTabModal = false
  491. }
  492. this.selectedTab = type
  493. this.page = 1
  494. this.getChatList()
  495. },
  496. confirmDelete(item){
  497. uni.showModal({
  498. title: '提示',
  499. content: '是否删除这条消息?',
  500. cancelText: '取消',
  501. confirmText: '删除',
  502. success: (res) => {
  503. if (res.confirm) {
  504. this.$Request.get(`/app/chat/deleteConversation?chatConversationId=${item.chatConversationId}`).then(res => {
  505. if(res.code == 0){
  506. uni.showToast({
  507. title: res.msg,
  508. icon: 'none'
  509. })
  510. }else{
  511. uni.showToast({
  512. title: res.msg || '删除失败',
  513. icon: 'none'
  514. })
  515. }
  516. });
  517. }
  518. }
  519. });
  520. },
  521. // 显示置顶
  522. showIsTop(item) {
  523. if (this.userType == 1) {
  524. return Boolean(item.isTop)
  525. } else if (this.userType == 2) {
  526. return Boolean(item.isTopQiye)
  527. }
  528. return false
  529. },
  530. //把时间转换为月日
  531. getMonthOrDay(data) {
  532. // 1️⃣ 手动解析字符串,避免 iOS 时区问题
  533. let timePublish;
  534. if (typeof data === 'string') {
  535. // 格式:2026-01-05 18:46:39
  536. const parts = data.split(/[- :]/);
  537. // 注意:月份从 0 开始
  538. timePublish = new Date(parts[0], parts[1] - 1, parts[2], parts[3] || 0, parts[4] || 0, parts[5] || 0);
  539. } else {
  540. timePublish = new Date(data);
  541. }
  542. const timeNow = new Date();
  543. const publishYear = timePublish.getFullYear();
  544. const publishMonth = timePublish.getMonth() + 1;
  545. const publishDate = timePublish.getDate();
  546. const publishHour = timePublish.getHours().toString().padStart(2, '0');
  547. const publishMinute = timePublish.getMinutes().toString().padStart(2, '0');
  548. const oneDay = 1000 * 60 * 60 * 24;
  549. // 用本地时间差计算天数
  550. const diffDays = Math.floor((timeNow.setHours(0, 0, 0, 0) - timePublish.setHours(0, 0, 0, 0)) / oneDay);
  551. const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  552. const weekStr = weekDays[timePublish.getDay()];
  553. const sameYear = publishYear === timeNow.getFullYear();
  554. let result = '';
  555. if (diffDays === 0) {
  556. result = `${publishHour}:${publishMinute}`;
  557. } else if (diffDays === 1) {
  558. result = `昨天 ${publishHour}:${publishMinute}`;
  559. } else if (diffDays < 7) {
  560. result = `${weekStr} ${publishHour}:${publishMinute}`;
  561. } else if (sameYear) {
  562. result = `${publishMonth}月${publishDate}日 ${publishHour}:${publishMinute}`;
  563. } else {
  564. result = `${publishYear}年${publishMonth}月${publishDate}日 ${publishHour}:${publishMinute}`;
  565. }
  566. return result;
  567. },
  568. // // 开启订阅消息
  569. // openMsg() {
  570. // console.log('订阅消息')
  571. // var that = this
  572. // uni.getSetting({
  573. // withSubscriptions: true, //是否获取用户订阅消息的订阅状态,默认false不返回
  574. // success(ret) {
  575. // console.log(ret.subscriptionsSetting.itemSettings, '*************************************')
  576. // // if (ret.subscriptionsSetting.itemSettings && Object.keys(ret.subscriptionsSetting.itemSettings).length == 2) {
  577. // if (ret.subscriptionsSetting.itemSettings) {
  578. // uni.setStorageSync('sendMsg', true)
  579. // uni.openSetting({ // 打开设置页
  580. // success(rea) {
  581. // console.log(rea.authSetting)
  582. // }
  583. // });
  584. // } else { // 用户没有点击“总是保持以上,不再询问”则每次都会调起订阅消息
  585. // uni.setStorageSync('sendMsg', false)
  586. // uni.showModal({
  587. // title: '提示',
  588. // content: '为了更好的体验,请绑定消息推送',
  589. // confirmText: '确定',
  590. // cancelText: '取消',
  591. // confirmColor: '#016BF6',
  592. // success: function(res) {
  593. // if (res.confirm) {
  594. // wx.requestSubscribeMessage({
  595. // tmplIds: that.arr,
  596. // success(re) {
  597. // console.log(JSON.stringify(re),
  598. // '++++++++++++++')
  599. // var datas = JSON.stringify(re);
  600. // if (datas.indexOf("accept") != -1) {
  601. // console.log(re)
  602. // // uni.setStorageSync('sendMsg', true)
  603. // }
  604. // },
  605. // fail: (res) => {
  606. // console.log(res)
  607. // }
  608. // })
  609. // // uni.setStorageSync('sendMsg', true)
  610. // console.log('确认')
  611. // that.showModal = false
  612. // } else if (res.cancel) {
  613. // console.log('取消')
  614. // // uni.setStorageSync('sendMsg', false)
  615. // that.showModal = true
  616. // }
  617. // }
  618. // })
  619. // }
  620. // }
  621. // })
  622. // },
  623. // getweiduMsg() {
  624. // this.$Request.get("/app/chats/userCount").then(res => {
  625. // uni.stopPullDownRefresh()
  626. // if (res.code == 0) {
  627. // this.userCount = res.data
  628. // }
  629. // });
  630. // },
  631. //在线客服
  632. goChat() {
  633. // uni.navigateTo({
  634. // url:'/my/setting/chat'
  635. // })
  636. // #ifdef MP-WEIXIN
  637. if (uni.getStorageSync('sendMsg')) {
  638. // console.log('授权+1')
  639. wx.requestSubscribeMessage({
  640. tmplIds: this.arr,
  641. success(re) {
  642. // console.log(JSON.stringify(re), 111111111111)
  643. var datas = JSON.stringify(re);
  644. if (datas.indexOf("accept") != -1) {
  645. // console.log(re)
  646. }
  647. },
  648. fail: (res) => {
  649. // console.log(res)
  650. }
  651. })
  652. }
  653. // #endif
  654. let that = this
  655. if (uni.getStorageSync('userType') == 1) { //用户端
  656. // #ifdef MP-WEIXIN
  657. wx.openCustomerServiceChat({
  658. extInfo: {
  659. url: that.$queue.getData('kefu')
  660. },
  661. corpId: that.$queue.getData('kefuAppid'),
  662. success(res) {
  663. console.log(res)
  664. },
  665. })
  666. // #endif
  667. // #ifdef H5
  668. window.location.href = that.$queue.getData('kefu');
  669. // #endif
  670. // #ifdef APP
  671. let kefu = that.$queue.getData('kefu')
  672. console.log(kefu)
  673. plus.runtime.openURL(kefu, function(res) {});
  674. // #endif
  675. } else { //企业端
  676. // #ifdef MP-WEIXIN
  677. wx.openCustomerServiceChat({
  678. extInfo: {
  679. url: that.$queue.getData('kefuq')
  680. },
  681. corpId: that.$queue.getData('kefuAppidq'),
  682. success(res) {
  683. console.log(res)
  684. },
  685. })
  686. // #endif
  687. // #ifdef H5
  688. window.location.href = that.$queue.getData('kefuq');
  689. // #endif
  690. // #ifdef APP
  691. let kefu = that.$queue.getData('kefuq')
  692. console.log(kefu)
  693. plus.runtime.openURL(kefu, function(res) {});
  694. // #endif
  695. }
  696. },
  697. getChatList() {
  698. this.refreshTime = (new Date()).getTime()
  699. this.$Request.get("/app/chat/selectChatConversationPage", {
  700. page: this.page,
  701. limit: this.limit,
  702. type: this.selectedTab
  703. }).then(res => {
  704. // uni.stopPullDownRefresh()
  705. if (res.code == 0) {
  706. this.chatList = this.page != 1 ? [...this.chatList, ...res.data.list] : res.data.list
  707. this.total = res.data.totalCount
  708. }
  709. }).finally(() => {
  710. this.refreshTime = (new Date()).getTime()
  711. this.isRefreshing = false
  712. });
  713. },
  714. getMsgList() {
  715. this.$Request.get("/app/message/selectMessageCountByUserId").then(res => {
  716. // uni.stopPullDownRefresh()
  717. if (res.code == 0) {
  718. // this.msgList = res.data.list
  719. this.systemCount = res.data.count
  720. this.systemMessageTime = res.data.lastTime
  721. }
  722. });
  723. },
  724. goIM: debounce(function(e) {
  725. // #ifdef MP-WEIXIN
  726. if (uni.getStorageSync('sendMsg')) {
  727. // console.log('授权+1')
  728. wx.requestSubscribeMessage({
  729. tmplIds: this.arr,
  730. success(re) {
  731. // console.log(JSON.stringify(re), 111111111111)
  732. var datas = JSON.stringify(re);
  733. if (datas.indexOf("accept") != -1) {
  734. // console.log(re)
  735. }
  736. },
  737. fail: (res) => {
  738. // console.log(res)
  739. }
  740. })
  741. }
  742. // #endif
  743. let userId = '';
  744. let userType = uni.getStorageSync('userType')
  745. if (userType == 2) { //当前登录用户为企业
  746. userId = e.userId
  747. } else { //当前登录用户为用户
  748. userId = e.focusedUserId
  749. }
  750. if (uni.getStorageSync('userType') == 1) {
  751. uni.navigateTo({
  752. url: '/pages/msg/im?chatConversationId=' + e.chatConversationId + '&byUserId=' + userId +
  753. '&postPushId=' + e.postPushId + '&resumesId=' + e.resumesId
  754. })
  755. } else {
  756. uni.navigateTo({
  757. url: '/pages/msg/im?chatConversationId=' + e.chatConversationId + '&byUserId=' + userId +
  758. '&resumesId=' + e.resumesId + '&postPushId=' + e.postPushId
  759. })
  760. }
  761. }, 300),
  762. goMsg: debounce(function() {
  763. if (!this.isLogin) return
  764. uni.navigateTo({
  765. url: '/pages/msg/message'
  766. })
  767. }, 300),
  768. // 显示设置弹窗
  769. showSettingsModal() {
  770. this.showSettings = true
  771. },
  772. // 切换通知开关
  773. toggleNotification() {
  774. // 开关状态已经通过v-model自动更新,这里可以添加其他逻辑
  775. console.log('通知开关状态:', this.notificationEnabled)
  776. },
  777. // 招呼语设置
  778. goGreetingSettings() {
  779. uni.navigateTo({
  780. url: '/pages/msg/addmsg'
  781. })
  782. },
  783. // 常用语设置
  784. goCommonPhrases() {
  785. uni.navigateTo({
  786. url: '/pages/msg/addmsg'
  787. })
  788. },
  789. // 搜索功能
  790. goSearch: debounce(function() {
  791. uni.navigateTo({
  792. url: '/pages/msg/search'
  793. })
  794. }, 300),
  795. // 刷新
  796. handleRefresh() {
  797. if (!uni.getStorageSync('token')) {
  798. return this.isRefreshing = false
  799. }
  800. if (this.isRefreshing) return
  801. this.isRefreshing = true
  802. this.page = 1
  803. this.getChatList()
  804. this.getMsgList()
  805. },
  806. // // 加载更多
  807. // loadMore() {
  808. // console.log('加载更多')
  809. // if (this.loading || this.chatList.length >= this.total || !uni.getStorageSync('token')) return
  810. // this.page++
  811. // this.getChatList()
  812. // },
  813. // // 获取未读消息数量
  814. // getUnreadCount() {
  815. // this.$Request.getT('/app/message/selectMessageCountByUserId')
  816. // .then(res => {
  817. // if (res.code == 0) {
  818. // this.unreadCount = res.data.count
  819. // }
  820. // })
  821. // }
  822. }
  823. }
  824. </script>
  825. <style lang="scss" scoped>
  826. .msg-box {
  827. display: flex;
  828. flex-direction: column;
  829. // height: 400px;
  830. font-family: DM Sans;
  831. .chat-title {
  832. background: linear-gradient(180deg, rgba(13, 39, 247, 1) 0%, rgb(191, 194, 201) 100%);
  833. -webkit-background-clip: text;
  834. background-clip: text;
  835. -webkit-text-fill-color: transparent;
  836. color: transparent;
  837. font-family: DM Sans;
  838. font-size: 42rpx;
  839. font-weight: 500;
  840. line-height: 28px;
  841. letter-spacing: 0%;
  842. text-align: left;
  843. margin: 20rpx 0 20rpx 20rpx;
  844. }
  845. .margin-top-sm {
  846. margin-top: 0 !important;
  847. }
  848. .nav-header {
  849. height: 80rpx;
  850. display: flex;
  851. align-items: center;
  852. justify-content: space-between;
  853. padding: 0 20rpx;
  854. }
  855. .nav-left {
  856. width: 60rpx;
  857. display: flex;
  858. justify-content: flex-start;
  859. }
  860. .nav-center {
  861. flex: 1;
  862. display: flex;
  863. justify-content: center;
  864. }
  865. .nav-title {
  866. font-size: 36rpx;
  867. font-weight: 600;
  868. color: #333333;
  869. }
  870. .nav-right {
  871. width: 60rpx;
  872. display: flex;
  873. justify-content: flex-end;
  874. align-items: center;
  875. }
  876. // 系统通知
  877. .system-message-wrapper {
  878. padding: 10rpx 0 0 32rpx;
  879. .system-message-image {
  880. width: 80rpx;
  881. height: 80rpx;
  882. background: linear-gradient(90.00deg, rgba(13, 39, 247, 1),rgba(19, 193, 234, 1));
  883. border-radius: 50%;
  884. margin-right: 32rpx;
  885. .letter-icon {
  886. width: 36rpx;
  887. height: 28rpx;
  888. }
  889. }
  890. .system-message-wrapper-r {
  891. flex: 1;
  892. height: 100%;
  893. padding: 20rpx 32rpx 20rpx 16rpx;
  894. border-bottom: 1px solid rgba(235, 236, 240, 1);
  895. .message-text {
  896. color: rgba(21, 22, 26, 1);
  897. font-size: 32rpx;
  898. font-weight: 400;
  899. }
  900. .message-count {
  901. min-width: 32rpx;
  902. height: 32rpx;
  903. line-height: 32rpx;
  904. padding: 0 10rpx;
  905. color: #fff;
  906. font-size: 20rpx;
  907. background: rgba(240, 35, 35, 1);
  908. border-radius: 32rpx;
  909. box-sizing: border-box;
  910. margin-left: 20rpx;
  911. }
  912. .system-message-time {
  913. color: rgba(189, 191, 198, 1);
  914. font-size: 20rpx;
  915. font-weight: 400;
  916. }
  917. }
  918. }
  919. // 搜索栏
  920. .search-bar {
  921. border: 1px solid rgba(231, 230, 228, 1);
  922. border-radius: 12rpx;
  923. background: rgba(237, 237, 237, 1);
  924. padding: 16rpx 24rpx;
  925. color: rgba(188, 188, 188, 1);
  926. font-size: 28rpx;
  927. margin: 24rpx 32rpx 24rpx;
  928. .search-icon {
  929. width: 32rpx;
  930. height: 32rpx;
  931. margin-right: 16rpx;
  932. }
  933. }
  934. // tabs
  935. .tabs-wrapper {
  936. padding: 8rpx 32rpx;
  937. margin-bottom: 16rpx;
  938. .tab {
  939. position: relative;
  940. padding: 8rpx 24rpx;
  941. border-radius: 50rpx;
  942. background: rgba(0, 0, 0, 0.04);
  943. color: rgba(102, 102, 102, 1);
  944. font-size: 24rpx;
  945. font-weight: 400;
  946. line-height: 28rpx;
  947. &.active-tab {
  948. font-weight: 500;
  949. color: rgba(1, 107, 246, 1);
  950. background: rgba(1, 107, 246, 0.1);
  951. }
  952. .red-dot {
  953. position: absolute;
  954. top: 2px;
  955. right: 2px;
  956. width: 8px;
  957. height: 8px;
  958. border-radius: 8px;
  959. background: #f53f3f;
  960. }
  961. }
  962. .icon-wrapper {
  963. position: relative;
  964. padding: 8rpx;
  965. .more-icon {
  966. width: 36rpx;
  967. height: 36rpx;
  968. }
  969. .tabs-list {
  970. position: absolute;
  971. right: 30rpx;
  972. width: 268rpx;
  973. background: #fff;
  974. border-radius: 4px;
  975. box-shadow: 0px 3px 6px -4px rgba(0, 0, 0, 0.12),0px 6px 16px 0px rgba(0, 0, 0, 0.08),0px 9px 28px 8px rgba(0, 0, 0, 0.05);
  976. z-index: 10;
  977. .tab-item {
  978. text-align: center;
  979. color: rgba(102, 102, 102, 1);
  980. font-size: 14px;
  981. font-weight: 400;
  982. line-height: 34px;
  983. }
  984. }
  985. }
  986. }
  987. // 聊天列表
  988. .scroll-view {
  989. .chat-item {
  990. padding-left: 32rpx;
  991. padding-bottom: 16rpx;
  992. margin-bottom: 20rpx;
  993. .avatar-wrapper {
  994. position: relative;
  995. width: 96rpx;
  996. height: 128rpx;
  997. margin-right: 16rpx;
  998. padding-top: 32rpx;
  999. .avatar {
  1000. display: block;
  1001. width: 100%;
  1002. height: 100%;
  1003. border: 1px solid #eee;
  1004. border-radius: 50%;
  1005. }
  1006. .dot {
  1007. position: absolute;
  1008. right: 8rpx;
  1009. bottom: 0;
  1010. width: 16rpx;
  1011. height: 16rpx;
  1012. border: 1px solid rgba(255, 255, 255, 1);
  1013. border-radius: 50%;
  1014. }
  1015. .online-dot {
  1016. background: rgba(0, 180, 42, 1);
  1017. }
  1018. .offline-dot {
  1019. background: rgb(153, 153, 153);
  1020. }
  1021. }
  1022. .chat-info-wrapper {
  1023. flex: 1;
  1024. padding-right: 32rpx;
  1025. padding-bottom: 24rpx;
  1026. border-bottom: 1px solid rgba(235, 236, 240, 1);
  1027. .chat-info-wrapper-l {
  1028. flex: 1;
  1029. width: 400rpx;
  1030. padding-top: 28rpx;
  1031. }
  1032. .user-name {
  1033. // max-width: 130rpx;
  1034. max-width: 70%;
  1035. color: rgba(21, 22, 26, 1);
  1036. font-size: 32rpx;
  1037. font-weight: 400;
  1038. margin-right: 16rpx;
  1039. overflow: hidden;
  1040. text-overflow: ellipsis;
  1041. white-space: nowrap;
  1042. }
  1043. .tip-wrapper {
  1044. max-width: 70%;
  1045. overflow: hidden;
  1046. text-overflow: ellipsis;
  1047. white-space: nowrap;
  1048. }
  1049. .text-tip {
  1050. color: rgba(117, 119, 124, 1);
  1051. font-size: 20rpx;
  1052. font-weight: 400;
  1053. }
  1054. .chat-info-wrapper-l-b {
  1055. width: 100%;
  1056. color: rgba(117, 119, 124, 1);
  1057. font-size: 24rpx;
  1058. font-weight: 400;
  1059. line-height: 36rpx;
  1060. overflow: hidden;
  1061. text-overflow: ellipsis;
  1062. white-space: nowrap;
  1063. }
  1064. .chat-info-wrapper-r-t {
  1065. display: flex;
  1066. justify-content: flex-end;
  1067. width: 100%;
  1068. height: 40rpx;
  1069. .up-icon {
  1070. display: block;
  1071. width: 40rpx;
  1072. height: 40rpx;
  1073. }
  1074. }
  1075. .chat-time {
  1076. color: rgba(189, 191, 198, 1);
  1077. font-size: 24rpx;
  1078. font-weight: 400;
  1079. line-height: 40rpx;
  1080. }
  1081. .count-wrapper {
  1082. display: flex;
  1083. justify-content: flex-end;
  1084. width: 100%;
  1085. height: 32rpx;
  1086. .count {
  1087. min-width: 32rpx;
  1088. line-height: 32rpx;
  1089. border-radius: 32rpx;
  1090. color: #fff;
  1091. font-size: 20rpx;
  1092. padding: 0 10rpx;
  1093. background: rgba(245, 63, 63, 1);
  1094. }
  1095. }
  1096. }
  1097. &:last-child {
  1098. .chat-info-wrapper {
  1099. border-bottom: 0;
  1100. }
  1101. }
  1102. }
  1103. }
  1104. // .bg {
  1105. // background: #FFFFFF;
  1106. // }
  1107. // .userNameleng {
  1108. // // width: 80%;
  1109. // flex: 1;
  1110. // overflow: hidden;
  1111. // white-space: nowrap;
  1112. // text-overflow: ellipsis;
  1113. // -o-text-overflow: ellipsis;
  1114. // }
  1115. // .avatar-container {
  1116. // position: relative;
  1117. // display: inline-block;
  1118. // }
  1119. // .online-dot {
  1120. // position: absolute;
  1121. // bottom: 2rpx;
  1122. // right: 2rpx;
  1123. // width: 20rpx;
  1124. // height: 20rpx;
  1125. // background-color: #00FF00;
  1126. // border-radius: 50%;
  1127. // border: 2rpx solid #FFFFFF;
  1128. // }
  1129. }
  1130. // 设置弹窗样式
  1131. .settings-modal {
  1132. background: #FFFFFF;
  1133. border-radius: 20rpx 20rpx 0 0;
  1134. padding: 0 30rpx 40rpx 30rpx;
  1135. min-width: 100%;
  1136. .modal-drag-bar {
  1137. width: 60rpx;
  1138. height: 8rpx;
  1139. background: #E5E5E5;
  1140. border-radius: 4rpx;
  1141. margin: 20rpx auto 30rpx auto;
  1142. }
  1143. .modal-title {
  1144. margin: 0 auto;
  1145. color: rgba(34, 37, 42, 1);
  1146. font-family: DM Sans;
  1147. font-size: 36rpx;
  1148. font-weight: 500;
  1149. line-height: 23px;
  1150. letter-spacing: 0px;
  1151. text-align: center;
  1152. padding-bottom: 20rpx;
  1153. border-bottom: 1rpx solid rgba(219, 218, 218, 1);
  1154. }
  1155. .setting-item {
  1156. display: flex;
  1157. align-items: center;
  1158. justify-content: space-between;
  1159. padding: 12rpx 32rpx;
  1160. margin-bottom: 30rpx;
  1161. border: 1px solid rgba(227, 231, 236, 1);
  1162. border-radius: 6px;
  1163. &:active {
  1164. background-color: #F8F8F8;
  1165. }
  1166. &.setting-item-first {
  1167. border: none;
  1168. padding: 40rpx 32rpx;
  1169. }
  1170. .setting-left {
  1171. display: flex;
  1172. flex-direction: column;
  1173. align-items: flex-start;
  1174. flex: 1;
  1175. .setting-title-row {
  1176. display: flex;
  1177. align-items: center;
  1178. justify-content: flex-start;
  1179. width: 100%;
  1180. margin-bottom: 16rpx;
  1181. .setting-label {
  1182. color: rgba(21, 22, 26, 1);
  1183. font-family: DM Sans;
  1184. font-size: 32rpx;
  1185. font-weight: 600;
  1186. line-height: 26px;
  1187. letter-spacing: 0%;
  1188. text-align: left;
  1189. margin-right: 16rpx;
  1190. }
  1191. .setting-desc {
  1192. color: rgba(153, 153, 153, 1);
  1193. font-family: DM Sans;
  1194. font-size: 22rpx;
  1195. font-weight: 400;
  1196. line-height: 13px;
  1197. letter-spacing: 0%;
  1198. text-align: left;
  1199. }
  1200. }
  1201. .switch-status {
  1202. font-size: 32rpx;
  1203. &.status-on {
  1204. color: #007AFF;
  1205. }
  1206. &.status-off {
  1207. color: #999999;
  1208. }
  1209. }
  1210. }
  1211. .setting-right {
  1212. display: flex;
  1213. align-items: center;
  1214. justify-content: flex-end;
  1215. .u-switch {
  1216. margin-top: 20rpx;
  1217. transform: scale(1.2); // 放大开关到1.5倍
  1218. }
  1219. .setting-desc {
  1220. color: rgba(153, 153, 153, 1);
  1221. font-family: DM Sans;
  1222. font-size: 22rpx;
  1223. font-weight: 400;
  1224. line-height: 13px;
  1225. letter-spacing: 0%;
  1226. text-align: left;
  1227. margin-right: 16rpx;
  1228. }
  1229. }
  1230. }
  1231. }
  1232. </style>