educationExp.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 editId = ref(null)
  61. const CtFormRef = ref()
  62. const dictItemsObj = reactive({})
  63. // 学校下拉列表
  64. const getSchoolListData = async (name, init = '') => {
  65. const item = formItems.value.options.find(e => e.key === 'schoolId')
  66. if (!item) return
  67. item[item.itemTextName] = name
  68. if (!init) item.value = null
  69. const data = await schoolSearchByName({ name })
  70. item.items = data
  71. }
  72. const debouncedCallbackSchool = debounce(newValue => {
  73. if (!newValue) return
  74. getSchoolListData(newValue)
  75. }, 500)
  76. // 专业下拉列表
  77. const getMajorListData = async (name, init = '') => {
  78. if (name === '') return // 此接口不支持传空值
  79. const item = formItems.value.options.find(e => e.key === 'majorId')
  80. item[item.itemTextName] = name
  81. if (!init) item.value = null
  82. const data = await schoolMajorByName({ name })
  83. item.items = data
  84. }
  85. const debouncedCallbackMajor = debounce(newValue => {
  86. getMajorListData(newValue)
  87. }, 500)
  88. const formItems = ref({
  89. options: [
  90. {
  91. type: 'combobox',
  92. key: 'schoolId',
  93. value: null,
  94. default: null,
  95. label: '学校名称 *',
  96. col: 6,
  97. outlined: true,
  98. clearable: true,
  99. canBeInputted: true, //
  100. itemTextName: 'schoolName',
  101. itemText: 'value',
  102. itemValue: 'key',
  103. rules: [v => !!v || '请选择学校名称'],
  104. search: debouncedCallbackSchool,
  105. items: []
  106. },
  107. {
  108. type: 'combobox',
  109. key: 'majorId',
  110. value: null,
  111. default: null,
  112. label: '所学专业 *',
  113. col: 6,
  114. outlined: true,
  115. clearable: true,
  116. canBeInputted: true, //
  117. itemTextName: 'major',
  118. itemText: 'nameCn',
  119. itemValue: 'id',
  120. rules: [v => !!v || '请选择所学专业'],
  121. search: debouncedCallbackMajor,
  122. items: []
  123. },
  124. {
  125. type: 'autocomplete',
  126. key: 'educationType',
  127. value: null,
  128. default: null,
  129. label: '学历 *',
  130. col: 6,
  131. outlined: true,
  132. itemText: 'label',
  133. itemValue: 'value',
  134. rules: [v => !!v || '请选择学历'],
  135. items: []
  136. },
  137. {
  138. type: 'autocomplete',
  139. key: 'educationSystemType',
  140. value: null,
  141. default: null,
  142. label: '学制类型 *',
  143. col: 6,
  144. outlined: true,
  145. itemText: 'label',
  146. itemValue: 'value',
  147. rules: [v => !!v || '请选择学制类型'],
  148. items: dictItemsObj.educationSystemType,
  149. },
  150. {
  151. type: 'datePicker',
  152. key: 'startTime',
  153. value: null,
  154. default: null,
  155. col: 6,
  156. class: 'mb-3',
  157. options: {
  158. type: 'month',
  159. format: 'timestamp',
  160. placeholder: '起始时间 *',
  161. },
  162. rules: [v => !!v || '请选择起始时间']
  163. },
  164. {
  165. type: 'datePicker',
  166. key: 'endTime',
  167. value: null,
  168. default: null,
  169. col: 6,
  170. class: 'mb-3',
  171. options: {
  172. type: 'month',
  173. format: 'timestamp',
  174. placeholder: '结束时间 *',
  175. },
  176. rules: [v => !!v || '请选择结束时间']
  177. },
  178. {
  179. type: 'textarea',
  180. key: 'content',
  181. value: null,
  182. default: null,
  183. rows: 5,
  184. resize: true,
  185. counter: 1600,
  186. label: '在校经历',
  187. outlined: true
  188. },
  189. ]
  190. })
  191. // 左侧加mr
  192. formItems.value.options.forEach((e, index) => {
  193. if (((index + 2) % 2 === 0) && Boolean(e.col) && e.col !== 12) e.flexStyle = 'mr-3'
  194. })
  195. // 获取数据
  196. const dataList = ref([])
  197. const getData = async () => {
  198. const data = await getResumeEduExp()
  199. dataList.value = data
  200. }
  201. getData()
  202. // 新增 或 编辑
  203. const isEdit = ref(false)
  204. const titleStatus = ref(0)
  205. const handle = (item) => {
  206. titleStatus.value = item ? 1 : 0
  207. if (item) { // 编辑
  208. editId.value = item.id
  209. formItems.value.options.forEach(e => { // 回显
  210. if (e.canBeInputted) { // 特殊处理可输入下拉框
  211. dealCanBeInputtedValueAndLabel(e, item)
  212. // if (item[e.key] && item[e.itemTextName]) { e.search(item[e.itemTextName], '触发下拉框内容'); e.value = item[e.key] }
  213. // else { e.value = item[e.itemTextName]; e[e.itemTextName] = item[e.itemTextName] }
  214. }
  215. else if (e.type === 'datepicker') e.value = timesTampChange(item[e.key], 'Y-M')
  216. else if (item[e.key]) e.value = item[e.key]
  217. })
  218. } else { // 新增
  219. editId.value = null
  220. formItems.value.options.forEach(e => e.value = e.default || null)
  221. }
  222. nextTick(() => {
  223. isEdit.value = true
  224. })
  225. }
  226. // 保存-基础信息
  227. const handleSave = async () => {
  228. const { valid } = await CtFormRef.value.formRef.validate()
  229. if (!valid) return
  230. const obj = {}
  231. formItems.value.options.forEach(e => {
  232. if (e.canBeInputted) { // 特殊处理可输入下拉框
  233. dealCanBeInputtedSave(e, obj)
  234. // if (e.value === e[e.itemTextName]) { obj[e.key] = ''; obj[e.itemTextName] = e[e.itemTextName] }
  235. // else { obj[e.key] = e.value; obj[e.itemTextName] = e[e.itemTextName] }
  236. }
  237. else if (e.type === 'datepicker') obj[e.key] = getTimeStamp(e.value)
  238. else obj[e.key] = e.value
  239. })
  240. if (editId.value) obj.id = editId.value
  241. await saveResumeEduExp(obj)
  242. Snackbar.success('保存成功!')
  243. isEdit.value = false
  244. await getData()
  245. }
  246. // 删除数据
  247. const handleDelete = ({ id }) => {
  248. Confirm('系统提示', '是否确认删除此教育经历?').then(async () => {
  249. await deleteResumeEduExp(id)
  250. getData(id)
  251. Snackbar.success('删除成功!')
  252. })
  253. }
  254. // 获取字典内容
  255. const dictList = [
  256. { type: 'menduner_education_type', key: 'educationType' },
  257. { type: 'menduner_education_system_type', key: 'educationSystemType' }
  258. ]
  259. const getDictData = async (obj) => {
  260. const item = formItems.value.options.find(e => e.key === obj.key)
  261. if (item) { // && !item.items?.length
  262. const { data } = await getDict(obj.type)
  263. item.items = data || []
  264. dictItemsObj[obj.key] = data || []
  265. }
  266. }
  267. const getOptions = () => {
  268. dictList.forEach(obj => getDictData(obj))
  269. }
  270. getOptions()
  271. </script>
  272. <style scoped lang="scss">
  273. .font15 { font-size: 15px;; }
  274. .color9 { color: var(--color-999); }
  275. .color6 { color: var(--color-666); }
  276. .educExpItem {
  277. cursor: pointer;
  278. border-radius: 6px;
  279. padding: 2px 10px 8px;
  280. &:hover {
  281. background-color: var(--color-f8);
  282. }
  283. }
  284. .educExpItem-edit {
  285. border-radius: 6px;
  286. padding: 2px 10px 8px;
  287. background-color: var(--color-f8);
  288. }
  289. </style>