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.
bocai_supplyChain/pages/changeGender/index.js

162 lines
3.3 KiB
JavaScript

// pages/changeGender/index.js
let app = getApp();
import { customRequest } from '../../utils/request.js';
Page({
/**
* 页面的初始数据
*/
data: {
items: [
{ name: "男", value: "1" },
{ name: "女", value: "2" },
],
userInfo: {},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad () { },
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady () { },
/**
* 生命周期函数--监听页面显示
*/
onShow () {
console.log(this.data.userInfo);
this.setData({
userInfo: app.globalData.user
})
if (this.data.userInfo.sex == 1) {
let data = "items[0].checked";
this.setData({
[data]: true,
});
} else if (this.data.userInfo.sex == 2) {
let data = "items[1].checked";
this.setData({
[data]: true,
});
}
console.log(this.data.items);
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide () { },
/**
* 生命周期函数--监听页面卸载
*/
onUnload (options) { },
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh () { },
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom () { },
/**
* 用户点击右上角分享
*/
1 year ago
onShareAppMessage() {
return app.sharePageImage()
},
radioChange (e) {
console.log(e);
this.data.items.forEach((item) => {
item.checked = false;
if (item.value == e.detail.value) {
item.checked = true;
}
});
this.setData({
items: this.data.items,
});
console.log(this.data);
},
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);
customRequest("/user/updateSex", { header: 'headers', method: 'POST', data: formData }).then((res) => {
if (res.data.status == 200) {
// let data = "user.sex";
// app.({
// [data]: formData.sex,
// });
app.globalData.user.sex = formData.sex;
console.log(app.globalData.user.sex);
wx.navigateBack({
delta: 1,
});
} else {
wx.showToast({
icon: "none",
title: res.data.msg,
duration: 2000,
});
that.setData({
btnLoading: false,
});
}
})
// 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) {
// // let data = "user.sex";
// // app.({
// // [data]: formData.sex,
// // });
// app.globalData.user.sex = formData.sex;
// console.log(app.globalData.user.sex );
// wx.navigateBack({
// delta: 1,
// });
// } else {
// wx.showToast({
// icon: "none",
// title: res.data.msg,
// duration: 2000,
// });
// that.setData({
// btnLoading: false,
// });
// }
// },
// });
},
});