You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
// pages/changeSex/index.js
|
|
|
|
|
|
const app = getApp();
|
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
data: {
|
|
|
|
|
|
items: [{
|
|
|
|
|
|
name: '男',
|
|
|
|
|
|
value: '1',
|
|
|
|
|
|
checked: false
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: '女',
|
|
|
|
|
|
value: '2',
|
|
|
|
|
|
checked: false
|
|
|
|
|
|
},
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
radioChange: function (e) {
|
|
|
|
|
|
console.log('radio发生change事件,携带value值为:', e.detail.value);
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
that.data.items.forEach(item => {
|
|
|
|
|
|
item.checked = false;
|
|
|
|
|
|
if (item.value == e.detail.value) {
|
|
|
|
|
|
item.checked = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
formSubmit(e) {
|
|
|
|
|
|
console.log('form发生了submit事件,携带数据为:', e.detail.value)
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
|
|
|
|
var sex = '';
|
|
|
|
|
|
that.data.items.forEach(item => {
|
|
|
|
|
|
if (item.checked) {
|
|
|
|
|
|
sex = item.value;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var formData = {
|
|
|
|
|
|
userId: app.globalData.user.id,
|
|
|
|
|
|
sex: sex
|
|
|
|
|
|
};
|
|
|
|
|
|
console.log(formData);
|
|
|
|
|
|
|
|
|
|
|
|
wx.request({
|
|
|
|
|
|
url: app.globalData.ip + "/user/updateSex",
|
|
|
|
|
|
method: "POST",
|
|
|
|
|
|
header: app.globalData.headers,
|
|
|
|
|
|
data: formData,
|
|
|
|
|
|
success: function (res) {
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
|
|
|
|
|
|
if (res.data.status == 200) {
|
|
|
|
|
|
|
|
|
|
|
|
app.globalData.user.sex = formData.sex;
|
|
|
|
|
|
|
|
|
|
|
|
wx.navigateBack({
|
|
|
|
|
|
delta: 1
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
wx.showToast({
|
|
|
|
|
|
icon: "none",
|
|
|
|
|
|
title: res.data.msg,
|
|
|
|
|
|
duration: 2000
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
that.setData({
|
|
|
|
|
|
btnLoading: false
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
|
*/
|
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
if (app.globalData.user.sex == 1) {
|
|
|
|
|
|
that.data.items[0].checked = true;
|
|
|
|
|
|
} else if (app.globalData.user.sex == 2) {
|
|
|
|
|
|
that.data.items[1].checked = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log(that.data.items);
|
|
|
|
|
|
|
|
|
|
|
|
that.setData({
|
|
|
|
|
|
items: that.data.items
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
|
*/
|
|
|
|
|
|
onReady: function () {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
|
*/
|
|
|
|
|
|
onShow: function () {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
|
*/
|
|
|
|
|
|
onHide: function () {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
|
*/
|
|
|
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
|
*/
|
|
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
|
*/
|
|
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 用户点击右上角分享
|
|
|
|
|
|
*/
|
|
|
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|