register.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <view>
  3. <view class="logo">
  4. <image src="../../static/logo.png" mode="aspectFit"></image>
  5. </view>
  6. <view class="form">
  7. <uni-forms ref="form" :modelValue="formData" :rules="rules" :label-width="90" label-align="right">
  8. <uni-forms-item label="所在地" name="provinceCode">
  9. <view class="form-item">
  10. <uni-data-select :clear="false" v-model="formData.provinceCode" placeholder="请选择您所在的省市"
  11. :localdata="provinces"></uni-data-select>
  12. <view class="des-text">省/市</view>
  13. </view>
  14. </uni-forms-item>
  15. <!-- <uni-forms-item label="学校" name="name">
  16. <uni-easyinput type="text" :clearable="false" v-model="formData.mobile" placeholder="请输入所在学校" />
  17. </uni-forms-item> -->
  18. <uni-forms-item label="高考年份" name="enrollYear">
  19. <view class="form-item">
  20. <uni-data-select :clear="false" v-model="formData.enrollYear" placeholder="请选择您的高考年份"
  21. :localdata="years"></uni-data-select>
  22. <view class="des-text"></view>
  23. </view>
  24. </uni-forms-item>
  25. <uni-forms-item label="姓名" name="name">
  26. <view class="form-item">
  27. <uni-easyinput type="text" :clearable="false" v-model="formData.name" placeholder="请输入姓名" />
  28. <view class="des-text"></view>
  29. </view>
  30. </uni-forms-item>
  31. <uni-forms-item label="性别" name="gender">
  32. <view class="form-item">
  33. <uni-data-checkbox v-model="formData.gender" :localdata="genders"></uni-data-checkbox>
  34. <view class="des-text"></view>
  35. </view>
  36. </uni-forms-item>
  37. </uni-forms>
  38. <button class="submit" :class="{'submit-disabled': !isDisabled}" @click="submit">提交</button>
  39. </view>
  40. </view>
  41. </template>
  42. <script lang="ts" setup>
  43. import { ref, reactive, computed } from 'vue'
  44. import { onLoad } from '@dcloudio/uni-app'
  45. import { getFutureYears } from '@/utils/index'
  46. import { provincesList, registerUser, prefUser } from '@/api/h5.js'
  47. const unitCode = ref('')
  48. const isDisabled = computed(() => {
  49. return formData.enrollYear && formData.gender && formData.name && formData.provinceCode
  50. })
  51. const formData = reactive({
  52. enrollYear: '',
  53. mobilePhone: '',
  54. gender: '',
  55. name: '',
  56. password: '',
  57. provinceCode: '',
  58. })
  59. const rules = reactive({
  60. enrollYear: {
  61. rules: [{
  62. required: true,
  63. errorMessage: '请选择您的高考年份',
  64. }]
  65. },
  66. gender: {
  67. rules: [{
  68. required: true,
  69. errorMessage: '请选择性别',
  70. }]
  71. },
  72. name: {
  73. rules: [{
  74. required: true,
  75. errorMessage: '请输入姓名',
  76. }]
  77. },
  78. provinceCode: {
  79. rules: [{
  80. required: true,
  81. errorMessage: '请选择您所在的省市',
  82. }]
  83. },
  84. })
  85. const genders = ref([
  86. { "value": '男', "text": "男" },
  87. { "value": '女', "text": "女" }
  88. ])
  89. const years = ref([])
  90. const provinces = ref([])
  91. const getProvincesList = async () => {
  92. const res = await provincesList({})
  93. if (res.code === 200) {
  94. provinces.value = Object.keys(res.data)?.map((item, index) => {
  95. return {
  96. value: item,
  97. text: res.data[item]
  98. }
  99. })?.filter(item => item.value != '65')
  100. }
  101. }
  102. const handlePrefUser = async () => {
  103. const res = await prefUser({
  104. mobilePhone: formData.mobilePhone,
  105. prefUnitCode: unitCode.value
  106. })
  107. if(res.code === 200) {
  108. // uni.showToast({
  109. // title: res.message,
  110. // icon: 'none'
  111. // })
  112. setTimeout(() => {
  113. uni.reLaunch({
  114. url: `/pages/result/result?provinceCode=${formData.provinceCode}`
  115. })
  116. }, 800)
  117. }
  118. }
  119. const form = ref()
  120. const submit = () => {
  121. if(isDisabled.value) {
  122. form.value.validate().then(async data => {
  123. const res = await registerUser(formData)
  124. if(res.code === 200) {
  125. handlePrefUser()
  126. }
  127. })
  128. }
  129. }
  130. onLoad((options) => {
  131. const parameter = JSON.parse(decodeURIComponent(options.parameter));
  132. unitCode.value = parameter.unitCode
  133. formData.mobilePhone = parameter.mobilePhone
  134. formData.password = parameter.password
  135. years.value = getFutureYears(3)?.map(item => {
  136. return {
  137. value: item,
  138. text: item
  139. }
  140. })
  141. getProvincesList()
  142. })
  143. </script>
  144. <style lang="scss" scoped>
  145. .form {
  146. padding: 0 40rpx;
  147. :deep(.uni-easyinput__content) {
  148. border: none;
  149. }
  150. :deep(.uni-forms-item__label) {
  151. height: 88rpx;
  152. font-weight: 500;
  153. font-size: 32rpx;
  154. color: #1D2129;
  155. line-height: 38rpx;
  156. }
  157. :deep(.uni-stat__select) {
  158. height: 88rpx;
  159. border-radius: 24rpx;
  160. background: #F1F5FE;
  161. .uni-stat-box {
  162. height: 88rpx;
  163. .uni-select {
  164. height: 100%;
  165. border: none;
  166. .uni-select__input-text {
  167. font-weight: 500;
  168. font-size: 32rpx;
  169. color: #1D2129;
  170. }
  171. .uni-select__input-placeholder {
  172. font-weight: 400;
  173. font-size: 32rpx;
  174. color: #86909C;
  175. line-height: 38rpx;
  176. }
  177. .uni-icons {
  178. font-size: 32rpx !important;
  179. margin-right: 10rpx;
  180. }
  181. }
  182. }
  183. }
  184. :deep(.uni-data-checklist) {
  185. height: 88rpx;
  186. display: flex;
  187. align-items: center;
  188. .radio__inner {
  189. width: 32rpx !important;
  190. height: 32rpx !important;
  191. }
  192. .radio__inner-icon {
  193. width: 16rpx !important;
  194. height: 16rpx !important;
  195. }
  196. .checklist-text {
  197. font-weight: 400;
  198. font-size: 36rpx !important;
  199. color: #1D2129;
  200. }
  201. }
  202. :deep(.uni-easyinput__content-input) {
  203. background: #F1F5FE;
  204. height: 88rpx;
  205. border-radius: 24rpx;
  206. font-weight: 500;
  207. font-size: 32rpx;
  208. color: #1D2129;
  209. line-height: 38rpx;
  210. }
  211. :deep(.uni-input-placeholder) {
  212. font-weight: 400;
  213. font-size: 32rpx;
  214. color: #86909C;
  215. line-height: 38rpx;
  216. }
  217. .form-area {
  218. width: 100%;
  219. background: #F1F5FE;
  220. border-radius: 24rpx;
  221. height: 88rpx;
  222. :deep(.input-block) {
  223. width: calc(100% - 10px);
  224. height: 88rpx;
  225. padding-left: 10px;
  226. }
  227. }
  228. .submit {
  229. height: 112rpx;
  230. background: #3682EA;
  231. border-radius: 24rpx;
  232. font-weight: 500;
  233. font-size: 36rpx;
  234. color: #FFFFFF;
  235. display: flex;
  236. align-items: center;
  237. justify-content: center;
  238. margin-top: 128rpx;
  239. }
  240. .submit-disabled {
  241. background: #B0CDFF;
  242. }
  243. .form-item {
  244. display: flex;
  245. align-items: center;
  246. .des-text {
  247. width: 80rpx;
  248. font-weight: 400;
  249. font-size: 32rpx;
  250. color: #4E5969;
  251. margin-left: 20rpx;
  252. }
  253. }
  254. }
  255. </style>