const util = require("../../utils/util.js"); const Http = require("../../utils/HttpBasics"); const config = require("../../config/config"); Page({ /** * 页面的初始数据 */ data: { date: '1988-03-12', flag: 1, flagsex: 0, items: [ { name: 1, value: '男', checked: false }, { name: 2, value: '女', checked: false }, ] }, /** * 获得生日 */ bindDateChange: function (e) { console.log('picker发送选择改变,携带值为', e.detail.value); console.log(typeof (e.detail.value)) this.setData({ date: e.detail.value, flag: 2 }) }, address: function () { let that = this; wx.chooseLocation({ success: function (res) { console.log(res); that.setData({ name: res.name, address: res, }) }, fail: function (error) { console.log(error) }, complete: function (data) { console.log(data); } }) }, formSubmit: function (e) { console.log(e); let that = this; /** * sex * 0 保密 * 1 男 * 2 女 */ if (that.data.flagsex == 0) { var sex = 0; } else { var sex = that.data.sex; } if (that.data.address) { var address = JSON.stringify(that.data.address); } else { var address = null; } if (e.detail.value.username) { var username = e.detail.value.username; } else if (that.data.username) { var username = that.data.username; } else { var username = null; } if (that.data.flag == 2 && that.data.date) { var birthdate = new Date(that.data.date).getTime(); } else { var birthdate = null; } console.log(username); console.log(address); console.log(sex); console.log(birthdate); if (username == null || address == null || sex == 0 || birthdate == null) { wx.showModal({ title: '提示', content: '请输入完整的用户信息', showCancel: false }) } else { Http.post({ url: config.api.updateInfo, data: { sex: sex, address: address, name: username, birthdate: birthdate, } }) .then(res => { console.log(res); wx.showModal({ title: '提示', content: '修改成功', showCancel: false, success: function (res) { wx.switchTab({ url: '/pages/user/index', }) } }) }) } }, radioChange: function (e) { console.log(e.detail.value) this.setData({ sex: e.detail.value, flagsex: 1 }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this; that.setData({ username: options.name, sex: options.sex, date: util.fmtDate(parseInt(options.birthdate)), name: JSON.parse(options.address).name, address: JSON.parse(options.address), flag: 2 }); if (options.sex == "1") { console.log(that.data.items); that.data.items[0].checked = true; var checked = 'items[' + 0 + '].checked' that.setData({ [checked]: true }) that.setData({ flagsex: 1 }) } else if (options.sex == "2") { that.data.items[1].checked = true; var checked = 'items[' + 1 + '].checked' that.setData({ [checked]: true }) that.setData({ flagsex: 1 }) console.log(that.data.items); } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { console.log("oShow") }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })