userinfo.vue 4.4 KB

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