register.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. console.log(option.type)
  107. this.form.type=option.type
  108. },
  109. created() {},
  110. methods: {
  111. startCount() {
  112. setTimeout(() => {
  113. let time = this.time;
  114. if (time == 0) {
  115. this.code = '重新获取';
  116. this.time = 60;
  117. return;
  118. }
  119. this.time = --time;
  120. this.code = time + '后重新获取';
  121. this.startCount();
  122. }, 1000)
  123. },
  124. getCode() {
  125. let time = this.time;
  126. if (time > 0 && time < 60) {
  127. return;
  128. }
  129. let phone = this.form.phone;
  130. if (!this.$common.isPhone(phone)) {
  131. this.$common.toast('请输入正确的手机号');
  132. return;
  133. }
  134. this.startCount();
  135. this.$api.getPhoneSmsCode().then(resp => {
  136. this.$common.toast('已发送');
  137. })
  138. },
  139. submit() {
  140. this.$refs.uForm.validate().then(res => {
  141. let value = this.value;
  142. if (value.length == 0) {
  143. this.$common.toast('请先同意协议');
  144. return;
  145. }
  146. this.$api.doRefister(this.form).then(res => {
  147. if (res.code == 200) {
  148. uni.$u.toast('注册成功')
  149. uni.navigateTo({
  150. url: '/pages/login/login'
  151. });
  152. }
  153. }).catch(err => {
  154. console.log(err)
  155. })
  156. }).catch(errors => {})
  157. },
  158. toLogin() {
  159. uni.navigateTo({
  160. url: '/pages/login/login'
  161. });
  162. },
  163. getAgreement(id) {
  164. this.$common.to('/pages/login/userAgreement?id='+id)
  165. }
  166. // changeHandler(e){
  167. // console.log(e)
  168. // this.form.type=e.value[0]
  169. // },
  170. // confirm(e) {
  171. // // console.log(e)
  172. // this.show=false
  173. // }
  174. }
  175. }
  176. </script>
  177. <style lang="scss">
  178. page {
  179. background-color: #fff;
  180. padding: 30px;
  181. }
  182. .remain {
  183. margin: 10px;
  184. margin: 30rpx 150rpx 0;
  185. text-align: center;
  186. }
  187. .wel {
  188. margin-top: 10px;
  189. }
  190. .form {
  191. height: 200px;
  192. }
  193. .form-input {
  194. width: 100%;
  195. background-color: #f5f5f5;
  196. margin-top: 5px;
  197. border-radius: 20rpx;
  198. border: none;
  199. }
  200. .btn {
  201. margin: 25px 10px;
  202. }
  203. .tip {
  204. margin-top: 30px;
  205. text-align: center;
  206. font-size: 14px;
  207. }
  208. .code {
  209. color: red;
  210. font-size: 13px;
  211. }
  212. .blue-class {
  213. color: #55aaff;
  214. cursor: pointer;
  215. }
  216. </style>