profile.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="body">
  3. <!-- 导航栏 -->
  4. <u-navbar title="个人资料" :placeholder="true" bgColor="rgba(255,255,255,0.3)" leftText="返回" :autoBack="true"
  5. titleStyle="font-weight:bold;color:#7a5831"></u-navbar>
  6. <view class="cu-card">
  7. <view class="cu-item margin-sm radius padding-sm">
  8. <view class="text-center padding-tb-xl" @tap="chooseAvatar()">
  9. <view>
  10. <image class="cu-avatar round" style="width: 200rpx;height: 200rpx;" :src="profile.avatar">
  11. </image>
  12. </view>
  13. <view class="text-center text-sm margin-top-xs text-gray">
  14. <text>点击更换头像</text>
  15. </view>
  16. </view>
  17. <view class="cu-form-group">
  18. <view class="title">
  19. <text>用户昵称</text>
  20. <text class="margin-left-xs text-red">*</text>
  21. </view>
  22. <input class="text-right" placeholder="请输入昵称" v-model="profile.nickname"></input>
  23. </view>
  24. <view class="cu-form-group">
  25. <view class="title">
  26. <text>性别</text>
  27. </view>
  28. <view>
  29. <u-radio-group
  30. v-model="selsex"
  31. placement="row"
  32. @change="swGender"
  33. >
  34. <u-radio
  35. :customStyle="{marginLeft: '10px'}"
  36. v-for="(item, index) in sexlist"
  37. :key="index"
  38. :label="item.name"
  39. :name="item.name"
  40. >
  41. </u-radio>
  42. </u-radio-group>
  43. </view>
  44. </view>
  45. <view class="cu-form-group">
  46. <view class="title">
  47. <text>联系方式</text>
  48. </view>
  49. <input class="text-right" placeholder="请输入手机号" v-model="profile.mobile"></input>
  50. </view>
  51. <!-- <view class="cu-form-group">
  52. <view class="title">
  53. <text>个人介绍</text>
  54. </view>
  55. <input class="text-right" placeholder="一句话介绍一下你自己" v-model="profile.bio"></input>
  56. </view> -->
  57. </view>
  58. <view class="bottom-group padding text-center ">
  59. <button class="cu-btn main-bg margin-lr-sm round lg" @click="submit">
  60. <text class="text">确认修改</text>
  61. </button>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. let _this;
  68. import {
  69. baseApiUrl
  70. } from '@/config/config.js';
  71. export default {
  72. data() {
  73. return {
  74. showLoad: false,
  75. vuex_user: {},
  76. upload: false,
  77. sexlist: [{
  78. name: '女',
  79. disabled: false
  80. },
  81. {
  82. name: '男',
  83. disabled: false
  84. }],
  85. selsex:'女',
  86. profile: {
  87. avatar: '',
  88. bio: '',
  89. nickname: '',
  90. openid: '',
  91. // mobile: '',
  92. // score: '',
  93. // token: '',
  94. // user_id: '',
  95. // username: '',
  96. // birthday: '',
  97. gender: 0
  98. }
  99. }
  100. },
  101. onLoad() {
  102. _this = this;
  103. },
  104. onShow() {
  105. this.vuex_user = this.$db.get('user');
  106. // 历遍并替换
  107. // for (let key in this.profile) {
  108. // this.profile[key] = this.vuex_user[key];
  109. // }
  110. //avatar: '', bio: '', nickname: '', openid:'' this.profile['']
  111. this.profile.nickname = this.vuex_user.nickname;
  112. this.profile.avatar = this.vuex_user.avatar;
  113. this.profile.bio = this.vuex_user.bio;
  114. this.profile.mobile = this.vuex_user.mobile;
  115. if(this.vuex_user.gender==0)
  116. this.selsex='女'
  117. else
  118. this.selsex='男'
  119. // this.profile.openid=this.vuex_user.TikTok_open_id;
  120. console.log(this.profile);
  121. },
  122. methods: {
  123. swGender(e) {
  124. if(e=='男')
  125. this.profile.gender=1;
  126. else
  127. this.profile.gender=0;
  128. console.log(e);
  129. //this.profile.gender = e.detail.value ? 1 : 0
  130. },
  131. chooseAvatar() {
  132. uni.navigateTo({
  133. url: '/user_fenbao/info/clipper?imgType=changeAvatar',
  134. });
  135. },
  136. submit() {
  137. let i = 0;
  138. if (this.upload) {
  139. uni.showToast({
  140. title: '请稍后上传中...'
  141. });
  142. return
  143. }
  144. console.log(this.profile)
  145. this.showLoad = true;
  146. console.log(this.profile);
  147. this.$api.profile(this.profile, res => {
  148. this.showLoad = false;
  149. if (res) {
  150. this.vuex_user.gender=this.profile.gender;
  151. this.vuex_user.nickname=this.profile.nickname;
  152. this.vuex_user.avatar=this.profile.avatar;
  153. this.$db.set('user', this.vuex_user);
  154. uni.showToast({
  155. title: '保存成功'
  156. });
  157. }
  158. });
  159. }
  160. }
  161. }
  162. </script>
  163. <style>
  164. </style>