memberinfo.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="pages">
  3. <u-navbar
  4. title="个人信息"
  5. :autoBack="true"
  6. :safeAreaInsetTop="true"
  7. >
  8. </u-navbar>
  9. <view class="page-wrap">
  10. <u-cell-group>
  11. <!-- <u-cell title="头像">
  12. <u-avatar slot="right-icon" :src="memberInfo.avatar" size="80rpx"></u-avatar>
  13. </u-cell> -->
  14. <view class="avatar u-flex u-row-between u-border-bottom">
  15. <text>头像</text>
  16. <view class="right">
  17. <u--image :src="memberInfo.avatar" shape="circle" width="80rpx" height="80rpx"></u--image>
  18. <u-upload
  19. width="80rpx"
  20. height="80rpx"
  21. :fileList="fileList"
  22. @afterRead="afterRead"
  23. :previewImage="false"
  24. multiple
  25. name="name"
  26. :maxCount="2"
  27. ></u-upload>
  28. </view>
  29. </view>
  30. <u-cell title="昵称" :value="memberInfo.name"></u-cell>
  31. <u-cell title="性别" :value="memberInfo.sex|filterSex"></u-cell>
  32. <u-cell title="生日" :value="memberInfo.birthdayTime||'未设置'" @click="timeShow = true" :isLink="true"></u-cell>
  33. <u-cell title="会员等级" :value="memberInfo.levelName"></u-cell>
  34. </u-cell-group>
  35. <u-datetime-picker
  36. :show="timeShow"
  37. :minDate="new Date().getTime()-365*100*24*3600*1000"
  38. v-model="birthday"
  39. :maxDate="new Date().getTime()"
  40. @confirm="updateBirthday"
  41. mode="date"
  42. :closeOnClickOverlay="true"
  43. @close="timeShow = false"
  44. @cancel="timeShow = false"
  45. ></u-datetime-picker>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import {uploadImg} from '../utils/uploadImg.js'
  51. export default {
  52. components:{
  53. },
  54. data() {
  55. return {
  56. uploadFileUrl:this.$commonConfig.uploadFileUrl,
  57. timeShow:false,
  58. birthday:'',
  59. memberInfo:{},
  60. fileList:[],
  61. avatarUrl:'',
  62. }
  63. },
  64. onShow() {
  65. this.getMemberInfo();
  66. console.log('1111',this.uploadFileUrl);
  67. },
  68. onLoad() {
  69. },
  70. methods: {
  71. getMemberInfo(){
  72. this.$u.api.memberInfo({id:this.vuex_user_info.userid}).then(res=>{
  73. this.memberInfo = res.data;
  74. this.avatar = res.data.avatar;
  75. console.log('memberInfo',this.memberInfo);
  76. }).catch(err=>{
  77. console.log('memberInfo',err.data);
  78. })
  79. },
  80. updateBirthday(e){
  81. // console.log('000',e);
  82. let birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
  83. this.birthday = birthday;
  84. this.updateMemberInfo('birthday');
  85. this.timeShow = false;
  86. },
  87. // 新增图片
  88. async afterRead(event){
  89. //使用这个封装
  90. const result = await uploadImg(event,this.fileList)
  91. let parseResult = JSON.parse(result.data).data;
  92. console.log('urlurl',parseResult.url);
  93. this.avatarUrl = parseResult.url;
  94. if(!this.avatarUrl){
  95. uni.showToast({
  96. title: '上传失败!',
  97. icon: "error"
  98. });
  99. return
  100. };
  101. this.updateMemberInfo('avatar');
  102. let item = this.fileList[result.fileListLen]
  103. this.fileList.splice(result.fileListLen, 1, Object.assign(item, {
  104. status: 'success',
  105. message: '成功',
  106. url: JSON.parse(result.data).data
  107. }));
  108. },
  109. updateMemberInfo(type){
  110. let params ={
  111. id:this.vuex_user_info.userid
  112. };
  113. if(type == 'avatar'){
  114. params.avatar = this.avatarUrl;
  115. }else if(type == 'birthday'){
  116. params.birthdayTime = this.birthday;
  117. }
  118. this.$u.api.updateMemberInfo(params).then(res=>{
  119. this.getMemberInfo();
  120. }).catch(err=>{
  121. console.log('err',err);
  122. })
  123. }
  124. }
  125. }
  126. </script>
  127. <style>
  128. page{
  129. background-color: #fff;
  130. }
  131. </style>
  132. <style lang="scss" scoped>
  133. .avatar{
  134. padding: 10px 15px;
  135. font-size: 15px;
  136. color: #303133;
  137. .right{
  138. position: relative;
  139. /deep/ .u-upload{
  140. position: absolute;
  141. left: 0;
  142. top: 0;
  143. opacity: 0;
  144. }
  145. }
  146. }
  147. </style>