projectExperience.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div class="resume-box elevation-2 mb-3" id="projectExperience">
  3. <div class="resume-header">
  4. <div class="resume-title">{{ $t('resume.projectExperience') }}</div>
  5. <v-btn variant="text" color="primary" prepend-icon="mdi-plus-box" @click="handleAdd">{{ $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.projectExperience') }}</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. <!-- 展示 -->
  16. <div v-else-if="!projectExp?.length" class="resumeNoDataText">{{ $t('resume.dataDefaultPrompt') }}{{ $t('resume.projectExperience') }}...</div>
  17. <div v-else v-for="(k, i) in projectExp" :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="d-flex align-center justify-space-between" style="height: 40px;">
  23. <div>
  24. <span style="font-size: 18px; font-family: 'MiSans-Bold';">{{ k.name }}</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>
  33. <span class="label-title">项目描述:</span>
  34. <span class="label-title">{{ k.content }}</span>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script setup name="projectExperience">
  40. import { ref } from 'vue'
  41. import { timesTampChange } from '@/utils/date'
  42. import { saveResumeProjectExp, getResumeProjectExp, deleteResumeProjectExp } from '@/api/recruit/personal/resume'
  43. import CtForm from '@/components/CtForm'
  44. import Snackbar from '@/plugins/snackbar'
  45. import Confirm from '@/plugins/confirm'
  46. const emit = defineEmits(['complete'])
  47. const isEdit = ref(false)
  48. const formPageRef = ref()
  49. const type = ref('')
  50. const editId = ref(null)
  51. const loading = ref(false)
  52. const items = ref({
  53. options: [
  54. {
  55. type: 'text',
  56. key: 'name',
  57. value: '',
  58. label: '项目名称 *',
  59. rules: [v => !!v || '请输入项目名称']
  60. },
  61. {
  62. type: 'datePicker',
  63. key: 'startTime',
  64. mode: 'month',
  65. value: null,
  66. label: '项目开始时间 *',
  67. format: 'YYYY-MM',
  68. labelWidth: 140,
  69. col: 6,
  70. disabledFutureDates: true,
  71. flexStyle: 'mr-3'
  72. },
  73. {
  74. type: 'datePicker',
  75. key: 'endTime',
  76. format: 'YYYY-MM',
  77. mode: 'month',
  78. value: null,
  79. disabledFutureDates: true,
  80. label: '项目结束时间 *',
  81. col: 6,
  82. flexStyle: 'mr-3',
  83. labelWidth: 140,
  84. },
  85. {
  86. type: 'textarea',
  87. key: 'content',
  88. value: '',
  89. label: '项目描述 *',
  90. counter: '500',
  91. rows: 5,
  92. resize: true,
  93. rules: [
  94. value => {
  95. if (value) return true
  96. return '请输入项目描述'
  97. },
  98. value => {
  99. if (value?.length <= 500) return true
  100. return '请输入2-200个字符'
  101. }
  102. ]
  103. }
  104. ]
  105. })
  106. const handleCancel = () => {
  107. isEdit.value = false
  108. type.value = ''
  109. editId.value = null
  110. items.value.options.forEach(e => {
  111. if (e.type === 'datePicker') e.value = {}
  112. else e.value = null
  113. })
  114. }
  115. // 获取项目经历
  116. const projectExp = ref([])
  117. const getResumeTrainExpData = async () => {
  118. const data = await getResumeProjectExp()
  119. // 完成度展示
  120. emit('complete', { status: Boolean(data?.length), id: 'projectExperience' })
  121. projectExp.value = data
  122. }
  123. getResumeTrainExpData()
  124. const handleAdd = () => {
  125. items.value.options.forEach(e => e.value = null)
  126. type.value = 'add'
  127. isEdit.value = true
  128. }
  129. // 保存项目经历
  130. const handleSave = async () => {
  131. const { valid } = await formPageRef.value.formRef.validate()
  132. if (!valid) return
  133. loading.value = true
  134. const obj = {}
  135. items.value.options.forEach(e => {
  136. obj[e.key] = e.value
  137. })
  138. if (!obj.startTime || !obj.endTime) return Snackbar.warning('请选择项目起始时间')
  139. if (editId.value) obj.id = editId.value
  140. try {
  141. await saveResumeProjectExp(obj)
  142. Snackbar.success('保存成功!')
  143. handleCancel()
  144. getResumeTrainExpData()
  145. } finally {
  146. loading.value = false
  147. }
  148. }
  149. const handleEdit = (item) => {
  150. editId.value = item.id
  151. items.value.options.forEach(e => {
  152. e.value = item[e.key]
  153. })
  154. isEdit.value = true
  155. }
  156. // 删除项目经历
  157. const handleDelete = ({ id }) => {
  158. Confirm('系统提示', '是否确认删除此项目经历?').then(async () => {
  159. await deleteResumeProjectExp(id)
  160. Snackbar.success('删除成功!')
  161. getResumeTrainExpData()
  162. })
  163. }
  164. </script>
  165. <style scoped lang="scss">
  166. .exp {
  167. font-size: 15px;
  168. cursor: pointer;
  169. border-radius: 6px;
  170. padding: 2px 10px 8px;
  171. &:hover {
  172. background-color: var(--color-f8);
  173. }
  174. }
  175. .label-title {
  176. color: var(--color-666);
  177. }
  178. .edit {
  179. background-color: var(--color-f8);
  180. padding: 2px 10px 8px;
  181. border-radius: 6px;
  182. }
  183. </style>