index.vue 16 KB

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