educationExp.vue 9.2 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).slice(0, 7) }}</span>
  29. <span class="mx-1">至</span>
  30. <span>{{ timesTampChange(item.endTime).slice(0, 7) }}</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. rows: 5,
  183. resize: true,
  184. counter: 1600,
  185. label: '在校经历 *',
  186. outlined: true,
  187. rules: [v => !!v || '请输入在校经历']
  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]).slice(0, 7)
  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: #666666; }
  276. .educExpItem {
  277. cursor: pointer;
  278. border-radius: 6px;
  279. padding: 2px 10px 8px;
  280. &:hover {
  281. background-color: #f8f8f8;
  282. }
  283. }
  284. .educExpItem-edit {
  285. border-radius: 6px;
  286. padding: 2px 10px 8px;
  287. background-color: #f8f8f8;
  288. }
  289. </style>