educationExp.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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" @click="handleDelete">删 除</button>
  33. <button size="default" :class="{'save-button': editId, 'commonBtnStyle': editId, 'send-button': !editId}" @click="submit">保 存</button>
  34. </view>
  35. </view>
  36. </template>
  37. <script setup>
  38. import { ref, unref } from 'vue'
  39. import { dictObj } from '@/utils/position.js'
  40. import { convertYearMonthToTimestamp, timesTampChange } from '@/utils/date.js'
  41. import { schoolSearchByName, schoolMajorByName, saveResumeEduExp, getResumeEduExp, deleteResumeEduExp } from '@/api/resume.js'
  42. import { onLoad } from '@dcloudio/uni-app'
  43. import { cloneDeep } from 'lodash-es'
  44. let formData = ref({
  45. startTime: '2014-01',
  46. endTime: '2018-01'
  47. })
  48. const editId = ref(null)
  49. const majorData = ref([])
  50. const schoolData = ref([])
  51. const form = ref()
  52. const date = new Date()
  53. const endDate = date.getFullYear() + '-' + (date.getMonth() + 1) // 不可选时间
  54. const searchData = ref({
  55. school: [],
  56. major: [],
  57. eduType: dictObj.edu.map(e => ({ text: e.label, value: e.value})),
  58. eduSystemType: dictObj.eduSystemType.map(e => ({ text: e.label, value: e.value}))
  59. })
  60. const rules = {
  61. schoolName:{
  62. rules: [{required: true, errorMessage: '请输入学校名称' }]
  63. },
  64. major:{
  65. rules: [{required: true, errorMessage: '请输入所学专业' }]
  66. },
  67. educationType:{
  68. rules: [{required: true, errorMessage: '请选择学历' }]
  69. },
  70. educationSystemType:{
  71. rules: [{required: true, errorMessage: '请选择学制类型' }]
  72. },
  73. startTime:{
  74. rules: [{required: true, errorMessage: '请选择开始时间' }]
  75. },
  76. endTime:{
  77. rules: [{required: true, errorMessage: '请选择结束时间' }]
  78. }
  79. }
  80. const getEduExp = async (id) => {
  81. const { data } = await getResumeEduExp()
  82. if (!data || !data.length) {
  83. return
  84. }
  85. const obj = data.find(e => e.id == id)
  86. formData.value = cloneDeep(obj)
  87. formData.value.startTime = obj.startTime ? timesTampChange(obj.startTime, 'Y-M') : '2014-01'
  88. formData.value.endTime = obj.endTime ? timesTampChange(obj.endTime, 'Y-M') : '2018-01'
  89. handleSearchSchool(obj.schoolName)
  90. handleSearchMajor(obj.major)
  91. }
  92. onLoad((options) => {
  93. if (options.id) {
  94. editId.value = options.id
  95. getEduExp(options.id)
  96. }
  97. })
  98. // 学校搜索
  99. const handleSearchSchool = (e) => {
  100. if (!e) return schoolData.value = []
  101. schoolSearchByName({ name: e }).then(res => {
  102. searchData.value.school = res.data
  103. schoolData.value = res.data && res.data?.length ? res.data.map(e => e.value) : []
  104. })
  105. }
  106. // 专业搜索
  107. const handleSearchMajor = (e) => {
  108. if (!e) return majorData.value = []
  109. schoolMajorByName({ name: e }).then(res => {
  110. searchData.value.major = res.data
  111. majorData.value = res.data && res.data?.length ? res.data.map(e => e.nameCn) : []
  112. })
  113. }
  114. // 保存
  115. const submit = async () => {
  116. const valid = await unref(form).validate()
  117. if (!valid) return
  118. formData.value.majorId = searchData.value.major.find(e => e.nameCn === formData.value.major)?.id
  119. formData.value.schoolId = searchData.value.school.find(e => e.value === formData.value.schoolName)?.key
  120. try {
  121. const startTime = convertYearMonthToTimestamp(formData.value.startTime)
  122. const endTime = convertYearMonthToTimestamp(formData.value.endTime)
  123. if (startTime > endTime) {
  124. uni.showToast({ icon: 'none', title: '开始时间不能大于结束时间' })
  125. return
  126. }
  127. await saveResumeEduExp({ ...formData.value, startTime, endTime })
  128. uni.showToast({
  129. icon: 'success',
  130. title: '保存成功'
  131. })
  132. setTimeout(() => {
  133. editId.value = null
  134. uni.navigateBack({
  135. delta: 1
  136. })
  137. }, 1000)
  138. } catch (err) {
  139. uni.showToast({
  140. icon: 'none',
  141. title: err.msg
  142. })
  143. }
  144. }
  145. // 删除
  146. const handleDelete = async () => {
  147. try {
  148. await deleteResumeEduExp(editId.value)
  149. uni.showToast({
  150. icon: 'success',
  151. title: '删除成功'
  152. })
  153. setTimeout(() => {
  154. editId.value = null
  155. uni.navigateBack({
  156. delta: 1
  157. })
  158. }, 1000)
  159. } catch (err) {
  160. uni.showToast({
  161. icon: 'none',
  162. title: err.msg
  163. })
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. </style>