edit-profile.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <ie-page bg-color="#F6F8FA" :safeAreaInsetBottom="false">
  3. <ie-navbar title="基本信息" />
  4. <view class="">
  5. <uv-form labelPosition="left" :model="form" labelWidth="70px" ref="formRef">
  6. <content-card title="个人信息">
  7. <uv-form-item label="姓名" prop="name" borderBottom>
  8. <uv-input v-model="form.nickName" border="none" :readonly="!userStore.isStudent" placeholder="请输入姓名"
  9. placeholderClass="text-30" font-size="30rpx" :custom-style="customStyle">
  10. </uv-input>
  11. </uv-form-item>
  12. <uv-form-item v-if="userStore.isStudent" label="手机号码" prop="name" borderBottom>
  13. <uv-input v-model="form.phonenumber" border="none" placeholder="请输入手机号码" maxlength="11" type="number"
  14. placeholderClass="text-30" font-size="30rpx" :custom-style="customStyle" readonly>
  15. </uv-input>
  16. <text slot="right" class="text-30 text-primary" @click="handleBindPhone">换绑</text>
  17. </uv-form-item>
  18. <uv-form-item label="所在省份" prop="name" borderBottom>
  19. <uv-input v-model="form.location" border="none" placeholder="" placeholderClass="text-30" font-size="30rpx"
  20. :custom-style="customStyle" readonly>
  21. </uv-input>
  22. <ie-image slot="right" src="/static/image/icon-lock.png" custom-class="w-24 h-30" mode="aspectFill" />
  23. </uv-form-item>
  24. <uv-form-item label="考试类别" prop="name" borderBottom>
  25. <view class="flex-1 pl-[26px] text-30">
  26. <ie-dict :dictName="EnumDictName.EXAM_TYPE" :dictValue="form.examType" />
  27. </view>
  28. <ie-image slot="right" src="/static/image/icon-lock.png" custom-class="w-24 h-30" mode="aspectFill" />
  29. </uv-form-item>
  30. <uv-form-item label="单招年份" prop="name">
  31. <uv-input v-model="form.endYear" border="none" placeholder="" placeholderClass="text-30" font-size="30rpx"
  32. :custom-style="customStyle" readonly>
  33. </uv-input>
  34. <ie-image slot="right" src="/static/image/icon-lock.png" custom-class="w-24 h-30" mode="aspectFill" />
  35. </uv-form-item>
  36. </content-card>
  37. <content-card title="文化素质">
  38. <uv-form-item label="语文" prop="name" borderBottom>
  39. <uv-input v-model="scores.chinese" border="none"
  40. :placeholder="form.examType === EnumExamType.OHS ? '' : '请输入'" placeholderClass="text-30"
  41. font-size="30rpx" :custom-style="customStyle" :readonly="form.examType === EnumExamType.OHS">
  42. </uv-input>
  43. <ie-image v-if="form.examType === EnumExamType.OHS" slot="right" src="/static/image/icon-lock.png"
  44. custom-class="w-24 h-30" mode="aspectFill" />
  45. </uv-form-item>
  46. <uv-form-item label="数学" prop="name" borderBottom>
  47. <uv-input v-model="scores.mathematics" border="none"
  48. :placeholder="form.examType === EnumExamType.OHS ? '' : '请输入'" placeholderClass="text-30"
  49. font-size="30rpx" :custom-style="customStyle" :readonly="form.examType === EnumExamType.OHS">
  50. </uv-input>
  51. <ie-image v-if="form.examType === EnumExamType.OHS" slot="right" src="/static/image/icon-lock.png"
  52. custom-class="w-24 h-30" mode="aspectFill" />
  53. </uv-form-item>
  54. <uv-form-item label="外语" prop="name" :borderBottom="form.examType === EnumExamType.OHS">
  55. <uv-input v-model="scores.foreign" border="none"
  56. :placeholder="form.examType === EnumExamType.OHS ? '' : '请输入'" placeholderClass="text-30"
  57. font-size="30rpx" :custom-style="customStyle" :readonly="form.examType === EnumExamType.OHS">
  58. </uv-input>
  59. <ie-image v-if="form.examType === EnumExamType.OHS" slot="right" src="/static/image/icon-lock.png"
  60. custom-class="w-24 h-30" mode="aspectFill" />
  61. </uv-form-item>
  62. <block v-if="[EnumExamType.OHS].includes(form.examType)">
  63. <uv-form-item label="物理" prop="name" borderBottom>
  64. <uv-input v-model="scores.physics" border="none"
  65. :placeholder="form.examType === EnumExamType.OHS ? '' : '请输入'" placeholderClass="text-30"
  66. font-size="30rpx" :custom-style="customStyle" :readonly="form.examType === EnumExamType.OHS">
  67. </uv-input>
  68. <ie-image v-if="form.examType === EnumExamType.OHS" slot="right" src="/static/image/icon-lock.png"
  69. custom-class="w-24 h-30" mode="aspectFill" />
  70. </uv-form-item>
  71. <uv-form-item label="政治" prop="name">
  72. <uv-input v-model="scores.political" border="none"
  73. :placeholder="form.examType === EnumExamType.OHS ? '' : '请输入'" placeholderClass="text-30"
  74. font-size="30rpx" :custom-style="customStyle" :readonly="form.examType === EnumExamType.OHS">
  75. </uv-input>
  76. <ie-image v-if="form.examType === EnumExamType.OHS" slot="right" src="/static/image/icon-lock.png"
  77. custom-class="w-24 h-30" mode="aspectFill" />
  78. </uv-form-item>
  79. </block>
  80. </content-card>
  81. <content-card v-if="([EnumExamType.OHS, EnumExamType.SVS].includes(form.examType))" title="职业技能成绩">
  82. <uv-form-item label="职业技能" prop="name">
  83. <uv-input v-model.number="scores.skill" border="none" placeholder="请输入" placeholderClass="text-30"
  84. font-size="30rpx" :custom-style="customStyle">
  85. </uv-input>
  86. </uv-form-item>
  87. </content-card>
  88. <template v-if="userStore.isStudent">
  89. <content-card v-if="userStore.isVip" title="学校信息">
  90. <uv-form-item label="学校名称" prop="form.name" borderBottom>
  91. <uv-input v-model="form.schoolName" border="none" placeholder="" placeholderClass="text-30"
  92. font-size="30rpx" :custom-style="customStyle" readonly>
  93. </uv-input>
  94. <ie-image slot="right" src="/static/image/icon-lock.png" custom-class="w-24 h-30" mode="aspectFill" />
  95. </uv-form-item>
  96. <uv-form-item label="所在班级" prop="form.name">
  97. <ie-picker ref="pickerRef" v-model="form.classId" :list="classList" title="选择班级" placeholder="请选择所在班级"
  98. :custom-style="customStyle" key-label="name" key-value="classId"></ie-picker>
  99. </uv-form-item>
  100. </content-card>
  101. </template>
  102. <content-card v-else title="学校信息">
  103. <uv-form-item label="学校名称" prop="form.campusName" borderBottom>
  104. <uv-input v-model="form.campusName" border="none" placeholder="" placeholderClass="text-30"
  105. font-size="30rpx" :custom-style="customStyle" readonly>
  106. </uv-input>
  107. <ie-image slot="right" src="/static/image/icon-lock.png" custom-class="w-24 h-30" mode="aspectFill" />
  108. </uv-form-item>
  109. <uv-form-item label="所在班级" prop="form.campusClassName">
  110. <uv-input v-model="form.campusClassName" border="none" placeholder="" placeholderClass="text-30"
  111. font-size="30rpx" :custom-style="customStyle" readonly>
  112. </uv-input>
  113. <ie-image slot="right" src="/static/image/icon-lock.png" custom-class="w-24 h-30" mode="aspectFill" />
  114. </uv-form-item>
  115. </content-card>
  116. </uv-form>
  117. </view>
  118. <ie-safe-toolbar :height="84" :shadow="false">
  119. <view class="px-30 py-16">
  120. <ie-button @click="handleSubmit">确认保存</ie-button>
  121. </view>
  122. </ie-safe-toolbar>
  123. </ie-page>
  124. <uv-popup ref="popupRef" title="换绑手机号" mode="bottom" :round="16">
  125. <view class="theme-ie popup-content pt-100 py-30 px-30">
  126. <ie-input v-model="phoneForm.phone" type="number" :maxlength="11" placeholder="请输入新手机号" />
  127. <ie-input custom-class="mt-28" type="number" :maxlength="6" v-model="phoneForm.code" placeholder="请输入验证码">
  128. <ie-sms :phone="phoneForm.phone" :sms-api-type="EnumSmsApiType.NO_TOKEN" :beforeSend="handleBeforeSend"
  129. @send="handleSendSuccess" />
  130. </ie-input>
  131. <view class="mt-80 mb-16">
  132. <ie-button @click="handleChangePhone">确认更换</ie-button>
  133. </view>
  134. </view>
  135. </uv-popup>
  136. </template>
  137. <script lang="ts" setup>
  138. import ContentCard from '@/pagesSystem/components/content-card.vue';
  139. import { updateUserInfo } from '@/api/modules/login';
  140. import { useUserStore } from '@/store/userStore';
  141. import { useSchool } from '@/composables/useSchool';
  142. import { BindCardInfo, UserInfo } from '@/types/user';
  143. import { EnumDictName, EnumSmsApiType, EnumExamType } from '@/common/enum';
  144. import { validatePhone } from '@/hooks/useValidation';
  145. import { validateSms } from '@/api/modules/system';
  146. const userStore = useUserStore();
  147. const userInfo = computed(() => userStore.userInfo);
  148. const cardInfo = computed(() => userStore.card);
  149. const { classList, loadClassData } = useSchool();
  150. const form = ref<UserInfo>({
  151. ...userInfo.value
  152. });
  153. if (userStore.isStudent) {
  154. form.value.schoolName = cardInfo.value?.schoolName || '';
  155. form.value.classId = cardInfo.value?.classId || undefined;
  156. form.value.schoolClassName = cardInfo.value?.className || '';
  157. form.value.schoolId = cardInfo.value?.schoolId || undefined
  158. }
  159. const scores = ref({
  160. ...userInfo.value.scores
  161. })
  162. const customStyle = {
  163. paddingLeft: '26px'
  164. };
  165. const handleSubmit = async () => {
  166. uni.$ie.showLoading();
  167. const params = {
  168. ...userInfo.value,
  169. ...form.value,
  170. scores: scores.value,
  171. } as UserInfo;
  172. await updateUserInfo(params);
  173. await userStore.getUserInfo();
  174. uni.$ie.hideLoading();
  175. uni.$ie.showToast('保存成功');
  176. }
  177. const popupRef = ref();
  178. const phoneForm = ref({
  179. phone: '',
  180. code: '',
  181. uuid: ''
  182. });
  183. const handleBeforeSend = () => {
  184. if (phoneForm.value.phone === userInfo.value.phonenumber) {
  185. uni.$ie.showToast('新手机号不能与旧手机号相同');
  186. return false;
  187. }
  188. return true;
  189. }
  190. const handleBindPhone = () => {
  191. popupRef.value.open();
  192. }
  193. const handleSendSuccess = (_phone: string, _code: string, _uuid: string) => {
  194. phoneForm.value.uuid = _uuid;
  195. }
  196. const handleChangePhone = async () => {
  197. if (phoneForm.value.phone.trim() === '') {
  198. uni.$ie.showToast('请输入新手机号');
  199. return;
  200. }
  201. if (phoneForm.value.code.trim() === '') {
  202. uni.$ie.showToast('请输入验证码');
  203. return;
  204. }
  205. if (phoneForm.value.phone === userInfo.value.phonenumber) {
  206. uni.$ie.showToast('新手机号不能与旧手机号相同');
  207. return;
  208. }
  209. uni.$ie.showLoading();
  210. const valid = await validateSms({
  211. code: phoneForm.value.code,
  212. uuid: phoneForm.value.uuid,
  213. mobile: phoneForm.value.phone
  214. });
  215. uni.$ie.hideLoading();
  216. if (!valid) {
  217. uni.$ie.showToast('请输入正确的验证码');
  218. return;
  219. }
  220. form.value.phonenumber = phoneForm.value.phone;
  221. popupRef.value.close();
  222. }
  223. onLoad(() => {
  224. loadClassData(cardInfo.value?.schoolId);
  225. });
  226. </script>
  227. <style lang="scss" scoped></style>