mysetting.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view class="mysetting-page">
  3. <view class="form-cont">
  4. <vew class="item">
  5. <text>头像</text>
  6. <button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="chooseAvatar">
  7. <image :src="avatar" mode="aspectFill" class="avatar"></image>
  8. <image src="@/static/upload_avatar.png" class="avatar_ico"></image>
  9. </button>
  10. </vew>
  11. <view class="item">
  12. <text>昵称</text>
  13. <input v-model="nickname" type="nickname" class="nick-field" placeholder="请输入昵称"/>
  14. </view>
  15. </view>
  16. <view class="btn-cont">
  17. <van-button round size="large" block color="#DBA665" @click="saveMySetting">保存</van-button>
  18. <van-button round size="large" block color="#F5F5F5" class="cancel" @click="cancel">取消</van-button>
  19. </view>
  20. <view class="bottom-text">专注为全球投资者提供中立客观的研究服务</view>
  21. </view>
  22. </template>
  23. <script>
  24. import { apiSetMyinfo } from '@/api/user'
  25. import { uploadToServer } from '@/utils/upload.js'
  26. export default {
  27. data() {
  28. return {
  29. avatar: '',
  30. nickname:'',
  31. }
  32. },
  33. methods: {
  34. chooseAvatar(e) {
  35. console.log(e)
  36. const { avatarUrl } = e.detail;
  37. uploadToServer(avatarUrl).then(res => {
  38. this.avatar = res;
  39. })
  40. },
  41. /* 保存我的设置 */
  42. async saveMySetting() {
  43. if(!this.avatar || !this.nickname ) return uni.showToast({
  44. title: '请先设置头像和昵称哦~',
  45. icon: 'none'
  46. })
  47. const { code } = await apiSetMyinfo({ nick_name: this.nickname, head_img_url: this.avatar })
  48. if(code !== 200) return
  49. uni.showToast({
  50. title: '保存成功',
  51. icon: 'none',
  52. success: ()=> {
  53. setTimeout(() =>{
  54. this.cancel()
  55. },1000)
  56. }
  57. })
  58. },
  59. cancel() {
  60. uni.navigateBack({
  61. delta: 1
  62. })
  63. },
  64. initData() {
  65. const { head_img_url,nick_name } = this.userInfo;
  66. this.avatar = head_img_url;
  67. this.nickname = nick_name;
  68. }
  69. },
  70. onShow() {
  71. this.initData()
  72. }
  73. }
  74. </script>
  75. <style lang="scss">
  76. .mysetting-page {
  77. padding: 120rpx 60rpx;
  78. .form-cont {
  79. .item {
  80. font-size: 34rpx;
  81. display: flex;
  82. margin-bottom: 30rpx;
  83. &:first-child {
  84. align-items: center;
  85. }
  86. .avatar-wrapper {
  87. position: relative;
  88. margin-left: 50rpx;
  89. background: #fff;
  90. padding: 0;
  91. &::after {
  92. border: none;
  93. }
  94. .avatar {
  95. width: 140rpx;
  96. height: 140rpx;
  97. border-radius: 50%;
  98. }
  99. .avatar_ico {
  100. width: 40rpx;
  101. height: 40rpx;
  102. position: absolute;
  103. bottom: 24rpx;
  104. right: 0;
  105. z-index: 2;
  106. }
  107. }
  108. .nick-field {
  109. font-size: 32rpx;
  110. width: 478rpx;
  111. margin-left: 50rpx;
  112. padding-bottom: 20rpx;
  113. border-bottom: 1px solid #DFAD6F;
  114. }
  115. }
  116. }
  117. .btn-cont {
  118. padding: 0 40rpx;
  119. margin-top: 150rpx;
  120. .cancel .van-button{
  121. color: #999 !important;
  122. margin-top: 30rpx;
  123. }
  124. }
  125. .bottom-text {
  126. width: 100%;
  127. position: fixed;
  128. left: 50%;
  129. text-align: center;
  130. color: #999999;
  131. transform: translateX(-50%);
  132. bottom: 10%;
  133. }
  134. }
  135. </style>