memberinfo.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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="昵称" @click="nameShow=true" :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. <u-modal :show="nameShow" title="修改昵称" @confirm="changeName" @cancel="nameShow=false" :showCancelButton="true" >
  48. <view class="slot-content">
  49. <u--input
  50. placeholder="请输入内容"
  51. border="surround"
  52. v-model="tempName"
  53. maxlength="8"
  54. >
  55. </u--input>
  56. </view>
  57. </u-modal>
  58. </view>
  59. </template>
  60. <script>
  61. import {uploadImg} from '../utils/uploadImg.js'
  62. export default {
  63. components:{
  64. },
  65. data() {
  66. return {
  67. nameShow:false,
  68. tempName:'',
  69. uploadFileUrl:this.$commonConfig.uploadFileUrl,
  70. timeShow:false,
  71. birthday:'',
  72. memberInfo:{},
  73. fileList:[],
  74. avatarUrl:'',
  75. }
  76. },
  77. onShow() {
  78. this.getMemberInfo();
  79. console.log('1111',this.uploadFileUrl);
  80. },
  81. onLoad() {
  82. },
  83. methods: {
  84. getMemberInfo(){
  85. this.$u.api.memberInfo({id:this.vuex_user_info.userid}).then(res=>{
  86. this.memberInfo = res.data;
  87. this.avatar = res.data.avatar;
  88. console.log('memberInfo',this.memberInfo);
  89. }).catch(err=>{
  90. console.log('memberInfo',err.data);
  91. })
  92. },
  93. updateBirthday(e){
  94. // console.log('000',e);
  95. let birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
  96. this.birthday = birthday;
  97. this.updateMemberInfo('birthday');
  98. this.timeShow = false;
  99. },
  100. // 新增图片
  101. async afterRead(event){
  102. //使用这个封装
  103. const result = await uploadImg(event,this.fileList)
  104. let parseResult = JSON.parse(result.data).data;
  105. console.log('urlurl',parseResult.url);
  106. this.avatarUrl = parseResult.url;
  107. if(!this.avatarUrl){
  108. uni.showToast({
  109. title: '上传失败!',
  110. icon: "error"
  111. });
  112. return
  113. };
  114. this.updateMemberInfo('avatar');
  115. let item = this.fileList[result.fileListLen]
  116. this.fileList.splice(result.fileListLen, 1, Object.assign(item, {
  117. status: 'success',
  118. message: '成功',
  119. url: JSON.parse(result.data).data
  120. }));
  121. },
  122. updateMemberInfo(type){
  123. let params ={
  124. id:this.vuex_user_info.userid
  125. };
  126. if(type == 'avatar'){
  127. params.avatar = this.avatarUrl;
  128. }else if(type == 'birthday'){
  129. params.birthdayTime = this.birthday;
  130. }else if(type == 'name'){
  131. if(!this.tempName){
  132. uni.showToast({
  133. title:'请输入昵称',
  134. icon:'error'
  135. })
  136. return
  137. }
  138. params.name = this.tempName;
  139. }
  140. this.$u.api.updateMemberInfo(params).then(res=>{
  141. this.getMemberInfo();
  142. this.nameShow = false;
  143. }).catch(err=>{
  144. console.log('err',err);
  145. })
  146. },
  147. changeName(){
  148. this.updateMemberInfo('name');
  149. console.log('memberInfo',this.memberInfo);
  150. }
  151. }
  152. }
  153. </script>
  154. <style>
  155. page{
  156. background-color: #fff;
  157. }
  158. </style>
  159. <style lang="scss" scoped>
  160. .avatar{
  161. padding: 10px 15px;
  162. font-size: 15px;
  163. color: #303133;
  164. .right{
  165. position: relative;
  166. /deep/ .u-upload{
  167. position: absolute;
  168. left: 0;
  169. top: 0;
  170. opacity: 0;
  171. }
  172. }
  173. }
  174. </style>