userinfo.vue 5.2 KB

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