bind-account.vue 6.0 KB

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