memberinfo.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. <view class="cell-title">个人信息</view>
  12. <u-cell-group :border="false" :customStyle="{background:'#fff','border-radius':'20rpx'}">
  13. <!-- <u-cell title="头像">
  14. <u-avatar slot="right-icon" :src="memberInfo.avatar" size="80rpx"></u-avatar>
  15. </u-cell> -->
  16. <view class="avatar u-flex u-row-between u-border-bottom">
  17. <text>头像</text>
  18. <view class="right">
  19. <u--image :src="memberInfo.avatar" shape="circle" width="80rpx" height="80rpx"></u--image>
  20. <u-upload
  21. width="80rpx"
  22. height="80rpx"
  23. :fileList="fileList"
  24. @afterRead="afterRead"
  25. :previewImage="false"
  26. multiple
  27. name="name"
  28. :maxCount="2"
  29. ></u-upload>
  30. </view>
  31. </view>
  32. <u-cell title="姓名" v-if="memberInfo.isAuth==1" @click="$u.toast('不允许修改')" :value="vuex_member_info.name" :border="true"></u-cell>
  33. <u-cell title="昵称" @click="nameShow=true" :value="vuex_member_info.nickName" :border="true"></u-cell>
  34. <!-- <u-cell title="性别" @click="handleChangeSex" :value="memberInfo.sex|filterSex"></u-cell> -->
  35. <!-- <u-cell title="生日" :value="memberInfo.birthdayTime||'未设置'" @click="handleChangeBirthday" :isLink="true"></u-cell> -->
  36. <!-- <u-cell title="会员等级" :value="memberInfo.levelName"></u-cell> -->
  37. <u-cell title="实名制认证" @click="factorAuth" :value="memberInfo.isAuth==1?'已认证':'去认证'"></u-cell>
  38. </u-cell-group>
  39. <u-button text="取消登录" type="error" @click="logOut" :customStyle="{'margin-top': '120rpx'}"></u-button>
  40. <u-datetime-picker
  41. :show="timeShow"
  42. :minDate="new Date().getTime()-365*100*24*3600*1000"
  43. v-model="birthday"
  44. :maxDate="new Date().getTime()"
  45. @confirm="updateBirthday"
  46. mode="date"
  47. :closeOnClickOverlay="true"
  48. @close="timeShow = false"
  49. @cancel="timeShow = false"
  50. ></u-datetime-picker>
  51. </view>
  52. <u-modal :show="nameShow" title="修改昵称" @confirm="changeName" @cancel="nameShow=false" :showCancelButton="true" >
  53. <view class="slot-content">
  54. <u--input
  55. placeholder="请输入内容"
  56. border="surround"
  57. v-model="tempName"
  58. maxlength="8"
  59. >
  60. </u--input>
  61. </view>
  62. </u-modal>
  63. <u-action-sheet
  64. :show="showSex"
  65. :actions="actions"
  66. title="请选择性别"
  67. @close="showSex = false"
  68. @select="sexSelect"
  69. >
  70. </u-action-sheet>
  71. <u-toast ref="uToast"></u-toast>
  72. </view>
  73. </template>
  74. <script>
  75. import {uploadImg} from '../utils/uploadImg.js'
  76. export default {
  77. components:{
  78. },
  79. data() {
  80. return {
  81. showSex:false,
  82. sex:'',
  83. nameShow:false,
  84. tempName:'',
  85. uploadFileUrl:this.$commonConfig.uploadFileUrl,
  86. timeShow:false,
  87. birthday:'',
  88. memberInfo:{},
  89. fileList:[],
  90. avatarUrl:'',
  91. actions: [
  92. {name: '男',val:1},
  93. {name: '女',val:2},
  94. {name: '保密',val:0},
  95. ],
  96. }
  97. },
  98. onShow() {
  99. this.getMemberInfo();
  100. // console.log('1111',this.uploadFileUrl);
  101. },
  102. onLoad() {
  103. },
  104. methods: {
  105. logOut(){
  106. this.$u.vuex('vuex_member_info', {});
  107. this.$u.vuex('vuex_user_info', {});
  108. uni.$u.route('/pages/index/index')
  109. // this.getMemberInfo()
  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. this.$u.vuex('vuex_member_info', res.data);
  117. }).catch(err=>{
  118. console.log('memberInfo',err);
  119. })
  120. },
  121. handleChangeSex(){
  122. if(this.memberInfo.isAuth==1){
  123. this.$refs.uToast.show({
  124. type: 'default',
  125. message: "实名信息不能修改!",
  126. })
  127. }else{
  128. this.showSex = true
  129. }
  130. },
  131. handleChangeBirthday(){
  132. if(this.memberInfo.isAuth==1){
  133. this.$refs.uToast.show({
  134. type: 'default',
  135. message: "实名信息不能修改!",
  136. })
  137. }else{
  138. this.timeShow = true
  139. }
  140. },
  141. updateBirthday(e){
  142. // console.log('000',e);
  143. let birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
  144. this.birthday = birthday;
  145. this.updateMemberInfo('birthday');
  146. this.timeShow = false;
  147. },
  148. // 新增图片
  149. async afterRead(event){
  150. //使用这个封装
  151. const result = await uploadImg(event,this.fileList)
  152. let parseResult = JSON.parse(result.data).data;
  153. console.log('urlurl',parseResult.url);
  154. this.avatarUrl = parseResult.url;
  155. if(!this.avatarUrl){
  156. uni.showToast({
  157. title: '上传失败!',
  158. icon: "error"
  159. });
  160. return
  161. };
  162. this.updateMemberInfo('avatar');
  163. let item = this.fileList[result.fileListLen]
  164. this.fileList.splice(result.fileListLen, 1, Object.assign(item, {
  165. status: 'success',
  166. message: '成功',
  167. url: JSON.parse(result.data).data
  168. }));
  169. },
  170. updateMemberInfo(type){
  171. let params ={
  172. id:this.vuex_user_info.userid
  173. };
  174. if(type == 'avatar'){
  175. params.avatar = this.avatarUrl;
  176. }else if(type == 'birthday'){
  177. params.birthdayTime = this.birthday;
  178. }else if(type == 'nickName'){
  179. if(!this.tempName){
  180. uni.showToast({
  181. title:'请输入昵称',
  182. icon:'error'
  183. })
  184. return
  185. }
  186. params.nickName = this.tempName;
  187. }else if(type == 'sex'){
  188. params.sex = this.sex;
  189. }
  190. this.$u.api.updateMemberInfo(params).then(res=>{
  191. this.getMemberInfo();
  192. this.nameShow = false;
  193. }).catch(err=>{
  194. console.log('err',err);
  195. })
  196. },
  197. changeName(){
  198. this.updateMemberInfo('nickName');
  199. console.log('memberInfo',this.memberInfo);
  200. },
  201. sexSelect(e){
  202. this.sex = e.val;
  203. this.updateMemberInfo('sex')
  204. console.log('sexSelect',e);
  205. },
  206. factorAuth(){
  207. if(this.memberInfo.isAuth==1){
  208. uni.showToast({
  209. title:'已认证',
  210. icon:'none'
  211. })
  212. return
  213. }
  214. uni.$u.route('/center/factorauth', {
  215. backUrl: '/center/center'
  216. });
  217. }
  218. }
  219. }
  220. </script>
  221. <style>
  222. page{
  223. background-color: #F7F7F9;
  224. }
  225. </style>
  226. <style lang="scss" scoped>
  227. .cell-title{
  228. font-size: 28rpx;
  229. font-weight: 400;
  230. color: #7F7F7F;
  231. margin-bottom: 34rpx;
  232. }
  233. .avatar{
  234. padding: 10px 15px;
  235. font-size: 15px;
  236. color: #303133;
  237. .right{
  238. position: relative;
  239. /deep/ .u-upload{
  240. position: absolute;
  241. left: 0;
  242. top: 0;
  243. opacity: 0;
  244. }
  245. }
  246. }
  247. </style>