userinfo.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="container">
  3. <view class="list flex_r flex_ac">
  4. <view class="list_title flex_r flex_ac flex_jb"><text>头</text><text>像:</text></view>
  5. <img @click="upheadimg" :src="formDa.head_pic" alt="" srcset="" class="head_pic" />
  6. </view>
  7. <view class="list flex_r flex_ac">
  8. <view class="list_title flex_r flex_ac flex_jb"><text>昵</text><text>称:</text></view>
  9. <input type="text" class="flex_grow" v-model="formDa.nickname" placeholder="请输入昵称" />
  10. </view>
  11. <view class="confimBtn flex_r flex_ac flex_jc" @tap="upda">提交</view>
  12. </view>
  13. </template>
  14. <script>
  15. let app = getApp();
  16. let appEv = app.$vm.$options;
  17. import { post } from "@/request/api.js";
  18. export default {
  19. data() {
  20. return {
  21. formDa: {
  22. nickname: undefined,
  23. head_pic: undefined
  24. },
  25. };
  26. },
  27. onLoad() {
  28. this.loadData();
  29. },
  30. methods: {
  31. loadData() {
  32. let da = uni.getStorageSync("userinfo");
  33. this.formDa.nickname = da.nickname;
  34. this.formDa.head_pic = da.head_pic;
  35. },
  36. upheadimg() {
  37. // 上传图片uploadImg
  38. let that = this;
  39. uni.chooseImage({
  40. count: 1, // 最多可以选择的图片张数,默认9
  41. sizeType: ["compressed"], // original 原图,compressed 压缩图,默认二者都有
  42. sourceType: ["album", "camera"], // album 从相册选图,camera 使用相机,默认二者都有
  43. success: function(res) {
  44. var arr = res.tempFiles;
  45. that.$up(arr[0].path).then((res) => {
  46. that.$set(that.formDa, "head_pic", res);
  47. // that.formDa.head_pic = res;
  48. });
  49. },
  50. });
  51. },
  52. upda() {
  53. post("user/setup", this.formDa).then((res) => {
  54. if (res.code === 0) {
  55. appEv.errTips(res.msg);
  56. this.getuserInfo();
  57. uni.navigateBack({
  58. delta: 1, //返回层数,2则上上页
  59. });
  60. }
  61. });
  62. },
  63. getuserInfo() {
  64. post("/user/userinfo").then((res) => {
  65. if (res.code === 0) {
  66. uni.setStorageSync("userinfo", res.data.data);
  67. this.loadData();
  68. }
  69. });
  70. },
  71. },
  72. };
  73. </script>
  74. <style lang="scss">
  75. // 页面配置
  76. .container {
  77. width: 100%;
  78. overflow: hidden;
  79. border-top: 20rpx solid #f5f5f5;
  80. }
  81. // 页面配置-end
  82. // 表单
  83. .list input {
  84. font-size: 30rpx;
  85. color: #343434;
  86. }
  87. .list_title {
  88. width: 120rpx;
  89. overflow: hidden;
  90. margin-right: 100rpx;
  91. font-size: 30rpx;
  92. color: #535353;
  93. }
  94. .confimBtn {
  95. width: 329rpx;
  96. height: 73rpx;
  97. margin: 74rpx auto 0;
  98. background: #18bb88;
  99. font-size: 40rpx;
  100. color: #fff;
  101. }
  102. .option {
  103. width: 172rpx;
  104. height: 54rpx;
  105. border-radius: 4rpx;
  106. background-color: #18bb88;
  107. color: #fff;
  108. font-size: 26rpx;
  109. margin-left: 12rpx;
  110. }
  111. .list {
  112. width: 100%;
  113. height: 92rpx;
  114. background-color: #fff;
  115. padding: 0 60rpx;
  116. box-sizing: border-box;
  117. border-bottom: 3rpx solid rgba(0, 0, 0, 0.12);
  118. &:first-child {
  119. height: 120rpx;
  120. justify-content: space-between;
  121. }
  122. }
  123. .g_color {
  124. background-color: #e8e8e8;
  125. color: #ff5758;
  126. }
  127. // 表单-end
  128. .flex_grow {
  129. text-align: right;
  130. }
  131. .head_pic {
  132. width: 92rpx;
  133. height: 92rpx;
  134. border-radius: 50%;
  135. }
  136. </style>