userinfo.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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(['userInfo']),
  36. },
  37. onShow() {
  38. this.name = this.userInfo.nickname + '';
  39. this.phone = this.userInfo.phone||'';
  40. },
  41. methods: {
  42. bindDateChange: function(e) {
  43. this.date = e.target.value
  44. },
  45. getDate(type) {
  46. const date = new Date();
  47. let year = date.getFullYear();
  48. let month = date.getMonth() + 1;
  49. let day = date.getDate();
  50. if (type === 'start') {
  51. year = year - 60;
  52. } else if (type === 'end') {
  53. year = year + 2;
  54. }
  55. month = month > 9 ? month : '0' + month;;
  56. day = day > 9 ? day : '0' + day;
  57. return `${year}-${month}-${day}`;
  58. },
  59. // 数据处理结果
  60. onConfirm(val) {
  61. this.resultInfo = { ...val };
  62. this.birthday = this.resultInfo.result;
  63. },
  64. confirm() {
  65. userEdit({ nickname: this.name, avatar: this.userInfo.avatar, birthday: this.date, phone: this.phone })
  66. .then(e => {
  67. this.$api.msg('修改成功');
  68. setTimeout(() => {
  69. uni.switchTab({
  70. url: '/pages/user/user'
  71. });
  72. }, 1000);
  73. console.log(e);
  74. })
  75. .catch(e => {
  76. console.log(e);
  77. });
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss">
  83. page {
  84. background: $page-color-base;
  85. padding-top: 16upx;
  86. }
  87. .uni-picker{
  88. }
  89. .row {
  90. display: flex;
  91. align-items: center;
  92. position: relative;
  93. padding: 0 30upx;
  94. height: 110upx;
  95. background: #fff;
  96. .tit {
  97. flex-shrink: 0;
  98. width: 120upx;
  99. font-size: 30upx;
  100. color: $font-color-dark;
  101. }
  102. .input {
  103. flex: 1;
  104. font-size: 30upx;
  105. color: $font-color-dark;
  106. }
  107. .iconlocation {
  108. font-size: 36upx;
  109. color: $font-color-light;
  110. }
  111. }
  112. .add-btn {
  113. display: flex;
  114. align-items: center;
  115. justify-content: center;
  116. width: 690upx;
  117. height: 80upx;
  118. margin: 60upx auto;
  119. font-size: $font-lg;
  120. color: #fff;
  121. background-color: $base-color;
  122. border-radius: 10upx;
  123. }
  124. </style>