retrieve-account.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <view class="container">
  3. <view class="login-wrap">
  4. <view class="login-form">
  5. <u--form
  6. labelPosition="left"
  7. :model="userInfo"
  8. :rules="rules"
  9. ref="form1"
  10. >
  11. <u-form-item
  12. label="手机号"
  13. prop="phonenumber"
  14. labelWidth="auto"
  15. labelAlign="right"
  16. >
  17. <u--input
  18. v-model="userInfo.phonenumber"
  19. placeholder="请输入手机号"
  20. border="bottom"
  21. type="number"
  22. maxlength="11"
  23. ></u--input>
  24. </u-form-item>
  25. <u-form-item
  26. labelWidth="auto"
  27. labelAlign="right"
  28. label="验证码"
  29. prop="smsCode"
  30. width="120"
  31. >
  32. <u--input
  33. v-model="userInfo.smsCode"
  34. disabledColor="#ffffff"
  35. placeholder="请输入验证码"
  36. border="bottom"
  37. maxlength="6"
  38. ></u--input>
  39. <template #right>
  40. <view class="identifying-code">
  41. <u-code
  42. ref="uCode2"
  43. @change="codeChange2"
  44. keep-running
  45. start-text="获取验证码"
  46. ></u-code>
  47. <text
  48. @tap="getCode2"
  49. :text="tips2"
  50. class="u-page__code-text"
  51. >{{tips2}}</text>
  52. </view>
  53. </template>
  54. </u-form-item>
  55. </u--form>
  56. </view>
  57. </view>
  58. <view @click="gotoBindAccountPassword()" class="op-btn-wrap">
  59. <view class="h-btn">
  60. <text>下一步</text>
  61. </view>
  62. </view>
  63. <!-- 密码正确 -->
  64. <u-popup :show="errShow" :round="10" mode="center" @close="close" @open="open">
  65. <view class="h-popo-content">
  66. <view class="h-img">
  67. <u-icon name="/static/login/u01.png" color="red" size="50"></u-icon>
  68. </view>
  69. <view class="h-text">
  70. <text>系统已检测到该手机号已绑定过账号</text>
  71. </view>
  72. <view class="h-text">
  73. <text>请选择</text>
  74. </view>
  75. <view class="h-btn-wrap">
  76. <view @click="createNewAccount()" class="h-left-btn">
  77. <text>创建新账号</text>
  78. </view>
  79. <view @click="loginOldAccount()" class="h-right-btn">
  80. <text>登录老账号</text>
  81. </view>
  82. </view>
  83. </view>
  84. </u-popup>
  85. </view>
  86. </template>
  87. <script>
  88. export default {
  89. data() {
  90. return {
  91. errShow: false,
  92. userInfo: {
  93. phonenumber: '',
  94. smsCode: '',
  95. openId: '',
  96. password: "",
  97. transactionPassword: "",
  98. reference: ""
  99. },
  100. tips2: '',
  101. rules: {
  102. phonenumber: [
  103. {
  104. required: true,
  105. min: 10,
  106. max: 12,
  107. message: '请输入11位电话号码',
  108. trigger: ['blur', 'change'],
  109. },
  110. {
  111. // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明
  112. validator: (rule, value, callback) => {
  113. // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
  114. return !this.$isDataEmpty(value);
  115. },
  116. message: "请认真填写电话号码",
  117. trigger: ['blur', 'change'],
  118. }
  119. ],
  120. smsCode: {
  121. required: true,
  122. min: 4,
  123. max: 6,
  124. message: '请输入6位验证码',
  125. trigger: ['blur', 'change'],
  126. },
  127. },
  128. }
  129. },
  130. onLoad(option) {
  131. // 判断Openid是否为空
  132. if(option.openId){
  133. this.userInfo.openId = option.openId;
  134. console.log(option)
  135. }
  136. },
  137. onReady() {
  138. this.$refs.form1.setRules(this.rules)
  139. },
  140. methods: {
  141. // 创建新账号
  142. createNewAccount(){
  143. this.errShow = false;
  144. uni.$u.route({
  145. url: '/pages/login/login-real-name-auth',
  146. params: {
  147. data: JSON.stringify(this.userInfo)
  148. }
  149. })
  150. },
  151. // 登录老账号
  152. loginOldAccount(){
  153. this.errShow = false;
  154. uni.$u.route({
  155. url: '/pages/login/account-password',
  156. params: {
  157. data: JSON.stringify(this.userInfo)
  158. }
  159. })
  160. },
  161. // 验证电话号码是否存在
  162. validateSmsCode(){
  163. let that = this;
  164. // 验证电话号码是否存在
  165. this.$api.validateSmsCode(this.userInfo).then((res)=>{
  166. console.log(res)
  167. if(res.phoneIsExist){ // 正确
  168. that.errShow = true;
  169. } else {
  170. uni.$u.route({
  171. url: '/pages/login/retrieve-account-phone',
  172. params: {
  173. data: JSON.stringify(that.userInfo)
  174. }
  175. })
  176. }
  177. }).catch(() =>{
  178. uni.showToast({
  179. title: "操作失败"
  180. })
  181. });
  182. },
  183. // 去绑定账号密码页面
  184. gotoBindAccountPassword(){
  185. let that = this;
  186. this.$refs.form1.validate().then(res => {
  187. that.validateSmsCode();
  188. }).catch(errors => {
  189. uni.$u.toast('校验失败,请认真填写')
  190. })
  191. },
  192. codeChange2(text) {
  193. this.tips2 = text;
  194. },
  195. getCode2() {
  196. let that = this;
  197. if (this.$refs.uCode2.canGetCode) {
  198. that.getSmsCode();
  199. } else {
  200. uni.$u.toast('倒计时结束后再发送');
  201. }
  202. },
  203. // 获取手机验证码
  204. getSmsCode(){
  205. let that = this;
  206. // 模拟向后端请求验证码
  207. uni.showLoading({
  208. title: '正在获取验证码'
  209. })
  210. this.$api.getSmsCode({phonenumber:this.userInfo.phonenumber,auth: true}).then((res)=>{
  211. uni.hideLoading();
  212. // 这里此提示会被this.start()方法中的提示覆盖
  213. uni.$u.toast('验证码已发送');
  214. // 通知验证码组件内部开始倒计时
  215. that.$refs.uCode2.start();
  216. }).catch(() =>{
  217. uni.showToast({
  218. title: "操作失败"
  219. })
  220. });
  221. },
  222. open(){},
  223. close() {}
  224. }
  225. }
  226. </script>
  227. <style lang="scss">
  228. page,body{
  229. background: #fff;
  230. }
  231. .h-popo-content{
  232. height: 190px;
  233. padding: 12px;
  234. width: 300px;
  235. text-align: center;
  236. font-size: 14px;
  237. font-family: PingFangSC-Semibold, PingFang SC;
  238. .h-img{
  239. display: flex;
  240. justify-content: center;
  241. }
  242. .h-text{
  243. margin-top: 12px;
  244. font-weight: 400;
  245. color: #666666;
  246. }
  247. .text{
  248. margin-top: 6px;
  249. font-weight: 400;
  250. color: #666666;
  251. }
  252. .h-btn-wrap{
  253. display: flex;
  254. justify-content: space-between;
  255. color: #333333;
  256. text-align: center;
  257. margin-top: 14px;
  258. .h-left-btn{
  259. height: 32px;
  260. line-height: 30px;
  261. background: #EEEEEE;
  262. width: 100px;
  263. text-align: center;
  264. border-radius: 16px;
  265. margin: 0 auto;
  266. }
  267. .h-right-btn{
  268. height: 32px;
  269. line-height: 30px;
  270. background: #FFE05C;
  271. width: 100px;
  272. border-radius: 16px;
  273. margin: 0 auto;
  274. }
  275. }
  276. }
  277. .container{
  278. background: #fff;
  279. height: 300px;
  280. .login-wrap {
  281. display: flex;
  282. justify-content: center;
  283. .login-form{
  284. width: 90%;
  285. }
  286. .account{
  287. display: flex;
  288. }
  289. .identifying-code{
  290. }
  291. }
  292. .op-btn-wrap{
  293. margin-top: 30px;
  294. display: flex;
  295. justify-content: center;
  296. align-items: center;
  297. .h-btn{
  298. text-align: center;
  299. width: 343px;
  300. height: 42px;
  301. background: #FFE05C;
  302. border-radius: 27px;
  303. line-height: 42px;
  304. }
  305. }
  306. }
  307. </style>