// pages/user/user.js const app = getApp() const host = app.globalData.host; Page({ /** * 页面的初始数据 */ data: { sexArray: ["女","男"], //性别 recordArray: ["小学", "初中", "高中", "大专", "本科", "硕士", "博士"], //学历 sex: 0, record: 0, show: false, data:{ } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.request({ url: host+'/api/wx/authinfo', header: { openid: app.globalData.openid }, success:res=>{ let edu = this.data.recordArray.indexOf(res.data.data.education) this.setData({ data:res.data.data, sex:res.data.data.sex, record:edu }) } }) }, inputChange:function(e){ var data=this.data.data data[e.target.dataset.name] = e.detail.value console.log(data) this.setData({ data: data }) }, pickerChange:function(e){ if (e.target.dataset.name == 'sex') { this.setData({ sex: e.detail.value }) }; if (e.target.dataset.name == 'record') { this.setData({ record: e.detail.value }) }; }, showImg: function (e) { this.setData({ show: true }) if (e.target.dataset.name == 0) { } }, hideImg: function (e) { this.setData({ show: false }) }, takePhoto: function (e) { let id = e.target.dataset.id var _this = this wx.chooseImage({ count: 1, success: function (res) { console.log(res.tempFilePaths[0]) wx.showLoading({ title: '正在上传', }) wx.uploadFile({ url: host + '/api/wx/uploadfile', filePath: res.tempFilePaths[0], name: 'file', formData: { 'file': res.tempFilePaths[0] }, success: res => { wx.hideLoading() var data = JSON.parse(res.data) var _data = _this.data.data console.log(_data) if (id == 1) { //正面 _data.idnoimg_face = data.data.url } if (id == 2) { //反面 _data.idnoimg_back = data.data.url } if (id == 3) { //半身照 _data.halfbody_img = data.data.url } if (id == 4) { //学历照 _data.education_img = data.data.url } _this.setData({ data:_data }) } }) }, }) }, post:function(){ var data=this.data.data data.sex=this.data.sex data.education = this.data.recordArray[this.data.record] wx.showLoading({ title: '', }) wx.request({ url: host + '/api/wx/authinfo', header: { openid: app.globalData.openid }, method:'PUT', success: res => { wx.showToast({ title: '提交成功', icon: 'success', duration: 2000 }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })