memberinfo.vue 5.4 KB

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