educationExp.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view class="f-straight wrapper">
  3. <uni-forms ref="form" :modelValue="formData" :rules="rules" validateTrigger="bind" label-width="90px">
  4. <uni-forms-item label="学校名称" name="schoolName" required>
  5. <uni-combox :candidates="schoolData" placeholder="学校名称" v-model="formData.schoolName" @input="handleSearchSchool"></uni-combox>
  6. </uni-forms-item>
  7. <uni-forms-item label="所学专业" name="major" required>
  8. <uni-combox :candidates="majorData" placeholder="所学专业" v-model="formData.major" @input="handleSearchMajor"></uni-combox>
  9. </uni-forms-item>
  10. <uni-forms-item label="学历" name="educationType" required>
  11. <uni-data-select v-model="formData.educationType" :localdata="searchData.eduType"></uni-data-select>
  12. </uni-forms-item>
  13. <uni-forms-item label="学制类型" name="educationSystemType" required>
  14. <uni-data-select v-model="formData.educationSystemType" :localdata="searchData.eduSystemType"></uni-data-select>
  15. </uni-forms-item>
  16. <uni-forms-item label="开始时间" name="startTime" required>
  17. <picker mode="date" :value="formData.startTime" fields="month" :end="endDate" @change="e => formData.startTime = e.detail.value">
  18. <view class="uni-input ss-m-t-20">{{ formData.startTime }}</view>
  19. </picker>
  20. </uni-forms-item>
  21. <uni-forms-item label="结束时间" name="endTime" required>
  22. <picker mode="date" :value="formData.endTime" fields="month" @change="e => formData.endTime = e.detail.value">
  23. <view class="uni-input ss-m-t-20">{{ formData.endTime }}</view>
  24. </picker>
  25. </uni-forms-item>
  26. <uni-forms-item label="在校经历" name="content">
  27. <uni-easyinput type="textarea" v-model="formData.content" autoHeight placeholder="请输入内容"></uni-easyinput>
  28. </uni-forms-item>
  29. </uni-forms>
  30. </view>
  31. </template>
  32. <script setup>
  33. import { cloneDeep } from 'lodash-es'
  34. import { ref, watch, unref } from 'vue'
  35. import { dictObj } from '@/utils/position.js'
  36. import { convertYearMonthToTimestamp, timesTampChange } from '@/utils/date.js'
  37. const props = defineProps({
  38. id: {
  39. type: String,
  40. default: ''
  41. },
  42. data: {
  43. type: Object,
  44. default: () => ({})
  45. }
  46. })
  47. let formData = ref({
  48. startTime: '2014-01',
  49. endTime: '2018-01'
  50. })
  51. const majorData = ref([])
  52. const schoolData = ref([])
  53. const form = ref()
  54. const date = new Date()
  55. const endDate = date.getFullYear() + '-' + (date.getMonth() + 1) // 不可选时间
  56. const searchData = ref({
  57. school: [],
  58. major: [],
  59. eduType: dictObj.edu.map(e => ({ text: e.label, value: e.value})),
  60. eduSystemType: dictObj.eduSystemType.map(e => ({ text: e.label, value: e.value}))
  61. })
  62. const getInfo = (data) => {
  63. data.startTime = data.startTime ? timesTampChange(data.startTime, 'Y-M') : '2014-01'
  64. data.endTime = data.endTime ? timesTampChange(data.endTime, 'Y-M') : '2018-01'
  65. formData.value = cloneDeep(data) || {
  66. startTime: '2014-01',
  67. endTime: '2018-01'
  68. }
  69. }
  70. watch(
  71. () => props.data,
  72. (newVal) => {
  73. if (newVal && Object.keys(newVal)) {
  74. getInfo(newVal)
  75. }
  76. },
  77. { immediate: true },
  78. )
  79. const rules = {
  80. schoolName:{
  81. rules: [{required: true, errorMessage: '请输入学校名称' }]
  82. },
  83. major:{
  84. rules: [{required: true, errorMessage: '请输入所学专业' }]
  85. },
  86. educationType:{
  87. rules: [{required: true, errorMessage: '请选择学历' }]
  88. },
  89. educationSystemType:{
  90. rules: [{required: true, errorMessage: '请选择学制类型' }]
  91. },
  92. startTime:{
  93. rules: [{required: true, errorMessage: '请选择开始时间' }]
  94. },
  95. endTime:{
  96. rules: [{required: true, errorMessage: '请选择结束时间' }]
  97. }
  98. }
  99. // 学校搜索
  100. const handleSearchSchool = (e) => {
  101. if (!e) return schoolData.value = []
  102. schoolSearchByName({ name: e }).then(res => {
  103. searchData.value.school = res.data
  104. schoolData.value = res.data && res.data?.length ? res.data.map(e => e.value) : []
  105. })
  106. }
  107. // 专业搜索
  108. const handleSearchMajor = (e) => {
  109. if (!e) return majorData.value = []
  110. schoolMajorByName({ name: e }).then(res => {
  111. searchData.value.major = res.data
  112. majorData.value = res.data && res.data?.length ? res.data.map(e => e.nameCn) : []
  113. })
  114. }
  115. const submit = async () => {
  116. const valid = await unref(form).validate()
  117. if (!valid) return { id: props.id, data: null}
  118. //
  119. const startTime = convertYearMonthToTimestamp(formData.value.startTime)
  120. const endTime = convertYearMonthToTimestamp(formData.value.endTime)
  121. return { id: props.id, data: { ...formData.value, startTime, endTime }}
  122. }
  123. defineExpose({
  124. id: props.id,
  125. submit
  126. })
  127. </script>
  128. <style lang="less" scoped>
  129. .wrapper{
  130. padding: 15px;
  131. // padding-top: 30px;
  132. }
  133. .upload-img{
  134. position: relative;
  135. width: 200rpx;
  136. height: 200rpx;
  137. border: 1px solid #f1f1f1;
  138. margin: 10rpx;
  139. }
  140. .upload-file{
  141. width: 200rpx;
  142. height: 200rpx;
  143. border: 1px solid #f1f1f1;
  144. margin: 10rpx;
  145. display: flex;
  146. justify-content: center;
  147. align-items: center;
  148. border-radius: 10rpx;
  149. }
  150. </style>