register.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view style="position: relative;">
  3. <back></back>
  4. <view class="content">
  5. <view class="bg"></view>
  6. <view class="bg1"></view>
  7. <view class="top">
  8. <view class="title">
  9. <text>注册联兑通账号</text>
  10. <text>请输入手机号进行注册</text>
  11. </view>
  12. </view>
  13. <view style="width: 76%;margin-top: 80rpx;">
  14. <u-form :model="form" ref="uForm" :rules="rules" :error-type="['message']">
  15. <u-form-item label="手机号" prop="phone" label-width="150">
  16. <u-input :border="false" placeholder="请输入手机号" v-model="form.phone" type="number"></u-input>
  17. </u-form-item>
  18. <u-form-item label="验证码" prop="code" label-width="150">
  19. <view class="flex">
  20. <u-input style="width: 100%;" :border="false" placeholder="请输入验证码" v-model="form.code"
  21. type="text"></u-input>
  22. <u-button shape="circle" slot="right" :custom-style="customStyle" size="mini"
  23. @click="getCode">{{codeTips}}</u-button>
  24. </view>
  25. </u-form-item>
  26. <u-form-item label="密码" prop="password" label-width="150">
  27. <u-input :border="false" placeholder="请设置登录密码" v-model="form.password" type="password">
  28. </u-input>
  29. </u-form-item>
  30. <u-form-item label="确认密码" prop="newPassword" label-width="150">
  31. <u-input :border="false" placeholder="请再次输入密码" v-model="form.newPassword" type="password">
  32. </u-input>
  33. </u-form-item>
  34. </u-form>
  35. </view>
  36. <view style="width: 86%;margin-top: 100rpx;">
  37. <view @click="next" class="btn cu-btn round" style="width:100%;height: 90rpx;font-size: 34rpx;">
  38. 确认
  39. </view>
  40. <!-- <view class="center" style="margin-top: 100rpx;">
  41. <text style="color: #949494;">确认注册即代表已阅读并同意</text>
  42. <text style="color: #0000ff;">《软件服务协议》</text>
  43. </view> -->
  44. </view>
  45. </view>
  46. <u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
  47. </view>
  48. </template>
  49. <script>
  50. import md5Libs from "uview-ui/libs/function/md5";
  51. import back from "@/components/back.vue"
  52. export default {
  53. components:{
  54. back
  55. },
  56. data() {
  57. return {
  58. customStyle: {
  59. 'backgroundColor': '#EF9944',
  60. 'color': '#ffffff'
  61. },
  62. codeTips: '',
  63. form: {
  64. phone: '',
  65. code: '',
  66. password: '',
  67. newPassword: ''
  68. },
  69. rules: {
  70. phone: [{
  71. required: true,
  72. message: '请输入手机号',
  73. trigger: ['change', 'blur'],
  74. }, {
  75. message: '手机号码不正确',
  76. trigger: ['change', 'blur'],
  77. validator: (rule, value, callback) => {
  78. return this.$u.test.mobile(value);
  79. },
  80. }],
  81. code: [{
  82. required: true,
  83. message: '请输入验证码',
  84. trigger: ['change', 'blur'],
  85. }],
  86. password: [{
  87. required: true,
  88. message: '请输入登录密码',
  89. trigger: ['change', 'blur'],
  90. }],
  91. newPassword: [{
  92. required: true,
  93. message: '请再次输入登录密码',
  94. trigger: ['change', 'blur'],
  95. }, {
  96. message: '密码不一致',
  97. trigger: ['change', 'blur'],
  98. validator: (rule, value, callback) => {
  99. return this.form.password == value
  100. },
  101. }],
  102. }
  103. }
  104. },
  105. onReady() {
  106. this.$refs.uForm.setRules(this.rules);
  107. },
  108. onLoad(options) {
  109. if (options != null) {
  110. if (this.$isNotEmpty(options.q)) {
  111. //获取普通二维码的参数
  112. let params= this.$util.getUrlParams(options.q)
  113. this.$cache.put('promotionCode', params.promotionCode)
  114. return
  115. }
  116. if (this.$isNotEmpty(options.promotionCode)) {
  117. //获取小程序码的参数
  118. this.$cache.put('promotionCode', options.promotionCode)
  119. }
  120. }
  121. },
  122. methods: {
  123. back() {
  124. uni.navigateTo({
  125. url: "account-login"
  126. })
  127. },
  128. next() {
  129. this.$refs.uForm.validate(valid => {
  130. if (valid) {
  131. this.register()
  132. }
  133. });
  134. },
  135. codeChange(text) {
  136. this.codeTips = text;
  137. },
  138. async register() {
  139. let p = {
  140. phone: this.form.phone,
  141. secret: md5Libs.md5(this.form.password),
  142. smsId: this.$cache.get('smsId'),
  143. value: this.form.code,
  144. }
  145. this.$api.accout.register(p).then(res => {
  146. if (res.success) {
  147. uni.navigateTo({
  148. url: "/pages/shop-info/shop-info?phone=" + this.form.phone
  149. })
  150. }
  151. })
  152. },
  153. // 获取验证码
  154. getCode() {
  155. if (this.$isEmpty(this.form.phone)) {
  156. this.$u.toast('请输入手机号')
  157. return
  158. }
  159. if (this.$refs.uCode.canGetCode) {
  160. // 模拟向后端请求验证码
  161. uni.showLoading({
  162. title: '正在获取验证码',
  163. mask: true
  164. })
  165. setTimeout(() => {
  166. let params = {
  167. phone: this.form.phone
  168. }
  169. let p = this.$u.queryParams(params)
  170. this.$api.sms.send(p).then(res => {
  171. if (res.data.success) {
  172. this.$cache.put('smsId', res.data.id)
  173. this.$u.toast('验证码已发送');
  174. // 通知验证码组件内部开始倒计时
  175. } else {
  176. this.$u.toast(res.data);
  177. }
  178. this.$refs.uCode.start();
  179. })
  180. uni.hideLoading()
  181. }, 200);
  182. } else {
  183. this.$u.toast('倒计时结束后再发送');
  184. }
  185. },
  186. }
  187. }
  188. </script>
  189. <style>
  190. page {
  191. background-color: #FFFFFF;
  192. }
  193. </style>
  194. <style lang="scss" scoped>
  195. page {
  196. background-color: #FFFFFF;
  197. }
  198. .btn {
  199. background-color: $color;
  200. color: #FFFFFF;
  201. }
  202. .btn {
  203. background-color: $color;
  204. color: #FFFFFF;
  205. }
  206. .bg {
  207. overflow: hidden;
  208. z-index: 99;
  209. height: 400rpx;
  210. width: 400rpx;
  211. position: absolute;
  212. right: -240rpx;
  213. top: -240rpx;
  214. background-color: $color;
  215. border-radius: 50%;
  216. box-shadow: 0rpx 0rpx 50rpx #e28e3f;
  217. }
  218. .bg1 {
  219. overflow: hidden;
  220. height: 460rpx;
  221. width: 460rpx;
  222. position: absolute;
  223. right: -240rpx;
  224. top: -240rpx;
  225. background-color: $color;
  226. border-radius: 50%;
  227. box-shadow: #c6813b;
  228. }
  229. .back {
  230. position: absolute;
  231. top: var(--status-bar-height);
  232. left: 20rpx;
  233. padding-top: var(--status-bar-height);
  234. }
  235. .content {
  236. height: 96vh;
  237. display: flex;
  238. flex-direction: column;
  239. justify-content: center;
  240. align-items: center;
  241. .top {
  242. width: 76%;
  243. display: flex;
  244. .title {
  245. margin-right: 20rpx;
  246. display: flex;
  247. flex-direction: column;
  248. justify-content: center;
  249. align-items: flex-start;
  250. text-align: left;
  251. text:first-child {
  252. font-weight: 800;
  253. font-size: 50rpx;
  254. color: #000;
  255. margin-bottom: 20rpx;
  256. }
  257. text:last-child {
  258. font-size: 28rpx;
  259. color: #7f7f7f;
  260. }
  261. }
  262. }
  263. }
  264. </style>