index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <template>
  2. <div class="default-width message" :style="`height: calc(100vh - ${isEnterprise ? '130px' : '50px'});`">
  3. <div class="message-left">
  4. <div class="message-left-search d-flex align-center px-3 justify-space-between" >
  5. <div>
  6. <v-icon class="mr-3">mdi-history</v-icon>
  7. 最近联系人
  8. </div>
  9. <div>
  10. <v-btn
  11. density="compact"
  12. :color="showDelete ? '' : 'red'"
  13. :icon="showDelete ? 'mdi-close' : 'mdi-trash-can-outline'"
  14. variant="text"
  15. @click="showDelete = !showDelete"
  16. >
  17. </v-btn>
  18. </div>
  19. <!-- {{ connected ? '连接成功': '连接失败' }} -->
  20. </div>
  21. <div class="message-chat-box mt-5">
  22. <v-overlay
  23. :model-value="!IM.connected"
  24. contained
  25. class="align-center justify-center"
  26. >
  27. <v-progress-circular
  28. color="primary"
  29. size="64"
  30. indeterminate
  31. ></v-progress-circular>
  32. </v-overlay>
  33. <div v-if="conversationList.length">
  34. <v-list density="compact" mandatory @update:selected="handleChange">
  35. <v-list-item
  36. v-for="(val, i) in conversationList"
  37. :key="i"
  38. :value="val"
  39. color="primary"
  40. class="mb-2"
  41. :active="val.channel.channelID === info?.channel?.channelID"
  42. :title="val.userInfoVo ? (val.userInfoVo.userInfoResp.name ? val.userInfoVo.userInfoResp.name : '游客') : '系统消息'"
  43. :subtitle="timesTampChange(+val.timestamp.padEnd(13, '0'))"
  44. >
  45. <template v-slot:title="{ title }">
  46. <div v-if="!isEnterprise" class="mt-2 d-flex align-center">
  47. {{ title }}
  48. <div class="ml-3 color-666 font-size-14 enterprise-name ellipsis" :style="{'color': val.channel.channelID === info?.channel?.channelID ? '#00897B' : '#666'}">
  49. {{ val.userInfoVo?.userInfoResp?.enterpriseAnotherName }}
  50. <span class="line" v-if="val.userInfoVo?.userInfoResp?.postNameCn && val.userInfoVo?.userInfoResp?.enterpriseAnotherName"></span>
  51. {{ val.userInfoVo?.userInfoResp?.postNameCn }}
  52. </div>
  53. </div>
  54. <div v-else class="mt-2">{{ title }}</div>
  55. </template>
  56. <template v-slot:subtitle="{ subtitle }">
  57. <div class="mt-2">{{ subtitle }}</div>
  58. </template>
  59. <template v-slot:prepend>
  60. <v-avatar :image="getUserAvatar(val?.userInfoVo?.userInfoResp?.avatar, val?.userInfoVo?.userInfoResp?.sex)"></v-avatar>
  61. </template>
  62. <template v-slot:append>
  63. <v-badge
  64. v-if="val.unread > 0"
  65. color="error"
  66. :content="val.unread"
  67. inline
  68. ></v-badge>
  69. <v-btn v-show="showDelete" density="compact" icon="mdi-trash-can-outline" variant="text" color="red" @click.stop="handleDelete(val)"></v-btn>
  70. </template>
  71. </v-list-item>
  72. </v-list>
  73. <div class="message-no-more-text mt-3">没有更多了</div>
  74. </div>
  75. <div v-else class="left-noData">
  76. <Empty :elevation="false" message="暂无30天内联系人" width="300" height="150"></Empty>
  77. </div>
  78. </div>
  79. </div>
  80. <div class="message-right">
  81. <div v-if="showRightNoData" class="right-noData">
  82. <Empty :elevation="false" message="与您进行过沟通的 Boss 都会在左侧列表中显示"></Empty>
  83. </div>
  84. <Chatting
  85. ref="chatRef"
  86. :items="messageItems"
  87. :info="info"
  88. :interview="interview"
  89. :has-more="hasMore"
  90. :updateConversation="updateConversation"
  91. :updateUnreadCount="updateUnreadCount"
  92. :resetUnread="resetUnread"
  93. @handleSend="handleUpdate"
  94. @handleMore="handleGetMore"
  95. @handleAgree="handleAgree"
  96. @handleRefuse="handleRefuse"
  97. @handlePreview="handlePreview"
  98. @handleSendResume="handleSendResume"
  99. >
  100. <template #tools>
  101. <v-btn
  102. v-for="tool in tools"
  103. :key="tool.name"
  104. size="small"
  105. class="mr-3"
  106. :color="tool.color"
  107. @click="tool.handle(tool)"
  108. >
  109. <v-progress-circular
  110. v-if="tool.loading"
  111. :width="2"
  112. :size="16"
  113. color="white"
  114. class="mr-2"
  115. indeterminate
  116. ></v-progress-circular>
  117. <v-icon v-else class="mr-2">{{ tool.icon }}</v-icon>
  118. {{ tool.name }}
  119. </v-btn>
  120. </template>
  121. </Chatting>
  122. </div>
  123. </div>
  124. <File ref="uploadFile" @success="handleUploadResume"></File>
  125. <CtDialog :visible="showInvite" :widthType="2" titleClass="text-h6" title="邀请面试" @close="showInvite = false" @submit="handleSubmit">
  126. <InvitePage v-if="showInvite" ref="inviteRef" :item-data="itemData" :position="positionList"></InvitePage>
  127. </CtDialog>
  128. <CtDialog :visible="showResume" :widthType="2" titleClass="text-h6" title="发送简历" @close="showResume = false; selectResume = null " @submit="handleSubmitResume">
  129. <div style="position: relative; min-height: 200px">
  130. <v-radio-group v-model="selectResume">
  131. <v-radio v-for="val in resumeList" :key="val.id" :value="val.id" :label="val.title" color="primary"></v-radio>
  132. </v-radio-group>
  133. </div>
  134. </CtDialog>
  135. </template>
  136. <script setup>
  137. defineOptions({ name: 'personal-message-index'})
  138. import InvitePage from '@/views/recruit/enterprise/interviewManagement/components/invite'
  139. import { timesTampChange } from '@/utils/date'
  140. import { ref, inject, watch,onMounted, nextTick } from 'vue'
  141. import Chatting from './components/chatting.vue'
  142. import { initConnect, send, initChart, getMoreMessages, checkConversation } from '@/hooks/web/useIM'
  143. import { useRoute } from 'vue-router'
  144. import { getPositionDetails } from '@/api/position'
  145. import { getInterviewInviteListByInviteUserId } from '@/api/common'
  146. import { getUserInfo } from '@/api/personal/user'
  147. import { useIMStore } from '@/store/im'
  148. import { useUserStore } from '@/store/user'
  149. import Snackbar from '@/plugins/snackbar'
  150. import { getUserAvatar } from '@/utils/avatar'
  151. import { getJobAdvertised } from '@/api/enterprise'
  152. import { dealDictArrayData } from '@/utils/position'
  153. import { saveInterviewInvite } from '@/api/recruit/enterprise/interview'
  154. import { savePersonResumeCv } from '@/api/recruit/personal/resume'
  155. import { useI18n } from '@/hooks/web/useI18n'
  156. import { userInterviewInviteReject, userInterviewInviteConsent } from '@/api/recruit/personal/personalCenter'
  157. import { getPersonResumeCv } from '@/api/recruit/personal/resume'
  158. import { previewFile } from '@/utils'
  159. import Confirm from '@/plugins/confirm'
  160. const { t } = useI18n()
  161. const chatRef = ref()
  162. const IM = useIMStore()
  163. // 自己的信息
  164. const { baseInfo } = useUserStore()
  165. const isEnterprise = inject('isEnterprise')
  166. // 实例
  167. const route = useRoute()
  168. const channelItem = ref(null)
  169. const messageItems = ref([])
  170. const pageSize = ref(1)
  171. const hasMore = ref(false)
  172. const showInvite = ref(false)
  173. const positionList = ref([])
  174. const showDelete = ref(false)
  175. const itemData = ref({})
  176. const inviteRef = ref()
  177. // 发送简历
  178. const uploadFile = ref()
  179. const showResume = ref(false)
  180. const resumeList = ref([])
  181. const selectResume = ref(null)
  182. // 求职者面试列表
  183. const interview = ref([])
  184. const showRightNoData = ref(false)
  185. const info = ref({})
  186. const enterpriseTools = ref([
  187. { name: '求简历', icon: 'mdi-email', color:"primary", loading: false, handle: handleRequest },
  188. { name: '面试邀约', icon: 'mdi-email', color:"primary", loading: false, handle: handleInvite }
  189. ])
  190. const userTools = ref([
  191. { name: '发送简历', icon: 'mdi-email', color:"primary", loading: false, handle: handleSendResume }
  192. ])
  193. const tools = isEnterprise ? enterpriseTools.value : userTools.value
  194. if (!IM) {
  195. console.log('IM is disconnected')
  196. }
  197. if (route.query.id) {
  198. const api = route.query.enterprise ? getPositionDetails : getUserInfo
  199. const res = await api({ id: route.query.id })
  200. const query = route.query.enterprise ? [res.contact?.userId, res.contact?.enterpriseId] : [res?.id]
  201. onMounted(() => {
  202. nextTick(async () => {
  203. const { channel } = await checkConversation(...query)
  204. const items = [
  205. {
  206. channel,
  207. userInfoVo: {
  208. userInfoResp: route.query.enterprise ? res.contact : { ...res, userId: res.id}
  209. }
  210. }
  211. ]
  212. handleChange(items)
  213. })
  214. })
  215. }
  216. const {
  217. conversationList,
  218. updateConversation,
  219. updateUnreadCount,
  220. deleteConversations,
  221. resetUnread
  222. } = initConnect(async (successful) => {
  223. if (!successful) {
  224. Snackbar.error('发送失败')
  225. return
  226. }
  227. chatRef.value.reset()
  228. // 发送成功
  229. const { list } = await getMoreMessages(1, channelItem.value)
  230. // updateConversation()
  231. messageItems.value = list.value
  232. chatRef.value.scrollBottom()
  233. })
  234. const getInterviewInviteList = async () => {
  235. if (!info.value.userId) return
  236. const data = await getInterviewInviteListByInviteUserId(info.value.userId)
  237. interview.value = data.slice(0, 1)
  238. }
  239. // 在当前频道中有新消息时更新未读消息数量
  240. const updateUnreadMessageCount = (val) => {
  241. const obj = val.find(e => e.userInfoVo.userId === info.value.userId)
  242. if (!obj?.unread || obj.unread === 0) return
  243. delete info.value.unread
  244. Object.assign(info.value, { unread: obj.unread, enterpriseId: baseInfo?.enterpriseId })
  245. }
  246. watch(
  247. () => conversationList.value,
  248. async (val) => {
  249. // 数据发生变化
  250. if (channelItem.value && IM.fromChannel === channelItem.value.channelID) {
  251. // 更新
  252. const { list } = await getMoreMessages(1, channelItem.value)
  253. messageItems.value = list.value
  254. if (Object.keys(info.value).length) updateUnreadMessageCount(val)
  255. chatRef.value.scrollBottom()
  256. }
  257. },
  258. {
  259. deep: true,
  260. immediate: true
  261. }
  262. )
  263. async function handleChange (items) {
  264. // console.log([...items])
  265. try {
  266. chatRef.value.changeOverlay(true)
  267. const { userInfoVo, channel: myChannel, unread } = items.pop()
  268. info.value = userInfoVo?.userInfoResp ?? { name: '系统消息' }
  269. Object.assign(info.value, {
  270. channel: myChannel,
  271. unread
  272. })
  273. // 个人端获取面试信息
  274. if (!isEnterprise) getInterviewInviteList()
  275. const userId = userInfoVo.userInfoResp.userId
  276. const enterpriseId = userInfoVo.userInfoResp.enterpriseId || undefined
  277. const { channel, list, more } = await initChart(userId, enterpriseId)
  278. // console.log('--------',list)
  279. channelItem.value = channel.value
  280. messageItems.value = list.value
  281. hasMore.value = more
  282. chatRef.value.scrollBottom()
  283. // 点开窗口消除未读数量
  284. await resetUnread(channel.value, baseInfo?.enterpriseId)
  285. await updateConversation()
  286. updateUnreadCount()
  287. } catch (error) {
  288. messageItems.value = []
  289. } finally {
  290. chatRef.value.changeOverlay(false)
  291. }
  292. }
  293. // 普通消息
  294. const handleUpdate = (val) => {
  295. send(val.value, channelItem.value)
  296. }
  297. // 获取简历
  298. async function handleSendResume (item) {
  299. try {
  300. item.loading = true
  301. // showResume.value = true
  302. // 获取简历列表
  303. const result = await getPersonResumeCv()
  304. if (result.length === 0) {
  305. Snackbar.error(t('resume.resumeYetSubmit'))
  306. uploadFile.value.trigger()
  307. return
  308. }
  309. resumeList.value = result
  310. showResume.value = true
  311. } finally {
  312. item.loading = false
  313. }
  314. }
  315. /**
  316. * 发送简历
  317. * text param
  318. * {
  319. * remark: 备注
  320. * query: {} 自定义参数 access -1 未确定 0 拒绝 1 同意
  321. * type: 1 => 发送简历
  322. * 2 => 索要简历
  323. * 3 => 信息描述
  324. * }
  325. */
  326. // 没有上传过简历的弹窗上传并发送给对方
  327. const handleUploadResume = async (url, title) => {
  328. if (!url || !title) return
  329. await savePersonResumeCv({ title, url })
  330. const text = {
  331. remark: '发送简历',
  332. query: {
  333. src: url,
  334. title
  335. },
  336. type: 1
  337. }
  338. send (JSON.stringify(text), channelItem.value, 105)
  339. }
  340. function handleSubmitResume () {
  341. if (!selectResume.value) {
  342. Snackbar.error(t('resume.selectResumeToSubmit'))
  343. return
  344. }
  345. const _info = resumeList.value.find((item) => item.id === selectResume.value)
  346. const text = {
  347. remark: '发送简历',
  348. query: {
  349. src: _info.url,
  350. title: _info.title,
  351. id: _info.id,
  352. },
  353. type: 1
  354. }
  355. send (JSON.stringify(text), channelItem.value, 105)
  356. showResume.value = false
  357. }
  358. // 求简历
  359. function handleRequest () {
  360. const text = {
  361. remark: '求简历',
  362. query: {
  363. src: '',
  364. title: '',
  365. id: '',
  366. },
  367. type: 2
  368. }
  369. send (JSON.stringify(text), channelItem.value, 105)
  370. }
  371. // 简历预览
  372. const handlePreview = (val) => {
  373. previewFile(val.content.query.src)
  374. }
  375. const handleGetMore = async () => {
  376. try {
  377. chatRef.value.changeLoading(true)
  378. pageSize.value++
  379. const { list, more } = await getMoreMessages(pageSize.value, channelItem.value)
  380. messageItems.value.unshift(...list.value)
  381. hasMore.value = more
  382. // chatRef.value.scrollBottom()
  383. } finally {
  384. chatRef.value.changeLoading(false)
  385. }
  386. }
  387. const handleDelete = async ({ channel }) => {
  388. await deleteConversations(channel, baseInfo?.enterpriseId)
  389. await updateConversation()
  390. updateUnreadCount()
  391. }
  392. // 没有企业ID则enterpriseId为undefined
  393. // 发送消息体 { text, type: 2 }
  394. // 面试邀约
  395. async function handleInvite (item) {
  396. item.loading = true
  397. positionList.value = []
  398. try {
  399. const data = await getJobAdvertised({ hire: false })
  400. if (!data.length) return
  401. const list = dealDictArrayData([], data)
  402. positionList.value = list.map(e => {
  403. return {
  404. label: `${e.name}${e.areaName ? '_' + e.areaName : ''} ${e.payFrom ? e.payFrom + '-' : ''}${e.payTo}${e.payName ? '/' + e.payName : ''}`,
  405. value: e.id,
  406. data: e
  407. }
  408. })
  409. // itemData.value = {
  410. // userId: '',
  411. // jobId: ''
  412. // }
  413. showInvite.value = true
  414. // send(JSON.stringify(msg), channelItem.value, 101)
  415. // console.log(query)
  416. } catch (error) {
  417. console.log(error)
  418. } finally {
  419. item.loading = false
  420. }
  421. }
  422. const handleSubmit = async () => {
  423. const { valid } = await inviteRef.value.CtFormRef.formRef.validate()
  424. if (!valid) {
  425. return
  426. }
  427. const query = inviteRef.value.getQuery()
  428. if (!query.time) {
  429. Snackbar.error('时间不能为空')
  430. return
  431. }
  432. query.userId = info.value.userId
  433. query.positionInfo = positionList.value.find(e => e.value === query.jobId)
  434. // 需要id
  435. const data = await saveInterviewInvite(query)
  436. // 保留邀请id
  437. query.id = data.id
  438. Snackbar.success(t('common.operationSuccessful'))
  439. send(JSON.stringify(query), channelItem.value, 101)
  440. showInvite.value = false
  441. }
  442. const handleAgree = (val) => {
  443. if (!val.id) return
  444. const query = {
  445. id: val.id
  446. }
  447. const type = route?.meta?.loginType === 'enterprise' ? 'entBaseInfo' : 'baseInfo'
  448. const baseInfo = localStorage.getItem(type)
  449. if (baseInfo) {
  450. const { phone } = JSON.parse(baseInfo)
  451. query.phone = phone
  452. }
  453. Confirm(t('common.confirmTitle'), '是否确定接收此面试邀请?').then(async () => {
  454. await userInterviewInviteConsent(query)
  455. Snackbar.success(t('common.operationSuccessful'))
  456. getInterviewInviteList()
  457. send(JSON.stringify({ id: val.id }), channelItem.value, 104)
  458. })
  459. }
  460. // 拒绝面试邀请
  461. const handleRefuse = (val) => {
  462. if (!val.id) return
  463. Confirm(t('common.confirmTitle'), '您是否确定要拒绝此面试邀请?').then(async () => {
  464. await userInterviewInviteReject(val.id)
  465. Snackbar.success(t('common.operationSuccessful'))
  466. getInterviewInviteList()
  467. send(JSON.stringify({ id: val.id }), channelItem.value, 103)
  468. })
  469. }
  470. </script>
  471. <style scoped lang="scss">
  472. .message {
  473. display: flex;
  474. &-left {
  475. position: relative;
  476. flex-shrink: 0;
  477. height: 100%;;
  478. width: 360px;
  479. background-color: #fff;
  480. border-radius: 8px;
  481. margin-right: 12px;
  482. .message-left-search {
  483. width: 100%;
  484. height: 60px;
  485. background: linear-gradient(90deg, #f5fcfc, #fcfbfa);
  486. border-radius: 8px 8px 0 0;
  487. }
  488. .message-chat-box {
  489. .chat-item {
  490. position: relative;
  491. width: 100%;
  492. height: 78px;
  493. padding: 14px 12px;
  494. cursor: pointer;
  495. &:hover {
  496. background-color: #f8f8f8;
  497. }
  498. .chat-item-time {
  499. position: absolute;
  500. right: 12px;
  501. top: 50%;
  502. transform: translateY(-50%);
  503. }
  504. .title-box {
  505. max-width: 114px;
  506. overflow: hidden;
  507. white-space: nowrap;
  508. text-overflow: ellipsis;
  509. display: inline-block;
  510. }
  511. }
  512. }
  513. .message-no-more-text {
  514. color: var(--color-999);
  515. font-size: 14px;
  516. text-align: center
  517. }
  518. .left-noData {
  519. position: absolute;
  520. top: 50%;
  521. left: 50%;
  522. transform: translate(-50%, -50%);
  523. }
  524. }
  525. &-right {
  526. height: 100%;
  527. flex: 1;
  528. width: 0;
  529. position: relative;
  530. background-color: #fff;
  531. border-radius: 8px;
  532. .right-noData {
  533. position: absolute;
  534. top: 50%;
  535. left: 50%;
  536. transform: translate(-50%, -50%);
  537. }
  538. }
  539. }
  540. .enterprise-name {
  541. max-width: 150px;
  542. .line {
  543. display: inline-block;
  544. width: 1px;
  545. height: 12px;
  546. vertical-align: middle;
  547. background-color: #e0e0e0;
  548. margin: 0 3px;
  549. }
  550. }
  551. </style>