memberinfo.vue 6.1 KB

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