register.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view>
  3. <navigation-bar background-color="#fff" front-color="#000000" />
  4. <view class="remain">
  5. <h1>账号注册</h1>
  6. </view>
  7. <view class="form">
  8. <u-form :model="form" ref="uForm" label-width="100px" label-position="top">
  9. <u-form-item label="手机号" prop="phone">
  10. <view class="form-input">
  11. <u-input v-model="form.phone" type="number" border="surround" maxlength='11'
  12. placeholder='请输入手机号码' :clearable='false' />
  13. </view>
  14. </u-form-item>
  15. <!-- <u-form-item label="选择你的身份" prop="type">
  16. <view class="form-input" @click="show=true" >
  17. <u-input v-model="form.type" type="text"
  18. placeholder='请选择你的身份' :clearable='false' disabled />
  19. <u-picker :show="show" :columns="columns" @confirm="confirm" @change="changeHandler"></u-picker>
  20. </view>
  21. </u-form-item> -->
  22. <u-form-item label="验证码" prop="smsCode">
  23. <view class="form-input">
  24. <u-input placeholder="请输入验证码" v-model="form.smsCode">
  25. <template slot="suffix">
  26. <span class="code" @click="getCode">{{code}}</span>
  27. </template>
  28. </u-input>
  29. </view>
  30. </u-form-item>
  31. <u-form-item label="密码" prop="password">
  32. <view class="form-input">
  33. <u-input v-model="form.password" type="password" placeholder='请输入密码' :clearable='false' />
  34. </view>
  35. </u-form-item>
  36. <u-form-item label="确认密码" prop="rePassword">
  37. <view class="form-input">
  38. <u-input v-model="form.rePassword" type="password" placeholder='请输入密码' :clearable='false' />
  39. </view>
  40. </u-form-item>
  41. </u-form>
  42. <view class="btn">
  43. <view style="margin-bottom: 20rpx;font-size: 28rpx;">
  44. <u-checkbox-group v-model="value" :wrap="true">
  45. <u-checkbox name="1"></u-checkbox>登录同意<text class="blue-class" @click="getAgreement(1)">《用户协议》</text>和<text
  46. class="blue-class" @click="getAgreement(2)">《隐私政策》</text>
  47. </u-checkbox-group>
  48. </view>
  49. <view>
  50. <u-button type="error" shape="circle" text="注册" @click="submit()"></u-button>
  51. </view>
  52. <view class="tip" @click="toLogin()">已有账号,去<text class="blue-class"
  53. style="margin-left: 10rpx;">登录</text></view>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. export default {
  60. data() {
  61. const passwordValid = (rule, value, callback) => {
  62. value == this.form.password ? callback() : callback(new Error('两次输入密码不一致'))
  63. };
  64. return {
  65. time: 60,
  66. code: '获取验证码',
  67. value: ['1'],
  68. form: {
  69. phone: '',
  70. smsCode: '',
  71. password: '',
  72. type: '',
  73. rePassword: '',
  74. },
  75. rules: {
  76. phone: [{
  77. required: true,
  78. message: '请输入手机号',
  79. trigger: 'blur,change'
  80. },
  81. {
  82. validator: (rule, value, callback) => {
  83. return uni.$u.test.mobile(value);
  84. },
  85. message: '手机号码不正确',
  86. trigger: ['change', 'blur'],
  87. }
  88. ],
  89. password: [{
  90. required: true,
  91. message: '请输入密码',
  92. trigger: 'blur,change'
  93. }],
  94. rePassword: [{
  95. validator: passwordValid,
  96. required: true,
  97. trigger:'blur'
  98. }],
  99. },
  100. }
  101. },
  102. onReady() {
  103. this.$refs.uForm.setRules(this.rules);
  104. },
  105. onLoad(option) {
  106. this.form.type=option.type
  107. },
  108. created() {},
  109. methods: {
  110. startCount() {
  111. setTimeout(() => {
  112. let time = this.time;
  113. if (time == 0) {
  114. this.code = '重新获取';
  115. this.time = 60;
  116. return;
  117. }
  118. this.time = --time;
  119. this.code = time + '后重新获取';
  120. this.startCount();
  121. }, 1000)
  122. },
  123. getCode() {
  124. let time = this.time;
  125. if (time > 0 && time < 60) {
  126. return;
  127. }
  128. let phone = this.form.phone;
  129. if (!this.$common.isPhone(phone)) {
  130. this.$common.toast('请输入正确的手机号');
  131. return;
  132. }
  133. this.startCount();
  134. this.$api.getPhoneSmsCode().then(resp => {
  135. this.$common.toast('已发送');
  136. })
  137. },
  138. submit() {
  139. this.$refs.uForm.validate().then(res => {
  140. let value = this.value;
  141. if (value.length == 0) {
  142. this.$common.toast('请先同意协议');
  143. return;
  144. }
  145. this.$api.doRefister(this.form).then(res => {
  146. if (res.code == 200) {
  147. uni.$u.toast('注册成功')
  148. uni.navigateTo({
  149. url: '/pages/login/login'
  150. });
  151. }
  152. }).catch(err => {
  153. console.log(err)
  154. })
  155. }).catch(errors => {})
  156. },
  157. toLogin() {
  158. uni.navigateTo({
  159. url: '/pages/login/login'
  160. });
  161. },
  162. getAgreement(id) {
  163. this.$common.to('/pages/login/userAgreement?id='+id)
  164. }
  165. // changeHandler(e){
  166. // console.log(e)
  167. // this.form.type=e.value[0]
  168. // },
  169. // confirm(e) {
  170. // // console.log(e)
  171. // this.show=false
  172. // }
  173. }
  174. }
  175. </script>
  176. <style lang="scss">
  177. page {
  178. background-color: #fff;
  179. padding: 30px;
  180. }
  181. .remain {
  182. margin: 10px;
  183. margin: 30rpx 150rpx 0;
  184. text-align: center;
  185. }
  186. .wel {
  187. margin-top: 10px;
  188. }
  189. .form {
  190. height: 200px;
  191. }
  192. .form-input {
  193. width: 100%;
  194. background-color: #f5f5f5;
  195. margin-top: 5px;
  196. border-radius: 20rpx;
  197. border: none;
  198. }
  199. .btn {
  200. margin: 25px 10px;
  201. }
  202. .tip {
  203. margin-top: 30px;
  204. text-align: center;
  205. font-size: 14px;
  206. }
  207. .code {
  208. color: red;
  209. font-size: 13px;
  210. }
  211. .blue-class {
  212. color: #55aaff;
  213. cursor: pointer;
  214. }
  215. </style>