memberinfo.vue 5.1 KB

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