updataUser.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <view>
  3. <view class="index">
  4. <view class="input" @tap="upload">
  5. <text class="left">头像</text>
  6. <view class="right"><image :src="userinfo.avatar" mode=""></image></view>
  7. <text class="icon">&#xe60f;</text>
  8. </view>
  9. <view class="input">
  10. <text class="left">手机号</text>
  11. <view class="right">{{ userinfo.mobile }}</view>
  12. <!-- <text class="icon">&#xe60f;</text> -->
  13. </view>
  14. <view class="input" style="border: none;" @tap="update('bio', userinfo.bio, '请输入个性签名')">
  15. <text class="left">个性签名</text>
  16. <view class="right">{{ userinfo.bio }}</view>
  17. <text class="icon">&#xe60f;</text>
  18. </view>
  19. </view>
  20. <prompt :visible.sync="promptVisible" :placeholder="placeholder" :defaultValue="defaultValue" @confirm="clickPromptConfirm" mainColor="#32c45e"></prompt>
  21. </view>
  22. </template>
  23. <script>
  24. import Prompt from '@/components/zz-prompt/index.vue';
  25. import helper from '../../common/helper.js';
  26. import api from '../../common/api.js';
  27. export default {
  28. components: {
  29. Prompt
  30. },
  31. data() {
  32. return {
  33. userinfo: {},
  34. promptVisible: false,
  35. placeholder: '',
  36. defaultValue: '',
  37. key: ''
  38. };
  39. },
  40. onLoad() {
  41. this.getUserInfo();
  42. },
  43. methods: {
  44. upload() {
  45. uni.chooseImage({
  46. success: async chooseImageRes => {
  47. let res = await api.upload(chooseImageRes.tempFilePaths[0]);
  48. if (res.code != 1) {
  49. helper.toast(res.msg);
  50. return false;
  51. }
  52. this.userinfo.avatar = helper.host + res.data.url;
  53. res = await api.updateUserInfo({ avatar: this.userinfo.avatar });
  54. helper.toast(res.msg);
  55. }
  56. });
  57. },
  58. async update(key, defaultValue, placeholder) {
  59. this.placeholder = placeholder;
  60. this.defaultValue = defaultValue;
  61. this.key = key;
  62. this.promptVisible = true;
  63. },
  64. async clickPromptConfirm(value) {
  65. this.promptVisible = false;
  66. let res = await api.updateUserInfo({ [this.key]: value });
  67. helper.toast(res.msg);
  68. if (res.code == 1) {
  69. this.userinfo[this.key] = value;
  70. }
  71. },
  72. async getUserInfo() {
  73. let res = await api.getUserInfo();
  74. this.userinfo = res.data;
  75. }
  76. }
  77. };
  78. </script>
  79. <style lang="scss" scoped>
  80. .index {
  81. border-top: 1px solid #e6e6e6;
  82. padding: 20upx 5%;
  83. }
  84. .input {
  85. display: flex;
  86. align-items: center;
  87. font-size: 28upx;
  88. padding: 30upx 0;
  89. border-bottom: 1px solid #eeeeee;
  90. .left {
  91. width: 20%;
  92. }
  93. .icon {
  94. width: 20upx;
  95. text-align: right;
  96. color: #b5b5b5;
  97. font-size: 28upx;
  98. }
  99. .right {
  100. width: 80%;
  101. text-align: right;
  102. color: #555555;
  103. image {
  104. width: 50upx;
  105. height: 50upx;
  106. border-radius: 50%;
  107. }
  108. }
  109. }
  110. </style>