updateNameAndIdNumber.vue 3.1 KB

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