index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="client-personInfo">
  3. <page-navbar bgColor="#fff" title="个人信息"></page-navbar>
  4. <view class="direction u-m-b-60">
  5. <u-avatar :src="avatar" size="108" />
  6. <view class="u-m-t-10 text-666">点击更换头像</view>
  7. </view>
  8. <base-card padding="0 24rpx">
  9. <u-cell-group :border="false">
  10. <u-cell title="昵称" isLink>
  11. <view slot="value" class="f-s-26" style="color: #616570">yizhiyang</view>
  12. </u-cell>
  13. <u-cell title="性别" isLink>
  14. <view slot="value" class="f-s-26" style="color: #616570">男</view>
  15. </u-cell>
  16. <u-cell title="生日" isLink>
  17. <view slot="value" class="f-s-26" style="color: #616570">男</view>
  18. </u-cell>
  19. <u-cell title="我的推广码" isLink :border="false" @click="handlePromotionCode" />
  20. </u-cell-group>
  21. </base-card>
  22. <view class="person-bottom">
  23. <base-button text="保存" :buttonStyle="customStyle"></base-button>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import { getUserInfo } from '@/api/user';
  29. import { uploadFile } from '@/utils/upload';
  30. export default {
  31. data() {
  32. return {
  33. queryParams: {
  34. avatar: '', // 头像
  35. gender: '', //性别
  36. birthday: '', //生日
  37. nickname: '', //昵称
  38. },
  39. time_value: '',
  40. timeShow: false,
  41. sexList: [
  42. {
  43. id: 0,
  44. name: '男',
  45. type: 'MALE',
  46. },
  47. {
  48. id: 1,
  49. name: '女',
  50. type: 'FEMALE',
  51. },
  52. ],
  53. current: 0,
  54. uoloadImg: '',
  55. maxDataTime: 0,
  56. };
  57. },
  58. computed: {
  59. customStyleOut() {
  60. return {
  61. fontSize: '30rpx',
  62. };
  63. },
  64. },
  65. mounted() {
  66. this.maxDataTime = new Date().getTime();
  67. getUserInfo().then(res => {
  68. let { avatar, nickname, gender, birthday } = res.data;
  69. this.uoloadImg = avatar;
  70. this.queryParams.avatar = avatar;
  71. this.queryParams.nickname = nickname;
  72. this.queryParams.birthday = uni.$u.timeFormat(birthday, 'yyyy-mm-dd');
  73. if (gender) {
  74. for (let key in gender) {
  75. this.sexList.map(rs => {
  76. if (key == rs.type) {
  77. this.current = rs.id;
  78. }
  79. });
  80. }
  81. }
  82. });
  83. },
  84. methods: {
  85. // 选择性别
  86. handlerSelectGender(item) {
  87. this.current = item.id;
  88. },
  89. // 选择时间
  90. confirmTime(e) {
  91. this.queryParams.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
  92. this.timeShow = false;
  93. },
  94. // 上传头像
  95. async handlerUploadImg() {
  96. try {
  97. const res = await uni.showActionSheet({
  98. itemList: ['拍照', '从相册选择'],
  99. });
  100. if (res.tapIndex === 0) {
  101. // 用户选择拍照
  102. this.takeOrChoosePhoto(0);
  103. } else if (res.tapIndex === 1) {
  104. // 用户选择从相册选择
  105. this.takeOrChoosePhoto(1);
  106. }
  107. } catch (error) {}
  108. },
  109. // 拍照
  110. takeOrChoosePhoto(idx) {
  111. uni.chooseImage({
  112. sourceType: idx == 0 ? ['camera'] : ['album'],
  113. count: 1,
  114. success: res => {
  115. const tempFilePaths = res.tempFilePaths;
  116. // 调用上传图片的方法
  117. this.uploadAvatar(tempFilePaths[0]);
  118. },
  119. fail: error => {
  120. console.error(error);
  121. },
  122. });
  123. },
  124. // 上传头像
  125. uploadAvatar(filePath) {
  126. this.uoloadImg = filePath;
  127. uploadFile(filePath).then(res => {
  128. this.queryParams.avatar = JSON.parse(res.data).data.url;
  129. });
  130. this.$forceUpdate(); // 手动触发组件的重新渲染
  131. },
  132. // 点击提交按钮
  133. handlerSubmitBtn() {
  134. this.queryParams.gender = this.sexList[this.current].type;
  135. this.$store.dispatch('UpdateUserInfo', this.queryParams).then(res => {
  136. setTimeout(() => {
  137. uni.navigateBack(-1);
  138. }, 1500);
  139. });
  140. },
  141. handlePromotionCode() {
  142. uni.switchTab({
  143. url: '/pages/extend/index',
  144. });
  145. },
  146. },
  147. };
  148. </script>
  149. <style lang="scss" scoped>
  150. .client-personInfo {
  151. padding: 60rpx 32rpx 0 32rpx;
  152. .person-bottom {
  153. width: 90%;
  154. position: fixed;
  155. bottom: 10%;
  156. }
  157. ::v-deep .u-cell__body {
  158. padding: 20rpx 0;
  159. color: #0c1223;
  160. font-size: 34rpx;
  161. }
  162. ::v-deep .u-cell__title-text {
  163. line-height: 65rpx !important;
  164. }
  165. }
  166. </style>