index.vue 19 KB

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