information.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <!-- 校验是否完善人才必填信息 -->
  2. <template>
  3. <scroll-view class="scrollBox" scroll-y="true">
  4. <view class="content">
  5. <!-- <view class="text-center ss-m-b-50 font-size-20 color-primary">学生信息认证</view> -->
  6. <uni-forms
  7. ref="baseInfoRef"
  8. v-model="formData"
  9. :rules="formRules"
  10. validateTrigger="bind"
  11. label-width="131px"
  12. labelAlign="right"
  13. >
  14. <uni-forms-item name="schoolId" label="就读学校" required>
  15. <uni-data-picker v-model="formData.schoolId" :localdata="selects?.schools" :clear-icon="false" popup-title="请选择就读学校" @change="getSelectData(0)" :map="{ text: 'name', value: 'schoolId' }"></uni-data-picker>
  16. </uni-forms-item>
  17. <uni-forms-item name="schoolDeptId" label="所在院系" required>
  18. <uni-data-picker v-model="formData.schoolDeptId" :localdata="selects?.dept" :clear-icon="false" popup-title="请选择所在院系" @change="getSelectData(2)" :map="{ text: 'name', value: 'id' }"></uni-data-picker>
  19. </uni-forms-item>
  20. <uni-forms-item name="majorId" label="所学专业" required>
  21. <uni-data-picker v-model="formData.majorId" :localdata="selects?.major" :clear-icon="false" popup-title="请选择所学专业" @change="getSelectData(2)" :map="{ text: 'nameCn', value: 'id' }"></uni-data-picker>
  22. </uni-forms-item>
  23. <uni-forms-item name="schoolClassId" label="所在班级">
  24. <searchComBox ref="schoolClassIdRef" v-model="formData.schoolClassId" :candidates="classList" itemTextName='schoolClassName' itemValueName='schoolClassId' labelKey='name' valueKey='id' placeholder="请选择所在班级"></searchComBox>
  25. </uni-forms-item>
  26. <uni-forms-item name="studentNo" label="学号">
  27. <uni-easyinput placeholder="请填写学号" v-model="formData.studentNo" :inputBorder="false" type="text"></uni-easyinput>
  28. </uni-forms-item>
  29. <uni-forms-item name="emergencyContactName" label="紧急联系人姓名">
  30. <uni-easyinput placeholder="请填写紧急联系人姓名" v-model="formData.emergencyContactName" :inputBorder="false" type="text"></uni-easyinput>
  31. </uni-forms-item>
  32. <uni-forms-item name="emergencyContactPhone" label="紧急联系人手机号">
  33. <uni-easyinput placeholder="请填写紧急联系人手机号" v-model="formData.emergencyContactPhone" :inputBorder="false" type="number"></uni-easyinput>
  34. </uni-forms-item>
  35. </uni-forms>
  36. <view class="f-horizon-center">
  37. <button type="primary" size="default" class="send-button" @click="submit">保 存</button>
  38. </view>
  39. </view>
  40. </scroll-view>
  41. </template>
  42. <script setup>
  43. import { ref, unref } from 'vue'
  44. import { mobile } from '@/utils/validate'
  45. import { saveStudentSimpleInfo, getStudentInfo } from '@/api/user'
  46. // import { userStore } from '@/store/user'; const useUserStore = userStore()
  47. import { getSchoolList, getDepartmentListBySchoolId, getMajorList } from '@/api/student'
  48. import searchComBox from '@/components/searchCombox'
  49. const baseInfoRef = ref()
  50. const formData = ref({ // 必填项目
  51. schoolId: null,
  52. schoolDeptId: null,
  53. majorId: null,
  54. schoolClassId: null,
  55. schoolClassName: null,
  56. studentNo: null,
  57. emergencyContactName: null,
  58. emergencyContactPhone: null,
  59. })
  60. // 获取学生基本信息
  61. const studentInfoFun = async () => {
  62. const { data } = await getStudentInfo()
  63. // 回显
  64. Object.keys(data).length && Object.keys(formData.value).length && Object.keys(formData.value).forEach(key => formData.value[key] = data[key])
  65. // if (!formData.value?.schoolClassId && formData.value?.schoolClassName) formData.value.schoolClassId = formData.value.schoolClassName
  66. await getSelectData('default', true)
  67. await getSelectData(0, true)
  68. await getSelectData(1, true)
  69. await getSelectData(2, true)
  70. }
  71. studentInfoFun()
  72. // // 下拉列表
  73. const selects = ref({})
  74. const classList = ref([])
  75. const getSelectData = async (type = 'default', init = false) => { // type: 0院系|1专业|2班级
  76. const params = { ...(type !== 'default' && { type }) }
  77. // 查院系用 schoolId 查班级用 parentId
  78. if (type === 0) {
  79. if (!formData.value?.schoolId) return
  80. params.schoolId = formData.value.schoolId
  81. }
  82. if (type === 2) {
  83. if (!formData.value?.schoolId && !formData.value?.schoolDeptId) return
  84. if (formData.value?.schoolId) params.schoolId = formData.value.schoolId
  85. if (formData.value?.schoolDeptId) params.parentId = formData.value.schoolDeptId
  86. }
  87. const api = {
  88. default: getSchoolList,
  89. 0: getDepartmentListBySchoolId,
  90. 1: getMajorList,
  91. 2: getDepartmentListBySchoolId,
  92. }
  93. const res = await api[type](params)
  94. if (type === 'default') {
  95. selects.value.schools = res?.data?.length ? res.data : []
  96. }
  97. if (type === 0) {
  98. if (!init) {
  99. formData.value.schoolDeptId = null
  100. formData.value.schoolClassId = null
  101. }
  102. selects.value.dept = res?.data?.length ? res.data : []
  103. }
  104. if (type === 1) {
  105. selects.value.major = res?.data?.length ? res.data : []
  106. }
  107. if (type === 2) {
  108. if (!init) formData.value.schoolClassId = null
  109. classList.value = res?.data?.length ? res.data : []
  110. schoolClassIdRef.value && schoolClassIdRef.value.setLabel()
  111. }
  112. }
  113. const formRules = {
  114. phone: mobile,
  115. schoolId:{
  116. rules: [{required: true, errorMessage: '请选择就读学校' }]
  117. },
  118. schoolDeptId:{
  119. rules: [{required: true, errorMessage: '请选择所在院系' }]
  120. },
  121. majorId: {
  122. rules: [{required: true, errorMessage: '请填写所在专业' }]
  123. }
  124. }
  125. const schoolClassIdRef = ref()
  126. const submit = async () => {
  127. const validate = await unref(baseInfoRef).validate()
  128. if (!validate) return uni.showToast({ title: '请将信息补充完整', icon: 'none' })
  129. let params = {...formData.value}
  130. const schoolClassObj = schoolClassIdRef.value?.getValue()
  131. params = { ...params, ...schoolClassObj }
  132. try {
  133. await saveStudentSimpleInfo(params)
  134. uni.showToast({
  135. icon: 'success',
  136. title: '保存成功'
  137. })
  138. setTimeout(() => {
  139. uni.navigateBack({
  140. delta: 1
  141. })
  142. }, 1000)
  143. } catch (err) {
  144. uni.showToast({ title: err?.msg || '保存失败', icon: 'none' })
  145. }
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .scrollBox {
  150. width: 100vw;
  151. // height: 100vh;
  152. height: calc(100vh - 30rpx);
  153. margin-bottom: 30rpx;
  154. }
  155. .content {
  156. padding: 30rpx;
  157. }
  158. .changeRole {
  159. color: var(--color-666);
  160. font-size: 15px;
  161. line-height: 26px;
  162. margin-bottom: 40rpx;
  163. }
  164. .upload-img{
  165. position: relative;
  166. width: 200rpx;
  167. height: 200rpx;
  168. border: 1px solid #f1f1f1;
  169. margin: 10rpx;
  170. }
  171. .upload-file{
  172. width: 200rpx;
  173. height: 200rpx;
  174. border: 1px solid #f1f1f1;
  175. margin: 10rpx;
  176. display: flex;
  177. justify-content: center;
  178. align-items: center;
  179. border-radius: 10rpx;
  180. }
  181. </style>