educationExp.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <div class="resume-box">
  3. <div class="resume-header mb-3">
  4. <div class="resume-title">{{ $t('resume.educationExp') }}</div>
  5. <v-btn variant="text" color="primary" prepend-icon="mdi-plus-box" @click="handle(0)">{{ $t('common.add') }}</v-btn>
  6. </div>
  7. <!-- 编辑-表单 -->
  8. <div v-if="isEdit" class="educExpItem-edit">
  9. <h4 class="color6 my-3 mx-2"> {{ titleStatus ? $t('common.edit') : $t('common.add') }}{{ $t('resume.educationExp') }}</h4>
  10. <CtForm ref="CtFormRef" :items="formItems" style="width: 100%;"></CtForm>
  11. <div class="text-end mt-3">
  12. <v-btn class="half-button mr-3" variant="tonal" @click="isEdit = false">{{ $t('common.cancel') }}</v-btn>
  13. <v-btn color="primary" class="half-button" @click="handleSave">{{ $t('common.save') }}</v-btn>
  14. </div>
  15. </div>
  16. <!-- 展示 -->
  17. <div v-else-if="!dataList?.length" class="resumeNoDataText">{{ $t('resume.dataDefaultPrompt') }}{{ $t('resume.educationExp') }}...</div>
  18. <div
  19. v-else
  20. v-for="(item, index) in dataList" :key="'educationExp' + index"
  21. :class="[' mx-n2', {'mt-5': index }]"
  22. >
  23. <div class="educExpItem" @mouseenter="item.active = true" @mouseleave="item.active = false">
  24. <div class="level1 d-flex align-center justify-space-between" style="height: 40px;">
  25. <div>
  26. <span style="font-size: 18px; font-weight: bold;">{{ item.schoolName }}</span>
  27. <span class="color6 font15 ml-5">
  28. <span>{{ timesTampChange(item.startTime, 'Y-M') }}</span>
  29. <span class="mx-1">至</span>
  30. <span>{{ timesTampChange(item.endTime, 'Y-M') }}</span>
  31. </span>
  32. </div>
  33. <div v-if="item.active">
  34. <v-btn variant="text" color="primary" prepend-icon="mdi-square-edit-outline" @click="handle(item)">{{ $t('common.edit') }}</v-btn>
  35. <v-btn variant="text" color="primary" prepend-icon="mdi-trash-can-outline" @click="handleDelete(item)">{{ $t('common.delete') }}</v-btn>
  36. </div>
  37. </div>
  38. <div class="level2 my-2">
  39. <span class="color6 font15">{{ item.major }}</span>
  40. <span class="septal-line" v-if="item.educationSystemType"></span>
  41. <span class="color6 font15">{{ getText(item.educationSystemType, dictItemsObj.educationSystemType) }}</span>
  42. </div>
  43. <div class="level3">
  44. <span class="color6 font15">在校经历:{{ item.content || '暂无描述' }}</span>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script setup name="educationExp">
  51. import CtForm from '@/components/CtForm'
  52. import Snackbar from '@/plugins/snackbar'
  53. import { getDict } from '@/hooks/web/useDictionaries'
  54. import { getTimeStamp, timesTampChange } from '@/utils/date'
  55. import { saveResumeEduExp, getResumeEduExp, deleteResumeEduExp, schoolSearchByName, schoolMajorByName } from '@/api/recruit/personal/resume'
  56. import Confirm from '@/plugins/confirm'
  57. import { getText, dealCanBeInputtedSave, dealCanBeInputtedValueAndLabel } from '@/utils/getText'
  58. import { debounce } from 'lodash'
  59. import { nextTick, reactive, ref } from 'vue'
  60. const emit = defineEmits(['complete'])
  61. const editId = ref(null)
  62. const CtFormRef = ref()
  63. const dictItemsObj = reactive({})
  64. // 学校下拉列表
  65. const schoolNameInput = ref('')
  66. const getSchoolListData = async (name) => {
  67. const item = formItems.value.options.find(e => e.key === 'schoolId')
  68. if (!item) return
  69. if (item.items?.length && (schoolNameInput.value === name)) return // 防抖
  70. item[item.itemTextName] = schoolNameInput.value = name
  71. if (name === null || name === '') { item.items = [] }
  72. else {
  73. const data = await schoolSearchByName({ name })
  74. item.items = data
  75. }
  76. }
  77. const debouncedCallbackSchool = debounce(newValue => {
  78. if (!newValue) return
  79. getSchoolListData(newValue)
  80. }, 500)
  81. // 专业下拉列表
  82. const majorNameInput = ref('')
  83. const getMajorListData = async (name) => {
  84. if (name === '') { // 此接口不支持传空值
  85. item.items = []
  86. return
  87. }
  88. const item = formItems.value.options.find(e => e.key === 'majorId')
  89. if (item.items?.length && (majorNameInput.value === name)) return // 防抖
  90. item[item.itemTextName] = majorNameInput.value = name
  91. if (name === null || name === '') { item.items = [] }
  92. else {
  93. const data = await schoolMajorByName({ name })
  94. item.items = data
  95. }
  96. }
  97. const debouncedCallbackMajor = debounce(newValue => {
  98. getMajorListData(newValue)
  99. }, 500)
  100. const formItems = ref({
  101. options: [
  102. {
  103. type: 'combobox',
  104. key: 'schoolId',
  105. value: null,
  106. default: null,
  107. label: '学校名称 *',
  108. col: 6,
  109. outlined: true,
  110. clearable: true,
  111. canBeInputted: true, //
  112. itemTextName: 'schoolName',
  113. itemText: 'value',
  114. itemValue: 'key',
  115. rules: [v => !!v || '请选择学校名称'],
  116. search: debouncedCallbackSchool,
  117. items: []
  118. },
  119. {
  120. type: 'combobox',
  121. key: 'majorId',
  122. value: null,
  123. default: null,
  124. label: '所学专业 *',
  125. col: 6,
  126. outlined: true,
  127. clearable: true,
  128. canBeInputted: true, //
  129. itemTextName: 'major',
  130. itemText: 'nameCn',
  131. itemValue: 'id',
  132. rules: [v => !!v || '请选择所学专业'],
  133. search: debouncedCallbackMajor,
  134. items: []
  135. },
  136. {
  137. type: 'autocomplete',
  138. key: 'educationType',
  139. value: null,
  140. default: null,
  141. label: '学历 *',
  142. col: 6,
  143. outlined: true,
  144. itemText: 'label',
  145. itemValue: 'value',
  146. rules: [v => !!v || '请选择学历'],
  147. items: []
  148. },
  149. {
  150. type: 'autocomplete',
  151. key: 'educationSystemType',
  152. value: null,
  153. default: null,
  154. label: '学制类型 *',
  155. col: 6,
  156. outlined: true,
  157. itemText: 'label',
  158. itemValue: 'value',
  159. rules: [v => !!v || '请选择学制类型'],
  160. items: dictItemsObj.educationSystemType,
  161. },
  162. {
  163. type: 'datePicker',
  164. key: 'startTime',
  165. dateType: 'month', // 时间类型 year month date time
  166. value: null,
  167. label: '起始时间 *',
  168. col: 6,
  169. outlined: true,
  170. clearable: true,
  171. rules: [v => !!v || '请选择起始时间']
  172. // options: {},
  173. },
  174. {
  175. type: 'datePicker',
  176. key: 'endTime',
  177. dateType: 'month', // 时间类型 year month date time
  178. value: null,
  179. label: '结束时间 *',
  180. col: 6,
  181. outlined: true,
  182. clearable: true,
  183. rules: [v => !!v || '请选择结束时间']
  184. // options: {},
  185. },
  186. {
  187. type: 'textarea',
  188. key: 'content',
  189. value: null,
  190. default: null,
  191. rows: 5,
  192. resize: true,
  193. counter: 1600,
  194. label: '在校经历',
  195. outlined: true
  196. },
  197. ]
  198. })
  199. // 左侧加mr
  200. formItems.value.options.forEach((e, index) => {
  201. if (((index + 2) % 2 === 0) && Boolean(e.col) && e.col !== 12) e.flexStyle = 'mr-3'
  202. })
  203. // 获取数据
  204. const dataList = ref([])
  205. const getData = async () => {
  206. const data = await getResumeEduExp()
  207. // 完成度展示
  208. emit('complete', { status: Boolean(data?.length), id: 'educationExp' })
  209. dataList.value = data
  210. }
  211. getData()
  212. // 新增 或 编辑
  213. const isEdit = ref(false)
  214. const titleStatus = ref(0)
  215. const handle = (item) => {
  216. titleStatus.value = item ? 1 : 0
  217. if (item) { // 编辑
  218. editId.value = item.id
  219. formItems.value.options.forEach(e => { // 回显
  220. if (e.canBeInputted) { // 特殊处理可输入下拉框
  221. dealCanBeInputtedValueAndLabel(e, item)
  222. // if (item[e.key] && item[e.itemTextName]) { e.search(item[e.itemTextName], '触发下拉框内容'); e.value = item[e.key] }
  223. // else { e.value = item[e.itemTextName]; e[e.itemTextName] = item[e.itemTextName] }
  224. }
  225. else if (e.type === 'datepicker') e.value = timesTampChange(item[e.key], 'Y-M')
  226. else if (item[e.key]) e.value = item[e.key]
  227. })
  228. } else { // 新增
  229. editId.value = null
  230. formItems.value.options.forEach(e => {
  231. e.value = e.default || null
  232. if (e.key === 'schoolId') e.items = []
  233. if (e.key === 'majorId') e.items = []
  234. })
  235. }
  236. nextTick(() => {
  237. isEdit.value = true
  238. })
  239. }
  240. // 保存-基础信息
  241. const handleSave = async () => {
  242. const { valid } = await CtFormRef.value.formRef.validate()
  243. if (!valid) return
  244. const obj = {}
  245. formItems.value.options.forEach(e => {
  246. if (e.canBeInputted) { // 特殊处理可输入下拉框
  247. dealCanBeInputtedSave(e, obj)
  248. // if (e.value === e[e.itemTextName]) { obj[e.key] = ''; obj[e.itemTextName] = e[e.itemTextName] }
  249. // else { obj[e.key] = e.value; obj[e.itemTextName] = e[e.itemTextName] }
  250. }
  251. else if (e.type === 'datepicker') obj[e.key] = getTimeStamp(e.value)
  252. else obj[e.key] = e.value
  253. })
  254. if (editId.value) obj.id = editId.value
  255. await saveResumeEduExp(obj)
  256. Snackbar.success('保存成功!')
  257. isEdit.value = false
  258. await getData()
  259. }
  260. // 删除数据
  261. const handleDelete = ({ id }) => {
  262. Confirm('系统提示', '是否确认删除此教育经历?').then(async () => {
  263. await deleteResumeEduExp(id)
  264. getData(id)
  265. Snackbar.success('删除成功!')
  266. })
  267. }
  268. // 获取字典内容
  269. const dictList = [
  270. { type: 'menduner_education_type', key: 'educationType' },
  271. { type: 'menduner_education_system_type', key: 'educationSystemType' }
  272. ]
  273. const getDictData = async (obj) => {
  274. const item = formItems.value.options.find(e => e.key === obj.key)
  275. if (item) { // && !item.items?.length
  276. const { data } = await getDict(obj.type)
  277. item.items = data || []
  278. dictItemsObj[obj.key] = data || []
  279. }
  280. }
  281. const getOptions = () => {
  282. dictList.forEach(obj => getDictData(obj))
  283. }
  284. getOptions()
  285. </script>
  286. <style scoped lang="scss">
  287. .font15 { font-size: 15px;; }
  288. .color9 { color: var(--color-999); }
  289. .color6 { color: var(--color-666); }
  290. .educExpItem {
  291. cursor: pointer;
  292. border-radius: 6px;
  293. padding: 2px 10px 8px;
  294. &:hover {
  295. background-color: var(--color-f8);
  296. }
  297. }
  298. .educExpItem-edit {
  299. border-radius: 6px;
  300. padding: 2px 10px 8px;
  301. background-color: var(--color-f8);
  302. }
  303. </style>