editMobile.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. <template>
  2. <view class="page">
  3. <view class="list_info">
  4. <!-- 标题和说明 -->
  5. <view class="title"> <template v-if="processProgress == 1">新</template> 手机号验证</view>
  6. <view class="subtitle">该账号绑定的原手机号 {{ formatPhoneNumber(originalPhoneNumber) }},完成手机验证</view>
  7. <!-- 手机号输入 -->
  8. <view class="phone_input">
  9. <text class="area_code">+86</text>
  10. <input type="number" class="input" placeholder="请输入手机号" v-model="mobile" maxlength="11" />
  11. </view>
  12. <!-- 验证码输入 -->
  13. <view class="code_input">
  14. <input type="number" class="input" placeholder="请输入验证码" v-model="code" maxlength="6" />
  15. <view class="btn" v-if="captchaTime === 0" @click="getCode">获取验证码</view>
  16. <view class="btn disabled" v-else>{{ captchaTime }}秒后重试</view>
  17. </view>
  18. <view class="blankHeight"></view>
  19. </view>
  20. <view class="btn_submit" @click="processProgress == 0 ? submitData() : newSubmitData()">确定</view>
  21. <view class="mobilePhoneNotAvailable" @click="openCustomPopup">现手机已不可用?</view>
  22. <DialogBox ref="DialogBox"></DialogBox>
  23. <CustomerServicePopup ref="customerServicePopup"></CustomerServicePopup>
  24. </view>
  25. </template>
  26. <script>
  27. import CustomPopup from '@/components/CustomPopup/CustomPopup.vue'
  28. import CustomerServicePopup from '@/components/CustomerServicePopup/CustomerServicePopup.vue'
  29. export default {
  30. components: { CustomPopup, CustomerServicePopup },
  31. data() {
  32. return {
  33. title: '',
  34. mobile: '',
  35. originalPhoneNumber: '',
  36. code: '',
  37. captchaTime: 0,
  38. processProgress: 0, // 0原手机号验证逻辑,1新手机号验证逻辑
  39. }
  40. },
  41. onLoad(e) {
  42. if (e.originalPhoneNumber) {
  43. this.originalPhoneNumber = e.originalPhoneNumber;
  44. }
  45. },
  46. onShow() {
  47. // this.loadData();
  48. },
  49. methods: {
  50. openCustomPopup() {
  51. this.$refs.customerServicePopup.$refs.customPopup.open()
  52. },
  53. formatPhoneNumber(phoneNumber) {
  54. if (phoneNumber && phoneNumber.length === 11) {
  55. return phoneNumber.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
  56. }
  57. return phoneNumber;
  58. },
  59. onBack() { },
  60. chkSel() {
  61. if (this.sel == 1) {
  62. this.sel = 0;
  63. } else {
  64. this.sel = 1;
  65. }
  66. },
  67. getCodeTime() {
  68. this.captchaTime = 60;
  69. let timer = setInterval(() => {
  70. this.captchaTime--;
  71. if (this.captchaTime < 1) {
  72. clearInterval(timer);
  73. this.captchaTime = 0
  74. }
  75. }, 1000)
  76. },
  77. getCode() {
  78. var _this = this
  79. if (this.mobile.length != 11) {
  80. uni.showToast({
  81. title: '请输入完整手机号',
  82. icon: 'none'
  83. });
  84. return;
  85. }
  86. // 验证原手机号的逻辑
  87. if (this.processProgress == 0 && this.mobile != this.originalPhoneNumber) {
  88. uni.showToast({
  89. title: '请输入正确的原手机号',
  90. icon: 'none'
  91. });
  92. return;
  93. }
  94. const phoneRegex = /^1[3-9]\d{9}$/;
  95. if (!phoneRegex.test(this.mobile)) {
  96. uni.showToast({
  97. title: '请输入有效的手机号',
  98. icon: 'none'
  99. });
  100. return;
  101. }
  102. if (this.captchaTime > 0) {
  103. uni.showToast({
  104. title: '不能重复获取',
  105. icon: 'none'
  106. });
  107. return;
  108. }
  109. this.captchaTime = 60;
  110. var url = '/Web/getcode'
  111. var data = {}
  112. if (this.processProgress == 0) {
  113. url = '/Member/getcode'
  114. data = {}
  115. }
  116. if (this.processProgress == 1) {
  117. url = '/Web/getcode'
  118. data = { mobile: _this.mobile, skey: this.skey, }
  119. }
  120. uni.request({
  121. url: this.$apiHost + url,
  122. data: {
  123. uuid: getApp().globalData.uuid,
  124. ...data
  125. },
  126. header: {
  127. 'content-type': 'application/json'
  128. },
  129. success: (res) => {
  130. console.log("----", res.data)
  131. uni.showToast({
  132. title: res.data.str,
  133. icon: 'none'
  134. })
  135. if (res.data.success == 'yes') {
  136. this.getCodeTime();
  137. } else {
  138. this.captchaTime = 0;
  139. }
  140. }
  141. });
  142. },
  143. submitData() {
  144. console.log('submitData');
  145. if (this.mobile == "") {
  146. uni.showToast({
  147. title: "请输入手机号",
  148. icon: 'none'
  149. });
  150. return;
  151. }
  152. if (this.code == "") {
  153. uni.showToast({
  154. title: "请输入验证码",
  155. icon: 'none'
  156. });
  157. return;
  158. }
  159. // 验证原始手机号
  160. uni.request({
  161. url: this.$apiHost + '/Member/checkMobile',
  162. data: {
  163. uuid: getApp().globalData.uuid,
  164. code: this.code,
  165. },
  166. header: {
  167. 'content-type': 'application/json'
  168. },
  169. success: (res) => {
  170. console.log("----", res.data);
  171. uni.showToast({
  172. title: res.data.str,
  173. icon: 'none'
  174. });
  175. if (res.data.success == "yes") {
  176. this.$refs['DialogBox'].confirm({
  177. title: '确认修改手机号',
  178. content: '当前绑定的手机号为 ' + this.mobile + ' 吗?',
  179. DialogType: "inquiry",
  180. btn1: "再考虑一下",
  181. btn2: "确认更换",
  182. animation: 0
  183. }).then(() => {
  184. // 用户点击确认后,发送请求
  185. this.mobile = ''
  186. this.code = ''
  187. this.captchaTime = 0
  188. this.processProgress = 1
  189. uni.showToast({
  190. title: "请输入新手机号",
  191. icon: 'none'
  192. });
  193. }).catch(() => {
  194. // 用户点击取消后,不发送请求
  195. console.log('用户取消了修改手机号');
  196. });
  197. }
  198. }
  199. });
  200. // 弹窗确认是否修改手机号
  201. },
  202. newSubmitData() {
  203. console.log("newSubmitData");
  204. if (this.mobile == "") {
  205. uni.showToast({
  206. title: "请输入手机号",
  207. icon: 'none'
  208. });
  209. return;
  210. }
  211. if (this.code == "") {
  212. uni.showToast({
  213. title: "请输入验证码",
  214. icon: 'none'
  215. });
  216. return;
  217. }
  218. const phoneRegex = /^1[3-9]\d{9}$/;
  219. if (!phoneRegex.test(this.mobile)) {
  220. uni.showToast({
  221. title: '请输入有效的手机号',
  222. icon: 'none'
  223. });
  224. return;
  225. }
  226. // 更改为新手机号时发送验证请求
  227. uni.request({
  228. url: this.$apiHost + '/Member/editMobile',
  229. data: {
  230. uuid: getApp().globalData.uuid,
  231. mobile: this.mobile,
  232. code: this.code,
  233. },
  234. header: {
  235. 'content-type': 'application/json'
  236. },
  237. success: (res) => {
  238. console.log("----", res.data);
  239. uni.showToast({
  240. title: res.data.str,
  241. icon: 'none'
  242. });
  243. if (res.data.success == "yes") {
  244. // 可以在此处添加修改成功后的逻辑
  245. if (this.mobile) {
  246. getApp().globalData.mobile = this.mobile
  247. uni.removeStorageSync("mobile" );
  248. uni.setStorageSync("mobile", this.mobile);
  249. }
  250. }
  251. }
  252. });
  253. }
  254. }
  255. }
  256. </script>
  257. <style scoped lang="scss">
  258. .list_info {
  259. display: flex;
  260. flex-direction: column;
  261. justify-content: flex-start;
  262. align-items: center;
  263. color: #fff;
  264. width: 750rpx;
  265. .textContent {
  266. color: #1f1f1f;
  267. max-width: 400rpx;
  268. }
  269. .textPrompt {
  270. color: #999999;
  271. }
  272. .name {
  273. width: 690rpx;
  274. display: flex;
  275. flex-direction: row;
  276. justify-content: space-between;
  277. align-items: flex-start;
  278. color: #333;
  279. font-size: 28rpx;
  280. margin-top: 20rpx;
  281. .right {
  282. font-size: 28rpx;
  283. color: #ff2a95;
  284. }
  285. }
  286. .desc {
  287. width: 690rpx;
  288. display: flex;
  289. flex-direction: row;
  290. justify-content: space-between;
  291. align-items: flex-start;
  292. color: #999;
  293. font-size: 24rpx;
  294. margin-top: 20rpx;
  295. }
  296. .item {
  297. width: 690rpx;
  298. height: 84rpx;
  299. margin-top: 20rpx;
  300. background: #ffffff;
  301. position: relative;
  302. border-radius: 24rpx 24rpx 24rpx 24rpx;
  303. input {
  304. width: 100%;
  305. height: 100%;
  306. padding-left: 20rpx;
  307. font-size: 28rpx;
  308. color: #333;
  309. border: solid 1px #f0f0f0;
  310. border-radius: 12rpx;
  311. }
  312. .btn {
  313. position: absolute;
  314. right: 20rpx;
  315. top: 0rpx;
  316. font-weight: 400;
  317. font-size: 28rpx;
  318. line-height: 84rpx;
  319. color: #ff2a95;
  320. }
  321. .arrow {
  322. width: 36rpx;
  323. position: absolute;
  324. right: 20rpx;
  325. top: 24rpx;
  326. }
  327. }
  328. .bcenter {
  329. display: flex;
  330. flex-direction: row;
  331. justify-content: center;
  332. align-items: center;
  333. margin-top: 120rpx;
  334. .avator {
  335. width: 200rpx;
  336. height: 200rpx;
  337. position: relative;
  338. .img {
  339. width: 172rpx;
  340. height: 172rpx;
  341. border-radius: 86rpx;
  342. }
  343. .photo {
  344. width: 64rpx;
  345. height: 64rpx;
  346. position: absolute;
  347. bottom: 0;
  348. right: 10rpx;
  349. }
  350. }
  351. }
  352. .item2 {
  353. width: 690rpx;
  354. height: 84rpx;
  355. margin-top: 20rpx;
  356. display: flex;
  357. flex-direction: row;
  358. justify-content: center;
  359. align-items: center;
  360. .sex {
  361. width: 334rpx;
  362. height: 84rpx;
  363. background: #ffffff;
  364. border-radius: 24rpx;
  365. border: 2rpx solid #282828;
  366. color: #999;
  367. display: flex;
  368. flex-direction: row;
  369. justify-content: center;
  370. align-items: center;
  371. }
  372. .active {
  373. border: 4rpx solid #ff2a95;
  374. color: #ff2a95;
  375. }
  376. .sex2 {
  377. image {
  378. width: 172rpx;
  379. }
  380. }
  381. }
  382. .itemSex {
  383. width: 690rpx;
  384. margin-top: 20rpx;
  385. display: flex;
  386. flex-direction: row;
  387. justify-content: center;
  388. align-items: center;
  389. .sex2 {
  390. display: flex;
  391. flex-direction: column;
  392. justify-content: flex-end;
  393. align-items: center;
  394. width: 210rpx;
  395. height: 210rpx;
  396. text {
  397. color: #999;
  398. }
  399. image {
  400. width: 132rpx;
  401. height: 132rpx;
  402. }
  403. }
  404. .active {
  405. text {
  406. color: #fff;
  407. }
  408. image {
  409. border: 4rpx solid #36d6ff;
  410. border-radius: 172rpx;
  411. width: 172rpx;
  412. height: 172rpx;
  413. }
  414. }
  415. }
  416. .itemSingle {
  417. width: 690rpx;
  418. height: 84rpx;
  419. margin-top: 20rpx;
  420. display: flex;
  421. flex-direction: row;
  422. justify-content: center;
  423. align-items: center;
  424. .slider {
  425. width: 100%;
  426. }
  427. }
  428. .itemXL {
  429. width: 690rpx;
  430. }
  431. .item_tag {
  432. display: flex;
  433. flex-direction: row;
  434. justify-content: flex-start;
  435. align-items: center;
  436. flex-wrap: wrap;
  437. width: 690rpx;
  438. padding: 20rpx;
  439. .tag {
  440. border-radius: 12rpx;
  441. margin-right: 10rpx;
  442. margin-top: 10rpx;
  443. padding: 8rpx 16rpx;
  444. height: 60rpx;
  445. border: 2rpx solid #eee;
  446. color: #333;
  447. display: flex;
  448. flex-direction: row;
  449. justify-content: center;
  450. align-items: center;
  451. background: #eeeeee;
  452. .close {
  453. width: 28rpx;
  454. margin-left: 2rpx;
  455. position: relative;
  456. }
  457. }
  458. .active {
  459. border-radius: 20rpx;
  460. border: 2rpx solid #ff5967;
  461. }
  462. .addNew {
  463. margin-right: 10rpx;
  464. margin-top: 10rpx;
  465. padding: 0rpx 20rpx;
  466. height: 60rpx;
  467. border-radius: 12rpx;
  468. background: #1f1f1f;
  469. color: #fff;
  470. display: flex;
  471. flex-direction: row;
  472. justify-content: center;
  473. align-items: center;
  474. }
  475. }
  476. .title {
  477. text-align: center;
  478. margin-top: 96rpx;
  479. width: 100%;
  480. font-weight: 600;
  481. font-family: PingFang SC, PingFang SC;
  482. font-weight: 500;
  483. font-size: 48rpx;
  484. color: #1F1F1F;
  485. }
  486. .subtitle {
  487. font-size: 24rpx;
  488. font-weight: 400;
  489. color: #959595;
  490. text-align: center;
  491. margin-top: 20rpx;
  492. width: 100%;
  493. }
  494. .phone_input {
  495. width: 626rpx;
  496. height: 84rpx;
  497. margin-top: 96rpx;
  498. background: #ffffff;
  499. border-radius: 24rpx;
  500. display: flex;
  501. align-items: center;
  502. border: 4rpx solid #000000;
  503. border-radius: 74rpx;
  504. .area_code {
  505. padding: 0 20rpx;
  506. font-size: 28rpx;
  507. color: #333;
  508. border-right: 1rpx solid #e0e0e0;
  509. }
  510. .input {
  511. flex: 1;
  512. height: 100%;
  513. padding-left: 20rpx;
  514. font-size: 28rpx;
  515. color: #333;
  516. }
  517. }
  518. .code_input {
  519. width: 626rpx;
  520. height: 84rpx;
  521. margin-top: 20rpx;
  522. background: #ffffff;
  523. border-radius: 24rpx;
  524. display: flex;
  525. align-items: center;
  526. border: 4rpx solid #000000;
  527. border-radius: 74rpx;
  528. padding-right: 8rpx;
  529. .input {
  530. flex: 1;
  531. height: 100%;
  532. padding-left: 20rpx;
  533. font-size: 28rpx;
  534. color: #333;
  535. }
  536. .btn {
  537. padding: 11rpx 26rpx;
  538. font-size: 28rpx;
  539. background: #000000;
  540. border-radius: 74rpx;
  541. font-family: 'PingFang SC-Bold';
  542. &.disabled {
  543. color: #999;
  544. background: transparent;
  545. }
  546. }
  547. }
  548. }
  549. .btn_submit {
  550. width: 660rpx;
  551. height: 96rpx;
  552. margin: 0 auto;
  553. margin-top: 74rpx;
  554. background: #1f1f1f;
  555. border-radius: 50rpx;
  556. font-weight: bold;
  557. font-size: 32rpx;
  558. color: #ffffff;
  559. display: flex;
  560. flex-direction: row;
  561. justify-content: center;
  562. align-items: center;
  563. }
  564. .mobilePhoneNotAvailable {
  565. font-family: PingFang SC, PingFang SC;
  566. font-weight: 400;
  567. font-size: 24rpx;
  568. color: #0084FF;
  569. text-align: center;
  570. margin-top: 42rpx;
  571. }
  572. </style>