// pages/upload/upload.js const app = getApp() const host = app.globalData.host; Page({ /** * 页面的初始数据 */ data: { show:false, idnoimg_face: "", //正面照 idnoimg_back: "", //反面照 halfbody_img: "", //半身照 education_img: "", //学历照 oldcard_img:'', id:'', train_type:'', img:'' }, /** * 生命周期函数--监听页面加载 */ 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, //学历照 oldcard_img: res.data.data.oldcard_img, train_type: res.data.data.train_type }) if (!res.data.data.idnoimg_face){ wx.request({ url: host + '/api/wx/authinfo', header: { openid: app.globalData.openid }, 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, //学历照 oldcard_img: res.data.data.oldcard_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 formData.oldcard_img = this.data.oldcard_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 } if (this.data.train_type == '换证' || this.data.train_type == '复审') { if (!formData.oldcard_img){ wx.showToast({ title: '换证/复审证件照不存在!', icon: 'none', duration: 2000 }) return false } } wx.showLoading({ title: '', }) wx.request({ url: host+'/api/wx/signup', method:'PUT', header: { openid: this.data.openid }, data: formData, success:res=>{ if(res.data.code == 0){ wx.hideLoading() wx.showToast({ title: '提交成功', icon: 'success', duration: 2000 }) setTimeout(function(){ wx.switchTab({ url: '../apply/apply', }) },2000) } }, fail:res=>{ wx.hideLoading() wx.showToast({ title: res.data.message, icon: 'none', duration: 2000 }) } }) }, showImg:function(e){ this.setData({ show: true, img: '../../images/zj' + e.target.dataset.id + '.jpg' }) }, hideImg: function (e) { this.setData({ show: false }) }, takePhoto:function(e){ var id=e.target.dataset.id var _this=this wx.chooseImage({ count:1, success: function(res) { 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) wx.showToast({ title: '上传成功', icon: 'none', duration: 2000 }) 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 }) } if (id == 5) { _this.setData({ oldcard_img: data.data.url }) } }, fail: res => { wx.hideLoading() wx.showToast({ title: res, icon: 'none', duration: 2000 }) } }) }, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })