bind-account.vue 6.2 KB

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