register.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view class="container">
  3. <u-form :model="registerForm" ref="registerForm" label-width="160"
  4. :label-style="{ color: '#000', fontSize: '30rpx'}">
  5. <u-form-item label="账号" prop="zhangHao" required :border-bottom="false">
  6. <u-input height="80" placeholder="请输入账号" border-color="#d0d0d0" v-model="registerForm.zhangHao"
  7. :border="true" class="form-item-input" />
  8. </u-form-item>
  9. <u-form-item label="密码" prop="miMa" required :border-bottom="false">
  10. <u-input height="80" placeholder="请输入密码" border-color="#d0d0d0" v-model="registerForm.miMa"
  11. :border="true" class="form-item-input" type="password" />
  12. </u-form-item>
  13. <u-form-item label="确认密码" prop="queRenMiMa" required :border-bottom="false">
  14. <u-input height="80" placeholder="请确认密码" border-color="#d0d0d0" v-model="registerForm.queRenMiMa"
  15. :border="true" class="form-item-input" type="password" />
  16. </u-form-item>
  17. <u-form-item label="手机号码" prop="shouJiHaoMa" required :border-bottom="false">
  18. <u-input height="80" placeholder="请输入手机号" border-color="#d0d0d0" v-model="registerForm.shouJiHaoMa"
  19. :border="true" class="form-item-input" type="number" />
  20. </u-form-item>
  21. <u-form-item label="身份证" prop="shenFenZheng" :border-bottom="false">
  22. <u-input height="80" placeholder="请输入身份证" border-color="#d0d0d0" v-model="registerForm.shenFenZheng"
  23. :border="true" class="form-item-input" />
  24. </u-form-item>
  25. <u-form-item label="性别" prop="xingBie" required :border-bottom="false">
  26. <u-radio-group v-model="registerForm.xingBie">
  27. <u-radio v-for="(item, index) in radioList1" :key="index" :name="item.name"
  28. :disabled="item.disabled">
  29. {{ item.text }}
  30. </u-radio>
  31. </u-radio-group>
  32. </u-form-item>
  33. <view class="form-button" @click="submit">
  34. 注册
  35. </view>
  36. <view class="form-tip" @click="back">已有账号,立即登录</view>
  37. </u-form>
  38. </view>
  39. </template>
  40. <script>
  41. import {
  42. msg
  43. } from "@/utils/common.js"
  44. export default {
  45. data() {
  46. return {
  47. registerForm: {
  48. zhangHao: '', //账号
  49. miMa: "", //密码
  50. queRenMiMa: '', // 确认密码
  51. shouJiHaoMa: '', // 手机号码
  52. shenFenZheng: '', // 身份证
  53. xingBie: '' // 性别
  54. },
  55. radioList1: [{
  56. name: '男',
  57. text: '男',
  58. disabled: false
  59. },
  60. {
  61. name: '女',
  62. text: '女',
  63. disabled: false
  64. }
  65. ],
  66. rules: {
  67. zhangHao: [{
  68. required: true,
  69. message: '请输入账号',
  70. trigger: ['blur']
  71. }],
  72. miMa: [{
  73. required: true,
  74. message: '请输入密码',
  75. trigger: ['blur']
  76. }],
  77. queRenMiMa: [{
  78. required: true,
  79. message: '请确认密码',
  80. trigger: ['blur']
  81. }, {
  82. required: true,
  83. message: "密码与确认密码不一致",
  84. trigger: ['blur'],
  85. validator: this.validateConfirmPassword
  86. }],
  87. shouJiHaoMa: [{
  88. required: true,
  89. message: '请输入手机号码',
  90. trigger: ['blur']
  91. }, {
  92. pattern: /^1[3-9]\d{9}$/,
  93. message: '请输入正确的手机号',
  94. trigger: ['blur']
  95. }],
  96. shenFenZheng: [{
  97. pattern: /^(?:\d{15}|\d{17}[\dXx])$/,
  98. transform(value) {
  99. return String(value);
  100. },
  101. message: '请输入正确的手机号',
  102. trigger: ['blur']
  103. }],
  104. xingBie: [{
  105. required: true,
  106. message: '请选择性别',
  107. trigger: ['change']
  108. }]
  109. }
  110. };
  111. },
  112. methods: {
  113. validateConfirmPassword(rule, value, callback) {
  114. if (value !== this.registerForm.miMa) {
  115. callback(new Error('密码与确认密码不一致'));
  116. } else {
  117. callback(); // 校验通过
  118. }
  119. },
  120. submit() {
  121. const that = this;
  122. that.$refs.registerForm.validate((valid) => {
  123. console.log(valid, that.registerForm.xingBie, 456);
  124. if (valid) {
  125. msg("数据验证成功")
  126. }
  127. })
  128. },
  129. // 提示
  130. showToast(msg, type) {
  131. uni.showToast({
  132. icon: type ? type : "none",
  133. title: msg
  134. })
  135. },
  136. back() {
  137. uni.navigateBack({
  138. delta: 1,
  139. animationType: 'pop-out',
  140. animationDuration: 200
  141. })
  142. }
  143. },
  144. onLoad() {},
  145. onReady() {
  146. this.$refs.registerForm.setRules(this.rules);
  147. }
  148. }
  149. </script>
  150. <style lang="scss">
  151. .u-form-item {
  152. padding: 30rpx 0 !important;
  153. }
  154. .u-form-item .u-input--border {
  155. border-radius: 16rpx !important;
  156. }
  157. .u-form-item .u-form-item--left__content__label {
  158. display: block !important;
  159. text-align: justify;
  160. text-align-last: justify;
  161. padding: 0 20rpx 0 10rpx;
  162. }
  163. .u-input {
  164. background-color: #f7f7f7 !important;
  165. }
  166. </style>
  167. <style lang="scss" scoped>
  168. .container {
  169. height: 100vh;
  170. width: 100vw;
  171. background-color: #ffffff;
  172. padding: 0 40rpx;
  173. }
  174. .form-item-input {
  175. width: 100%;
  176. }
  177. .form-button {
  178. background: linear-gradient(90deg, #006af5, #21b0fc);
  179. border-radius: 20rpx;
  180. line-height: 80rpx;
  181. text-align: center;
  182. color: #fff;
  183. margin: 20rpx 0 50rpx;
  184. }
  185. .form-tip {
  186. text-align: center;
  187. color: #000000;
  188. }
  189. </style>