index.vue 36 KB

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