register.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view class="login">
  3. <view class="dk" style="margin-top: 30px">
  4. <view class="bg">
  5. <text class="icon">&#xe8b9;</text>
  6. <input type="number" maxlength="11" v-model="form.phone" placeholder="请输入手机号" />
  7. </view>
  8. <view class="bg">
  9. <text class="icon">&#xe624;</text>
  10. <input type="number" v-model="form.smsCode" placeholder="验证码" />
  11. <view class="label">获取验证码</view>
  12. </view>
  13. <view class="bg">
  14. <text class="icon">&#xe8b2;</text>
  15. <input :password="show" v-model="form.password" placeholder="请输入密码" />
  16. <view class="label">
  17. <view class="icon" :class="{ active: !show }" @click="show = !show">&#xe7a6;</view>
  18. </view>
  19. </view>
  20. <view class="bg">
  21. <text class="icon">&#xe8b2;</text>
  22. <input :password="show" v-model="form.rePassword" placeholder="确认密码" />
  23. <view class="label">
  24. <view class="icon" :class="{ active: !show }" @click="show = !show">&#xe7a6;</view>
  25. </view>
  26. </view>
  27. <view class="xy">
  28. <u-checkbox-group class="checkbox" v-model="form.checked">
  29. <u-checkbox size="15" shape="circle" label="我已阅读并同意" labelSize="13" name="true"></u-checkbox>
  30. </u-checkbox-group>
  31. <text class="a" @click="getAgreement(1)">《用户协议》</text>
  32. <text>和</text>
  33. <text class="a" @click="getAgreement(2)">《隐私政策》</text>
  34. </view>
  35. <button class="btn" @click="submit()">确定</button>
  36. <button class="btn register" @click="toLogin()">返回</button>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. show: true,
  45. time: 60,
  46. code: '获取验证码',
  47. form: {}
  48. };
  49. },
  50. onLoad(option) {
  51. this.form.type = option.type;
  52. },
  53. created() {},
  54. methods: {
  55. startCount() {
  56. setTimeout(() => {
  57. let time = this.time;
  58. if (time == 0) {
  59. this.code = '重新获取';
  60. this.time = 60;
  61. return;
  62. }
  63. this.time = --time;
  64. this.code = time + '后重新获取';
  65. this.startCount();
  66. }, 1000);
  67. },
  68. getCode() {
  69. let time = this.time;
  70. if (time > 0 && time < 60) {
  71. return;
  72. }
  73. let phone = this.form.phone;
  74. if (!this.$common.isPhone(phone)) {
  75. this.$common.toast('请输入正确的手机号');
  76. return;
  77. }
  78. this.startCount();
  79. this.$api.getPhoneSmsCode().then(resp => {
  80. this.$common.toast('已发送');
  81. });
  82. },
  83. submit() {
  84. let rule = [{
  85. name: 'phone',
  86. checkType: 'phone',
  87. errorMsg: '请输入正确的手机号码'
  88. },
  89. {
  90. name: 'smsCode',
  91. checkType: 'notnull',
  92. errorMsg: '请输入验证码'
  93. },
  94. {
  95. name: 'password',
  96. checkType: 'notnull',
  97. errorMsg: '请输入密码'
  98. },
  99. {
  100. name: 'rePassword',
  101. checkType: 'same',
  102. checkRule: this.form.password,
  103. errorMsg: '两次输入不一致'
  104. },
  105. {
  106. name: 'checked',
  107. checkType: 'notnull',
  108. errorMsg: '请同意并勾选协议'
  109. }
  110. ];
  111. if (!this.verify.check(this.form, rule)) {
  112. uni.showModal({
  113. content: this.verify.error,
  114. showCancel: false
  115. });
  116. return false;
  117. }
  118. this.http.request({
  119. url: '/sp-admin/app/AppUser/register',
  120. data: this.form,
  121. contentType: 'application/json; charset=utf-8',
  122. method: 'POST',
  123. success: resp => {
  124. setTimeout(function (){
  125. uni.showToast({title: '注册成功'});
  126. uni.navigateTo({
  127. url: '/pages/login/login'
  128. });
  129. },1000)
  130. }
  131. });
  132. },
  133. toLogin() {
  134. uni.navigateTo({
  135. url: '/pages/login/login'
  136. });
  137. },
  138. getAgreement(id) {
  139. uni.navigateTo({
  140. url: '/pages/login/userAgreement?id=' + id
  141. });
  142. }
  143. }
  144. };
  145. </script>
  146. <style lang="scss"></style>