educationExp.vue 9.2 KB

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