// pages/upload/upload.js const app = getApp() const host = app.globalData.host; Page({ /** * 页面的初始数据 */ data: { show:false, idnoimg_face: "", //正面照 idnoimg_back: "", //反面照 halfbody_img: "", //半身照 education_img: "", //学历照 id:'' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ id:JSON.parse(options.id), openid: app.globalData.openid }) wx.request({ url: host + '/api/wx/signup', method: 'GET', data: { id: options.id }, success:res=>{ this.setData({ idnoimg_face: res.data.data.idnoimg_face, //正面照 idnoimg_back: res.data.data.idnoimg_back, //反面照 halfbody_img: res.data.data.halfbody_img, //半身照 education_img: res.data.data.education_img, //学历照 }) } }) }, post:function(){ var formData ={} formData.id=this.data.id formData.idnoimg_face = this.data.idnoimg_face formData.idnoimg_back = this.data.idnoimg_back formData.halfbody_img = this.data.halfbody_img formData.education_img = this.data.education_img if (formData.idnoimg_face == '') { wx.showToast({ title: '正面照不存在!', icon: 'none', duration: 2000 }) return false } if (formData.idnoimg_back == '') { wx.showToast({ title: '反面照不存在!', icon: 'none', duration: 2000 }) return false } if (formData.halfbody_img == '') { wx.showToast({ title: '半身照不存在!', icon: 'none', duration: 2000 }) return false } if (formData.education_img == '') { wx.showToast({ title: '学历照不存在!', icon: 'none', duration: 2000 }) return false } wx.request({ url: host+'/api/wx/signup', method:'PUT', header: { openid: this.data.openid }, data: formData, success:res=>{ if(res.data.status == 'suc'){ wx.showToast({ title: '提交成功', icon: 'success', duration: 2000 }) setTimeout(function(){ wx.switchTab({ url: '../apply/apply', }) },2000) } } }) }, 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.uploadFile({ url: host+'/api/wx/uploadfile', filePath: res.tempFilePaths[0], name: 'file', formData: { 'file': res.tempFilePaths[0] }, success:res=>{ var data=JSON.parse(res.data) console.log(data) if(id == 1){ //正面 _this.setData({ idnoimg_face: data.data.url }) } if (id == 2) { //反面 _this.setData({ idnoimg_back: data.data.url }) } if (id == 3) { //半身照 _this.setData({ halfbody_img: data.data.url }) } if (id == 4) { //学历照 _this.setData({ education_img: data.data.url }) } } }) }, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })