updateNameAndIdNumber.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view>
  3. <view class="infoItem">
  4. <view class="tip">
  5. <u-text text="姓名:"></u-text>
  6. </view>
  7. <u-input placeholder="请输入姓名" border="surround" v-model="name" clearable></u-input>
  8. </view>
  9. <view class="infoItem">
  10. <view class="tip">
  11. <u-text text="身份证:"></u-text>
  12. </view>
  13. <u-input placeholder="请输入身份证号" border="surround" v-model="idNumber" type="idcard" clearable></u-input>
  14. </view>
  15. <view class="btn">
  16. <u-button text="确定" color="#7896F5" @click="updateNameAndIdNumber"></u-button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. mapState,
  23. mapMutations
  24. } from 'vuex'
  25. export default {
  26. data() {
  27. return {
  28. idNumber: '',
  29. name: '',
  30. };
  31. },
  32. computed: {
  33. ...mapState('m_user', ['token', 'userInfo'])
  34. },
  35. methods: {
  36. ...mapMutations('m_user', ['updateUserInfo']),
  37. async updateNameAndIdNumber() {
  38. if (this.idNumber.length < 18) {
  39. uni.$showMsg('身份证格式错误!')
  40. return;
  41. }
  42. if (this.name.length < 2) {
  43. uni.$showMsg('姓名格式错误!')
  44. return;
  45. }
  46. let res = await uni.$http.put('/userInfo/' + this.userInfo.id, {
  47. idNumber: this.idNumber,
  48. name: this.name
  49. });
  50. if (res.data.code === 200 && res.data.success === true) {
  51. uni.$showMsg('修改成功!');
  52. let info = this.userInfo;
  53. info.idNumber = this.idNumber;
  54. info.name = this.name;
  55. this.updateUserInfo(info);
  56. var pages = getCurrentPages(); // 当前页面
  57. var beforePage = pages[pages.length - 2]; // 前一个页面
  58. if (beforePage.route == "subpkg/myAccount/myAccount") {
  59. setTimeout(() => {
  60. uni.navigateBack();
  61. }, 1000);
  62. } else {
  63. setTimeout(() => {
  64. uni.switchTab({
  65. url: '/pages/home/home'
  66. });
  67. }, 1000);
  68. }
  69. } else {
  70. uni.$showMsg('修改失败:' + value.data.msg);
  71. }
  72. }
  73. },
  74. onLoad() {
  75. var pages = getCurrentPages(); // 当前页面
  76. var beforePage = pages[pages.length - 2]; // 前一个页面
  77. console.log(beforePage)
  78. this.name = this.userInfo.name
  79. this.idNumber = this.userInfo.idNumber
  80. }
  81. }
  82. </script>
  83. <style lang="scss">
  84. .top-tip {
  85. padding-left: 20rpx;
  86. font-size: 12px;
  87. color: darkgray
  88. }
  89. .infoItem {
  90. height: 100rpx;
  91. display: flex;
  92. justify-content: space-between;
  93. align-items: center;
  94. margin: 0 40rpx;
  95. border-bottom: black 1px solid;
  96. }
  97. .get-code-text,
  98. .tip {
  99. margin: 0 20rpx;
  100. width: 120rpx;
  101. }
  102. .u-input {
  103. width: 70vw;
  104. }
  105. .btn {
  106. margin: 40rpx auto;
  107. width: 80vw;
  108. color: #FFFFFF;
  109. }
  110. ::v-deep .is-disabled {
  111. color: black !important;
  112. }
  113. </style>