index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div class="px-3">
  3. <div class="resume-header mb-3">
  4. <div class="resume-title">学生信息编辑</div>
  5. </div>
  6. <div class="d-flex flex-column align-center pt-5">
  7. <CtForm ref="CtFormRef" :items="items" style="width: 900px;"></CtForm>
  8. <v-btn class="buttons mt-5 elevation-5" color="primary" @click.stop="handleSubmit">{{ $t('common.save') }}</v-btn>
  9. </div>
  10. </div>
  11. <Loading :visible="overlay"></Loading>
  12. </template>
  13. <script setup>
  14. defineOptions({name: 'personal-personCenter-studentInformation-index'})
  15. import { ref, onMounted } from 'vue'
  16. import { saveStudentSimpleInfo } from '@/api/recruit/personal/shareJob'
  17. import { useI18n } from '@/hooks/web/useI18n'
  18. import Snackbar from '@/plugins/snackbar'
  19. import { isValidIdCard18 } from '@/utils/validate'
  20. import { useUserStore } from '@/store/user'
  21. import { getSchoolList, getDepartmentListBySchoolId, getMajorList } from '@/api/recruit/personal/student'
  22. const { t } = useI18n()
  23. const userStore = useUserStore()
  24. const overlay = ref(false)
  25. const CtFormRef = ref()
  26. // 专业名称下拉列表
  27. let majorName = null
  28. const getMajorData = async (name) => {
  29. const item = items.value.options.find(e => e.key === 'majorId')
  30. if (!item) return
  31. if (item.items?.length && (majorName === name)) return // 防抖
  32. majorName = name
  33. if (name) {
  34. const data = await getMajorList({ name })
  35. item.items = data
  36. }
  37. }
  38. const items = ref({
  39. options: [
  40. {
  41. type: 'autocomplete',
  42. key: 'schoolId',
  43. value: null,
  44. default: null,
  45. label: '就读学校 *',
  46. outlined: true,
  47. itemText: 'name',
  48. itemValue: 'schoolId',
  49. rules: [v => !!v || '请选择就读学校'],
  50. items: [],
  51. change: e => getDepartmentList(e, 'schoolDeptId', 0, true),
  52. },
  53. {
  54. type: 'autocomplete',
  55. key: 'schoolDeptId',
  56. value: null,
  57. default: null,
  58. label: '所在院系 *',
  59. outlined: true,
  60. itemText: 'name',
  61. itemValue: 'id',
  62. rules: [v => !!v || '请选择所在院系'],
  63. change: e => getDepartmentList(e, 'schoolClassId', 2, true),
  64. items: []
  65. },
  66. {
  67. type: 'combobox',
  68. key: 'schoolClassId',
  69. value: null,
  70. label: '所在班级 *',
  71. outlined: true,
  72. clearable: true,
  73. canBeInputted: true,
  74. itemTextName: 'schoolClassName',
  75. itemText: 'name',
  76. itemValue: 'id',
  77. rules: [v => !!v || '请选择所在班级'],
  78. items: []
  79. },
  80. {
  81. type: 'autocomplete',
  82. key: 'majorId',
  83. value: null,
  84. label: '所学专业 *',
  85. outlined: true,
  86. itemText: 'nameCn',
  87. itemValue: 'id',
  88. rules: [v => !!v || '请选择所学专业'],
  89. search: e => getMajorData(e),
  90. items: []
  91. },
  92. {
  93. type: 'text',
  94. key: 'studentNo',
  95. value: '',
  96. default: null,
  97. label: '学号',
  98. outlined: true
  99. },
  100. {
  101. type: 'text',
  102. key: 'emergencyContactName',
  103. value: '',
  104. default: null,
  105. label: '紧急联系人姓名',
  106. outlined: true
  107. },
  108. {
  109. type: 'phoneNumber',
  110. key: 'emergencyContactPhone',
  111. value: '',
  112. label: '紧急联系人手机号'
  113. }
  114. ]
  115. })
  116. // 左侧加mr
  117. items.value.options.forEach((e, index) => {
  118. e.col = 6
  119. if ((index + 2) % 2 === 0) e.flexStyle = 'mr-3'
  120. })
  121. // 学校下拉列表
  122. const getSchoolListData = async () => {
  123. const item = items.value.options.find(e => e.key === 'schoolId')
  124. if (!item) return
  125. const data = await getSchoolList()
  126. item.items = data || []
  127. }
  128. // 根据学校id获取院系、班级列表
  129. const getDepartmentList = async (id, key, type, isRefreshValue = false) => {
  130. const item = items.value.options.find(e => e.key === key)
  131. if (!item) return
  132. let params = { type } // type: 0院系|1专业|2班级
  133. // 查院系用schoolId,查班级用parentId
  134. if (key === 'schoolDeptId') params.schoolId = id
  135. else params.parentId = id
  136. const data = await getDepartmentListBySchoolId(params)
  137. item.items = data || []
  138. // 下拉框选择时需清空下级value
  139. if (isRefreshValue) item.value = null
  140. }
  141. // 获取学生基本信息
  142. const studentInfoFun = async () => {
  143. // await userStore.getStudentInformation()
  144. const data = JSON.parse(localStorage.getItem('studentInfo') || '{}')
  145. if (data.schoolId) getDepartmentList(data.schoolId, 'schoolDeptId', 0)
  146. if (data?.schoolClassId) getDepartmentList(data.schoolDeptId, 'schoolClassId', 2)
  147. if (data?.majorId) {
  148. getMajorData(data?.major?.nameCn)
  149. }
  150. // 回显
  151. items.value.options.forEach(e => {
  152. if (data[e.key]) {
  153. e.value = data[e.key]
  154. }
  155. })
  156. }
  157. onMounted(() => {
  158. // 获取学校列表
  159. getSchoolListData()
  160. // 获取学生基本信息
  161. studentInfoFun()
  162. })
  163. // 提交
  164. const handleSubmit = async () => {
  165. const { valid } = await CtFormRef.value.formRef.validate()
  166. if (!valid) return
  167. overlay.value = true
  168. const params = {}
  169. items.value.options.forEach(item => {
  170. // 班级有下拉选择的,需要根据选择的值赋值
  171. if (item.key === 'schoolClassId') {
  172. const classObj = item.items.find(e => e[item.itemValue] === item.value)
  173. if (!classObj) {
  174. params[item.key] = null
  175. params[item.itemTextName] = item.value
  176. } else params[item.key] = item.value
  177. } else params[item.key] = item.value
  178. })
  179. await saveStudentSimpleInfo(params)
  180. setTimeout(async () => {
  181. await userStore.getStudentInformation()
  182. studentInfoFun()
  183. Snackbar.success(t('common.submittedSuccessfully'))
  184. overlay.value = false
  185. }, 1000)
  186. }
  187. </script>
  188. <style scoped lang="scss">
  189. </style>