userinfo.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view class="content">
  3. <view class="row1">
  4. <text class="tit">头像</text>
  5. <view class="background-img">
  6. <image class="background-img" v-model="avatar" :src="userInfo.avatar"></image>
  7. </view>
  8. </view>
  9. <view class="row">
  10. <text class="tit">用户名</text>
  11. <input class="input" type="button" v-model="name" placeholder-class="placeholder" />
  12. </view>
  13. <view class="row" style="margin-top: 50rpx;height: 100rpx;" @click="toLogout">
  14. <text class="tit1">退出登录</text>
  15. <!-- <input class="input" type="button" v-model="name" placeholder-class="placeholder" /> -->
  16. </view>
  17. <!-- <view class="row">
  18. <text class="tit">性别</text>
  19. <picker @change="bindPickerChange" :value="index" :range="array" class="input">
  20. <text>{{ sex }}</text>
  21. </picker>
  22. </view> -->
  23. <!-- <view class="row">
  24. <text class="tit">生日</text>
  25. <picker @change="bindDateChange" mode="date" :value="date" :start="startDate" :end="endDate" class="input">
  26. <text>{{birthday}}</text>
  27. </picker>
  28. </view>
  29. <view class="row">
  30. <text class="tit">邀请码</text>
  31. <input class="input" disabled type="text" v-model="uid" placeholder-class="placeholder" />
  32. </view> -->
  33. <button class="add-btn" @click="confirm">修改</button>
  34. </view>
  35. </template>
  36. <script>
  37. import { mapState, mapMutations } from 'vuex';
  38. import { logout } from '@/api/set.js';
  39. import { userEdit } from '@/api/set.js';
  40. import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';
  41. import wPicker from '@/components/w-picker/w-picker.vue';
  42. export default {
  43. data() {
  44. return {
  45. name: '',
  46. sex:'',
  47. array:['男','女'],
  48. index:0,
  49. birthday: '',
  50. birthdaynum:0,
  51. date:'',
  52. uid: '',
  53. avatar: '',
  54. resultInfo: {
  55. result: '2019-12-20 10:00:00'
  56. },
  57. year:'',
  58. };
  59. },
  60. components: {
  61. wPicker,
  62. pickerAddress
  63. },
  64. computed: {
  65. ...mapState('user',['userInfo']),
  66. startDate() {
  67. console.log('start');
  68. },
  69. endDate() {
  70. console.log('end');
  71. }
  72. },
  73. onShow(option) {
  74. console.log(this);
  75. // 获取生日日期
  76. let date = new Date(this.userInfo.birthday * 1000);
  77. let month = date.getMonth() + 1; //获取月份
  78. let day = date.getDate();
  79. this.name = this.userInfo.nickname + '';
  80. this.uid = this.userInfo.uid || '';
  81. this.avatar = this.userInfo.avatar || '';
  82. this.birthday = date.getFullYear() + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
  83. this.year = new Date().getFullYear();
  84. let sex;
  85. if (this.userInfo.sex == 0) {
  86. sex = '未知';
  87. } else if (this.userInfo.sex == 1) {
  88. sex = '男';
  89. } else {
  90. sex = '女';
  91. }
  92. this.sex = sex; //性别赋值
  93. this.index=this.userInfo.sex;
  94. },
  95. methods: {
  96. //退出登录
  97. toLogout(){
  98. let obj = this;
  99. uni.showModal({
  100. content: '确定要退出登录么',
  101. success: (e)=>{
  102. if(e.confirm){
  103. logout({}).then((e) => {
  104. uni.navigateBack();
  105. }).catch((e) => {
  106. console.log(e);
  107. })
  108. obj.logout();
  109. }
  110. }
  111. });
  112. },
  113. bindDateChange:function(e){
  114. console.log(e.detail.value);
  115. this.birthday=e.detail.value;
  116. this.birthdaynum=(new Date(e.detail.value).getTime())/1000;
  117. console.log(this.birthdaynum);
  118. },
  119. bindPickerChange: function(e) {
  120. this.sex=this.array[e.target.value];
  121. this.index = e.target.value+1;
  122. },
  123. // 显示日期选择器
  124. // toggleTab(str) {
  125. // this.$refs[str].show();
  126. // },
  127. // 数据处理结果
  128. onConfirm(val) {
  129. //如果页面需要调用多个mode类型,可以根据mode处理结果渲染到哪里;
  130. // switch(this.mode){
  131. // case "date":
  132. // break;
  133. // }
  134. this.resultInfo = { ...val };
  135. this.birthday = this.resultInfo.result;
  136. },
  137. switchChange(e) {
  138. this.addressData.default = e.value;
  139. },
  140. confirm() {
  141. userEdit({ nickname: this.name, avatar: this.avatar, sex: this.index, phone: this.phone ,birthday:this.birthdaynum })
  142. .then(e => {
  143. this.$api.msg('修改成功');
  144. setTimeout(() => {
  145. uni.switchTab({
  146. url: '/pages/user/user'
  147. });
  148. }, 1000);
  149. console.log(e);
  150. })
  151. .catch(e => {
  152. console.log(e);
  153. });
  154. }
  155. }
  156. };
  157. </script>
  158. <style lang="scss">
  159. page {
  160. background: $page-color-base;
  161. }
  162. .row1 {
  163. display: flex;
  164. align-items: center;
  165. justify-content: space-between;
  166. position: relative;
  167. padding: 0 30upx;
  168. height: 110upx;
  169. background: #fff;
  170. margin-bottom: 20upx;
  171. .tit {
  172. flex-shrink: 0;
  173. width: 120upx;
  174. font-size:$font-lg;
  175. color: $font-color-dark;
  176. }
  177. .background-img{
  178. width:80rpx;
  179. height:80rpx;
  180. border-radius:50%;
  181. background: #F2F2F2;
  182. }
  183. }
  184. .row {
  185. display: flex;
  186. align-items: center;
  187. justify-content: space-between;
  188. position: relative;
  189. padding: 0 30upx;
  190. height: 110upx;
  191. background: #fff;
  192. .tit1{
  193. margin: 0 auto;
  194. flex-shrink: 0;
  195. font-size:$font-lg;
  196. color: $font-color-dark;
  197. }
  198. .tit {
  199. flex-shrink: 0;
  200. width: 120upx;
  201. font-size:$font-lg;
  202. color: $font-color-dark;
  203. }
  204. .input {
  205. flex: 1;
  206. font-size: $font-base;
  207. color: $color-gray;
  208. }
  209. .iconlocation {
  210. font-size: 36upx;
  211. color: $font-color-light;
  212. }
  213. }
  214. .add-btn {
  215. display: flex;
  216. align-items: center;
  217. justify-content: center;
  218. width: 560upx;
  219. height: 80upx;
  220. margin: 100rpx auto;
  221. font-size: $font-lg;
  222. color: #fff;
  223. background: #FF727E;
  224. border-radius: 40upx;
  225. }
  226. </style>