mydetails.vue
4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<template>
<div>
<header-box title="个人信息" ref="header"></header-box>
<ul>
<li>
<label @click="setAvatar">头像
<span class="details-icon">
<img class="head-portrait user-avatar" :src="currentIco" @error="imgerror">
<span class="icon icon-right"></span>
</span>
</label>
</li>
<li>
<label>昵称<input class="nickname" v-model='currentNick' maxlength="16" @input="setNickname" @change="checkNickname"></label>
</li>
<li>
<label @click="setAender">性别
<span class="details-gender">
<span class="gender">{{ currentGender ? currentGender : '选择性别' }}</span>
<span class="icon icon-right"></span>
</span>
</label>
</li>
<li>
<label>生日
<span class="details-birthday">
<span class="birthday-span">{{spanbirthday}}</span>
<input class="birthday" type="date" v-model='currentBirthday' @change="setBirthday" required></input>
</span>
</label>
</li>
<li>
<label>会员等级
<a class="grade" href="/me/grade">
<span class="vip-span">{{vip_level}}</span>
<span class="icon icon-right"></span>
</a>
</label>
</li>
</ul>
</div>
</template>
<script>
import $ from 'jquery';
import yoho from 'yoho';
import tip from 'common/tip';
import select from 'common/select';
import HeaderBox from 'component/header.vue';
const genderSel = select([{
key: '1',
val: 'MEN'
}, {
key: '2',
val: 'WOMEN'
}]);
export default {
props: ['head_ico', 'nickname', 'gender', 'birthday', 'vip_level'],
data() {
return {
currentNick: this.nickname,
currentIco: this.head_ico,
currentGender: this.gender,
currentBirthday: this.birthday
};
},
computed: {
spanbirthday: function() {
const arr = this.currentBirthday.split('-');
return arr.length === 3 ? `${arr[0]}年${arr[1]}月${arr[2]}日` : '1900年01月01日';
}
},
methods: {
imgerror: function() {
// 图片报错时,给个默认透明图片
this.currentIco = 'data:image/png;base64,R0lGODlhFAAUAIAAAP///wAAACH5BAEAAAAALAAAAAAUABQAAAIRhI+py+0Po5y02ouz3rz7rxUAOw==';
},
setAvatar: function() {
yoho.goSetAvatar();
},
checkNickname: function() {
if (!(this.currentNick.trim())) {
tip('昵称不能为空');
this.currentNick = this.nickname;
return false;
}
},
setNickname: function() {
if (!(this.currentNick.trim()) || this.nickname === this.currentNick) {
return false;
}
this.saveDetails({
nickname: this.currentNick
});
},
setAender: function() {
genderSel.show(item => {
this.currentGender = item.val;
this.saveDetails({
nickname: this.currentNick,
gender: item.key
});
});
},
setBirthday: function() {
this.saveDetails({
nickname: this.currentNick,
birthday: this.currentBirthday
});
},
saveDetails: function(params) {
$.ajax({
method: 'POST',
url: '/me/save-mydetails',
data: params
}).then(result => {
if (result.code !== 200) {
tip(result.message || '设置失败');
}
}).fail(() => {
tip('网络错误');
});
}
},
components: {HeaderBox}
};
</script>
<style>
@import "../../scss/me/_details.css";
</style>