trainingExperience.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div class="resume-box elevation-2 mb-3" id="trainingExperience">
  3. <div class="resume-header">
  4. <div class="resume-title">{{ $t('resume.trainingExperience') }}</div>
  5. <v-btn variant="text" color="primary" prepend-icon="mdi-plus-box" @click="isEdit = true; type = 'add'">{{ $t('common.add') }}</v-btn>
  6. </div>
  7. <div v-if="isEdit" class="edit">
  8. <h4 class="label-title my-3 mx-2"> {{ type === 'add' ? $t('common.add') : $t('common.edit') }}{{ $t('resume.trainingExperience') }}</h4>
  9. <CtForm ref="formPageRef" :items="items" style="width: 100%;"></CtForm>
  10. <div class="text-end">
  11. <v-btn class="half-button mr-3" variant="tonal" @click="handleCancel">{{ $t('common.cancel') }}</v-btn>
  12. <v-btn color="primary" class="half-button" :loading="loading" @click="handleSave">{{ $t('common.save') }}</v-btn>
  13. </div>
  14. </div>
  15. <div v-else>
  16. <div v-if="trainExp.length">
  17. <div v-for="(k, i) in trainExp" :key="i" class="exp mx-n2 mt-5" @mouseenter="k.active = true" @mouseleave="k.active = false">
  18. <span class="float-right" v-if="k.active">
  19. <v-btn variant="text" color="primary" prepend-icon="mdi-square-edit-outline" @click="handleEdit(k)">{{ $t('common.edit') }}</v-btn>
  20. <v-btn variant="text" color="primary" prepend-icon="mdi-trash-can-outline" @click="handleDelete(k)">{{ $t('common.delete') }}</v-btn>
  21. </span>
  22. <div class="level1 d-flex align-center justify-space-between" style="height: 40px;">
  23. <div>
  24. <span style="font-size: 18px; font-weight: bold;">{{ k.orgName }}</span>
  25. <span class="label-title ml-5">
  26. <span>{{ timesTampChange(k.startTime, 'Y-M') }}</span>
  27. <span class="mx-1">至</span>
  28. <span>{{ timesTampChange(k.endTime, 'Y-M') }}</span>
  29. </span>
  30. </div>
  31. </div>
  32. <div class="my-2">
  33. <span class="label-title">培训课程:{{ k.course }}</span>
  34. </div>
  35. <div>
  36. <span class="label-title">培训描述:</span>
  37. <span class="label-title">{{ k.content || '暂无描述' }}</span>
  38. </div>
  39. </div>
  40. </div>
  41. <div v-else class="resumeNoDataText">{{ $t('resume.dataDefaultPrompt') }}{{ $t('resume.trainingExperience') }}...</div>
  42. </div>
  43. </div>
  44. </template>
  45. <script setup name="trainingExperience">
  46. import { ref } from 'vue'
  47. import { timesTampChange } from '@/utils/date'
  48. import { saveResumeTrainExp, getResumeTrainExp, deleteResumeTrainExp } from '@/api/recruit/personal/resume'
  49. import CtForm from '@/components/CtForm'
  50. import Snackbar from '@/plugins/snackbar'
  51. import Confirm from '@/plugins/confirm'
  52. const emit = defineEmits(['complete'])
  53. const isEdit = ref(false)
  54. const formPageRef = ref()
  55. const type = ref('')
  56. const editId = ref(null)
  57. const loading = ref(false)
  58. const startTimeChange = (v) => {
  59. const item1 = items.value.options.find(e => e.key === 'startTime')
  60. const item2 = items.value.options.find(e => e.key === 'endTime')
  61. if (item1?.value && item2?.value && item1.value > item2.value) {
  62. Snackbar.warning('开始时间不能大于结束时间!')
  63. nextTick(() => {
  64. item1.value = item2.value
  65. })
  66. }
  67. }
  68. const endTimeChange = (v) => {
  69. const item1 = items.value.options.find(e => e.key === 'startTime')
  70. const item2 = items.value.options.find(e => e.key === 'endTime')
  71. if (item1?.value && item2?.value && item1.value > item2.value) {
  72. Snackbar.warning('结束时间不能小于开始时间')
  73. nextTick(() => {
  74. item2.value = item1.value
  75. })
  76. }
  77. }
  78. const items = ref({
  79. options: [
  80. {
  81. type: 'text',
  82. key: 'orgName',
  83. value: '',
  84. col: 6,
  85. label: '培训中心 *',
  86. flexStyle: 'mr-3',
  87. rules: [v => !!v || '请输入培训中心']
  88. },
  89. {
  90. type: 'text',
  91. key: 'course',
  92. value: '',
  93. col: 6,
  94. label: '培训课程 *',
  95. rules: [v => !!v || '请输入培训课程']
  96. },
  97. {
  98. type: 'datePicker',
  99. key: 'startTime',
  100. mode: 'month',
  101. value: new Date(2014, 1).getTime(),
  102. labelWidth: 140,
  103. defaultValue: new Date(2020, 1),
  104. label: '培训开始时间 *',
  105. disabledFutureDates: true,
  106. col: 6,
  107. flexStyle: 'mr-3',
  108. rules: [v => !!v || '请选择培训开始时间'],
  109. change: startTimeChange
  110. },
  111. {
  112. type: 'datePicker',
  113. key: 'endTime',
  114. mode: 'month',
  115. value: new Date(2022, 1).getTime(),
  116. labelWidth: 140,
  117. defaultValue: new Date(2022, 1),
  118. label: '培训结束时间 *',
  119. disabledFutureDates: true,
  120. col: 6,
  121. rules: [v => !!v || '请选择培训结束时间'],
  122. change: endTimeChange
  123. },
  124. {
  125. type: 'textarea',
  126. key: 'content',
  127. value: '',
  128. label: '培训描述',
  129. rows: 5,
  130. flexStyle: 'mt-5',
  131. resize: true,
  132. counter: 2000,
  133. rules: [
  134. value => {
  135. if (value?.length <= 2000) return true
  136. return '请输入2-2000个字符'
  137. }
  138. ]
  139. }
  140. ]
  141. })
  142. const handleCancel = () => {
  143. isEdit.value = false
  144. type.value = ''
  145. editId.value = null
  146. items.value.options.forEach(e => {
  147. e.value = null
  148. })
  149. }
  150. // 获取培训经历
  151. const trainExp = ref([])
  152. const getResumeTrainExpData = async () => {
  153. const data = await getResumeTrainExp()
  154. // 完成度展示
  155. emit('complete', { status: Boolean(data?.length), id: 'trainingExperience' })
  156. trainExp.value = data
  157. }
  158. getResumeTrainExpData()
  159. // 保存培训经历
  160. const handleSave = async () => {
  161. const { valid } = await formPageRef.value.formRef.validate()
  162. if (!valid) return
  163. loading.value = true
  164. const obj = {}
  165. items.value.options.forEach(e => {
  166. obj[e.key] = e.value
  167. })
  168. if (!obj.startTime || !obj.endTime) return Snackbar.warning('请选择培训起始时间!')
  169. if (obj.startTime > obj.endTime) return Snackbar.warning('开始时间不能大于结束时间!')
  170. if (editId.value) obj.id = editId.value
  171. try {
  172. await saveResumeTrainExp(obj)
  173. Snackbar.success('保存成功!')
  174. handleCancel()
  175. getResumeTrainExpData()
  176. } finally {
  177. loading.value = false
  178. }
  179. }
  180. const handleEdit = (item) => {
  181. editId.value = item.id
  182. items.value.options.forEach(e => {
  183. e.value = item[e.key]
  184. })
  185. isEdit.value = true
  186. }
  187. // 删除培训经历
  188. const handleDelete = ({ id }) => {
  189. Confirm('系统提示', '是否确认删除此项培训经历?').then(async () => {
  190. await deleteResumeTrainExp(id)
  191. Snackbar.success('删除成功!')
  192. getResumeTrainExpData()
  193. })
  194. }
  195. </script>
  196. <style scoped lang="scss">
  197. .exp {
  198. font-size: 15px;
  199. cursor: pointer;
  200. border-radius: 6px;
  201. padding: 2px 10px 8px;
  202. &:hover {
  203. background-color: var(--color-f8);
  204. }
  205. }
  206. .label-title {
  207. color: var(--color-666);
  208. }
  209. .edit {
  210. background-color: var(--color-f8);
  211. padding: 2px 10px 8px;
  212. border-radius: 6px;
  213. }
  214. :deep(.el-input--large .el-input__wrapper) {
  215. background-color: #f8f8f8;
  216. }
  217. </style>