index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div class="bg">
  3. <div class="content">
  4. <div @click="() => {
  5. userFormShow = true
  6. }" class="nickname">
  7. <div style="display: flex;align-items: center;height: 100%;">
  8. <image class="headImg" mode="widthFix" src="/static/icon/user_nickname.png"></image>
  9. <div>用户昵称</div>
  10. </div>
  11. <div style="display: flex;align-items: center;height: 100%;">
  12. <div style="margin-right: 20rpx;">{{ userInfo.nickName }}</div>
  13. <image class="arrow" mode="widthFix" src="/static/icon/user_arrow2@2x.png"></image>
  14. </div>
  15. </div>
  16. <div @click="() => {
  17. userFormShow = true
  18. }" class="nickname">
  19. <div style="display: flex;align-items: center;height: 100%;">
  20. <image class="headImg" mode="widthFix" src="/static/icon/user_phone.png"></image>
  21. <div>手机号</div>
  22. </div>
  23. <div style="display: flex;align-items: center;height: 100%;">
  24. <div style="margin-right: 20rpx;">{{ userInfo.phone }}</div>
  25. <image class="arrow" mode="widthFix" src="/static/icon/user_arrow2@2x.png"></image>
  26. </div>
  27. </div>
  28. </div>
  29. <van-popup :z-index="9999" :close-on-click-overlay="true" position="bottom" :show="userFormShow">
  30. <view class="userform">
  31. <!-- <view></view> -->
  32. <view class="userform-close">
  33. <van-icon @click="() => {
  34. userFormShow = false;
  35. }
  36. " color="#a8a8a8" size="18" name="cross" />
  37. </view>
  38. <view>
  39. <van-field :value="userInfo.nickName" type="nickname" required clearable label="用户名"
  40. @blur="changeUserName" placeholder="请输入用户名" />
  41. <van-field :value="userInfo.phone" clearable label="手机号" placeholder="请绑定手机号" @change="changeUserPhone">
  42. </van-field>
  43. </view>
  44. <view class="userform-bind">
  45. <van-button @click="sendUserInfo" custom-style="width:690rpx;" round type="primary">确定</van-button>
  46. </view>
  47. </view>
  48. </van-popup>
  49. </div>
  50. </template>
  51. <script>
  52. import api from '@/api/index';
  53. export default {
  54. data() {
  55. return {
  56. userInfo: uni.getStorageSync("userInfo"),
  57. userFormShow: false
  58. }
  59. },
  60. methods: {
  61. sendUserInfo() {
  62. if (/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/g.test(this.userInfo.phone)) {
  63. api.user.userInfoUserInfo(this.userInfo).then(res => {
  64. this.userFormShow = false
  65. api.user.userInfoGetUserInfo().then(res => {
  66. this.userInfo = res.data.data
  67. uni.setStorageSync('userInfo', this.userInfo)
  68. })
  69. })
  70. }
  71. else {
  72. uni.showToast({
  73. title: '手机格式错误',
  74. icon: 'error'
  75. })
  76. }
  77. },
  78. changeUserName(e) {
  79. console.log(e);
  80. const name =e.detail.value||e.detail
  81. this.userInfo.nickName =name;
  82. },
  83. changeUserPhone(e) {
  84. console.log(e);
  85. this.userInfo.phone = e.detail;
  86. },
  87. },
  88. }
  89. </script>
  90. <style lang="less" scoped>
  91. .bg {
  92. background-color: #F6ECDB;
  93. width: 100vw;
  94. min-height: 100vh;
  95. .content {
  96. padding-top: 40rpx;
  97. padding-left: 30rpx;
  98. padding-right: 30rpx;
  99. .nickname {
  100. padding: 0 30rpx;
  101. font-size: 30rpx;
  102. display: flex;
  103. justify-content: space-between;
  104. align-items: center;
  105. height: 140rpx;
  106. background-color: #FFFBF5;
  107. .headImg {
  108. width: 80rpx;
  109. margin-right: 20rpx;
  110. }
  111. .arrow {
  112. width: 16rpx;
  113. }
  114. }
  115. }
  116. .userform {
  117. width: 100%;
  118. height: auto;
  119. background: #fff;
  120. .userform-close {
  121. text-align: right;
  122. padding-right: 15rpx;
  123. padding-top: 15rpx;
  124. }
  125. .userform-bind {
  126. width: 100%;
  127. padding: 30rpx 30rpx;
  128. display: flex;
  129. justify-content: center;
  130. }
  131. }
  132. }
  133. </style>