bindMobile.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. <template>
  2. <view class="container">
  3. <text class="back-btn iconfont iconziyuan2" @click="navBack"></text>
  4. <!-- 设置白色背景防止软键盘把下部绝对定位元素顶上来盖住输入框等 -->
  5. <view class="wrapper" v-if="bindState">
  6. <view class="login-title">
  7. {{$L('绑定手机号')}}
  8. </view>
  9. <view class="input-content">
  10. <view class="input-item">
  11. <input type="number" :value="mobile" :placeholder="$L('请输入手机号')" maxlength="11" data-key="mobile" @input="inputChange"
  12. @focus="setFocus" />
  13. <text class="clear-account iconfont iconziyuan34" v-show="mobile&&curFocus=='mobile'" @click="clearContent('mobile')"></text>
  14. </view>
  15. <view class="input-item pwd_wrap">
  16. <input type="number" :value="smsCode" maxlength="6" :placeholder="$L('请输入短信验证码')" data-key="smsCode" @input="inputChange"
  17. @confirm="toLogin" @focus="setFocus" />
  18. <view class="pwd-right">
  19. <text class="clear-pwd iconfont iconziyuan34" v-show="smsCode&&curFocus=='smsCode'" @click="clearContent('smsCode')"></text>
  20. <view :style="{opacity: countDownM?0.3:1}" class="sms-code-view" @click="getSmsCode">
  21. <text class="sms-code">{{countDownM?`${countDownM}s后重新获取`:'获取验证码'}}</text>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <button class="confirm-btn" @click="toLogin" :style="{opacity: (!(mobile&&smsCode)||logining)?0.5:1}">{{$L('确认绑定')}}</button>
  27. </view>
  28. <!-- 绑定选择部分 -->
  29. <view class="wrapper" v-else>
  30. <view class="bind_state_top">
  31. <image class="mobile_logo" :src="imgUrl+'bind_mobile.png'"></image>
  32. <text class="mobile_num">{{mobile}}</text>
  33. <text class="mobile_binded">{{$L('该手机号已被绑定')}}</text>
  34. </view>
  35. <view class="bind_change_info">
  36. <view class="bind_change_info_text">{{$L('继续绑定:将解除与账号')}}<text class="change_info_mobile">{{bindedAccount}}</text>{{$L('的绑定关系')}}</view>
  37. <view class="bind_change_info_text">{{$L('更新信息:授权信息将绑定到账号')}}<text class="change_info_mobile">{{bindedAccount}}</text>{{$L('上')}}</view>
  38. </view>
  39. <view class="bind_state_btn_con">
  40. <view class="update_btn" @click="confirmBind(3)">{{$L('更新信息')}}</view>
  41. <view class="go_on_btn" @click="confirmBind(2)">{{$L('继续绑定')}}</view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import {
  48. mapMutations
  49. } from 'vuex';
  50. export default {
  51. data() {
  52. return {
  53. bindState: true,
  54. imgUrl: getApp().globalData.imgUrl,
  55. mobile: '',
  56. smsCode: '',
  57. logining: false,
  58. countDownM: 0, //短信验证码倒计时
  59. timeOutId: '', //定时器的返回值
  60. curFocus: '', //当前光标所在的位置
  61. code: '', //用户code
  62. bindType: 1, //绑定方式,默认 1==去绑定,检测手机号是否已绑定其他账号;2==继续绑定,新增一条会员信息;3==更新信息,更新原会员的微信信息
  63. client: 1, //终端类型, 1、H5(微信内部浏览器) 2、H5(微信小程序);3、app
  64. bindedAccount:'',//已经绑定的账号
  65. source:'', //页面来源,该用户已登录,却强行被解绑了,来源为 ’account‘
  66. }
  67. },
  68. onLoad(option) {
  69. this.initClient();
  70. if (option.code) {
  71. this.code = option.code;
  72. }
  73. this.source = 'account'
  74. },
  75. methods: {
  76. ...mapMutations(['login', 'setUserCenterData']),
  77. //光标聚焦事件
  78. setFocus(e) {
  79. this.curFocus = e.currentTarget.dataset.key;
  80. },
  81. inputChange(e) {
  82. const key = e.currentTarget.dataset.key;
  83. this[key] = e.detail.value;
  84. },
  85. navBack() {
  86. uni.navigateBack();
  87. },
  88. //初始化终端类型
  89. initClient() {
  90. let {
  91. client
  92. } = this;
  93. //#ifdef APP-PLUS
  94. client = 2;
  95. //#endif
  96. //#ifdef MP-WEIXIN
  97. client = 4;
  98. //#endif
  99. //#ifdef H5
  100. client = 3;
  101. //#endif
  102. this.client = client;
  103. },
  104. toLogin() {
  105. const {
  106. mobile,
  107. smsCode,
  108. logining,
  109. code,
  110. bindType,
  111. client,
  112. } = this;
  113. let _this = this;
  114. if (!(mobile && smsCode) || logining) {
  115. return;
  116. }
  117. _this.logining = true;
  118. let param = {};
  119. param.url = 'v3/member/front/login/wechat/bindMobile';
  120. param.data = {};
  121. param.data.bindType = bindType;
  122. param.data.mobile = mobile;
  123. param.data.smsCode = smsCode;
  124. param.data.resource = client;
  125. if (!_this.$checkMobile(mobile)) {
  126. return false
  127. }
  128. //如果有缓存的购物车数据,登录需要把数据同步,并清除本地缓存
  129. let local_cart_list = uni.getStorageSync('cart_list')
  130. let cartInfo = []
  131. if (local_cart_list) {
  132. local_cart_list.cartInfoList.map(item => {
  133. if (item.isChecked == 1) {
  134. cartInfo.push({
  135. goodsId: item.goodsId,
  136. productId: item.productId,
  137. buyNum: item.buyNum,
  138. productPrice: item.productPrice,
  139. checked: 1
  140. })
  141. }
  142. })
  143. param.data.cartInfo = JSON.stringify(cartInfo);
  144. }
  145. param.data.bindKey = code;
  146. param.method = 'POST';
  147. _this.$request(param).then(res => {
  148. if (res.state == 200) {
  149. uni.removeStorage({
  150. key: 'cart_data'
  151. }); //清除购物车数据
  152. res.data.loginTime = Date.parse(new Date()); //登录时间
  153. _this.login(res.data);
  154. //获取个人中心的数据
  155. _this.$request({
  156. url: 'v3/member/front/member/memberInfo',
  157. }).then(result => {
  158. if(_this.source == 'account'){
  159. const pages = getCurrentPages(); //当前页面栈
  160. if (pages.length > 1) {
  161. const beforePage = pages[pages.length - 2]; //获取上一个页面实例对象
  162. beforePage.$vm.isBindMobile = true; //修改上一页的数据 isBindMobile 为true,即为已绑定
  163. }
  164. uni.navigateBack();
  165. }else{
  166. _this.setUserCenterData(result.data);
  167. _this.$loginGoPage();
  168. }
  169. }).catch((e) => {})
  170. } else if (res.state == 267) {
  171. //手机号已被绑定,提示用户
  172. _this.bindState = false;
  173. _this.bindedAccount = res.data;
  174. } else {
  175. //错误提示
  176. _this.$api.msg(res.msg);
  177. }
  178. _this.logining = false;
  179. }).catch((e) => {})
  180. },
  181. //提示绑定操作
  182. confirmBind(type){
  183. this.bindType = type;
  184. this.toLogin();
  185. },
  186. //清空输入的内容
  187. clearContent(type) {
  188. this[type] = '';
  189. },
  190. //获取短信验证码
  191. getSmsCode() {
  192. if (this.countDownM) {
  193. return;
  194. }
  195. if (!this.$checkMobile(this.mobile)) {
  196. return false
  197. } else {
  198. let param = {};
  199. param.url = 'v3/msg/front/commons/smsCode';
  200. param.data = {};
  201. param.data.mobile = this.mobile;
  202. param.data.type = 'wxAuth';
  203. this.$request(param).then(res => {
  204. this.$api.msg(res.msg)
  205. if (res.state == 200) {
  206. this.countDownM = 60;
  207. this.countDown();
  208. }
  209. })
  210. }
  211. },
  212. //跳转事件 type:跳转类型,1为redirectTo 2为navigateTo
  213. navTo(url, type) {
  214. if (type == 1) {
  215. uni.redirectTo({
  216. url
  217. })
  218. } else if (type == 2) {
  219. uni.navigateTo({
  220. url
  221. })
  222. }
  223. },
  224. //倒计时
  225. countDown() {
  226. this.countDownM--;
  227. if (this.countDownM == 0) {
  228. clearTimeout(this.timeOutId);
  229. } else {
  230. this.timeOutId = setTimeout(this.countDown, 1000);
  231. }
  232. }
  233. },
  234. }
  235. </script>
  236. <style lang='scss'>
  237. page {
  238. background: #fff;
  239. }
  240. .container {
  241. position: relative;
  242. width: 750rpx;
  243. height: 100vh;
  244. overflow: hidden;
  245. background: #fff;
  246. }
  247. .wrapper {
  248. position: relative;
  249. z-index: 90;
  250. background: #fff;
  251. padding-bottom: 40upx;
  252. }
  253. .back-btn {
  254. margin-left: 40rpx;
  255. margin-top: 40rpx;
  256. /* #ifndef H5 */
  257. margin-top: 88rpx;
  258. /* #endif */
  259. font-size: 32rpx;
  260. color: $main-font-color;
  261. display: inline-block;
  262. }
  263. .login-title {
  264. position: relative;
  265. margin-top: 90rpx;
  266. margin-bottom: 70rpx;
  267. margin-left: 65rpx;
  268. font-size: 36rpx;
  269. color: #333;
  270. font-weight: bold;
  271. &:after {
  272. position: absolute;
  273. left: 0;
  274. bottom: -10rpx;
  275. content: '';
  276. width: 76rpx;
  277. height: 6rpx;
  278. background: linear-gradient(90deg, rgba(252, 28, 28, 1) 0%, rgba(255, 138, 0, 0) 100%);
  279. }
  280. }
  281. .input-content {
  282. padding: 0 65rpx;
  283. }
  284. .input-item {
  285. display: flex;
  286. flex-direction: column;
  287. align-items: flex-start;
  288. justify-content: center;
  289. height: 80rpx;
  290. margin-bottom: 50upx;
  291. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  292. position: relative;
  293. input {
  294. color: #2D2D2D;
  295. font-size: 30rpx;
  296. }
  297. .clear-account {
  298. position: absolute;
  299. right: 6rpx;
  300. top: 28rpx;
  301. font-size: 26rpx;
  302. color: #ddd;
  303. }
  304. &:last-child {
  305. margin-bottom: 0;
  306. .pwd-right {
  307. position: absolute;
  308. right: 6rpx;
  309. top: 6rpx;
  310. display: flex;
  311. align-items: center;
  312. .clear-pwd {
  313. font-size: 26rpx;
  314. color: #ddd;
  315. }
  316. .sms-code-view {
  317. border: 1px solid $main-color;
  318. padding: 14rpx;
  319. border-radius: 6rpx;
  320. line-height: 0;
  321. margin-left: 20rpx;
  322. .sms-code {
  323. color: $main-color;
  324. font-size: 24rpx;
  325. line-height: 24rpx;
  326. }
  327. }
  328. }
  329. }
  330. .tit {
  331. height: 50upx;
  332. line-height: 56upx;
  333. font-size: $font-sm+2upx;
  334. color: $font-color-base;
  335. }
  336. input {
  337. height: 60upx;
  338. font-size: $font-base + 2upx;
  339. color: $font-color-dark;
  340. }
  341. }
  342. .confirm-btn {
  343. width: 620rpx;
  344. height: 88rpx;
  345. line-height: 88rpx;
  346. margin-top: 90rpx;
  347. background: linear-gradient(90deg, rgba(252, 31, 29, 1) 0%, rgba(253, 115, 38, 1) 100%);
  348. box-shadow: 0px 3rpx 14rpx 1rpx rgba(253, 38, 29, 0.26);
  349. border-radius: 44rpx;
  350. color: #fff;
  351. font-size: 36rpx;
  352. }
  353. .other-login {
  354. position: absolute;
  355. left: 0;
  356. bottom: 140rpx;
  357. width: 100%;
  358. display: flex;
  359. flex-direction: column;
  360. .title {
  361. display: flex;
  362. justify-content: center;
  363. align-items: center;
  364. &:before {
  365. content: ' ';
  366. width: 150rpx;
  367. height: 1rpx;
  368. background: #CBCBCB;
  369. }
  370. &:after {
  371. content: ' ';
  372. width: 150rpx;
  373. height: 1rpx;
  374. background: #CBCBCB;
  375. }
  376. text {
  377. color: #999999;
  378. font-size: 26rpx;
  379. margin: 0 20rpx;
  380. }
  381. }
  382. .login-method {
  383. display: flex;
  384. justify-content: center;
  385. margin-top: 20rpx;
  386. .wechat-login {
  387. display: flex;
  388. flex-direction: column;
  389. align-items: center;
  390. width: 100%;
  391. .wechat-icon {
  392. width: 110rpx;
  393. height: 110rpx;
  394. }
  395. text {
  396. color: #666666;
  397. font-size: 26rpx;
  398. }
  399. }
  400. }
  401. }
  402. .agreement-part {
  403. position: absolute;
  404. left: 0;
  405. bottom: 60rpx;
  406. width: 100%;
  407. font-size: 26rpx;
  408. color: #999999;
  409. text-align: center;
  410. .agreement {
  411. color: #FC1E1E;
  412. border-bottom: 1rpx solid #FC1E1E;
  413. }
  414. }
  415. .login-register {
  416. display: flex;
  417. justify-content: center;
  418. margin-top: 33rpx;
  419. .mobile-login {
  420. color: #2D2D2D;
  421. font-size: 28rpx;
  422. line-height: 34rpx;
  423. border-right: 1px solid rgba(0, 0, 0, .1);
  424. padding-right: 30rpx;
  425. margin-right: 30rpx;
  426. }
  427. .register {
  428. color: #FC1C1C;
  429. font-size: 28rpx;
  430. line-height: 34rpx;
  431. }
  432. }
  433. /* 绑定结果页 */
  434. .bind_state_top {
  435. margin-top: 172rpx;
  436. display: flex;
  437. flex-direction: column;
  438. align-items: center;
  439. .mobile_logo {
  440. width: 120rpx;
  441. height: 120rpx;
  442. }
  443. .mobile_num{
  444. font-size: 30rpx;
  445. font-weight: 500;
  446. color: #FC2624;
  447. margin-top: 39rpx;
  448. }
  449. .mobile_binded{
  450. font-size: 30rpx;
  451. font-weight: 500;
  452. color: #333333;
  453. margin-top: 19rpx;
  454. }
  455. }
  456. .bind_change_info{
  457. font-size: 28rpx;
  458. text-align: center;
  459. color: #666666;
  460. line-height: 39rpx;
  461. margin-top: 51rpx;
  462. .change_info_mobile{
  463. color: #333333;
  464. }
  465. }
  466. .bind_state_btn_con{
  467. width: 620rpx;
  468. height: 70rpx;
  469. margin: 0 auto;
  470. margin-top: 80rpx;
  471. font-size: 30rpx;
  472. display: flex;
  473. .update_btn{
  474. width: 308rpx;
  475. height: 69rpx;
  476. line-height: 69rpx;
  477. color: #ff0000;
  478. text-align: center;
  479. border-radius: 35rpx 0 0 35rpx;
  480. border: 1px solid #ff0000;
  481. }
  482. .go_on_btn{
  483. width: 308rpx;
  484. height: 69rpx;
  485. line-height: 69rpx;
  486. text-align: center;
  487. background-color: #ff0000;
  488. color: white;
  489. border-radius: 0 35rpx 35rpx 0;
  490. border: 1px solid #ff0000;
  491. }
  492. }
  493. </style>