index.vue 6.8 KB

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