userInfo.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view class="content">
  3. <view class="row1">
  4. <text class="tit">头像</text>
  5. <view class="background-img" @click.stop="imgsub"><image class="background-img" v-model="userInfo.avatar" :src="userInfo.avatar" mode="aspectFill"></image></view>
  6. </view>
  7. <view class="row">
  8. <text class="tit">家长</text>
  9. <input class="input" type="text" disabled="true" v-model="userInfo.real_name" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row">
  12. <text class="tit">学生</text>
  13. <input class="input" type="text" disabled="true" v-model="student" placeholder-class="placeholder" />
  14. </view>
  15. <view class="row">
  16. <text class="tit">手机号</text>
  17. <input class="input" type="text" disabled="true" v-model="userInfo.phone" placeholder-class="placeholder" />
  18. </view>
  19. <button class="add-btn" @click="confirm">提交</button>
  20. </view>
  21. </template>
  22. <script>
  23. import { mapState } from 'vuex';
  24. import { uploads,my } from '@/api/user.js';
  25. import {userEdit} from '@/api/set.js'
  26. export default{
  27. data(){
  28. return{
  29. student:''
  30. }
  31. },
  32. onLoad() {
  33. this.loadData();
  34. console.log(this.userInfo)
  35. },
  36. computed: {
  37. ...mapState( ['userInfo'])
  38. },
  39. methods: {
  40. async loadData(){
  41. my({}).then(({ data }) => {
  42. this.student = data.full_name;
  43. });
  44. },
  45. imgsub() {
  46. console.log('上传头像')
  47. uploads({
  48. filename: ''
  49. }).then(data => {
  50. console.log("data",data);
  51. this.userInfo.avatar = data[0].url;
  52. })
  53. },
  54. confirm() {
  55. userEdit({ avatar: this.userInfo.avatar })
  56. .then(e => {
  57. this.$api.msg('修改成功');
  58. setTimeout(()=> {
  59. uni.switchTab({
  60. url:'/pages/user/user'
  61. });
  62. }, 1000);
  63. console.log(e);
  64. })
  65. .catch(e => {
  66. console.log(e);
  67. });
  68. }
  69. }
  70. }
  71. </script>
  72. <style lang="scss">
  73. .row1 {
  74. display: flex;
  75. align-items: center;
  76. justify-content: space-between;
  77. position: relative;
  78. padding: 0 30upx;
  79. height: 110upx;
  80. background: #fff;
  81. margin-bottom: 20upx;
  82. .tit {
  83. flex-shrink: 0;
  84. width: 120upx;
  85. font-size: $font-lg;
  86. color: $font-color-dark;
  87. }
  88. .background-img {
  89. width: 80rpx;
  90. height: 80rpx;
  91. border-radius: 50%;
  92. background: #f2f2f2;
  93. }
  94. }
  95. .row {
  96. display: flex;
  97. align-items: center;
  98. padding: 0 30upx;
  99. height: 110upx;
  100. background: #fff;
  101. .tit {
  102. flex-shrink: 0;
  103. width: 120upx;
  104. font-size: $font-lg;
  105. color: $font-color-dark;
  106. }
  107. .input {
  108. flex: 1;
  109. text-align: right;
  110. font-size: $font-base;
  111. color: $color-gray;
  112. }
  113. }
  114. .add-btn {
  115. display: flex;
  116. align-items: center;
  117. justify-content: center;
  118. width: 690upx;
  119. height: 80upx;
  120. margin: 60upx auto;
  121. font-size: $font-lg;
  122. color: #fff;
  123. background-color: #1CC7C7;
  124. border-radius: 10upx;
  125. }
  126. </style>