basicInfo.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <template>
  2. <div class="resume-box mb-3 elevation-2">
  3. <div class="resume-header">
  4. <div class="resume-title">{{ $t('resume.basicInfo') }}</div>
  5. <v-btn v-if="!isEdit" variant="text" color="primary" prepend-icon="mdi-square-edit-outline" @click="isEdit = true">{{ $t('common.edit') }}</v-btn>
  6. </div>
  7. <div class="d-flex align-start mt-5">
  8. <!-- 头像 -->
  9. <div class="avatarsBox" @mouseover="showIcon = true" @mouseleave="showIcon = false">
  10. <v-badge
  11. bordered
  12. :color="baseInfo?.sex ? (baseInfo?.sex === '1' ? '#1867c0' : 'error') : 'error'"
  13. :icon="baseInfo?.sex ? (baseInfo?.sex === '1' ? 'mdi-gender-male' : 'mdi-gender-female') : 'mdi-gender-female'">
  14. <v-img :src="getUserAvatar(baseInfo?.avatar, baseInfo?.sex)" width="130" height="130" style="border-radius: 6px;"></v-img>
  15. <div v-show="showIcon" @click="openFileInput" class="mdi mdi-camera-outline camera">
  16. <input
  17. type="file"
  18. ref="fileInput"
  19. accept="image/png, image/jpg, image/jpeg"
  20. style="display: none;"
  21. @change="handleUploadFile"
  22. />
  23. </div>
  24. </v-badge>
  25. </div>
  26. <!-- 基础信息 -->
  27. <div style="flex: 1;" class="mr-8">
  28. <!-- 编辑 -->
  29. <div v-if="isEdit" class="ml-5">
  30. <CtForm ref="CtFormRef" :items="items" style="width: 100%;">
  31. <template v-slot:phone>
  32. <v-btn variant="text" class="ml-2" color="primary">{{ $t('common.change') }}</v-btn>
  33. </template>
  34. </CtForm>
  35. <div class="text-end">
  36. <v-btn class="half-button mr-3" variant="tonal" @click="isEdit = false">{{ $t('common.cancel') }}</v-btn>
  37. <v-btn color="primary" class="half-button" @click="handleSave">{{ $t('common.save') }}</v-btn>
  38. </div>
  39. </div>
  40. <!-- 展示 -->
  41. <div v-else>
  42. <span class="ml-50" style="font-size: 20px; font-weight: 600;color: var(--color-666);">{{ baseInfo?.name || userInfo.phone }}</span>
  43. <div class="mt-3 d-flex">
  44. <div class="listBox ml-50">
  45. <div>
  46. <span class="mdi mdi-map-marker-outline"></span>
  47. <span>{{ baseInfo?.areaName || $t('common.currentlyUnavailable') }}</span>
  48. </div>
  49. <div>
  50. <span class="mdi mdi-phone-outline"></span>
  51. <span>{{ baseInfo?.phone || $t('common.currentlyUnavailable') }}</span>
  52. </div>
  53. <div>
  54. <span class="mdi mdi-email-outline"></span>
  55. <span>{{ baseInfo?.email || $t('common.currentlyUnavailable') }}</span>
  56. </div>
  57. <div>
  58. <span class="mdi mdi-calendar-blank-outline"></span>
  59. <span>{{ baseInfo?.expTypeText || $t('common.currentlyUnavailable') }}</span>
  60. </div>
  61. <div>
  62. <span class="mdi mdi-school-outline"></span>
  63. <span>{{ baseInfo?.eduTypeText || $t('common.currentlyUnavailable') }}</span>
  64. </div>
  65. <div>
  66. <span class="mdi mdi-tag-outline"></span>
  67. <span>{{ baseInfo?.jobStatusText || $t('common.currentlyUnavailable') }}</span>
  68. </div>
  69. <div>
  70. <span class="mdi mdi-cake-variant-outline"></span>
  71. <span>{{ baseInfo?.birthdayText || $t('common.currentlyUnavailable') }}</span>
  72. </div>
  73. <div>
  74. <span class="mdi mdi-home-map-marker"></span>
  75. <span>{{ baseInfo?.regName || $t('common.currentlyUnavailable') }}</span>
  76. </div>
  77. <div>
  78. <span class="mdi mdi-account-heart"></span>
  79. <span>{{ baseInfo?.maritalText || $t('common.currentlyUnavailable') }}</span>
  80. </div>
  81. <div>
  82. <span>{{ $t('resume.firstWorkTime') }}:</span>
  83. <span>{{ baseInfo?.firstWorkTimeText || $t('common.currentlyUnavailable') }}</span>
  84. </div>
  85. </div>
  86. </div>
  87. <div class="mt-4 ml-50">
  88. <span style="font-size: 15px;">个人画像:</span>
  89. <v-chip size="small" label v-for="(k, i) in welfareList.slice(0, 8)" :key="i" class="mr-2" color="primary">{{ k }}</v-chip>
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. <Loading :visible="overlay"></Loading>
  96. <!-- 图片裁剪 -->
  97. <ImgCropper :visible="isShowCopper" :image="selectPic" :cropBoxResizable="true" @submit="handleHideCopper" :aspectRatio="1 / 1" @close="isShowCopper = false, selectPic = ''"></ImgCropper>
  98. </template>
  99. <script setup>
  100. import CtForm from '@/components/CtForm'
  101. import Snackbar from '@/plugins/snackbar'
  102. import { getDict } from '@/hooks/web/useDictionaries'
  103. import { cityToProvince } from '@/utils/areaDeal'
  104. import { getTimeStamp, timesTampChange } from '@/utils/date'
  105. import { updatePersonAvatar, saveResumeBasicInfo } from '@/api/recruit/personal/resume'
  106. import { useUserStore } from '@/store/user'
  107. import { uploadFile } from '@/api/common'
  108. import { getUserAvatar } from '@/utils/avatar'
  109. import { useI18n } from '@/hooks/web/useI18n'
  110. import { ref } from 'vue';
  111. defineOptions({name: 'resume-components-basicInfo'})
  112. const emit = defineEmits(['complete'])
  113. const { t } = useI18n()
  114. const userStore = useUserStore()
  115. const CtFormRef = ref()
  116. const isEdit = ref(false)
  117. const showIcon = ref(false)
  118. const overlay = ref(false) // 加载中
  119. const welfareList = ref(['响应', '改变', '诚信', '进取精神', '信任', '卓越'])
  120. let baseInfo = ref({})
  121. let userInfo = ref({})
  122. const getBasicInfo = () => { // 获取基础信息
  123. const key = localStorage.getItem('baseInfo')
  124. if (!key || !Object.keys(key).length) return
  125. baseInfo.value = JSON.parse(key) // 人才信息
  126. userInfo.value = JSON.parse(localStorage.getItem('userInfo'))
  127. }
  128. getBasicInfo()
  129. // 选择文件
  130. const fileInput = ref()
  131. const clicked = ref(false)
  132. const openFileInput = () => {
  133. if (clicked.value) return
  134. clicked.value = true
  135. fileInput.value.click()
  136. clicked.value = false
  137. }
  138. // 上传头像
  139. const selectPic = ref('')
  140. const isShowCopper = ref(false)
  141. const handleUploadFile = async (e) => {
  142. const file = e.target.files[0]
  143. const reader = new FileReader()
  144. reader.readAsDataURL(file)
  145. reader.onload = () => {
  146. selectPic.value = String(reader.result)
  147. isShowCopper.value = true
  148. }
  149. }
  150. // 图片裁剪
  151. const handleHideCopper = (data) => {
  152. isShowCopper.value = false
  153. if (data) {
  154. const { file } = data
  155. if (!file) return
  156. const formData = new FormData()
  157. formData.append('file', file)
  158. overlay.value = true
  159. uploadFile(formData).then(async ({data}) => {
  160. if (!data) return
  161. await updatePersonAvatar(data)
  162. setTimeout(async () => {
  163. await userStore.getUserBaseInfos(baseInfo.value.userId)
  164. getBasicInfo()
  165. overlay.value = false
  166. Snackbar.success(t('common.uploadSucMsg'))
  167. }, 1000)
  168. })
  169. }
  170. }
  171. const items = ref({
  172. options: [
  173. {
  174. type: 'text',
  175. key: 'name',
  176. value: null,
  177. default: null,
  178. label: '中文名 *',
  179. col: 6,
  180. outlined: true,
  181. rules: [
  182. value => {
  183. if (value) return true
  184. return '请输入您的中文名'
  185. },
  186. value => {
  187. var regex = /^[\u4e00-\u9fa5]+$/
  188. if (regex.test(value)) return true
  189. return '请输入正确的中文名'
  190. }
  191. ]
  192. },
  193. {
  194. type: 'ifRadio',
  195. key: 'sex',
  196. value: '0', // '1' ? '男' : '女'
  197. default: 0,
  198. label: '性别',
  199. col: 6,
  200. width: 70,
  201. dictTypeName: 'menduner_sex',
  202. items: [],
  203. },
  204. {
  205. type: 'datePicker',
  206. key: 'birthday',
  207. // dateType: 'date', // 时间类型 year month date time
  208. value: null,
  209. label: '出生日期 *',
  210. col: 6,
  211. outlined: true,
  212. rules: [v => !!v || '请选择出生日期']
  213. // options: {},
  214. },
  215. {
  216. type: 'phoneNumber',
  217. key: 'phone',
  218. value: null,
  219. default: null,
  220. label: '电话号码',
  221. col: 6,
  222. outlined: true,
  223. rules: [v => !!v || '请填写手机号码']
  224. // disabled: true,
  225. // slotName: 'phone',
  226. },
  227. {
  228. type: 'text',
  229. key: 'email',
  230. value: null,
  231. default: null,
  232. label: '常用邮箱 *',
  233. col: 6,
  234. outlined: true,
  235. rules: [v => !!v || '请输入常用邮箱']
  236. },
  237. {
  238. type: 'autocomplete',
  239. key: 'expType',
  240. value: null,
  241. default: null,
  242. label: '工作年限 *',
  243. col: 6,
  244. outlined: true,
  245. itemText: 'label',
  246. itemValue: 'value',
  247. dictTypeName: 'menduner_exp_type',
  248. rules: [v => !!v || '请选择工作年限'],
  249. items: []
  250. },
  251. {
  252. type: 'autocomplete',
  253. key: 'eduType',
  254. value: null,
  255. default: null,
  256. label: '最高学历 *',
  257. col: 6,
  258. outlined: true,
  259. itemText: 'label',
  260. itemValue: 'value',
  261. dictTypeName: 'menduner_education_type',
  262. rules: [v => !!v || '请选择最高学历'],
  263. items: []
  264. },
  265. {
  266. type: 'autocomplete',
  267. key: 'jobType',
  268. value: null,
  269. default: null,
  270. label: '求职类型 *',
  271. col: 6,
  272. outlined: true,
  273. itemText: 'label',
  274. itemValue: 'value',
  275. dictTypeName: 'menduner_job_type',
  276. rules: [v => !!v || '请选择求职类型'],
  277. items: []
  278. },
  279. {
  280. type: 'autocomplete',
  281. key: 'jobStatus',
  282. value: null,
  283. default: null,
  284. label: '求职状态 *',
  285. col: 6,
  286. outlined: true,
  287. itemText: 'label',
  288. itemValue: 'value',
  289. dictTypeName: 'menduner_job_status',
  290. rules: [v => !!v || '请选择求职状态'],
  291. items: []
  292. },
  293. {
  294. type: 'autocomplete',
  295. key: 'maritalStatus',
  296. value: null,
  297. default: null,
  298. label: '婚姻状况 *',
  299. col: 6,
  300. outlined: true,
  301. itemText: 'label',
  302. itemValue: 'value',
  303. dictTypeName: 'menduner_marital_status',
  304. rules: [v => !!v || '请选择婚姻状况'],
  305. items: []
  306. },
  307. {
  308. type: 'autocomplete',
  309. key: 'workAreaProvinceId',
  310. value: null,
  311. label: '所在城市:省 *',
  312. outlined: true,
  313. itemText: 'name',
  314. itemValue: 'id',
  315. returnSelect: true,
  316. noParam: true,
  317. col: 6,
  318. flexStyle: 'mr-3',
  319. rules: [v => !!v || '请选择所在城市:省'],
  320. items: [],
  321. change: null
  322. },
  323. {
  324. type: 'autocomplete',
  325. key: 'areaId',
  326. value: null,
  327. label: '所在城市:市 *',
  328. outlined: true,
  329. itemText: 'name',
  330. itemValue: 'id',
  331. col: 6,
  332. rules: [v => !!v || '请选择所在城市:市'],
  333. items: [],
  334. change: null
  335. },
  336. {
  337. type: 'autocomplete',
  338. key: 'regProvinceId',
  339. value: null,
  340. label: '户籍地:省',
  341. outlined: true,
  342. clearable: true,
  343. itemText: 'name',
  344. itemValue: 'id',
  345. returnSelect: true,
  346. noParam: true,
  347. col: 6,
  348. flexStyle: 'mr-3',
  349. items: [],
  350. change: null
  351. },
  352. {
  353. type: 'autocomplete',
  354. key: 'regId',
  355. value: null,
  356. label: '户籍地:市',
  357. outlined: true,
  358. clearable: true,
  359. itemText: 'name',
  360. itemValue: 'id',
  361. col: 6,
  362. items: [],
  363. change: null
  364. },
  365. {
  366. type: 'datePicker',
  367. dateType: 'month',
  368. key: 'firstWorkTime',
  369. value: null,
  370. label: '首次工作时间 *',
  371. col: 6,
  372. outlined: true,
  373. // clearable: true,
  374. rules: [v => !!v || '请选择首次工作时间']
  375. // options: {},
  376. },
  377. ]
  378. })
  379. // 保存-基础信息
  380. const handleSave = async () => {
  381. const { valid } = await CtFormRef.value.formRef.validate()
  382. if (!valid) return
  383. const obj = {}
  384. let clearRegProvinceId = false
  385. items.value.options.forEach(e => {
  386. if (e.key === 'regId' && !obj[e.key]) clearRegProvinceId = true
  387. if (e.type === 'datepicker') obj[e.key] = getTimeStamp(e.value)
  388. else obj[e.key] = e.value
  389. })
  390. await saveResumeBasicInfo(obj)
  391. Snackbar.success(t('common.saveMsg'))
  392. isEdit.value = false
  393. // 获取当前登录账户信息
  394. // if (baseInfo.value.userId) await userStore.getUserBaseInfos(baseInfo.value.userId)
  395. await userStore.getUserBaseInfos(baseInfo.value.userId || null)
  396. getBasicInfo()
  397. // 清除户籍地:省
  398. if (clearRegProvinceId) items.value.options.forEach(e => { if (e.key === 'regProvinceId') e.value = null })
  399. }
  400. // 获取字典内容
  401. const getDictData = async (dictTypeName) => {
  402. const item = items.value.options.find(e => e.dictTypeName === dictTypeName)
  403. if (item) {
  404. const { data } = await getDict(dictTypeName)
  405. item.items = data
  406. }
  407. }
  408. const timeCount = {}
  409. const deal = async (id, cityKey, provinceKey) => {
  410. if (!id && id !== 0) return
  411. // 省份回显
  412. const province = items.value.options.find(pv => pv.key === provinceKey)
  413. if (!province?.items.length) { // 字典数据未获取
  414. timeCount[provinceKey] = 0
  415. setTimeout(() => {
  416. timeCount[provinceKey]++
  417. if (timeCount[provinceKey] < 6) deal(id, cityKey, provinceKey)
  418. }, 2000)
  419. return
  420. }
  421. if (province) {
  422. const dealReturnObj = await cityToProvince(id, {}, province.items || [])
  423. const city = items.value.options.find(pv => pv.key === cityKey)
  424. if (city) city.items = dealReturnObj.cityList || []
  425. province.value = dealReturnObj.pid || ''
  426. }
  427. }
  428. let completeStatus = false
  429. items.value.options.forEach((e, index) => {
  430. if ((index + 2) % 2 === 0) e.flexStyle = 'mr-3'
  431. if (e.dictTypeName) getDictData(e.dictTypeName) // 查字典set options
  432. // formItems回显
  433. const infoExist = baseInfo.value && Object.keys(baseInfo.value).length
  434. if (infoExist) completeStatus = true
  435. if (infoExist && baseInfo.value[e.key]) e.value = baseInfo.value[e.key]
  436. // 日期相关
  437. if (e.type === 'datepicker') e.value = timesTampChange(e.value, 'Y-M-D')
  438. // 所在城市回显
  439. // if (infoExist && e.nameKey) e[e.nameKey] = baseInfo.value[e.nameKey]
  440. if (infoExist && e.key === 'areaId' && baseInfo.value[e.key]) {
  441. const id = baseInfo.value[e.key]
  442. deal(id, e.key, 'workAreaProvinceId')
  443. }
  444. if (infoExist && e.key === 'regId' && baseInfo.value[e.key]) {
  445. const id = baseInfo.value[e.key]
  446. deal(id, e.key, 'regProvinceId')
  447. }
  448. if (e.value === undefined || e.value === null || e.value === '') completeStatus = false
  449. })
  450. // 完成度展示
  451. emit('complete', { status: completeStatus, id: 'basicInfo' })
  452. const provinceChange = (value, val, obj) => {
  453. let cityKey
  454. if (val?.key === 'workAreaProvinceId') cityKey = 'areaId'
  455. if (val?.key === 'regProvinceId') cityKey = 'regId'
  456. if (!cityKey) return
  457. const item = items.value.options.find(e => e.key === cityKey)
  458. if (!item) return
  459. item.items = obj?.children || []
  460. item.value = null
  461. }
  462. getDict('areaTreeData', null, 'areaTreeData').then(({ data }) => {
  463. data = data?.length && data || []
  464. if (!data?.length) return console.error('areaTreeData获取失败!')
  465. //
  466. // const china = data.find(e => e.id === '1')
  467. // const chinaTreeData = china?.children?.length ? china.children : []
  468. const chinaTreeData = data
  469. //
  470. if (!chinaTreeData?.length) return console.error('chinaTreeData获取失败!')
  471. const workAreaProvince = items.value.options.find(e => e.key === 'workAreaProvinceId')
  472. const regAreaProvince = items.value.options.find(e => e.key === 'regProvinceId')
  473. if (workAreaProvince?.items) {
  474. workAreaProvince.items = chinaTreeData
  475. workAreaProvince.change = provinceChange
  476. }
  477. if (regAreaProvince?.items) {
  478. regAreaProvince.items = chinaTreeData
  479. regAreaProvince.change = provinceChange
  480. }
  481. })
  482. </script>
  483. <style lang="scss" scoped>
  484. .jobTypeCardBox {
  485. position: absolute;
  486. top: -22px;
  487. left: 0;
  488. }
  489. .ml-50 {
  490. margin-left: 50px;
  491. }
  492. .avatarsBox {
  493. height: 150px;
  494. width: 120px;
  495. position: relative;
  496. cursor: pointer;
  497. margin: 0 32px;
  498. .camera {
  499. color: #fff;
  500. font-size: 42px;
  501. position: absolute;
  502. top: 50%;
  503. left: 50%;
  504. transform: translate(-50%, -50%);
  505. }
  506. }
  507. .listBox {
  508. display: flex;
  509. flex-wrap: wrap; /* 允许换行 */
  510. width: 100%; /* 设置容器宽度 */
  511. overflow: hidden;
  512. color: var(--color-666);
  513. div {
  514. width: 50%;
  515. margin-bottom: 10px;
  516. span {
  517. height: 32px;
  518. line-height: 32px;
  519. }
  520. .mdi {
  521. font-size: 22px;
  522. margin-right: 8px;
  523. }
  524. }
  525. }
  526. </style>