editMobile.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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. }
  246. }
  247. });
  248. }
  249. }
  250. }
  251. </script>
  252. <style scoped lang="scss">
  253. .list_info {
  254. display: flex;
  255. flex-direction: column;
  256. justify-content: flex-start;
  257. align-items: center;
  258. color: #fff;
  259. width: 750rpx;
  260. .textContent {
  261. color: #1f1f1f;
  262. max-width: 400rpx;
  263. }
  264. .textPrompt {
  265. color: #999999;
  266. }
  267. .name {
  268. width: 690rpx;
  269. display: flex;
  270. flex-direction: row;
  271. justify-content: space-between;
  272. align-items: flex-start;
  273. color: #333;
  274. font-size: 28rpx;
  275. margin-top: 20rpx;
  276. .right {
  277. font-size: 28rpx;
  278. color: #ff2a95;
  279. }
  280. }
  281. .desc {
  282. width: 690rpx;
  283. display: flex;
  284. flex-direction: row;
  285. justify-content: space-between;
  286. align-items: flex-start;
  287. color: #999;
  288. font-size: 24rpx;
  289. margin-top: 20rpx;
  290. }
  291. .item {
  292. width: 690rpx;
  293. height: 84rpx;
  294. margin-top: 20rpx;
  295. background: #ffffff;
  296. position: relative;
  297. border-radius: 24rpx 24rpx 24rpx 24rpx;
  298. input {
  299. width: 100%;
  300. height: 100%;
  301. padding-left: 20rpx;
  302. font-size: 28rpx;
  303. color: #333;
  304. border: solid 1px #f0f0f0;
  305. border-radius: 12rpx;
  306. }
  307. .btn {
  308. position: absolute;
  309. right: 20rpx;
  310. top: 0rpx;
  311. font-weight: 400;
  312. font-size: 28rpx;
  313. line-height: 84rpx;
  314. color: #ff2a95;
  315. }
  316. .arrow {
  317. width: 36rpx;
  318. position: absolute;
  319. right: 20rpx;
  320. top: 24rpx;
  321. }
  322. }
  323. .bcenter {
  324. display: flex;
  325. flex-direction: row;
  326. justify-content: center;
  327. align-items: center;
  328. margin-top: 120rpx;
  329. .avator {
  330. width: 200rpx;
  331. height: 200rpx;
  332. position: relative;
  333. .img {
  334. width: 172rpx;
  335. height: 172rpx;
  336. border-radius: 86rpx;
  337. }
  338. .photo {
  339. width: 64rpx;
  340. height: 64rpx;
  341. position: absolute;
  342. bottom: 0;
  343. right: 10rpx;
  344. }
  345. }
  346. }
  347. .item2 {
  348. width: 690rpx;
  349. height: 84rpx;
  350. margin-top: 20rpx;
  351. display: flex;
  352. flex-direction: row;
  353. justify-content: center;
  354. align-items: center;
  355. .sex {
  356. width: 334rpx;
  357. height: 84rpx;
  358. background: #ffffff;
  359. border-radius: 24rpx;
  360. border: 2rpx solid #282828;
  361. color: #999;
  362. display: flex;
  363. flex-direction: row;
  364. justify-content: center;
  365. align-items: center;
  366. }
  367. .active {
  368. border: 4rpx solid #ff2a95;
  369. color: #ff2a95;
  370. }
  371. .sex2 {
  372. image {
  373. width: 172rpx;
  374. }
  375. }
  376. }
  377. .itemSex {
  378. width: 690rpx;
  379. margin-top: 20rpx;
  380. display: flex;
  381. flex-direction: row;
  382. justify-content: center;
  383. align-items: center;
  384. .sex2 {
  385. display: flex;
  386. flex-direction: column;
  387. justify-content: flex-end;
  388. align-items: center;
  389. width: 210rpx;
  390. height: 210rpx;
  391. text {
  392. color: #999;
  393. }
  394. image {
  395. width: 132rpx;
  396. height: 132rpx;
  397. }
  398. }
  399. .active {
  400. text {
  401. color: #fff;
  402. }
  403. image {
  404. border: 4rpx solid #36d6ff;
  405. border-radius: 172rpx;
  406. width: 172rpx;
  407. height: 172rpx;
  408. }
  409. }
  410. }
  411. .itemSingle {
  412. width: 690rpx;
  413. height: 84rpx;
  414. margin-top: 20rpx;
  415. display: flex;
  416. flex-direction: row;
  417. justify-content: center;
  418. align-items: center;
  419. .slider {
  420. width: 100%;
  421. }
  422. }
  423. .itemXL {
  424. width: 690rpx;
  425. }
  426. .item_tag {
  427. display: flex;
  428. flex-direction: row;
  429. justify-content: flex-start;
  430. align-items: center;
  431. flex-wrap: wrap;
  432. width: 690rpx;
  433. padding: 20rpx;
  434. .tag {
  435. border-radius: 12rpx;
  436. margin-right: 10rpx;
  437. margin-top: 10rpx;
  438. padding: 8rpx 16rpx;
  439. height: 60rpx;
  440. border: 2rpx solid #eee;
  441. color: #333;
  442. display: flex;
  443. flex-direction: row;
  444. justify-content: center;
  445. align-items: center;
  446. background: #eeeeee;
  447. .close {
  448. width: 28rpx;
  449. margin-left: 2rpx;
  450. position: relative;
  451. }
  452. }
  453. .active {
  454. border-radius: 20rpx;
  455. border: 2rpx solid #ff5967;
  456. }
  457. .addNew {
  458. margin-right: 10rpx;
  459. margin-top: 10rpx;
  460. padding: 0rpx 20rpx;
  461. height: 60rpx;
  462. border-radius: 12rpx;
  463. background: #1f1f1f;
  464. color: #fff;
  465. display: flex;
  466. flex-direction: row;
  467. justify-content: center;
  468. align-items: center;
  469. }
  470. }
  471. .title {
  472. text-align: center;
  473. margin-top: 96rpx;
  474. width: 100%;
  475. font-weight: 600;
  476. font-family: PingFang SC, PingFang SC;
  477. font-weight: 500;
  478. font-size: 48rpx;
  479. color: #1F1F1F;
  480. }
  481. .subtitle {
  482. font-size: 24rpx;
  483. font-weight: 400;
  484. color: #959595;
  485. text-align: center;
  486. margin-top: 20rpx;
  487. width: 100%;
  488. }
  489. .phone_input {
  490. width: 626rpx;
  491. height: 84rpx;
  492. margin-top: 96rpx;
  493. background: #ffffff;
  494. border-radius: 24rpx;
  495. display: flex;
  496. align-items: center;
  497. border: 4rpx solid #000000;
  498. border-radius: 74rpx;
  499. .area_code {
  500. padding: 0 20rpx;
  501. font-size: 28rpx;
  502. color: #333;
  503. border-right: 1rpx solid #e0e0e0;
  504. }
  505. .input {
  506. flex: 1;
  507. height: 100%;
  508. padding-left: 20rpx;
  509. font-size: 28rpx;
  510. color: #333;
  511. }
  512. }
  513. .code_input {
  514. width: 626rpx;
  515. height: 84rpx;
  516. margin-top: 20rpx;
  517. background: #ffffff;
  518. border-radius: 24rpx;
  519. display: flex;
  520. align-items: center;
  521. border: 4rpx solid #000000;
  522. border-radius: 74rpx;
  523. padding-right: 8rpx;
  524. .input {
  525. flex: 1;
  526. height: 100%;
  527. padding-left: 20rpx;
  528. font-size: 28rpx;
  529. color: #333;
  530. }
  531. .btn {
  532. padding: 11rpx 26rpx;
  533. font-size: 28rpx;
  534. background: #000000;
  535. border-radius: 74rpx;
  536. font-family: 'PingFang SC-Bold';
  537. &.disabled {
  538. color: #999;
  539. background: transparent;
  540. }
  541. }
  542. }
  543. }
  544. .btn_submit {
  545. width: 660rpx;
  546. height: 96rpx;
  547. margin: 0 auto;
  548. margin-top: 74rpx;
  549. background: #1f1f1f;
  550. border-radius: 50rpx;
  551. font-weight: bold;
  552. font-size: 32rpx;
  553. color: #ffffff;
  554. display: flex;
  555. flex-direction: row;
  556. justify-content: center;
  557. align-items: center;
  558. }
  559. .mobilePhoneNotAvailable {
  560. font-family: PingFang SC, PingFang SC;
  561. font-weight: 400;
  562. font-size: 24rpx;
  563. color: #0084FF;
  564. text-align: center;
  565. margin-top: 42rpx;
  566. }
  567. </style>