memberinfo.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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-button text="取消登录" type="warning" @click="clearStorage" style="margin-top: 30rpx;"></u-button>
  36. <u-datetime-picker
  37. :show="timeShow"
  38. :minDate="new Date().getTime()-365*100*24*3600*1000"
  39. v-model="birthday"
  40. :maxDate="new Date().getTime()"
  41. @confirm="updateBirthday"
  42. mode="date"
  43. :closeOnClickOverlay="true"
  44. @close="timeShow = false"
  45. @cancel="timeShow = false"
  46. ></u-datetime-picker>
  47. </view>
  48. <u-modal :show="nameShow" title="修改昵称" @confirm="changeName" @cancel="nameShow=false" :showCancelButton="true" >
  49. <view class="slot-content">
  50. <u--input
  51. placeholder="请输入内容"
  52. border="surround"
  53. v-model="tempName"
  54. maxlength="8"
  55. >
  56. </u--input>
  57. </view>
  58. </u-modal>
  59. <u-action-sheet
  60. :show="showSex"
  61. :actions="actions"
  62. title="请选择性别"
  63. @close="showSex = false"
  64. @select="sexSelect"
  65. >
  66. </u-action-sheet>
  67. </view>
  68. </template>
  69. <script>
  70. import {uploadImg} from '../utils/uploadImg.js'
  71. export default {
  72. components:{
  73. },
  74. data() {
  75. return {
  76. showSex:false,
  77. sex:'',
  78. nameShow:false,
  79. tempName:'',
  80. uploadFileUrl:this.$commonConfig.uploadFileUrl,
  81. timeShow:false,
  82. birthday:'',
  83. memberInfo:{},
  84. fileList:[],
  85. avatarUrl:'',
  86. actions: [
  87. {name: '男',val:1},
  88. {name: '女',val:2},
  89. {name: '保密',val:0},
  90. ],
  91. }
  92. },
  93. onShow() {
  94. this.getMemberInfo();
  95. // console.log('1111',this.uploadFileUrl);
  96. },
  97. onLoad() {
  98. },
  99. methods: {
  100. clearStorage(){
  101. uni.clearStorage();
  102. uni.showToast({
  103. title:'清楚完成,请手动重新进入小程序',
  104. icon:'none',
  105. complete() {
  106. }
  107. })
  108. },
  109. getMemberInfo(){
  110. this.$u.api.memberInfo({id:this.vuex_user_info.userid}).then(res=>{
  111. this.memberInfo = res.data;
  112. this.avatar = res.data.avatar;
  113. console.log('memberInfo',this.memberInfo);
  114. }).catch(err=>{
  115. console.log('memberInfo',err.data);
  116. })
  117. },
  118. updateBirthday(e){
  119. // console.log('000',e);
  120. let birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
  121. this.birthday = birthday;
  122. this.updateMemberInfo('birthday');
  123. this.timeShow = false;
  124. },
  125. // 新增图片
  126. async afterRead(event){
  127. //使用这个封装
  128. const result = await uploadImg(event,this.fileList)
  129. let parseResult = JSON.parse(result.data).data;
  130. console.log('urlurl',parseResult.url);
  131. this.avatarUrl = parseResult.url;
  132. if(!this.avatarUrl){
  133. uni.showToast({
  134. title: '上传失败!',
  135. icon: "error"
  136. });
  137. return
  138. };
  139. this.updateMemberInfo('avatar');
  140. let item = this.fileList[result.fileListLen]
  141. this.fileList.splice(result.fileListLen, 1, Object.assign(item, {
  142. status: 'success',
  143. message: '成功',
  144. url: JSON.parse(result.data).data
  145. }));
  146. },
  147. updateMemberInfo(type){
  148. let params ={
  149. id:this.vuex_user_info.userid
  150. };
  151. if(type == 'avatar'){
  152. params.avatar = this.avatarUrl;
  153. }else if(type == 'birthday'){
  154. params.birthdayTime = this.birthday;
  155. }else if(type == 'name'){
  156. if(!this.tempName){
  157. uni.showToast({
  158. title:'请输入昵称',
  159. icon:'error'
  160. })
  161. return
  162. }
  163. params.name = this.tempName;
  164. }else if(type == 'sex'){
  165. params.sex = this.sex;
  166. }
  167. this.$u.api.updateMemberInfo(params).then(res=>{
  168. this.getMemberInfo();
  169. this.nameShow = false;
  170. }).catch(err=>{
  171. console.log('err',err);
  172. })
  173. },
  174. changeName(){
  175. this.updateMemberInfo('name');
  176. console.log('memberInfo',this.memberInfo);
  177. },
  178. sexSelect(e){
  179. this.sex = e.val;
  180. this.updateMemberInfo('sex')
  181. console.log('sexSelect',e);
  182. }
  183. }
  184. }
  185. </script>
  186. <style>
  187. page{
  188. background-color: #fff;
  189. }
  190. </style>
  191. <style lang="scss" scoped>
  192. .avatar{
  193. padding: 10px 15px;
  194. font-size: 15px;
  195. color: #303133;
  196. .right{
  197. position: relative;
  198. /deep/ .u-upload{
  199. position: absolute;
  200. left: 0;
  201. top: 0;
  202. opacity: 0;
  203. }
  204. }
  205. }
  206. </style>