profile.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view>
  3. <!-- <view class="container">
  4. <view class="list-cell b-b m-t" @click="inputShowModal('nickname')" hover-class="cell-hover" :hover-stay-time="50">
  5. <text class="cell-tit">修改昵称</text>
  6. <text class="cell-more yticon icon-you"></text>
  7. </view>
  8. <view class="list-cell b-b" @click="genderShowModal" hover-class="cell-hover" :hover-stay-time="50">
  9. <text class="cell-tit">修改性别</text>
  10. <text class="cell-more yticon icon-you"></text>
  11. </view>
  12. <neil-modal :show="inputShow" @close="cancel" title="编辑" @cancel="cancel" @confirm="confirm">
  13. <input v-model="inputContent" style="margin:20upx" placeholder="请输入..." />
  14. </neil-modal>
  15. <neil-modal :show="genderShow" @close="cancel" title="选择性别" @cancel="cancel" @confirm="confirmGender">
  16. <view>
  17. <radio-group style="text-align:center" @change="genderRadioChange">
  18. <label v-for="(item, index) in genders" :key="item.value">
  19. <radio :value="item.value + ''" :checked="index === gender" style="margin:10upx" />{{item.name}}
  20. </label>
  21. </radio-group>
  22. </view>
  23. </neil-modal>
  24. </view> -->
  25. <view style="height: 120rpx;"
  26. class="solid-top bg-white flex justify-between align-center margin-bottom-sm padding-lr padding-tb-s">
  27. <view class="title text-black">头像</view>
  28. <image @click="chooseImg" :src="userInfo.avatar ? userInfo.avatar :'../../static/user/touxiang-@2x.png'"
  29. class="round" mode="aspectFill"
  30. style="width: 90rpx;height: 90rpx;"></image>
  31. </view>
  32. <view style="height: 100rpx;"
  33. class="solid-bottom bg-white flex justify-between align-center padding-lr padding-tb-s">
  34. <view class="title text-black">昵称</view>
  35. <view class="flex align-center">
  36. <!-- <view class="nick-name">
  37. {{ userInfo.nickname ?userInfo.nickname : '未设置昵称' }}
  38. </view> -->
  39. <input @blur="changeName" @confirm="changeName"
  40. v-model="userInfo.nickname" placeholder="请输入昵称" class="text-df" style="text-align: right;" />
  41. <!-- <image src="../../static/icon/arrow_right.png" mode="aspectFit"
  42. class="icon-right"></image> -->
  43. </view>
  44. </view>
  45. <view style="height: 100rpx;"
  46. class="solid-bottom bg-white flex justify-between align-center padding-lr padding-tb-s">
  47. <view class="title text-black">性别</view>
  48. <view class="flex align-center">
  49. <view @click="changeGender(1)" class="flex align-center">
  50. <image
  51. :src="gender == 1 ?'/static/cart/selected.png':'/static/cart/select.png'"
  52. mode="aspectFill"
  53. style="width: 40rpx;height: 40rpx;"></image>
  54. <view style="font-size: 28rpx;line-height: 38rpx;color: #5E5E66;padding-left: 20rpx;">男</view>
  55. </view>
  56. <view @click="changeGender(2)" class="flex align-center" style="padding-left: 80rpx;">
  57. <image
  58. :src="gender == 2 ?'/static/cart/selected.png':'/static/cart/select.png'"
  59. mode="aspectFit"
  60. style="width: 40rpx;height: 40rpx;"></image>
  61. <view style="font-size: 28rpx;line-height: 38rpx;color: #5E5E66;padding-left: 20rpx;">女</view>
  62. </view>
  63. </view>
  64. </view>
  65. <view style="height: 100rpx;"
  66. class="solid-bottom bg-white flex justify-between align-center padding-lr padding-tb-s">
  67. <view class="title text-black">生日</view>
  68. <view class="flex align-center">
  69. <picker mode="date" @change="bindDateChange">
  70. <view class="lem-text-grey content">{{date}}</view>
  71. </picker>
  72. <!-- <view class="lem-text-grey content">2000年10月09日</view> -->
  73. <image src="../../static/icon/arrow_right.png" mode="aspectFit"
  74. class="icon-right"></image>
  75. </view>
  76. </view>
  77. <view style="height: 100rpx;"
  78. class=" bg-white flex justify-between align-center padding-lr padding-tb-s">
  79. <view class="title text-black">手机号</view>
  80. <view class="lem-text-grey content" style="padding-right: 34rpx;">{{phone}}</view>
  81. </view>
  82. <show-modal></show-modal>
  83. </view>
  84. </template>
  85. <script>
  86. import {
  87. mapState,
  88. mapMutations
  89. } from 'vuex';
  90. export default {
  91. data() {
  92. return {
  93. date:'选择您的出生日期',
  94. gender: undefined,
  95. phone:''
  96. };
  97. },
  98. computed: {
  99. ...mapState(['userInfo']),
  100. },
  101. onLoad() {
  102. if(this.userInfo.birthday){
  103. var date = new Date(this.userInfo.birthday)
  104. var month = date.getMonth() >= 9 ? date.getMonth()+1 : '0'+parseInt(date.getMonth()+1)
  105. var day = date.getDate() >= 9 ? date.getDate() : '0'+parseInt(date.getDate())
  106. this.date = date.getFullYear()+'-'+month+'-'+day
  107. }
  108. this.gender = this.userInfo.gender
  109. this.phone = this.userInfo.phone[0]+this.userInfo.phone[1]+this.userInfo.phone[2]+'****'+this.userInfo.phone[7]+this.userInfo.phone[8]+this.userInfo.phone[9]+this.userInfo.phone[10]
  110. },
  111. methods: {
  112. chooseImg(){
  113. this.$api.uploadImg(1,(res)=>{
  114. console.log(res)
  115. this.userInfo.avatar = res
  116. var info = this.userInfo
  117. var tempObj = Object.assign({},this.userInfo,info)
  118. this.userInfo = this.login(tempObj)
  119. this.syncUser()
  120. //uni.setStorageSync('userInfo',this.userInfo)
  121. })
  122. },
  123. changeGender(index){
  124. this.gender = index
  125. this.userInfo.gender = index
  126. this.syncUser()
  127. },
  128. changeName(){
  129. this.syncUser()
  130. },
  131. syncUser(){
  132. this.$api.request('post', 'user/app/updateUser', this.userInfo).then(syncRes => {
  133. //同步过后
  134. uni.setStorageSync('userInfo', this.userInfo)
  135. })
  136. },
  137. bindDateChange: function(e) {
  138. console.log(e)
  139. this.userInfo.birthday = new Date(e.target.value).getTime()
  140. console.log(this.userInfo.birthday)
  141. this.date = e.target.value
  142. this.syncUser()
  143. },
  144. ...mapMutations(['login'])
  145. }
  146. }
  147. </script>
  148. <style lang="scss">
  149. page {
  150. background: $page-color-base;
  151. }
  152. .solid-top{
  153. border-top: #F2F2F2 solid 2rpx;
  154. }
  155. .solid-bottom{
  156. border-bottom: #F2F2F2 solid 2rpx;
  157. }
  158. .padding-tb-s{
  159. padding: 15rpx 30rpx;
  160. }
  161. .title{
  162. font-size: 32rpx;
  163. line-height: 38rpx;
  164. }
  165. .content{
  166. font-size: 28rpx;
  167. line-height: 38rpx;
  168. }
  169. .nick-name{
  170. color: #2AAB34;
  171. font-size: 28rpx;
  172. line-height: 38rpx;
  173. }
  174. .icon-right{
  175. width: 14rpx;
  176. height: 27rpx;
  177. margin-left: 18rpx;
  178. }
  179. </style>