updateTel.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <!-- 修改手机号 -->
  3. <view class="container">
  4. <u--form
  5. labelPosition="left"
  6. labelWidth="90"
  7. :model="fmData"
  8. :rules="rules"
  9. ref="uForm"
  10. >
  11. <u-form-item label="新手机号" prop="phone" borderBottom>
  12. <c-input
  13. placeholder="请输入新手机号"
  14. v-model="fmData.phone"
  15. maxlength="11"
  16. border="none"
  17. ></c-input>
  18. </u-form-item>
  19. <u-form-item label="验证码" prop="code" borderBottom>
  20. <c-input
  21. placeholder="请输入验证码"
  22. v-model="fmData.code"
  23. border="none"
  24. >
  25. <view class="send-code" slot="suffix">
  26. <text class="vertical-line">|</text>
  27. <c-code
  28. :phone="fmData.phone"
  29. :uniqueKey="updateTelCode"
  30. codeType="putPhone"
  31. ></c-code>
  32. </view>
  33. </c-input>
  34. </u-form-item>
  35. </u--form>
  36. <c-button type="primary" @click="handleComplete">完成</c-button>
  37. </view>
  38. </template>
  39. <script>
  40. import uniqueKey from '@/components/c-code/uniqueKey';
  41. const { updateTelCode } = uniqueKey;
  42. import { changePhone } from '@/api/user/my.js';
  43. export default {
  44. name: 'updateTel',
  45. data() {
  46. return {
  47. updateTelCode,
  48. rules: {
  49. phone: [
  50. {
  51. type: 'string',
  52. required: true,
  53. message: '请输入新手机号',
  54. trigger: ['change'],
  55. },
  56. {
  57. type: 'string',
  58. required: true,
  59. message: '手机号格式不正确',
  60. trigger: ['change'],
  61. pattern: /^(?:(?:\+|00)86)?1[3-9]\d{9}$/,
  62. },
  63. ],
  64. code: {
  65. type: 'string',
  66. required: true,
  67. message: '请输入验证码',
  68. trigger: ['change'],
  69. },
  70. },
  71. fmData: {
  72. phone: '',
  73. code: '',
  74. },
  75. };
  76. },
  77. methods: {
  78. async handleComplete() {
  79. await this.$refs.uForm.validate();
  80. try {
  81. this.$c.loading();
  82. await changePhone(this.fmData);
  83. uni.hideLoading();
  84. await this.$c.toast({
  85. title: '修改成功',
  86. icon: 'success',
  87. });
  88. uni.switchTab({
  89. url: '/pages/my/index',
  90. });
  91. } catch (e) {
  92. uni.hideLoading();
  93. console.error(e);
  94. }
  95. },
  96. },
  97. };
  98. </script>
  99. <style scoped lang="scss">
  100. .container {
  101. padding: $pg-pd;
  102. .u-form {
  103. background-color: #fff;
  104. margin-bottom: 100rpx;
  105. padding: 0px 30rpx;
  106. .u-form-item {
  107. .send-code {
  108. display: flex;
  109. align-items: center;
  110. .vertical-line {
  111. color: #e4e4e4;
  112. margin-right: 10rpx;
  113. }
  114. }
  115. }
  116. }
  117. }
  118. </style>