memberinfo.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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="性别" @click="showSex=true" :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. <u-action-sheet
  59. :show="showSex"
  60. :actions="actions"
  61. title="请选择性别"
  62. @close="showSex = false"
  63. @select="sexSelect"
  64. >
  65. </u-action-sheet>
  66. </view>
  67. </template>
  68. <script>
  69. import {uploadImg} from '../utils/uploadImg.js'
  70. export default {
  71. components:{
  72. },
  73. data() {
  74. return {
  75. showSex:false,
  76. sex:'',
  77. nameShow:false,
  78. tempName:'',
  79. uploadFileUrl:this.$commonConfig.uploadFileUrl,
  80. timeShow:false,
  81. birthday:'',
  82. memberInfo:{},
  83. fileList:[],
  84. avatarUrl:'',
  85. actions: [
  86. {name: '男',val:1},
  87. {name: '女',val:2},
  88. {name: '保密',val:0},
  89. ],
  90. }
  91. },
  92. onShow() {
  93. this.getMemberInfo();
  94. // console.log('1111',this.uploadFileUrl);
  95. },
  96. onLoad() {
  97. },
  98. methods: {
  99. getMemberInfo(){
  100. this.$u.api.memberInfo({id:this.vuex_user_info.userid}).then(res=>{
  101. this.memberInfo = res.data;
  102. this.avatar = res.data.avatar;
  103. console.log('memberInfo',this.memberInfo);
  104. }).catch(err=>{
  105. console.log('memberInfo',err.data);
  106. })
  107. },
  108. updateBirthday(e){
  109. // console.log('000',e);
  110. let birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
  111. this.birthday = birthday;
  112. this.updateMemberInfo('birthday');
  113. this.timeShow = false;
  114. },
  115. // 新增图片
  116. async afterRead(event){
  117. //使用这个封装
  118. const result = await uploadImg(event,this.fileList)
  119. let parseResult = JSON.parse(result.data).data;
  120. console.log('urlurl',parseResult.url);
  121. this.avatarUrl = parseResult.url;
  122. if(!this.avatarUrl){
  123. uni.showToast({
  124. title: '上传失败!',
  125. icon: "error"
  126. });
  127. return
  128. };
  129. this.updateMemberInfo('avatar');
  130. let item = this.fileList[result.fileListLen]
  131. this.fileList.splice(result.fileListLen, 1, Object.assign(item, {
  132. status: 'success',
  133. message: '成功',
  134. url: JSON.parse(result.data).data
  135. }));
  136. },
  137. updateMemberInfo(type){
  138. let params ={
  139. id:this.vuex_user_info.userid
  140. };
  141. if(type == 'avatar'){
  142. params.avatar = this.avatarUrl;
  143. }else if(type == 'birthday'){
  144. params.birthdayTime = this.birthday;
  145. }else if(type == 'name'){
  146. if(!this.tempName){
  147. uni.showToast({
  148. title:'请输入昵称',
  149. icon:'error'
  150. })
  151. return
  152. }
  153. params.name = this.tempName;
  154. }else if(type == 'sex'){
  155. params.sex = this.sex;
  156. }
  157. this.$u.api.updateMemberInfo(params).then(res=>{
  158. this.getMemberInfo();
  159. this.nameShow = false;
  160. }).catch(err=>{
  161. console.log('err',err);
  162. })
  163. },
  164. changeName(){
  165. this.updateMemberInfo('name');
  166. console.log('memberInfo',this.memberInfo);
  167. },
  168. sexSelect(e){
  169. this.sex = e.val;
  170. this.updateMemberInfo('sex')
  171. console.log('sexSelect',e);
  172. }
  173. }
  174. }
  175. </script>
  176. <style>
  177. page{
  178. background-color: #fff;
  179. }
  180. </style>
  181. <style lang="scss" scoped>
  182. .avatar{
  183. padding: 10px 15px;
  184. font-size: 15px;
  185. color: #303133;
  186. .right{
  187. position: relative;
  188. /deep/ .u-upload{
  189. position: absolute;
  190. left: 0;
  191. top: 0;
  192. opacity: 0;
  193. }
  194. }
  195. }
  196. </style>