family-userInfo.page.js
2.34 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
import 'home/family-userInfo.page.css';
import 'home/family/city-swiper.css';
import CitySwiper from './family/city-swiper';
import $ from 'yoho-jquery';
import Page from 'yoho-page';
import tip from 'plugin/tip';
class UserInfo extends Page {
constructor() {
super();
this.selector = {
$chosenCity: $('#chosen-city'),
$citySwiper: $('.city-swiper'),
$modifyInp: $('.inp.modify'),
$nickName: $('.inp.nick-name'),
$gender: $('.inp.gender'),
$birthday: $('.inp.birthday'),
$height: $('.inp.height'),
$weight: $('.inp.weight'),
$userAvatar: $('.user-avatar')
};
this.init();
}
init() {
this.bindEvents();
this.on('citySwiperCb', (event, data) => { // 返回选中的slide对象
console.log(data);
});
this.defaultPic();
}
bindEvents() {
this.selector.$chosenCity.on('click', this.chosenCity.bind(this));
this.selector.$modifyInp.on('blur', this.modifyInp.bind(this));
}
defaultPic() {
let myImage = new Image(),
avatar;
avatar = this.selector.$userAvatar.data('avatar');
myImage.src = avatar;
myImage.onload = () => {
this.selector.$userAvatar.css('background-image', 'url(' + avatar + ')');
};
}
modifyInp() {
this.ajax({
url: '/home/family/modify',
data: {
nickName: this.selector.$nickName.val(),
gender: this.selector.$gender.val(),
birthday: this.selector.$birthday.val(),
height: this.selector.$height.val(),
weight: this.selector.$weight.val()
},
}).then(result => {
if (result && result.code === 200) {
location.href = location.href;
} else {
tip.show(result.message);
}
}).catch(error => {
tip.show(error);
});
}
chosenCity() {
this.selector.$citySwiper.show();
new CitySwiper({
swiperNum: 2, // swiper列数
lineNum: 5, // 每列行数
centeredSlides: true, // 剧中显示
hidePartingLine: false // 隐藏两条分割线
});
}
}
$(() => {
new UserInfo();
});