SetUser.vue 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div class="setInfo-box">
  3. <div class="setInfo">
  4. <!-- <van-nav-bar title="修改个人信息" left-text="返回" left-arrow @click-left="onClickLeft" /> -->
  5. <van-form @submit="onSubmit">
  6. <van-field
  7. v-model="personInfo.name"
  8. label="姓名"
  9. placeholder="姓名"
  10. :rules="[{ required: true, message: '请填写姓名' }]"
  11. />
  12. <van-field
  13. v-model="personInfo.phone"
  14. type="number"
  15. maxlength="11"
  16. label="手机号"
  17. placeholder="手机号"
  18. :rules="[{ required: true, message: '请填写手机号码' }]"
  19. />
  20. <field-picker
  21. label="性别"
  22. placeholder="点击选择性别"
  23. v-model="personInfo.sex"
  24. value-id="id"
  25. value-key="label"
  26. :columns="sexArry"
  27. />
  28. <field-picker
  29. v-model="personInfo.termId"
  30. label="学期"
  31. placeholder="点击选择学期"
  32. value-id="termId"
  33. value-key="name"
  34. :columns="SemesterArry"
  35. />
  36. <field-picker
  37. v-model="personInfo.classId"
  38. label="班级"
  39. placeholder="点击选择班级"
  40. value-id="classId"
  41. value-key="name"
  42. :columns="ClasssArry"
  43. />
  44. <div style="margin: 20px; margin-top:3em;">
  45. <van-button round block type="info" native-type="submit">提交</van-button>
  46. </div>
  47. </van-form>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import { mapState } from 'vuex'
  53. import { SetUser, getSchoolterm, getSchoolClass } from '@/util/api'
  54. export default {
  55. components: {
  56. FieldPicker: () => import('@/components/FieldPicker')
  57. },
  58. data() {
  59. return {
  60. personInfo: {
  61. name: null,
  62. sex: null,
  63. phone: null,
  64. termId: null,
  65. classId: null,
  66. },
  67. sexArry: [{id: 1, label: '男'}, {id: 2, label: '女'}],
  68. SemesterArry: [],
  69. ClasssArry: [],
  70. }
  71. },
  72. computed: {
  73. ...mapState({
  74. user: (state) => state.user
  75. })
  76. },
  77. watch: {
  78. user: {
  79. handler(nw) {
  80. if (nw) {
  81. this.personInfo.name = nw.name
  82. this.personInfo.phone = nw.phone
  83. this.personInfo.classId = nw.classId
  84. this.personInfo.termId = nw.termId
  85. this.personInfo.sex = nw.sex
  86. }
  87. },
  88. immediate: true
  89. }
  90. },
  91. mounted() {
  92. this.getSemester()
  93. },
  94. methods: {
  95. // 获取学期班级 star
  96. getSemester() {
  97. getSchoolterm({ pageSize: 999 }).then((e) => {
  98. console.log('获取学期', e)
  99. this.SemesterArry = e.records
  100. if ((!this.ClasssArry || this.ClasssArry.length < 1) && e.total > 0) {
  101. const first = this.SemesterArry[0]
  102. this.getClass(first.termId)
  103. }
  104. })
  105. },
  106. getClass(termId) {
  107. getSchoolClass(termId, { pageSize: 999 }).then((e) => {
  108. console.log('获取班级', e)
  109. this.ClasssArry = e.records
  110. })
  111. },
  112. // 获取学期班级 end
  113. onClickLeft() {
  114. this.$router.go(-1)
  115. },
  116. //学期区------------------------
  117. onSubmit(values) {
  118. console.log('submit', values)
  119. this.$toast.success('修改成功!')
  120. SetUser(this.$store.state.user.personId, {
  121. ...this.personInfo,
  122. personId: this.$store.state.user.personId,
  123. }).then((e) => {
  124. this.$store.commit('SET_USER_INFO', this.personInfo)
  125. this.$router.go(-1)
  126. })
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="less" scoped>
  132. .setInfo-box {
  133. background-color: #fff;
  134. height: 100%;
  135. width: 100vw;
  136. display: flex;
  137. .setInfo {
  138. align-items: center;
  139. margin: 0 auto;
  140. width: 100%;
  141. height: 50vh;
  142. // border-bottom-left-radius: 20px;
  143. // border-bottom-right-radius: 20px;
  144. .van-form {
  145. position: relative;
  146. top: 4vh;
  147. .van-field {
  148. margin-bottom: 2em;
  149. font-size: 17px;
  150. font-weight: 600;
  151. }
  152. }
  153. }
  154. }
  155. </style>