register.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view class="container">
  3. <view class="status_bar"><!-- 这里是状态栏 --></view>
  4. <view class="loginTitle">欢迎注册和合商城</view>
  5. <view class="loginText">请认真填写个人信息</view>
  6. <view class="login-box">
  7. <view class="username">账号</view>
  8. <input class="input-box" type="text" v-model="phone" placeholder="请输入电话" />
  9. </view>
  10. <view class="login-box">
  11. <view class="username">验证码</view>
  12. <view class="flex">
  13. <input class="input-box" type="number" v-model="code" placeholder="请输入验证码" />
  14. <view class="code" @click="verification">{{ countDown == 0 ? '获取验证码' : countDown }}</view>
  15. </view>
  16. </view>
  17. <view class="login-box">
  18. <view class="username">登录密码</view>
  19. <input class="input-box" type="password" v-model="loginPass" placeholder="请输入登录密码" />
  20. </view>
  21. <!-- <view class="login-box">
  22. <view class="username">交易密码</view>
  23. <input class="input-box" type="password" v-model="payPass" placeholder="请输入6位数的交易密码" />
  24. </view> -->
  25. <view class="login-box" style="margin-bottom: 50rpx;">
  26. <view class="username">邀请码</view>
  27. <input class="input-box" type="text" v-model="invitation" placeholder="请输入邀请码" />
  28. </view>
  29. <label class="two" @click="checkboxChange">
  30. <radio style="transform:scale(0.7)" color="#30d9da" :checked="istype" />
  31. 我已阅读并同意
  32. <text @click.stop="navTo('/pages/contract/agreement')">《用户协议》</text>
  33. &nbsp
  34. <text @click.stop="navTo('/pages/contract/privacy')">《隐私政策》</text>
  35. </label>
  36. <view class="login" @click="register">注册</view>
  37. </view>
  38. </template>
  39. <script>
  40. import { register, verify } from '@/api/login.js';
  41. export default {
  42. data() {
  43. return {
  44. istype: false,
  45. phone: '', //用户
  46. loginPass: '', //密码
  47. payPass: '',
  48. invitation: '', //邀请码
  49. code: '', //验证码
  50. time: '', //保存倒计时对象
  51. countDown: 0 //倒计时
  52. };
  53. },
  54. onLoad() {
  55. // 获取扫码邀请人id
  56. this.invitation = uni.getStorageSync('spread') || '';
  57. },
  58. watch: {
  59. // 监听倒计时
  60. countDown(i) {
  61. if (i == 0) {
  62. clearInterval(this.time);
  63. }
  64. }
  65. },
  66. methods: {
  67. navTo(url){
  68. uni.navigateTo({
  69. url
  70. })
  71. },
  72. // 注册
  73. register() {
  74. let obj = this;
  75. if (obj.phone == '') {
  76. obj.$api.msg('请输入账号');
  77. return;
  78. }
  79. if (!/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(obj.phone) && (!/(^1[3|4|5|6|7|8|9][0-9]{9}$)/.test(this.phone))) {
  80. obj.$api.msg('请输入正确的手机');
  81. return;
  82. }
  83. if (obj.loginPass == '') {
  84. obj.$api.msg('请输入登录密码');
  85. return;
  86. }
  87. // if (obj.payPass == '') {
  88. // obj.$api.msg('请输入交易密码');
  89. // return;
  90. // }
  91. // if (obj.payPass.length != 6) {
  92. // obj.$api.msg('请输入交易密码只能为6位数');
  93. // return;
  94. // }
  95. if (obj.code == '') {
  96. obj.$api.msg('请输入验证码');
  97. return;
  98. }
  99. if (!obj.istype) {
  100. obj.$api.msg('请查看并同意用户协议和隐私政策');
  101. return;
  102. }
  103. if (obj.invitation == '') {
  104. obj.$api.msg('请输入邀请码');
  105. return;
  106. }
  107. register({
  108. account: obj.phone, //账号
  109. captcha: obj.code, //验证码
  110. password: obj.loginPass,
  111. trade_password: obj.payPass,
  112. spread: obj.invitation
  113. }).then(function(e) {
  114. uni.showToast({
  115. title: '注册成功',
  116. duration: 2000,
  117. position: 'top',
  118. icon: 'none'
  119. });
  120. setTimeout(function() {
  121. uni.navigateTo({
  122. url: '/pages/public/login'
  123. });
  124. }, 1000);
  125. }) ;
  126. //调用注册接口,成功跳转登录页
  127. },
  128. checkboxChange(){
  129. this.istype = !this.istype
  130. console.log(this.istype);
  131. },
  132. //发送验证码
  133. verification() {
  134. let obj = this;
  135. if (this.phone == '') {
  136. this.$api.msg('请输入账号');
  137. return;
  138. }
  139. if (!/^([a-zA-Z]|[0-9])(\w|\-|\.)+@[a-zA-Z0-9]+(\.([a-zA-Z]{2,4}))+$/.test(obj.phone) && (!/(^1[3|4|5|6|7|8|9][0-9]{9}$)/.test(this.phone))) {
  140. obj.$api.msg('请输入正确的账号');
  141. return;
  142. }
  143. // 判断是否在倒计时
  144. if (obj.countDown > 0) {
  145. return false;
  146. } else {
  147. obj.countDown = 60;
  148. obj.time = setInterval(() => {
  149. obj.countDown--;
  150. }, 1000);
  151. //调用验证码接口
  152. verify({
  153. phone: obj.phone,
  154. type: 'register'
  155. })
  156. .then(({ data }) => {
  157. uni.showToast({
  158. title: '验证码已发送',
  159. duration: 2000,
  160. position: 'top',
  161. icon: 'none'
  162. });
  163. })
  164. .catch(err => {
  165. console.log(err);
  166. });
  167. }
  168. }
  169. }
  170. };
  171. </script>
  172. <style lang="scss">
  173. page {
  174. min-height: 100%;
  175. background-color: #ffffff;
  176. .container {
  177. width: 100%;
  178. padding: 10% 60rpx 0rpx 60rpx;
  179. }
  180. }
  181. .status_bar {
  182. height: var(--status-bar-height);
  183. width: 100%;
  184. }
  185. .loginTitle {
  186. font-weight: bold;
  187. color: #333333;
  188. font-size: 58rpx;
  189. padding-bottom: 25rpx;
  190. }
  191. .loginText {
  192. font-weight: 500;
  193. color: #333333;
  194. font-size: 34rpx;
  195. }
  196. .login-box {
  197. padding-top: 70rpx;
  198. .username {
  199. padding-bottom: 25rpx;
  200. font-weight: 500;
  201. color: #333333;
  202. font-size: 32rpx;
  203. }
  204. }
  205. .login {
  206. background: linear-gradient(0deg, #2E58FF, #1dcbe4);
  207. margin-top: 20rpx;
  208. color: #ffffff;
  209. text-align: center;
  210. padding: 26rpx 0rpx;
  211. border-radius: 50rpx;
  212. margin-top: 60rpx;
  213. }
  214. .code {
  215. background: linear-gradient(0deg, #2E58FF, #1dcbe4);
  216. color: #ffffff;
  217. border-radius: 10rpx;
  218. font-weight: 500;
  219. color: #ffffff;
  220. font-size: 26rpx;
  221. padding: 12rpx 19rpx;
  222. }
  223. .two {
  224. margin: 20rpx 0;
  225. font-size: 28rpx;
  226. text-align: center;
  227. font-family: PingFang SC;
  228. font-weight: 500;
  229. color: #999999;
  230. text {
  231. color: #30d9da;
  232. }
  233. }
  234. // /* input 样式 */
  235. // .input-placeholder {
  236. // color: #ffffff;
  237. // }
  238. // .placeholder {
  239. // color: #ffffff;
  240. // }
  241. </style>