index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <template>
  2. <view class="box">
  3. <view class="box-top">
  4. <view class="box-top-title">
  5. {{ info.name }}
  6. </view>
  7. </view>
  8. <!-- newsId 需要和聊天列表里面的id对应 永远取最后列表中的最后一个就可以做到发送消息即时滚动到底部 -->
  9. <scroll-view ref="chatRef" :scroll-with-animation="scrollAnimation" :scroll-into-view="newsId" class="box-main" scroll-y="true">
  10. <view class="box-main-more" v-if="hasMore">
  11. <text @click="handleMore">查看更多</text>
  12. </view>
  13. <view v-for="(val, index) in items" :key="val.id" :id="'s'+val.id+index">
  14. <view class="box-main-time">{{ timesTampChange(+(val.timestamp.padEnd(13, '0'))) }}</view>
  15. <template v-if="val.payload?.type === 102">
  16. <view class="jobCard">
  17. <view class="jobCard-title"> {{ formatName(val.payload?.content?.positionInfo?.name) }}</view>
  18. <view
  19. v-if="!val.payload?.content?.positionInfo?.payFrom && !val.payload?.content?.positionInfo?.payTo"
  20. class="jobCard-subtitle">
  21. 薪酬待遇: 面议
  22. </view>
  23. <view
  24. v-else
  25. class="jobCard-subtitle"
  26. >
  27. 薪酬待遇:
  28. {{ val.payload?.content?.positionInfo?.payFrom ? val.payload?.content?.positionInfo?.payFrom + ' - ' : '' }}
  29. {{ val.payload?.content?.positionInfo?.payTo }}
  30. </view>
  31. <view class="jobCard-tag">
  32. <view
  33. v-for="(v, i) in (val.payload?.content?.positionInfo?.enterprise?.welfareList || [])"
  34. :key="val.message_id + v + i"
  35. style="margin: 10rpx"
  36. >
  37. <uni-tag
  38. :text="v"
  39. type="success"
  40. />
  41. </view>
  42. </view>
  43. <view class="jobCard-divider"></view>
  44. <view class="jobCard-subtitle text-right">
  45. <v-avatar size="24">
  46. <v-img :src="val.payload?.content?.positionInfo?.contact?.avatar"></v-img>
  47. </v-avatar>
  48. {{ val.payload?.content?.positionInfo?.contact?.name }}
  49. {{ val.payload?.content?.positionInfo?.contact?.postNameCn }}
  50. {{ formatName(val.payload?.content?.positionInfo?.enterprise?.anotherName || val.payload?.content?.positionInfo?.enterprise?.name) }}
  51. </view>
  52. <div class="jobCard-subtitle text-right">
  53. 地址:{{ val.payload?.content?.positionInfo?.address }}
  54. </div>
  55. </view>
  56. </template>
  57. <view :class="['message-view_item', val.from_uid === IM.uid ? 'is-self' : 'is-other']">
  58. <view class="image">
  59. <image
  60. :data-target="getUserAvatar(info.avatar, info.sex, info.channelID === 'system' ? true : false)"
  61. class="header"
  62. :src="(
  63. val.from_uid === IM.uid ?
  64. getUserAvatar(useUserStore.userInfo?.avatar, useUserStore.userInfo?.sex) :
  65. getUserAvatar(info.avatar, info.sex, info.channelID === 'system' ? true : false)
  66. )"
  67. ></image>
  68. </view>
  69. <!-- 显示沟通职位 -->
  70. <template v-if="val.payload?.type === 102">
  71. <view class="message-text" :class="val.from_uid === IM.uid ? 'active' : ''">
  72. {{ val.payload?.content.text }}
  73. </view>
  74. </template>
  75. <!-- 发起面试邀请 -->
  76. <view class="message-text none" v-else-if="val.payload?.type === 101">
  77. <uni-tag text="发起了面试邀请" custom-style="background-color: #00B760; border-color: #00B760; color: #fff;" />
  78. </view>
  79. <view class="message-text none" v-else-if="val.payload?.type === 103">
  80. <uni-tag text="拒绝了面试邀请" type="error" />
  81. </view>
  82. <view class="message-text none" v-else-if="val.payload?.type === 104">
  83. <uni-tag text="接受了面试邀请" custom-style="background-color: #00B760; border-color: #00B760; color: #fff;" />
  84. </view>
  85. <view v-else-if="val.payload.type === 105" class="text-end">
  86. <uni-tag
  87. v-if="val.from_uid === IM.uid"
  88. :text="val.payload.content?.type === 1 ? '附件简历已发送' : '简历请求已发送'"
  89. custom-style="background-color: #00B760; border-color: #00B760; color: #fff;"
  90. />
  91. <view
  92. v-if="val.payload.content?.type !== 2 || val.from_uid !== IM.uid"
  93. class="message-text card"
  94. >
  95. <view class="text-left">
  96. <text v-if="val.payload.content?.type === 1">{{
  97. val.payload.content?.query?.title || '附件简历' }}
  98. </text>
  99. <text v-if="val.payload.content?.type === 2">
  100. 我想要一份您的简历,您是否同意
  101. </text>
  102. </view>
  103. <!-- <view class="btn-actions">
  104. <text class="btn" v-if="val.payload.content?.type === 1" @tap="handlePreview(val.payload)">点击预览附件简历</text>
  105. <text class="btn" v-if="val.payload.content?.type === 2" @tap="handleFindResume">点击发送附件简历</text>
  106. </view> -->
  107. </view>
  108. </view>
  109. <view v-else-if="val.payload.type === -1" class="message-text" :class="{ active: val.from_uid === IM.uid}">
  110. {{ val.payload?.content?.text }}
  111. </view>
  112. <view v-else class="message-text" :class="{ active: val.from_uid === IM.uid}">
  113. {{ val.payload?.content }}
  114. </view>
  115. </view>
  116. </view>
  117. </scroll-view>
  118. <view class="box-bottom" v-if="channelItem?.channelID !== 'system'">
  119. <view class="box-bottom-tool" style="display: flex; justify-content: space-between;">
  120. <!-- <text class="toolBtn" :class="{ disabled: !isSendResume }" @tap="handleFindResume">{{ isSendResume ? '简历已投递' : '发送简历' }}</text> -->
  121. </view>
  122. <view class="d-flex align-end textBox" v-if="channelItem?.channelID !== 'system'">
  123. <textarea
  124. v-model="inputValue"
  125. :cursor-spacing="25"
  126. :show-confirm-bar="false"
  127. :disable-default-padding="true"
  128. confirm-type="send"
  129. auto-height
  130. @confirm="handleSend"
  131. />
  132. <text class="submitBtn" @tap="handleSend">发 送</text>
  133. </view>
  134. </view>
  135. </view>
  136. </template>
  137. <script setup>
  138. import { ref, watch, onMounted, computed } from 'vue'
  139. import { onLoad } from '@dcloudio/uni-app'
  140. import { useIMStore } from '@/store/im'
  141. import { userStore } from '@/store/user'
  142. import { initConnect, send, initChart, getMoreMessages, toChannel } from '@/hooks/useIM'
  143. import { getDict } from '@/hooks/useDictionaries'
  144. import { timesTampChange } from '@/utils/date'
  145. import { getUserAvatar } from '@/utils/avatar'
  146. import { formatName } from '@/utils/getText'
  147. import { preview } from '@/utils/preview'
  148. const useUserStore = userStore()
  149. const userInfo = computed(() => useUserStore?.userInfo)
  150. const IM = useIMStore()
  151. const info = ref({})
  152. const chatRef = ref()
  153. const items = ref([])
  154. const channelItem = ref(null)
  155. const hasMore = ref(false)
  156. const pageSize = ref(1)
  157. // 求职者面试列表
  158. // 求职端-获取求职者与当前邀请人的面试记录
  159. const statusList = ref([])
  160. const inputValue = ref('')
  161. const newsId = ref('') // newsId 需要和聊天列表里面的id对应 永远取最后列表中的最后一个就可以做到发送消息即时滚动到底部
  162. const scrollAnimation = ref(false)
  163. const isSendResume = ref(false)
  164. const positionInfo = ref({})
  165. const isEmployment = ref('-1')
  166. onMounted(() => {
  167. setTimeout(() => {
  168. scrollAnimation.value = true
  169. }, 1500)
  170. })
  171. const {
  172. conversationList,
  173. updateUnreadCount,
  174. resetUnread
  175. } = initConnect(async (successful) => {
  176. if (!successful) {
  177. uni.showToast({
  178. title: '发送失败',
  179. icon: 'none',
  180. mask: true,
  181. })
  182. return
  183. }
  184. inputValue.value = ''
  185. // // 发送成功
  186. const { list } = await getMoreMessages(1, channelItem.value)
  187. items.value = list.value
  188. })
  189. watch(
  190. () => conversationList.value,
  191. async (val) => {
  192. if (!channelItem.value) {
  193. return
  194. }
  195. const { list } = await getMoreMessages(1, channelItem.value)
  196. items.value = list.value
  197. setScrollBottom()
  198. // 清除未读消息
  199. resetUnread(channelItem.value, userInfo.value?.enterpriseId)
  200. },
  201. {
  202. deep: true,
  203. immediate: true
  204. }
  205. )
  206. async function init(userId, enterpriseId) {
  207. const { channel, list, more } = await initChart(userId, enterpriseId)
  208. hasMore.value = more
  209. channelItem.value = channel.value
  210. items.value = list.value
  211. setScrollBottom()
  212. }
  213. const setScrollBottom = () => {
  214. if (items.value?.length) {
  215. const lastOne = items.value[items.value.length-1]
  216. const index = items.value.length-1
  217. newsId.value = 's' + lastOne.id + index // newsId 需要和聊天列表里面的id对应 永远取最后列表中的最后一个就可以做到发送消息即时滚动到底部
  218. }
  219. }
  220. const getStatusList = async () => {
  221. try {
  222. const { data } = await getDict('menduner_interview_invite_status')
  223. if (data.data.length) {
  224. statusList.value = data.data
  225. }
  226. } catch (error) {
  227. }
  228. }
  229. function handleSend () {
  230. if (!inputValue.value) {
  231. uni.showToast({ title: '不能发送空白信息', icon: 'none' })
  232. return
  233. }
  234. send(inputValue.value, channelItem.value)
  235. }
  236. // 预览简历
  237. function handlePreview (payload) {
  238. if (!payload?.content?.query?.src) {
  239. uni.showToast({ title: '简历地址不存在', icon: 'none' })
  240. return
  241. }
  242. preview(payload.content.query.src)
  243. }
  244. // 查看更多
  245. async function handleMore () {
  246. try {
  247. uni.showLoading({
  248. title: '加载中...'
  249. })
  250. pageSize.value++
  251. const { list, more } = await getMoreMessages(pageSize.value, channelItem.value)
  252. items.value.unshift(...list.value)
  253. hasMore.value = more
  254. } finally {
  255. uni.hideLoading()
  256. }
  257. }
  258. onLoad(async (options) => {
  259. info.value = Object.keys(options).reduce((r, k) => {
  260. r[k] = decodeURIComponent(options[k])
  261. return r
  262. }, {})
  263. isEmployment.value = info.value.isEmployment
  264. channelItem.value = toChannel(info.value.channelID, info.value.channelType)
  265. if (channelItem.value.channelID === 'system') {
  266. const { list, more } = await getMoreMessages(1, channelItem.value)
  267. hasMore.value = more
  268. items.value = list.value
  269. setScrollBottom()
  270. // 清除未读消息
  271. resetUnread(channelItem.value, userInfo.value?.enterpriseId)
  272. // 更新未读消息
  273. updateUnreadCount()
  274. return
  275. }
  276. await init(info.value.id, info.value.enterpriseId)
  277. await getStatusList()
  278. // 清除未读消息
  279. resetUnread(channelItem.value, userInfo.value?.enterpriseId)
  280. // 更新未读消息
  281. updateUnreadCount()
  282. })
  283. </script>
  284. <style lang="scss" scoped>
  285. .white {
  286. color: #FFF !important;
  287. }
  288. .text-left {
  289. text-align: left !important;
  290. }
  291. .text-right {
  292. text-align: right !important;
  293. }
  294. .box {
  295. width: 100%;
  296. height: 100vh;
  297. display: flex;
  298. flex-direction: column;
  299. &-top {
  300. &-title {
  301. padding: 0 60rpx;
  302. box-sizing: border-box;
  303. width: 100%;
  304. height: 80rpx;
  305. line-height: 80rpx;
  306. // text-align: center;
  307. border-bottom: 2rpx solid #EEE;
  308. overflow: hidden;
  309. white-space: nowrap;
  310. text-overflow: ellipsis;
  311. .subText {
  312. font-size: .85em;
  313. color: #999;
  314. .gun {
  315. padding: 0 10rpx;
  316. }
  317. }
  318. }
  319. &-content {
  320. padding: 20rpx 50rpx;
  321. padding-bottom: 20rpx;
  322. border-bottom: 2rpx solid #eee;
  323. .color-666 {
  324. color: #666;
  325. }
  326. .font-weight-bold {
  327. font-weight: bold;
  328. }
  329. .color-primary {
  330. color: #009688;
  331. }
  332. .ml-3 {
  333. margin-left: 40rpx;
  334. }
  335. .mt-1 {
  336. margin-top: 12rpx;
  337. }
  338. .font-size-14 {
  339. font-size: 24rpx;
  340. }
  341. .py-1 {
  342. padding: 4rpx 0;
  343. }
  344. .tipsText {
  345. font-size: .75em;
  346. color: #999;
  347. }
  348. &-t {
  349. display: flex;
  350. justify-content: space-between;
  351. }
  352. .btnBox {
  353. display: flex;
  354. padding: 20rpx 60rpx;
  355. justify-content: space-around;
  356. }
  357. }
  358. }
  359. &-main {
  360. flex: 1;
  361. height: 0;
  362. padding: 40rpx;
  363. // overflow-y: auto;
  364. box-sizing: border-box;
  365. &-more {
  366. display: flex;
  367. justify-content: center;
  368. align-items: center;
  369. color: #24bc3e;
  370. font-size: .9em;
  371. padding: 20rpx 0;
  372. }
  373. &-time {
  374. user-select: none;
  375. position: relative;
  376. top: 16rpx;
  377. margin: 40rpx 0;
  378. text-align: center;
  379. max-height: 40rpx;
  380. text-align: center;
  381. font-weight: 400;
  382. font-size: .85em;
  383. color: #999;
  384. }
  385. .jobCard {
  386. padding: 30rpx;
  387. background: #E2F2F0;
  388. color: #009688 ;
  389. margin-top: 20rpx;
  390. max-width: unset;
  391. margin-right: 0;
  392. &-title {
  393. font-size: 1.2em;
  394. }
  395. &-subtitle {
  396. padding: 10rpx 0;
  397. // font-size: .5em;
  398. }
  399. &-divider {
  400. width: 100%;
  401. height: 2rpx;
  402. margin: 20rpx 0;
  403. background: #ddd;
  404. }
  405. &-tag {
  406. display: flex;
  407. flex-wrap: wrap;
  408. }
  409. }
  410. .message-view_item {
  411. display: flex;
  412. flex-direction: row;
  413. align-items: flex-start;
  414. margin: 16rpx 0;
  415. position: relative;
  416. .image {
  417. width: 60rpx;
  418. height: 60rpx;
  419. border-radius: 180rpx;
  420. // flex-grow: 1;
  421. // flex-shrink: 0;
  422. overflow: hidden;
  423. .header {
  424. width: 60rpx;
  425. height: 60rpx;
  426. }
  427. }
  428. .text-end {
  429. text-align: right !important;
  430. width: 400rpx;
  431. margin-right: 20rpx;
  432. }
  433. .message-text {
  434. overflow-wrap: break-word;
  435. background-color: #f0f2f5;
  436. border-radius: 12rpx;
  437. max-width: 75%;
  438. padding: 20rpx;
  439. &.active {
  440. background: #d5e6e8;
  441. }
  442. &.card {
  443. background: #E2F2F0;
  444. color: #009688 ;
  445. margin-top: 20rpx;
  446. max-width: unset;
  447. margin-right: 0;
  448. .btn-actions {
  449. margin: 40rpx auto 20rpx auto ;
  450. text-align: center;
  451. .btn {
  452. padding: 10rpx 30rpx;
  453. background: #C8E7D8;
  454. color: #43AC57;
  455. font-size: .75em;
  456. border-radius: 10rpx;
  457. }
  458. }
  459. }
  460. &.none {
  461. padding: 10rpx 0;
  462. background-color: unset;
  463. }
  464. &.active {
  465. background: #d5e6e8;
  466. }
  467. }
  468. }
  469. .is-self {
  470. flex-direction: row-reverse;
  471. display: flex;
  472. .message-text {
  473. margin-right: 20rpx;
  474. }
  475. }
  476. .is-other {
  477. .message-text {
  478. margin-left: 20rpx;
  479. }
  480. }
  481. }
  482. &-bottom {
  483. max-height: 300rpx;
  484. border-top: 2rpx solid #EEE;
  485. background: rgba(230, 230, 230, 0.5);
  486. padding: 20rpx 40rpx;
  487. box-sizing: border-box;
  488. &-tool {
  489. margin-bottom: 30rpx;
  490. .toolBtn {
  491. padding: 12rpx 20rpx;
  492. font-size: 24rpx;
  493. background: #18bc37;
  494. color: #FFF;
  495. border-radius: 10rpx;
  496. }
  497. }
  498. .textBox {
  499. align-items: flex-end;
  500. }
  501. textarea {
  502. border-radius: 10rpx;
  503. width: 100%;
  504. min-height: 80rpx;
  505. max-height: 180rpx;
  506. padding: 20rpx;
  507. box-sizing: border-box;
  508. background: #FFF;
  509. }
  510. .submitBtn {
  511. width: 140rpx;
  512. line-height: 80rpx;
  513. height: 80rpx;
  514. font-size: 28rpx;
  515. background: #18bc37;
  516. color: #FFF;
  517. margin-left: 20rpx;
  518. text-align: center;
  519. border-radius: 10rpx;
  520. }
  521. }
  522. .popup-title {
  523. padding: 30rpx 20rpx;
  524. display: flex;
  525. justify-content: space-between;
  526. border-bottom: 2rpx solid #DDD;
  527. }
  528. .popup-content {
  529. padding: 20rpx 40rpx;
  530. color: #999;
  531. display: flex;
  532. align-content: center;
  533. justify-items: center;
  534. .iconBox {
  535. width: 40rpx;
  536. }
  537. .text {
  538. margin-left: 20rpx;
  539. &.active {
  540. color: #00B760;
  541. }
  542. }
  543. }
  544. .popup-upload {
  545. // display: flex;
  546. // align-items: center;
  547. // justify-content: center;
  548. // flex-direction: column;
  549. // width: 70%;
  550. width: 80vw;
  551. font-size: .75em;
  552. color: #999;
  553. padding: 40rpx;
  554. &-box {
  555. width: 200rpx;
  556. height: 200rpx;
  557. text-align: center;
  558. line-height: 200rpx;
  559. border: 4rpx solid #ddd;
  560. border-radius: 8rpx;
  561. margin: 0 auto;
  562. }
  563. }
  564. .popup-actions {
  565. padding: 60rpx;
  566. .default {
  567. background: #00B760;
  568. color: #DDD;
  569. font-size: .9em;
  570. }
  571. }
  572. }
  573. </style>