123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- // 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 () {
- }
- })
|