retrieve-account.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. import color from 'uview-plus/libs/config/color';
  89. import {validateSmsCode,wechatRegister,getSmsCode} from '/src/api/login/login.js';
  90. export default {
  91. data() {
  92. return {
  93. errShow: false,
  94. userInfo: {
  95. phonenumber: '',
  96. smsCode: '',
  97. openId: '',
  98. password: "",
  99. transactionPassword: "",
  100. reference: ""
  101. },
  102. tips2: '',
  103. rules: {
  104. phonenumber: [
  105. {
  106. required: true,
  107. min: 10,
  108. max: 12,
  109. message: '请输入11位电话号码',
  110. trigger: ['blur', 'change'],
  111. },
  112. {
  113. // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明
  114. validator: (rule, value, callback) => {
  115. // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
  116. return !this.$isDataEmpty(value);
  117. },
  118. message: "请认真填写电话号码",
  119. trigger: ['blur', 'change'],
  120. }
  121. ],
  122. smsCode: {
  123. required: true,
  124. min: 4,
  125. max: 6,
  126. message: '请输入6位验证码',
  127. trigger: ['blur', 'change'],
  128. },
  129. },
  130. }
  131. },
  132. onLoad(option) {
  133. // 判断Openid是否为空
  134. if(!this.$isDataEmpty(option.openId)){
  135. this.userInfo.openId = option.openId;
  136. console.log(option)
  137. }
  138. },
  139. onReady() {
  140. this.$refs.form1.setRules(this.rules)
  141. },
  142. methods: {
  143. // 创建新账号
  144. createNewAccount(){
  145. this.errShow = false;
  146. uni.$u.route({
  147. url: '/pages/login/login-real-name-auth',
  148. params: {
  149. data: JSON.stringify(this.userInfo)
  150. }
  151. })
  152. },
  153. // 登录老账号
  154. loginOldAccount(){
  155. this.errShow = false;
  156. uni.$u.route({
  157. url: '/pages/login/account-password',
  158. params: {
  159. data: JSON.stringify(this.userInfo)
  160. }
  161. })
  162. },
  163. // 验证电话号码是否存在
  164. validateSmsCode(){
  165. let that = this;
  166. // 验证电话号码是否存在
  167. validateSmsCode(null,{data:this.userInfo}).then((res)=>{
  168. console.log(res)
  169. if(res.phoneIsExist){ // 正确
  170. that.errShow = true;
  171. } else {
  172. uni.$u.route({
  173. url: '/pages/login/retrieve-account-phone',
  174. params: {
  175. data: JSON.stringify(that.userInfo)
  176. }
  177. })
  178. }
  179. }).catch(() =>{
  180. uni.showToast({
  181. title: "操作失败"
  182. })
  183. });
  184. },
  185. // 去绑定账号密码页面
  186. gotoBindAccountPassword(){
  187. let that = this;
  188. this.$refs.form1.validate().then(res => {
  189. that.validateSmsCode();
  190. }).catch(errors => {
  191. uni.$u.toast('校验失败,请认真填写')
  192. })
  193. },
  194. codeChange2(text) {
  195. this.tips2 = text;
  196. },
  197. getCode2() {
  198. let that = this;
  199. if (this.$refs.uCode2.canGetCode) {
  200. that.getSmsCode();
  201. } else {
  202. uni.$u.toast('倒计时结束后再发送');
  203. }
  204. },
  205. // 获取手机验证码
  206. getSmsCode(){
  207. let that = this;
  208. // 模拟向后端请求验证码
  209. uni.showLoading({
  210. title: '正在获取验证码'
  211. })
  212. getSmsCode({data:{phonenumber:this.userInfo.phonenumber,auth: true}}).then((res)=>{
  213. uni.hideLoading();
  214. // 这里此提示会被this.start()方法中的提示覆盖
  215. uni.$u.toast('验证码已发送');
  216. // 通知验证码组件内部开始倒计时
  217. that.$refs.uCode2.start();
  218. }).catch(() =>{
  219. uni.showToast({
  220. title: "操作失败"
  221. })
  222. });
  223. },
  224. open(){},
  225. close() {}
  226. }
  227. }
  228. </script>
  229. <style lang="scss">
  230. page,body{
  231. background: #fff;
  232. }
  233. .h-popo-content{
  234. height: 190px;
  235. padding: 12px;
  236. width: 300px;
  237. text-align: center;
  238. font-size: 14px;
  239. font-family: PingFangSC-Semibold, PingFang SC;
  240. .h-img{
  241. display: flex;
  242. justify-content: center;
  243. }
  244. .h-text{
  245. margin-top: 12px;
  246. font-weight: 400;
  247. color: #666666;
  248. }
  249. .text{
  250. margin-top: 6px;
  251. font-weight: 400;
  252. color: #666666;
  253. }
  254. .h-btn-wrap{
  255. display: flex;
  256. justify-content: space-between;
  257. color: #333333;
  258. text-align: center;
  259. margin-top: 14px;
  260. .h-left-btn{
  261. height: 32px;
  262. line-height: 30px;
  263. background: #EEEEEE;
  264. width: 100px;
  265. text-align: center;
  266. border-radius: 16px;
  267. margin: 0 auto;
  268. }
  269. .h-right-btn{
  270. height: 32px;
  271. line-height: 30px;
  272. background: #FFE05C;
  273. width: 100px;
  274. border-radius: 16px;
  275. margin: 0 auto;
  276. }
  277. }
  278. }
  279. .container{
  280. background: #fff;
  281. height: 300px;
  282. .login-wrap {
  283. display: flex;
  284. justify-content: center;
  285. .login-form{
  286. width: 90%;
  287. }
  288. .account{
  289. display: flex;
  290. }
  291. .identifying-code{
  292. }
  293. }
  294. .op-btn-wrap{
  295. margin-top: 30px;
  296. display: flex;
  297. justify-content: center;
  298. align-items: center;
  299. .h-btn{
  300. text-align: center;
  301. width: 343px;
  302. height: 42px;
  303. background: #FFE05C;
  304. border-radius: 27px;
  305. line-height: 42px;
  306. }
  307. }
  308. }
  309. </style>