register.vue 6.0 KB

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