information.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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="所在班级" required>
  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="学号" required>
  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. schoolClassId: {
  125. rules: [{required: true, errorMessage: '请填写所在班级' }]
  126. },
  127. studentNo: {
  128. rules: [{required: true, errorMessage: '请填写学号' }]
  129. }
  130. }
  131. const schoolClassIdRef = ref()
  132. const submit = async () => {
  133. const validate = await unref(baseInfoRef).validate()
  134. if (!validate) return uni.showToast({ title: '请将信息补充完整', icon: 'none' })
  135. let params = {...formData.value}
  136. const schoolClassObj = schoolClassIdRef.value?.getValue()
  137. params = { ...params, ...schoolClassObj }
  138. try {
  139. await saveStudentSimpleInfo(params)
  140. uni.showToast({
  141. icon: 'success',
  142. title: '保存成功'
  143. })
  144. setTimeout(() => {
  145. uni.navigateBack({
  146. delta: 1
  147. })
  148. }, 1000)
  149. } catch (err) {
  150. uni.showToast({ title: err?.msg || '保存失败', icon: 'none' })
  151. }
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. .scrollBox {
  156. width: 100vw;
  157. // height: 100vh;
  158. height: calc(100vh - 30rpx);
  159. margin-bottom: 30rpx;
  160. }
  161. .content {
  162. padding: 30rpx;
  163. }
  164. .changeRole {
  165. color: var(--color-666);
  166. font-size: 15px;
  167. line-height: 26px;
  168. margin-bottom: 40rpx;
  169. }
  170. .upload-img{
  171. position: relative;
  172. width: 200rpx;
  173. height: 200rpx;
  174. border: 1px solid #f1f1f1;
  175. margin: 10rpx;
  176. }
  177. .upload-file{
  178. width: 200rpx;
  179. height: 200rpx;
  180. border: 1px solid #f1f1f1;
  181. margin: 10rpx;
  182. display: flex;
  183. justify-content: center;
  184. align-items: center;
  185. border-radius: 10rpx;
  186. }
  187. </style>