updateIdNumber.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view>
  3. <text class="top-tip">姓名仅允许修改一次;所填信息须与身份证上姓名一致</text>
  4. <view class="infoItem">
  5. <text class="tip">身份证</text>
  6. <uni-easyinput class="info-disabled" v-model="idNumber" :inputBorder="false" type="idcard" />
  7. </view>
  8. <view class="infoItem">
  9. <text class="tip">手机号</text>
  10. <uni-easyinput class="info" v-model="phone" :inputBorder="false" disabled />
  11. </view>
  12. <view class="infoItem">
  13. <text class="tip">验证码</text>
  14. <uni-easyinput class="info" v-model="verificationCode" :inputBorder="false" placeholder="请输入验证码"
  15. maxlength="4" />
  16. <text class="get-code-text" @click="getVerificationCode" :style="{color:codeColor,}">{{codeText}}</text>
  17. </view>
  18. <button class="btn" type="primary" @click="updateIdNumber">确定</button>
  19. </view>
  20. </template>
  21. <script>
  22. import {
  23. mapState,
  24. mapMutations
  25. } from 'vuex'
  26. export default {
  27. data() {
  28. return {
  29. phone: '',
  30. phoneOrigin: '',
  31. verificationCode: '',
  32. idNumber: '',
  33. codeColor: "#0271c1",
  34. codeText: "获取验证码",
  35. countDownTime: 6,
  36. timeNum: 6,
  37. timer: {},
  38. };
  39. },
  40. computed: {
  41. ...mapState('m_user', ['token', 'userInfo'])
  42. },
  43. methods: {
  44. ...mapMutations('m_user', ['updateUserInfo']),
  45. async getVerificationCode() {
  46. var pattern = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
  47. if (!pattern.test(this.phoneOrigin)) {
  48. uni.$showMsg("手机号格式错误! ")
  49. return;
  50. }
  51. if (this.countDownTime == this.timeNum) {
  52. const res = await uni.$http.get(`/verificationCode/${this.phoneOrigin}`)
  53. // this.verificationCode = res.data.data
  54. if (res.data.data === true) {
  55. uni.$showMsg('验证码发送成功!')
  56. // this.verificationCode = res.data.data;
  57. this.codeColor = "#e6252b";
  58. this.timer = setInterval(this.codeCallback, 1000)
  59. this.codeText = this.countDownTime + "s";
  60. } else {
  61. uni.$showMsg('验证码发送失败!')
  62. }
  63. } else {
  64. uni.$showMsg('操作频繁!请一分钟后重试!')
  65. }
  66. },
  67. //防止重复点击获取验证码及倒计时显示
  68. codeCallback() {
  69. this.countDownTime--
  70. if (this.countDownTime < 1) {
  71. clearInterval(this.timer)
  72. this.codeColor = "#0271c1";
  73. this.codeText = "获取验证码";
  74. this.countDownTime = this.timeNum
  75. } else {
  76. this.codeColor = "#e6252b";
  77. this.codeText = this.countDownTime + "s";
  78. }
  79. },
  80. async updateIdNumber() {
  81. if (this.idNumber.length < 4) {
  82. uni.$showMsg('身份证格式错误!')
  83. return;
  84. }
  85. let res = uni.$http.put('/userIdNumber', {
  86. idNumber: this.idNumber,
  87. verificationCode: this.verificationCode,
  88. phone: this.phoneOrigin
  89. });
  90. res.then(value => {
  91. if (value.data.success) {
  92. uni.$showMsg('修改成功!');
  93. let info = this.userInfo;
  94. info.idNumber = this.idNumber;
  95. this.updateUserInfo(info);
  96. setTimeout(() => {
  97. // uni.navigateTo({
  98. // url: '/subpkg/myAccount/myAccount'
  99. // })
  100. uni.navigateBack();
  101. }, 1000);
  102. } else {
  103. uni.$showMsg('修改失败:' + value.data.msg);
  104. };
  105. }, reason => {
  106. // console.log(reason);
  107. })
  108. }
  109. },
  110. created() {
  111. this.phoneOrigin = this.userInfo.phone.slice(0, this.userInfo.phone.length)
  112. this.phone = this.phoneOrigin.slice(0, 3) + '****' + this.phoneOrigin.slice(7, 11)
  113. }
  114. }
  115. </script>
  116. <style lang="scss">
  117. .top-tip {
  118. padding-left: 20rpx;
  119. font-size: 12px;
  120. color: darkgray
  121. }
  122. .infoItem {
  123. height: 100rpx;
  124. display: flex;
  125. justify-content: space-between;
  126. align-items: center;
  127. margin: 0 40rpx;
  128. border-bottom: black 1px solid;
  129. background-color: #F7F6F6;
  130. }
  131. .get-code-text,
  132. .tip {
  133. margin: 0 20rpx;
  134. }
  135. .btn {
  136. width: 80%;
  137. margin-top: 40rpx;
  138. }
  139. ::v-deep .is-disabled {
  140. color: black !important;
  141. }
  142. </style>