userinfo.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <view class="content">
  3. <view class="row b-b">
  4. <text class="tit">昵称</text>
  5. <input class="input" type="text" v-model="name" placeholder="修改昵称" placeholder-class="placeholder" />
  6. </view>
  7. <view class="row b-b">
  8. <text class="tit">生日</text>
  9. <picker mode="date" @change="bindDateChange">
  10. <input class="input" type="text" v-model="date" placeholder="请选择日期" placeholder-class="placeholder" />
  11. </picker>
  12. </view>
  13. <view class="row b-b">
  14. <text class="tit">手机</text>
  15. <input class="input" type="text" v-model="phone" placeholder="请填写手机号" placeholder-class="placeholder" />
  16. </view>
  17. <button class="add-btn" @click="confirm">提交</button>
  18. </view>
  19. </template>
  20. <script>
  21. import { mapState } from 'vuex';
  22. import { userEdit } from '@/api/set.js';
  23. export default {
  24. data() {
  25. const currentDate = this.getDate({
  26. format: true
  27. })
  28. return {
  29. name: '',
  30. phone: '',
  31. date: currentDate,
  32. };
  33. },
  34. computed: {
  35. ...mapState('user',['userInfo']),
  36. },
  37. onShow() {
  38. console.log(this.userInfo)
  39. this.name = this.userInfo.nickname + '';
  40. this.phone = this.userInfo.phone||'';
  41. },
  42. methods: {
  43. bindDateChange: function(e) {
  44. this.date = e.target.value
  45. },
  46. getDate(type) {
  47. const date = new Date();
  48. let year = date.getFullYear();
  49. let month = date.getMonth() + 1;
  50. let day = date.getDate();
  51. if (type === 'start') {
  52. year = year - 60;
  53. } else if (type === 'end') {
  54. year = year + 2;
  55. }
  56. month = month > 9 ? month : '0' + month;;
  57. day = day > 9 ? day : '0' + day;
  58. return `${year}-${month}-${day}`;
  59. },
  60. // 数据处理结果
  61. onConfirm(val) {
  62. this.resultInfo = { ...val };
  63. this.birthday = this.resultInfo.result;
  64. },
  65. switchChange(e) {
  66. this.addressData.default = e.value;
  67. },
  68. confirm() {
  69. userEdit({ nickname: this.name, avatar: this.userInfo.avatar, birthday: this.date, phone: this.phone })
  70. .then(e => {
  71. this.$api.msg('修改成功');
  72. setTimeout(() => {
  73. uni.switchTab({
  74. url: '/pages/user/user'
  75. });
  76. }, 1000);
  77. console.log(e);
  78. })
  79. .catch(e => {
  80. console.log(e);
  81. });
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="scss">
  87. page {
  88. background: $page-color-base;
  89. padding-top: 16upx;
  90. }
  91. .uni-picker{
  92. }
  93. .row {
  94. display: flex;
  95. align-items: center;
  96. position: relative;
  97. padding: 0 30upx;
  98. height: 110upx;
  99. background: #fff;
  100. .tit {
  101. flex-shrink: 0;
  102. width: 120upx;
  103. font-size: 30upx;
  104. color: $font-color-dark;
  105. }
  106. .input {
  107. flex: 1;
  108. font-size: 30upx;
  109. color: $font-color-dark;
  110. }
  111. .iconlocation {
  112. font-size: 36upx;
  113. color: $font-color-light;
  114. }
  115. }
  116. .add-btn {
  117. display: flex;
  118. align-items: center;
  119. justify-content: center;
  120. width: 690upx;
  121. height: 80upx;
  122. margin: 60upx auto;
  123. font-size: $font-lg;
  124. color: #fff;
  125. background-color: $base-color;
  126. border-radius: 10upx;
  127. }
  128. </style>