register.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view>
  3. <cu-custom :bgColor="'bg-'+theme.backgroundColor" :isBack="true">
  4. <block slot="backText">返回</block>
  5. <block slot="content">账号{{typeName}}</block>
  6. </cu-custom>
  7. <form @submit="regSub">
  8. <view class="cu-form-group margin-top">
  9. <view class="title">手机号</view>
  10. <input placeholder="请输入手机号" name="phone" v-model="form.phone"></input>
  11. </view>
  12. <view class="cu-form-group">
  13. <view class="title">验证码</view>
  14. <input placeholder="请输入验证码" name="code" maxlength=4 v-model="form.code"></input>
  15. <span @click="getPhoneCode"
  16. class="cu-btn bg-gray"
  17. :class="'display:' + msgKey">{{msgText}}</span>
  18. </view>
  19. <view class="cu-form-group">
  20. <view class="title">新密码</view>
  21. <input placeholder="请输入密码" password name="password" v-model="form.password"></input>
  22. </view>
  23. <view class="padding flex flex-direction">
  24. <button class="cu-btn margin-tb-sm lg round" :class="'bg-'+theme.backgroundColor" form-type="submit">立即{{typeName}}</button>
  25. </view>
  26. </form>
  27. <view class="text-center" v-if="typeName != '修改'">
  28. 已有账号?<text class="text-red" @click="toLogin">立即登录</text>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. const app = getApp();
  34. const util = require("utils/util.js");
  35. import api from 'utils/api';
  36. import validate from 'utils/validate'
  37. const MSGINIT = "发送验证码",
  38. MSGSCUCCESS = "${time}秒后可重发",
  39. MSGTIME = 60;
  40. export default {
  41. data() {
  42. return {
  43. theme: app.globalData.theme, //全局颜色变量
  44. CustomBar: this.CustomBar,
  45. type: '2',
  46. typeName: '注册',
  47. form: {},
  48. msgText: MSGINIT,
  49. msgTime: MSGTIME,
  50. msgKey: false
  51. };
  52. },
  53. components: {
  54. },
  55. props: {},
  56. onLoad(options) {
  57. // 保存别人分享来的 userCode
  58. util.saveSharerUserCode(options);
  59. let type = options.type
  60. if(type == 'reset'){
  61. this.typeName = '重置'
  62. this.type = '4'
  63. }else{
  64. if(type == 'editpwd'){
  65. this.typeName = '修改'
  66. this.type = '4'
  67. }
  68. }
  69. },
  70. onShow() {
  71. },
  72. methods: {
  73. toLogin(){
  74. uni.reLaunch({
  75. url: '/pages/login/index'
  76. });
  77. return
  78. },
  79. regSub(e){
  80. let that = this
  81. if(!validate.validateMobile(this.form.phone)){
  82. uni.showToast({
  83. title: '请输入正确的手机号码',
  84. icon: 'none',
  85. duration: 3000
  86. });
  87. return;
  88. }
  89. if(!this.form.code){
  90. uni.showToast({
  91. title: '请输入验证码',
  92. icon: 'none',
  93. duration: 3000
  94. });
  95. return;
  96. }
  97. if(!this.form.password){
  98. uni.showToast({
  99. title: '请输入密码',
  100. icon: 'none',
  101. duration: 3000
  102. });
  103. return;
  104. }
  105. api.register(this.form).then(res => {
  106. uni.showModal({
  107. title: '提示',
  108. content: '恭喜您' + this.typeName + '成功',
  109. success(res) {
  110. that.toLogin()
  111. }
  112. });
  113. });
  114. },
  115. getPhoneCode(){
  116. if (this.msgKey) return
  117. if (!validate.validateMobile(this.form.phone)) {
  118. uni.showToast({
  119. title: '请输入正确的手机号码',
  120. icon: 'none',
  121. duration: 3000
  122. });
  123. return;
  124. }
  125. this.msgKey = true
  126. api.getPhoneCode({
  127. type: this.type,
  128. phone: this.form.phone
  129. }).then(res => {
  130. this.msgKey = false
  131. if (res.code == '0') {
  132. uni.showToast({
  133. title: '验证码发送成功',
  134. icon: 'none',
  135. duration: 3000
  136. });
  137. this.msgText = MSGSCUCCESS.replace('${time}', this.msgTime)
  138. this.msgKey = true
  139. const time = setInterval(() => {
  140. this.msgTime--
  141. this.msgText = MSGSCUCCESS.replace('${time}', this.msgTime)
  142. if (this.msgTime == 0) {
  143. this.msgTime = MSGTIME
  144. this.msgText = MSGINIT
  145. this.msgKey = false
  146. clearInterval(time)
  147. }
  148. }, 1000)
  149. }else{
  150. }
  151. }).catch(() => {
  152. this.msgKey = false
  153. });
  154. }
  155. }
  156. };
  157. </script>
  158. <style>
  159. </style>