register.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="container">
  3. <u-form :model="registerForm" ref="registerForm" label-width="180"
  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="#b1b1b1" 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="#b1b1b1" 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="#b1b1b1" 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="#b1b1b1" 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="#b1b1b1" 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. export default {
  42. data() {
  43. return {
  44. registerForm: {
  45. zhanghao: '', //账号
  46. mima: "", //密码
  47. querenmima: '', // 确认密码
  48. shoujihaoma: '', // 手机号码
  49. shenfenzheng: '', // 身份证
  50. xingbie: '' // 性别
  51. },
  52. radioList1: [{
  53. name: '男',
  54. text: '男',
  55. disabled: false
  56. },
  57. {
  58. name: '女',
  59. text: '女',
  60. disabled: false
  61. }
  62. ],
  63. rules: {
  64. zhanghao: [{
  65. required: true,
  66. message: '请输入账号',
  67. trigger: ['blur']
  68. }],
  69. mima: [{
  70. required: true,
  71. message: '请输入密码',
  72. trigger: ['blur']
  73. }],
  74. querenmima: [{
  75. required: true,
  76. message: "密码与确认密码不一致",
  77. trigger: ['blur'],
  78. validator: this.validateConfirmPassword
  79. }],
  80. shoujihaoma: [{
  81. required: true,
  82. message: '请输入手机号码',
  83. trigger: ['blur']
  84. }, {
  85. pattern: /^1[3-9]\d{9}$/,
  86. message: '请输入正确的手机号',
  87. trigger: ['blur']
  88. }],
  89. shenfenzheng: [{
  90. pattern: /^(?:\d{15}|\d{17}[\dXx])$/,
  91. transform(value) {
  92. return String(value);
  93. },
  94. message: '请输入正确的手机号',
  95. trigger: ['blur']
  96. }],
  97. xingbie: [{
  98. required: true,
  99. message: '请选择性别',
  100. trigger: ['change']
  101. }]
  102. }
  103. };
  104. },
  105. methods: {
  106. validateConfirmPassword(rule, value, callback) {
  107. if (value !== this.registerForm.mima) {
  108. callback(new Error('密码与确认密码不一致'));
  109. } else {
  110. callback(); // 校验通过
  111. }
  112. },
  113. submit() {
  114. const that = this;
  115. that.$refs.registerForm.validate((valid) => {
  116. console.log(valid, that.registerForm.xingbie, 456);
  117. if (valid) {
  118. that.showToast("数据验证成功")
  119. }
  120. })
  121. },
  122. // 提示
  123. showToast(msg, type) {
  124. this.$refs.uToast.show({
  125. title: msg,
  126. type: type ? type : "error",
  127. position: "top"
  128. })
  129. },
  130. back(){
  131. uni.navigateBack({
  132. delta: 1,
  133. animationType: 'pop-out',
  134. animationDuration: 200
  135. })
  136. }
  137. },
  138. onLoad() {},
  139. onReady() {
  140. this.$refs.registerForm.setRules(this.rules);
  141. }
  142. }
  143. </script>
  144. <style lang="scss">
  145. .u-form-item {
  146. padding: 30rpx 0 !important;
  147. }
  148. .u-form-item .u-form-item--left__content__label {
  149. display: block !important;
  150. text-align: justify;
  151. text-align-last: justify;
  152. padding: 0 20rpx 0 10rpx;
  153. }
  154. .u-input {
  155. background-color: #f7f7f7 !important;
  156. }
  157. </style>
  158. <style lang="scss" scoped>
  159. .container {
  160. height: 100vh;
  161. width: 100vw;
  162. background-color: #ffffff;
  163. padding: 0 40rpx;
  164. }
  165. .form-item-input {
  166. width: 100%;
  167. }
  168. .form-button {
  169. background: linear-gradient(90deg, #006af5, #21b0fc);
  170. border-radius: 20rpx;
  171. line-height: 80rpx;
  172. text-align: center;
  173. color: #fff;
  174. margin: 20rpx 0 50rpx;
  175. }
  176. .form-tip{
  177. text-align: center;
  178. color: #000000;
  179. }
  180. </style>