index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. </view>
  106. </view>
  107. </view>
  108. <view v-else-if="val.payload.type === -1" class="message-text" :class="{ active: val.from_uid === IM.uid}">
  109. {{ val.payload?.content?.text }}
  110. </view>
  111. <view v-else class="message-text" :class="{ active: val.from_uid === IM.uid}">
  112. {{ val.payload?.content }}
  113. </view>
  114. </view>
  115. </view>
  116. </scroll-view>
  117. <view class="box-bottom" v-if="channelItem?.channelID !== 'system'">
  118. <!-- <view class="box-bottom-tool" style="display: flex; justify-content: start;">
  119. <text class="toolBtn" @tap="handleFindResume">求简历</text>
  120. <text class="toolBtn ss-m-l-10" @tap="handleInviteInterview">面试邀约</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. <!-- <uni-popup ref="invitePopup" background-color="#fff" type="bottom">
  136. <view style="background-color: #fff; height: 70vh;">
  137. </view>
  138. </uni-popup> -->
  139. </view>
  140. </template>
  141. <script setup>
  142. import { ref, watch, onMounted, computed } from 'vue'
  143. import { onLoad } from '@dcloudio/uni-app'
  144. import { useIMStore } from '@/store/im'
  145. import { userStore } from '@/store/user'
  146. import { initConnect, send, initChart, getMoreMessages, toChannel } from '@/hooks/useIM'
  147. import { timesTampChange } from '@/utils/date'
  148. import { getUserAvatar } from '@/utils/avatar'
  149. import { formatName } from '@/utils/getText'
  150. import { preview } from '@/utils/preview'
  151. import { getAccessToken } from '@/utils/request'
  152. import { showAuthModal } from '@/hooks/useModal'
  153. import { getJobAdvertisedList } from '@/api/new/position'
  154. const useUserStore = userStore()
  155. const userInfo = computed(() => useUserStore?.userInfo)
  156. const IM = useIMStore()
  157. const info = ref({})
  158. const chatRef = ref()
  159. const items = ref([])
  160. const channelItem = ref(null)
  161. const hasMore = ref(false)
  162. const pageSize = ref(1)
  163. const inputValue = ref('')
  164. const newsId = ref('') // newsId 需要和聊天列表里面的id对应 永远取最后列表中的最后一个就可以做到发送消息即时滚动到底部
  165. const scrollAnimation = ref(false)
  166. const isEmployment = ref('-1')
  167. onMounted(() => {
  168. setTimeout(() => {
  169. scrollAnimation.value = true
  170. }, 1500)
  171. })
  172. const {
  173. conversationList,
  174. updateUnreadCount,
  175. resetUnread
  176. } = initConnect(async (successful) => {
  177. if (!successful) {
  178. uni.showToast({
  179. title: '发送失败',
  180. icon: 'none',
  181. mask: true,
  182. })
  183. return
  184. }
  185. inputValue.value = ''
  186. // // 发送成功
  187. const { list } = await getMoreMessages(1, channelItem.value)
  188. items.value = list.value
  189. })
  190. watch(
  191. () => conversationList.value,
  192. async (val) => {
  193. if (!channelItem.value) {
  194. return
  195. }
  196. const { list } = await getMoreMessages(1, channelItem.value)
  197. items.value = list.value
  198. setScrollBottom()
  199. // 清除未读消息
  200. resetUnread(channelItem.value, userInfo.value?.enterpriseId)
  201. },
  202. {
  203. deep: true,
  204. immediate: true
  205. }
  206. )
  207. async function init(userId, enterpriseId) {
  208. const { channel, list, more } = await initChart(userId, enterpriseId)
  209. hasMore.value = more
  210. channelItem.value = channel.value
  211. items.value = list.value
  212. setScrollBottom()
  213. }
  214. const setScrollBottom = () => {
  215. if (items.value?.length) {
  216. const lastOne = items.value[items.value.length-1]
  217. const index = items.value.length-1
  218. newsId.value = 's' + lastOne.id + index // newsId 需要和聊天列表里面的id对应 永远取最后列表中的最后一个就可以做到发送消息即时滚动到底部
  219. }
  220. }
  221. function handleSend () {
  222. if (!inputValue.value) {
  223. uni.showToast({ title: '不能发送空白信息', icon: 'none' })
  224. return
  225. }
  226. send(inputValue.value, channelItem.value)
  227. }
  228. // 职位列表
  229. const jobNum = ref(0)
  230. const jobList = ref([])
  231. const getJobList = async () => {
  232. const { data } = await getJobAdvertisedList({ pageNo: 1, pageSize: 10, hasExpiredData: false, status: 0 })
  233. jobNum.value = data?.total || 0
  234. jobList.value = data?.list ? data?.list.map(e => {
  235. return { text: formatName(e.name), value: e.id, ...e }
  236. }) : []
  237. }
  238. // 求简历
  239. const handleFindResume = async () => {
  240. if (!getAccessToken()) {
  241. showAuthModal()
  242. return
  243. }
  244. // 企业必须有招聘中的职位才能发起面试邀请
  245. if (jobNum.value === 0) {
  246. uni.showToast({
  247. title: '请先发布招聘职位',
  248. icon: 'none',
  249. duration: 2000
  250. })
  251. return
  252. }
  253. }
  254. // 邀约面试
  255. const invitePopup = ref()
  256. const handleInviteInterview = () => {
  257. if (!getAccessToken()) {
  258. showAuthModal()
  259. return
  260. }
  261. // 企业必须有招聘中的职位才能发起面试邀请
  262. if (jobNum.value === 0) {
  263. uni.showToast({
  264. title: '请先发布招聘职位',
  265. icon: 'none',
  266. duration: 2000
  267. })
  268. return
  269. }
  270. console.log(info.value, '邀请面试', jobList.value, invitePopup.value)
  271. invitePopup.value.open()
  272. // uni.navigateTo({
  273. // url: `/pagesB/InviteInterview/index?id=${info.value.id}`
  274. // })
  275. }
  276. // 预览简历
  277. function handlePreview (payload) {
  278. if (!payload?.content?.query?.src) {
  279. uni.showToast({ title: '简历地址不存在', icon: 'none' })
  280. return
  281. }
  282. preview(payload.content.query.src)
  283. }
  284. // 查看更多
  285. async function handleMore () {
  286. try {
  287. uni.showLoading({
  288. title: '加载中...'
  289. })
  290. pageSize.value++
  291. const { list, more } = await getMoreMessages(pageSize.value, channelItem.value)
  292. items.value.unshift(...list.value)
  293. hasMore.value = more
  294. } finally {
  295. uni.hideLoading()
  296. }
  297. }
  298. onLoad(async (options) => {
  299. info.value = Object.keys(options).reduce((r, k) => {
  300. r[k] = decodeURIComponent(options[k])
  301. return r
  302. }, {})
  303. isEmployment.value = info.value.isEmployment
  304. channelItem.value = toChannel(info.value.channelID, info.value.channelType)
  305. if (channelItem.value.channelID === 'system') {
  306. const { list, more } = await getMoreMessages(1, channelItem.value)
  307. hasMore.value = more
  308. items.value = list.value
  309. setScrollBottom()
  310. // 清除未读消息
  311. resetUnread(channelItem.value, userInfo.value?.enterpriseId)
  312. // 更新未读消息
  313. updateUnreadCount()
  314. return
  315. }
  316. await init(info.value.id, info.value.enterpriseId)
  317. // await getJobList() // 获取招聘中的职位
  318. // 清除未读消息
  319. resetUnread(channelItem.value, userInfo.value?.enterpriseId)
  320. // 更新未读消息
  321. updateUnreadCount()
  322. })
  323. </script>
  324. <style lang="scss" scoped>
  325. .white {
  326. color: #FFF !important;
  327. }
  328. .text-left {
  329. text-align: left !important;
  330. }
  331. .text-right {
  332. text-align: right !important;
  333. }
  334. .box {
  335. width: 100%;
  336. height: 100vh;
  337. display: flex;
  338. flex-direction: column;
  339. &-top {
  340. &-title {
  341. padding: 0 60rpx;
  342. box-sizing: border-box;
  343. width: 100%;
  344. height: 80rpx;
  345. line-height: 80rpx;
  346. // text-align: center;
  347. border-bottom: 2rpx solid #EEE;
  348. overflow: hidden;
  349. white-space: nowrap;
  350. text-overflow: ellipsis;
  351. .subText {
  352. font-size: .85em;
  353. color: #999;
  354. .gun {
  355. padding: 0 10rpx;
  356. }
  357. }
  358. }
  359. &-content {
  360. padding: 20rpx 50rpx;
  361. padding-bottom: 20rpx;
  362. border-bottom: 2rpx solid #eee;
  363. .color-666 {
  364. color: #666;
  365. }
  366. .font-weight-bold {
  367. font-weight: bold;
  368. }
  369. .color-primary {
  370. color: #009688;
  371. }
  372. .ml-3 {
  373. margin-left: 40rpx;
  374. }
  375. .mt-1 {
  376. margin-top: 12rpx;
  377. }
  378. .font-size-14 {
  379. font-size: 24rpx;
  380. }
  381. .py-1 {
  382. padding: 4rpx 0;
  383. }
  384. .tipsText {
  385. font-size: .75em;
  386. color: #999;
  387. }
  388. &-t {
  389. display: flex;
  390. justify-content: space-between;
  391. }
  392. .btnBox {
  393. display: flex;
  394. padding: 20rpx 60rpx;
  395. justify-content: space-around;
  396. }
  397. }
  398. }
  399. &-main {
  400. flex: 1;
  401. height: 0;
  402. padding: 40rpx;
  403. // overflow-y: auto;
  404. box-sizing: border-box;
  405. &-more {
  406. display: flex;
  407. justify-content: center;
  408. align-items: center;
  409. color: #24bc3e;
  410. font-size: .9em;
  411. padding: 20rpx 0;
  412. }
  413. &-time {
  414. user-select: none;
  415. position: relative;
  416. top: 16rpx;
  417. margin: 40rpx 0;
  418. text-align: center;
  419. max-height: 40rpx;
  420. text-align: center;
  421. font-weight: 400;
  422. font-size: .85em;
  423. color: #999;
  424. }
  425. .jobCard {
  426. padding: 30rpx;
  427. background: #E2F2F0;
  428. color: #009688 ;
  429. margin-top: 20rpx;
  430. max-width: unset;
  431. margin-right: 0;
  432. &-title {
  433. font-size: 1.2em;
  434. }
  435. &-subtitle {
  436. padding: 10rpx 0;
  437. // font-size: .5em;
  438. }
  439. &-divider {
  440. width: 100%;
  441. height: 2rpx;
  442. margin: 20rpx 0;
  443. background: #ddd;
  444. }
  445. &-tag {
  446. display: flex;
  447. flex-wrap: wrap;
  448. }
  449. }
  450. .message-view_item {
  451. display: flex;
  452. flex-direction: row;
  453. align-items: flex-start;
  454. margin: 16rpx 0;
  455. position: relative;
  456. .image {
  457. width: 60rpx;
  458. height: 60rpx;
  459. border-radius: 180rpx;
  460. // flex-grow: 1;
  461. // flex-shrink: 0;
  462. overflow: hidden;
  463. .header {
  464. width: 60rpx;
  465. height: 60rpx;
  466. }
  467. }
  468. .text-end {
  469. text-align: right !important;
  470. width: 400rpx;
  471. margin-right: 20rpx;
  472. }
  473. .message-text {
  474. overflow-wrap: break-word;
  475. background-color: #f0f2f5;
  476. border-radius: 12rpx;
  477. max-width: 75%;
  478. padding: 20rpx;
  479. &.active {
  480. background: #d5e6e8;
  481. }
  482. &.card {
  483. background: #E2F2F0;
  484. color: #009688 ;
  485. margin-top: 20rpx;
  486. max-width: unset;
  487. margin-right: 0;
  488. .btn-actions {
  489. margin: 40rpx auto 20rpx auto ;
  490. text-align: center;
  491. .btn {
  492. padding: 10rpx 30rpx;
  493. background: #C8E7D8;
  494. color: #43AC57;
  495. font-size: .75em;
  496. border-radius: 10rpx;
  497. }
  498. }
  499. }
  500. &.none {
  501. padding: 10rpx 0;
  502. background-color: unset;
  503. }
  504. &.active {
  505. background: #d5e6e8;
  506. }
  507. }
  508. }
  509. .is-self {
  510. flex-direction: row-reverse;
  511. display: flex;
  512. .message-text {
  513. margin-right: 20rpx;
  514. }
  515. }
  516. .is-other {
  517. .message-text {
  518. margin-left: 20rpx;
  519. }
  520. }
  521. }
  522. &-bottom {
  523. max-height: 300rpx;
  524. border-top: 2rpx solid #EEE;
  525. background: rgba(230, 230, 230, 0.5);
  526. padding: 20rpx 40rpx;
  527. box-sizing: border-box;
  528. &-tool {
  529. margin-bottom: 30rpx;
  530. .toolBtn {
  531. padding: 12rpx 20rpx;
  532. font-size: 24rpx;
  533. background: #18bc37;
  534. color: #FFF;
  535. border-radius: 10rpx;
  536. }
  537. }
  538. .textBox {
  539. align-items: flex-end;
  540. }
  541. textarea {
  542. border-radius: 10rpx;
  543. width: 100%;
  544. min-height: 80rpx;
  545. max-height: 180rpx;
  546. padding: 20rpx;
  547. box-sizing: border-box;
  548. background: #FFF;
  549. }
  550. .submitBtn {
  551. width: 140rpx;
  552. line-height: 80rpx;
  553. height: 80rpx;
  554. font-size: 28rpx;
  555. background: #18bc37;
  556. color: #FFF;
  557. margin-left: 20rpx;
  558. text-align: center;
  559. border-radius: 10rpx;
  560. }
  561. }
  562. .popup-title {
  563. padding: 30rpx 20rpx;
  564. display: flex;
  565. justify-content: space-between;
  566. border-bottom: 2rpx solid #DDD;
  567. }
  568. .popup-content {
  569. padding: 20rpx 40rpx;
  570. color: #999;
  571. display: flex;
  572. align-content: center;
  573. justify-items: center;
  574. .iconBox {
  575. width: 40rpx;
  576. }
  577. .text {
  578. margin-left: 20rpx;
  579. &.active {
  580. color: #00B760;
  581. }
  582. }
  583. }
  584. .popup-upload {
  585. // display: flex;
  586. // align-items: center;
  587. // justify-content: center;
  588. // flex-direction: column;
  589. // width: 70%;
  590. width: 80vw;
  591. font-size: .75em;
  592. color: #999;
  593. padding: 40rpx;
  594. &-box {
  595. width: 200rpx;
  596. height: 200rpx;
  597. text-align: center;
  598. line-height: 200rpx;
  599. border: 4rpx solid #ddd;
  600. border-radius: 8rpx;
  601. margin: 0 auto;
  602. }
  603. }
  604. .popup-actions {
  605. padding: 60rpx;
  606. .default {
  607. background: #00B760;
  608. color: #DDD;
  609. font-size: .9em;
  610. }
  611. }
  612. }
  613. </style>