register.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view>
  3. <navigation-bar background-color="#fff" front-color="#000000" />
  4. <view class="remain">
  5. <h1>欢迎注册</h1>
  6. <view class="wel">请注册您的账号</view>
  7. </view>
  8. <view class="form">
  9. <u-form :model="form" ref="uForm" label-width="100px" label-position="top">
  10. <u-form-item label="手机号" prop="phone">
  11. <view class="form-input">
  12. <u-input v-model="form.phone" type="number" border="surround" maxlength='11'
  13. placeholder='请输入手机号码' :clearable='false' />
  14. </view>
  15. </u-form-item>
  16. <u-form-item label="选择你的身份" prop="type">
  17. <view class="form-input" @click="show=true" >
  18. <u-input v-model="form.type" type="text"
  19. placeholder='请选择你的身份' :clearable='false' disabled />
  20. <u-picker :show="show" :columns="columns" @confirm="confirm" @change="changeHandler"></u-picker>
  21. </view>
  22. </u-form-item>
  23. <u-form-item label="验证码" prop="smsCode">
  24. <view class="form-input">
  25. <view class="u-demo-block__content">
  26. <!-- 注意:由于兼容性差异,如果需要使用前后插槽,nvue下需使用u--input,非nvue下需使用u-input -->
  27. <!-- #ifndef APP-NVUE -->
  28. <u-input placeholder="请输入验证码">
  29. <!-- #endif -->
  30. <!-- #ifdef APP-NVUE -->
  31. <u--input placeholder="请输入验证码">
  32. <!-- #endif -->
  33. <template slot="suffix">
  34. <u-code ref="uCode" @change="codeChange" seconds="20"
  35. changeText="X秒重新获取哈哈哈"></u-code>
  36. <u-button @tap="getCode" :text="tips" type="error" size="mini"></u-button>
  37. </template>
  38. <!-- #ifndef APP-NVUE -->
  39. </u-input>
  40. <!-- #endif -->
  41. <!-- #ifdef APP-NVUE -->
  42. </u--input>
  43. <!-- #endif -->
  44. </view>
  45. </view>
  46. </u-form-item>
  47. <u-form-item label="密码" prop="password">
  48. <view class="form-input">
  49. <u-input v-model="form.password" type="password" placeholder='请输入密码' :clearable='false' />
  50. </view>
  51. </u-form-item>
  52. <u-form-item label="确认密码" prop="rePassword">
  53. <view class="form-input">
  54. <u-input v-model="form.rePassword" type="password" placeholder='请输入密码' :clearable='false' />
  55. </view>
  56. </u-form-item>
  57. </u-form>
  58. <view style="font-size: 13px;">忘记密码?</view>
  59. <view class="btn">
  60. <view style="margin-bottom: 10px;">
  61. <u-radio-group v-model="value" :wrap="true">
  62. <u-radio :label="radioLabel"></u-radio>
  63. </u-radio-group>
  64. </view>
  65. <view>
  66. <u-button type="error" shape="circle" text="注册" @click="submit()"></u-button>
  67. </view>
  68. <view class="tip" @click="toLogin()">已有账号,去登录</view>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. export default {
  75. data() {
  76. return {
  77. form: {
  78. phone: '',
  79. smsCode: '',
  80. password: '',
  81. type: '',
  82. nickName:'',
  83. rePassword: '',
  84. },
  85. rules: {
  86. phone: [{
  87. required: true,
  88. message: '请输入手机号',
  89. trigger: 'blur,change'
  90. },
  91. {
  92. validator: (rule, value, callback) => {
  93. return uni.$u.test.mobile(value);
  94. },
  95. message: '手机号码不正确',
  96. trigger: ['change', 'blur'],
  97. }
  98. ],
  99. password: [{
  100. required: true,
  101. message: '请输入密码',
  102. trigger: 'blur,change'
  103. }]
  104. },
  105. radioLabel: "登录同意《用户协议》和《隐私政策》",
  106. tips: '获取验证码',
  107. value: '',
  108. columns: [
  109. // ['边民', '经销商', '外籍商户','司机']
  110. [1,2,3,4]
  111. ],
  112. show: false
  113. }
  114. },
  115. onReady() {
  116. this.$refs.uForm.setRules(this.rules);
  117. },
  118. methods: {
  119. getCode() {
  120. if (this.$refs.uCode.canGetCode) {
  121. // 模拟向后端请求验证码
  122. uni.showLoading({
  123. title: '正在获取验证码'
  124. })
  125. setTimeout(() => {
  126. uni.hideLoading();
  127. // 这里此提示会被this.start()方法中的提示覆盖
  128. uni.$u.toast('验证码已发送');
  129. // 通知验证码组件内部开始倒计时
  130. this.$refs.uCode.start();
  131. }, 2000);
  132. } else {
  133. uni.$u.toast('倒计时结束后再发送');
  134. }
  135. },
  136. submit() {
  137. this.$refs.uForm.validate().then(res => {
  138. this.$api.doRefister(this.form).then(res => {
  139. console.log(res)
  140. if(res.code==200){
  141. uni.$u.toast('注册成功')
  142. uni.navigateTo({
  143. url: '/pages/login/login'
  144. });
  145. }
  146. }).catch(err => {
  147. console.log(err)
  148. })
  149. }).catch(errors => {
  150. uni.$u.toast('注册失败')
  151. })
  152. },
  153. radioChange() {
  154. console.log("1111")
  155. },
  156. toLogin() {
  157. uni.navigateTo({
  158. url: '/pages/login/login'
  159. });
  160. },
  161. changeHandler(e){
  162. console.log(e)
  163. this.form.type=e.value[0]
  164. },
  165. confirm(e) {
  166. // console.log(e)
  167. this.show=false
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss">
  173. page {
  174. background-color: #fff;
  175. padding: 30px;
  176. }
  177. .remain {
  178. margin: 50px 100px 0;
  179. text-align: center;
  180. }
  181. .wel {
  182. margin-top: 10px;
  183. }
  184. .form {
  185. height: 200px;
  186. }
  187. .form-input {
  188. width: 100%;
  189. background-color: #E8E8E8;
  190. border-radius: 5px;
  191. margin-top: 5px;
  192. }
  193. .btn {
  194. margin: 25px 10px;
  195. }
  196. .tip {
  197. margin-top: 30px;
  198. text-align: center;
  199. font-size: 14px;
  200. }
  201. </style>