userphone.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <template>
  2. <view class="modify-phone-page">
  3. <!-- 自定义导航栏 -->
  4. <view class="custom-navbar">
  5. <view class="navbar-content">
  6. <view class="nav-left" @click="goBack">
  7. <u-icon name="arrow-leftward" color="#333" size="42"></u-icon>
  8. </view>
  9. <view class="nav-title">修改手机号</view>
  10. <view class="nav-right"></view>
  11. </view>
  12. </view>
  13. <!-- 主要内容 -->
  14. <view class="main-content">
  15. <!-- 页面标题 -->
  16. <view class="page-title">修改手机号</view>
  17. <!-- 说明文字 -->
  18. <view class="description">
  19. <text>修改手机号后,可以使用新手机号登录亿职赞,聊天时"交换电话"功能的手机号会统一修改</text>
  20. </view>
  21. <!-- 当前手机号显示 -->
  22. <view class="current-phone-section">
  23. <text class="current-label">当前手机号:</text>
  24. <text class="current-phone">{{currentPhoneMask}}</text>
  25. </view>
  26. <!-- 新手机号输入 -->
  27. <view class="input-section">
  28. <view class="phone-input-container">
  29. <view class="country-selector" @click="showCountrySelector">
  30. <text class="country-code">+ 86</text>
  31. <u-icon name="arrow-down" color="#999" size="24"></u-icon>
  32. </view>
  33. <input
  34. v-model="newPhone"
  35. type="number"
  36. placeholder="请输入新手机号"
  37. maxlength="11"
  38. class="phone-input"
  39. />
  40. </view>
  41. </view>
  42. <!-- 验证码输入 -->
  43. <view class="verification-section">
  44. <view class="verify-input-container">
  45. <view class="verify-boxes">
  46. <input
  47. v-for="(digit, index) in verificationDigits"
  48. :key="index"
  49. v-model="verificationDigits[index]"
  50. type="number"
  51. maxlength="1"
  52. :focus="focusIndex === index"
  53. class="verify-box"
  54. @input="handleDigitInput(index, $event)"
  55. @keyup.delete="handleDelete(index)"
  56. />
  57. </view>
  58. <view class="get-code-btn" @click="getVerificationCode" :class="{ disabled: isCountingDown }">
  59. <text>{{ countdownText }}</text>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- 底部确定按钮 -->
  65. <view class="bottom-btn-container">
  66. <view class="confirm-btn" @click="confirmChange" :class="{ disabled: !canConfirm }">
  67. <text>确定</text>
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. import configdata from '../../common/config.js';
  74. export default {
  75. data() {
  76. return {
  77. currentPhone: '18800000097', // 当前手机号
  78. newPhone: '', // 新手机号
  79. verificationDigits: ['', '', '', '', ''], // 验证码
  80. focusIndex: 0,
  81. isCountingDown: false,
  82. countdown: 60,
  83. countdownText: '获取验证码',
  84. };
  85. },
  86. computed: {
  87. // 当前手机号脱敏显示
  88. currentPhoneMask() {
  89. if (this.currentPhone && this.currentPhone.length >= 11) {
  90. return this.currentPhone.substring(0, 3) + '********' + this.currentPhone.substring(9);
  91. }
  92. return this.currentPhone || '请设置手机号';
  93. },
  94. // 是否可以确认
  95. canConfirm() {
  96. return this.newPhone.length === 11 && this.verificationDigits.join('').length === 5;
  97. }
  98. },
  99. onLoad(options) {
  100. // 从用户信息页面获取当前手机号
  101. if (options.currentPhone) {
  102. this.currentPhone = options.currentPhone;
  103. }
  104. },
  105. methods: {
  106. // 返回上一页
  107. goBack() {
  108. uni.navigateBack();
  109. },
  110. // 显示国家选择器
  111. showCountrySelector() {
  112. uni.showToast({
  113. title: '选择国家/地区',
  114. icon: 'none'
  115. });
  116. },
  117. // 验证码输入处理
  118. handleDigitInput(index, event) {
  119. const value = event.detail.value;
  120. this.verificationDigits[index] = value;
  121. // 自动跳转到下一框
  122. if (value && index < 4) {
  123. this.$nextTick(() => {
  124. this.focusIndex = index + 1;
  125. return;
  126. const nextInput = this.$el.querySelector(`input[data-index="${index + 1}"]`);
  127. console.log(nextInput)
  128. if (nextInput) nextInput.focus();
  129. });
  130. }
  131. },
  132. // 删除处理
  133. handleDelete(index) {
  134. if (!this.verificationDigits[index] && index > 0) {
  135. this.$nextTick(() => {
  136. //this.focusIndex = index - 1;
  137. return;
  138. const prevInput = this.$el.querySelector(`input[data-index="${index - 1}"]`);
  139. if (prevInput) prevInput.focus();
  140. });
  141. }
  142. },
  143. // 获取验证码
  144. async getVerificationCode() {
  145. if (!this.newPhone) {
  146. uni.showToast({
  147. title: '请输入新手机号',
  148. icon: 'none'
  149. });
  150. return;
  151. }
  152. if (this.newPhone.length !== 11) {
  153. uni.showToast({
  154. title: '请输入正确的手机号',
  155. icon: 'none'
  156. });
  157. return;
  158. }
  159. uni.showLoading({
  160. title: '发送中...'
  161. });
  162. try {
  163. // 调用发送验证码API
  164. const res = await this.request({
  165. url: '/msg/sendMsg/' + this.newPhone + '/changePhone',
  166. method: 'GET'
  167. });
  168. uni.hideLoading();
  169. if (res.status === 0) {
  170. uni.showToast({
  171. title: '验证码发送成功',
  172. icon: 'success'
  173. });
  174. this.startCountdown();
  175. } else {
  176. uni.showToast({
  177. title: res.msg || '发送失败,请重试',
  178. icon: 'none'
  179. });
  180. }
  181. } catch (error) {
  182. uni.hideLoading();
  183. uni.showToast({
  184. title: '网络错误,请重试',
  185. icon: 'none'
  186. });
  187. }
  188. },
  189. // 开始倒计时
  190. startCountdown() {
  191. this.isCountingDown = true;
  192. this.countdown = 60;
  193. this.countdownText = '60秒后重新获取';
  194. const timer = setInterval(() => {
  195. this.countdown--;
  196. this.countdownText = `${this.countdown}秒后重新获取`;
  197. if (this.countdown <= 0) {
  198. clearInterval(timer);
  199. this.isCountingDown = false;
  200. this.countdownText = '获取验证码';
  201. }
  202. }, 1000);
  203. },
  204. // 确认修改
  205. async confirmChange() {
  206. if (!this.canConfirm) {
  207. uni.showToast({
  208. title: '请完整填写信息',
  209. icon: 'none'
  210. });
  211. return;
  212. }
  213. uni.showLoading({
  214. title: '处理中...'
  215. });
  216. try {
  217. const userId = uni.getStorageSync('userId');
  218. const res = await this.request({
  219. url: '/user/changePhone',
  220. method: 'GET',
  221. data: {
  222. userId: userId,
  223. phone: this.newPhone,
  224. msg: this.verificationDigits.join('')
  225. }
  226. });
  227. uni.hideLoading();
  228. if (res.status === 0) {
  229. uni.showToast({
  230. title: '修改成功',
  231. icon: 'success'
  232. });
  233. setTimeout(() => {
  234. uni.navigateBack();
  235. }, 1500);
  236. } else {
  237. uni.showToast({
  238. title: res.msg || '修改失败',
  239. icon: 'none'
  240. });
  241. }
  242. } catch (error) {
  243. uni.hideLoading();
  244. uni.showToast({
  245. title: '网络错误,请重试',
  246. icon: 'none'
  247. });
  248. }
  249. },
  250. // 请求封装
  251. request(options) {
  252. return new Promise((resolve, reject) => {
  253. uni.request({
  254. url: configdata.APIHOST1 + options.url,
  255. method: options.method || 'POST',
  256. data: options.data || {},
  257. success: resolve,
  258. fail: reject
  259. });
  260. });
  261. }
  262. }
  263. }
  264. </script>
  265. <style lang="scss" scoped>
  266. .modify-phone-page {
  267. min-height: 100vh;
  268. background: #ffffff;
  269. }
  270. /* 导航栏 */
  271. .custom-navbar {
  272. position: fixed;
  273. top: 0;
  274. left: 0;
  275. right: 0;
  276. padding-top: 80rpx;
  277. background-color: #ffffff;
  278. z-index: 9999;
  279. // border-bottom: 1rpx solid #f0f0f0;
  280. .navbar-content {
  281. display: flex;
  282. align-items: center;
  283. justify-content: space-between;
  284. height: 88rpx;
  285. padding: 0 40rpx;
  286. .nav-left, .nav-right {
  287. width: 60rpx;
  288. height: 60rpx;
  289. display: flex;
  290. align-items: center;
  291. justify-content: center;
  292. }
  293. .nav-title {
  294. color: rgba(51, 51, 51, 1);
  295. font-family: PingFang SC;
  296. font-size: 36rpx;
  297. font-weight: 600;
  298. line-height: 50rpx;
  299. text-align: center;
  300. }
  301. }
  302. }
  303. /* 主要内容 */
  304. .main-content {
  305. margin-top: 168rpx;
  306. padding: 40rpx 30rpx;
  307. }
  308. .page-title {
  309. color: rgba(51, 51, 51, 1);
  310. font-family: DM Sans;
  311. font-size: 48rpx;
  312. font-weight: 700;
  313. line-height: 60rpx;
  314. letter-spacing: 0px;
  315. text-align: left;
  316. margin-bottom: 20rpx;
  317. }
  318. .description {
  319. color: rgba(102, 102, 102, 1);
  320. font-family: DM Sans;
  321. font-size: 24rpx;
  322. font-weight: 400;
  323. line-height: 32rpx;
  324. letter-spacing: 0.5%;
  325. text-align: left;
  326. margin-bottom: 20rpx;
  327. }
  328. .current-phone-section {
  329. display: flex;
  330. align-items: center;
  331. margin-bottom: 20rpx;
  332. gap: 16rpx;
  333. .current-label , .current-phone{
  334. color: rgba(102, 102, 102, 1);
  335. font-family: DM Sans;
  336. font-size: 24rpx;
  337. font-weight: 400;
  338. line-height: 32rpx;
  339. letter-spacing: 0.5%;
  340. text-align: left;
  341. }
  342. }
  343. /* 手机号输入 */
  344. .input-section {
  345. margin-bottom: 40rpx;
  346. }
  347. .phone-input-container {
  348. width: 100%;
  349. height: 88rpx;
  350. // border: 1px solid rgba(227, 231, 236, 1);
  351. // border-radius: 24px;
  352. background: rgba(255, 255, 255, 1);
  353. display: flex;
  354. align-items: center;
  355. // padding: 0 20rpx;
  356. .country-selector {
  357. display: flex;
  358. align-items: center;
  359. justify-content: center;
  360. width: 208rpx;
  361. height: 96rpx;
  362. border-radius: 12rpx;
  363. background: rgba(247, 248, 249, 1);
  364. // border-right: 1rpx solid #e4e6ea;
  365. margin-right: 20rpx;
  366. gap: 26rpx;
  367. .country-code {
  368. color: rgba(56, 59, 70, 1);
  369. font-family: DM Sans;
  370. font-size: 32rpx;
  371. font-weight: 500;
  372. line-height: 48rpx;
  373. letter-spacing: 0%;
  374. text-align: center;
  375. }
  376. }
  377. .phone-input {
  378. flex: 1;
  379. width: 446rpx;
  380. height: 96rpx;
  381. border-radius: 12rpx;
  382. padding: 0 32rpx;
  383. background: rgba(247, 248, 249, 1);
  384. // color: rgba(195, 196, 199, 1);
  385. font-family: DM Sans;
  386. font-size: 32rpx;
  387. font-weight: 400;
  388. line-height: 48rpx;
  389. letter-spacing: 0%;
  390. text-align: left;
  391. &::placeholder {
  392. color: rgba(195, 196, 199, 1);
  393. }
  394. }
  395. }
  396. /* 验证码部分 */
  397. .verification-section {
  398. margin-bottom: 60rpx;
  399. }
  400. .verify-input-container {
  401. display: flex;
  402. flex-direction: column;
  403. width: 100%;
  404. gap: 20rpx;
  405. padding: 20rpx 0;
  406. }
  407. .verify-boxes {
  408. display: flex;
  409. gap: 20rpx;
  410. justify-content: space-between;
  411. width: 100%;
  412. .verify-box {
  413. width: 110rpx;
  414. height: 96rpx;
  415. border: 1px solid rgba(234, 239, 245, 1);
  416. border-radius: 24rpx;
  417. background: rgba(245, 249, 254, 1);
  418. text-align: center;
  419. color: rgba(23, 23, 37, 1);
  420. font-family: PingFang SC;
  421. font-size: 32rpx;
  422. font-weight: 500;
  423. line-height: 80rpx;
  424. &:focus {
  425. border-color: rgba(24, 144, 255, 1);
  426. background: rgba(255, 255, 255, 1);
  427. }
  428. &::placeholder {
  429. color: rgba(155, 155, 155, 1);
  430. }
  431. }
  432. }
  433. .get-code-btn {
  434. color:rgba(1, 107, 246, 1);
  435. font-family: DM Sans;
  436. font-size: 26rpx;
  437. font-weight: 400;
  438. line-height: 32rpx;
  439. letter-spacing: 0.5%;
  440. text-align: left;
  441. &.disabled {
  442. color: rgba(155, 155, 155, 1);
  443. }
  444. }
  445. /* 底部按钮 */
  446. .bottom-btn-container {
  447. padding: 30rpx;
  448. background: #fff;
  449. // border-top: 1rpx solid #f0f0f0;
  450. z-index: 9999;
  451. }
  452. .confirm-btn {
  453. width: 100%;
  454. height: 88rpx;
  455. background: var(--线性渐变, linear-gradient(90.00deg, rgba(13, 39, 247, 1),rgba(19, 193, 234, 1) 100%));
  456. border-radius: 44rpx;
  457. display: flex;
  458. align-items: center;
  459. justify-content: center;
  460. &.disabled {
  461. opacity: 0.4;
  462. }
  463. text {
  464. color: rgba(255, 255, 255, 1);
  465. font-family: PingFang SC;
  466. font-size: 32rpx;
  467. font-weight: 600;
  468. line-height: 44rpx;
  469. }
  470. }
  471. </style>