memberinfo.vue 6.5 KB

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