educationExp.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <!-- 教育经历 -->
  2. <template>
  3. <view class="ss-m-x-30 ss-m-y-30">
  4. <uni-forms ref="form" :modelValue="formData" :rules="rules" validateTrigger="bind" label-width="90px">
  5. <uni-forms-item label="学校名称" name="schoolName" required>
  6. <uni-combox :candidates="schoolData" placeholder="学校名称" v-model="formData.schoolName" @input="handleSearchSchool"></uni-combox>
  7. </uni-forms-item>
  8. <uni-forms-item label="所学专业" name="major" required>
  9. <uni-combox :candidates="majorData" placeholder="所学专业" v-model="formData.major" @input="handleSearchMajor"></uni-combox>
  10. </uni-forms-item>
  11. <uni-forms-item label="学历" name="educationType" required>
  12. <uni-data-select v-model="formData.educationType" :localdata="searchData.eduType"></uni-data-select>
  13. </uni-forms-item>
  14. <uni-forms-item label="学制类型" name="educationSystemType" required>
  15. <uni-data-select v-model="formData.educationSystemType" :localdata="searchData.eduSystemType"></uni-data-select>
  16. </uni-forms-item>
  17. <uni-forms-item label="开始时间" name="startTime" required>
  18. <picker mode="date" :value="formData.startTime" fields="month" :end="endDate" @change="e => formData.startTime = e.detail.value">
  19. <view class="uni-input ss-m-t-20">{{ formData.startTime }}</view>
  20. </picker>
  21. </uni-forms-item>
  22. <uni-forms-item label="结束时间" name="endTime" required>
  23. <picker mode="date" :value="formData.endTime" fields="month" @change="e => formData.endTime = e.detail.value">
  24. <view class="uni-input ss-m-t-20">{{ formData.endTime }}</view>
  25. </picker>
  26. </uni-forms-item>
  27. <uni-forms-item label="在校经历" name="content">
  28. <uni-easyinput type="textarea" v-model="formData.content" autoHeight placeholder="请输入内容"></uni-easyinput>
  29. </uni-forms-item>
  30. </uni-forms>
  31. <view class="f-horizon-center">
  32. <button v-if="editId" size="default" class="delete-button commonBtnStyle MiSans-Medium" :disabled="deleteDisabled" @click="handleDelete">删 除</button>
  33. <button
  34. size="default"
  35. class="MiSans-Medium"
  36. :class="{'save-button': editId, 'commonBtnStyle': editId, 'send-button': !editId}"
  37. @click="submit"
  38. :disabled="disabled"
  39. >保 存</button>
  40. </view>
  41. </view>
  42. </template>
  43. <script setup>
  44. import { ref, unref } from 'vue'
  45. import { dictObj } from '@/utils/position.js'
  46. import { convertYearMonthToTimestamp, timesTampChange } from '@/utils/date.js'
  47. import { schoolSearchByName, schoolMajorByName, saveResumeEduExp, getResumeEduExp, deleteResumeEduExp } from '@/api/resume.js'
  48. import { onLoad } from '@dcloudio/uni-app'
  49. import { cloneDeep } from 'lodash-es'
  50. let formData = ref({
  51. startTime: '2014-01',
  52. endTime: '2018-01'
  53. })
  54. const editId = ref(null)
  55. const majorData = ref([])
  56. const schoolData = ref([])
  57. const form = ref()
  58. const date = new Date()
  59. const endDate = date.getFullYear() + '-' + (date.getMonth() + 1) // 不可选时间
  60. const searchData = ref({
  61. school: [],
  62. major: [],
  63. eduType: dictObj.edu.map(e => ({ text: e.label, value: e.value})),
  64. eduSystemType: dictObj.eduSystemType.map(e => ({ text: e.label, value: e.value}))
  65. })
  66. const rules = {
  67. schoolName:{
  68. rules: [{required: true, errorMessage: '请输入学校名称' }]
  69. },
  70. major:{
  71. rules: [{required: true, errorMessage: '请输入所学专业' }]
  72. },
  73. educationType:{
  74. rules: [{required: true, errorMessage: '请选择学历' }]
  75. },
  76. educationSystemType:{
  77. rules: [{required: true, errorMessage: '请选择学制类型' }]
  78. },
  79. startTime:{
  80. rules: [{required: true, errorMessage: '请选择开始时间' }]
  81. },
  82. endTime:{
  83. rules: [{required: true, errorMessage: '请选择结束时间' }]
  84. }
  85. }
  86. const getEduExp = async (id) => {
  87. const { data } = await getResumeEduExp()
  88. if (!data || !data.length) {
  89. return
  90. }
  91. const obj = data.find(e => e.id == id)
  92. formData.value = cloneDeep(obj)
  93. formData.value.startTime = obj.startTime ? timesTampChange(obj.startTime, 'Y-M') : '2014-01'
  94. formData.value.endTime = obj.endTime ? timesTampChange(obj.endTime, 'Y-M') : '2018-01'
  95. handleSearchSchool(obj.schoolName)
  96. handleSearchMajor(obj.major)
  97. }
  98. onLoad((options) => {
  99. if (options.id) {
  100. editId.value = options.id
  101. getEduExp(options.id)
  102. }
  103. })
  104. // 学校搜索
  105. const handleSearchSchool = (e) => {
  106. if (!e) return schoolData.value = []
  107. schoolSearchByName({ name: e }).then(res => {
  108. searchData.value.school = res.data
  109. schoolData.value = res.data && res.data?.length ? res.data.map(e => e.value) : []
  110. })
  111. }
  112. // 专业搜索
  113. const handleSearchMajor = (e) => {
  114. if (!e) return majorData.value = []
  115. schoolMajorByName({ name: e }).then(res => {
  116. searchData.value.major = res.data
  117. majorData.value = res.data && res.data?.length ? res.data.map(e => e.nameCn) : []
  118. })
  119. }
  120. // 保存
  121. const disabled = ref(false)
  122. const submit = async () => {
  123. const valid = await unref(form).validate()
  124. if (!valid) return
  125. formData.value.majorId = searchData.value.major.find(e => e.nameCn === formData.value.major)?.id
  126. formData.value.schoolId = searchData.value.school.find(e => e.value === formData.value.schoolName)?.key
  127. const startTime = convertYearMonthToTimestamp(formData.value.startTime)
  128. const endTime = convertYearMonthToTimestamp(formData.value.endTime)
  129. if (startTime > endTime) {
  130. uni.showToast({ icon: 'none', title: '开始时间不能大于结束时间' })
  131. return
  132. }
  133. disabled.value = true
  134. try {
  135. await saveResumeEduExp({ ...formData.value, startTime, endTime })
  136. uni.showToast({
  137. icon: 'success',
  138. title: '保存成功'
  139. })
  140. setTimeout(() => {
  141. editId.value = null
  142. uni.navigateBack({
  143. delta: 1
  144. })
  145. disabled.value = false
  146. }, 1000)
  147. } catch (err) {
  148. disabled.value = false
  149. uni.showToast({
  150. icon: 'none',
  151. title: err.msg
  152. })
  153. }
  154. }
  155. // 删除
  156. const deleteDisabled = ref(false)
  157. const handleDelete = async () => {
  158. deleteDisabled.value = true
  159. try {
  160. await deleteResumeEduExp(editId.value)
  161. uni.showToast({
  162. icon: 'success',
  163. title: '删除成功'
  164. })
  165. setTimeout(() => {
  166. editId.value = null
  167. uni.navigateBack({
  168. delta: 1
  169. })
  170. deleteDisabled.value = false
  171. }, 1000)
  172. } catch (err) {
  173. deleteDisabled.value = false
  174. uni.showToast({
  175. icon: 'none',
  176. title: err.msg
  177. })
  178. }
  179. }
  180. </script>
  181. <style lang="scss" scoped>
  182. </style>