// pages/operation/operationadd.js var dateTimePicker = require('../../utils/dateTimePicker.js'); Page({ /** * 页面的初始数据 */ data: { zyimg:[], zyqy:'', chosespr:false, serverUrl:getApp().globalData.serverUrl }, bindspr1change: function (e) { this.setData({ spr1index: e.detail.value, }) this.data.spr1s = this.data.spr1Array[e.detail.value].value }, bindspr2change: function (e) { this.setData({ spr2index: e.detail.value, }) this.data.spr2s = this.data.spr2Array[e.detail.value].value }, checkboxChangefxcs: function (e) { console.log(e) var x = this.data.fxcslist; var values = e.detail.value; for (var j = 0, lenJ = x.length; j < lenJ; ++j) { if (values.indexOf(x[j]['id'].toString()) >= 0){ x[j].checked=true }else{ x[j].checked=false } } this.setData({ fxcslist:x, fxcs: values }) }, bindzyddInput: function (e) { this.data.zydd = e.detail.value }, bindzynrInput: function (e) { this.data.zynr = e.detail.value }, chosesprChange: function (e) { if (e.detail.value) { this.setData({ chosespr:true }) } else { this.setData({ chosespr:false }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // 获取完整的年月日 时分秒,以及默认显示的数组 var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear); var dateTimeArray1 = obj1.dateTimeArray var dateTime1 = obj1.dateTime var time = dateTimeArray1[0][dateTime1[0]] + '-' + dateTimeArray1[1][dateTime1[1]] + '-' + dateTimeArray1[2][dateTime1[2]] + ' ' + dateTimeArray1[3][dateTime1[3]] + ':' + dateTimeArray1[4][dateTime1[4]] this.setData({ dateTimeArray1: obj1.dateTimeArray, dateTime1: obj1.dateTime, dateshow1: 0 }); // 获取完整的年月日 时分秒,以及默认显示的数组 var obj2 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear); var dateTimeArray2 = obj2.dateTimeArray var dateTime2 = obj2.dateTime var time = dateTimeArray2[0][dateTime2[0]] + '-' + dateTimeArray2[1][dateTime2[1]] + '-' + dateTimeArray2[2][dateTime2[2]] + ' ' + dateTimeArray2[3][dateTime2[3]] + ':' + dateTimeArray2[4][dateTime2[4]] this.setData({ dateTimeArray2: obj2.dateTimeArray, dateTime2: obj2.dateTime, dateshow2: 0 }); this.getZy(options.zyid); //拉取地图权限 if (getApp().globalData.userInfo.perms.indexOf(30) != -1) { this.setData({ mapright: true }) } else { this.setData({ mapright: false }) } }, getZy: function (zyid) { wx.showLoading({ title: '加载中', }), wx.request({ url: getApp().globalData.serverUrl + 'api/operation?a=detail&zyid=' + zyid, header: { 'content-type': 'application/json', // 默认值 'Cookie': getApp().globalData.sessionId, }, data: {}, success: res => { wx.hideLoading(); if (res.statusCode === 200) { var zydata = res.data //格式化信息 for (var i = 0; i < zydata.zyimg.length; i++) { zydata.zyimg[i] = getApp().globalData.serverUrl + zydata.zyimg[i]; } for (var i = 0; i < zydata.zyimg2.length; i++) { zydata.zyimg2[i] = getApp().globalData.serverUrl + zydata.zyimg2[i]; } this.setData(zydata) this.getspr12array() let zylx = zydata.zylx //风险分析和控制措施 wx.request({ url: getApp().globalData.serverUrl + 'api/fxcs?a=listall&zylx='+zylx, header: { 'content-type': 'application/json', // 'Cookie': getApp().globalData.sessionId, }, method: 'GET', success: res => { if (res.statusCode === 200) { let fxcslist = res.data.rows for(var i=0;i { if (res.statusCode === 200) { this.setData({ spr1Array:res.data.data.spr1Array, spr2Array:res.data.data.spr2Array }) } } }); }, submit:function(){ var that = this; if (!that.data.kssj) { that.Tap1('请选择开始时间!') } else if (!that.data.jssj) { that.Tap1('请选择结束时间!') } else if (!that.data.zydd) { that.Tap1('请输入作业地点!') }else if (!that.data.sdbm) { that.Tap1('请输入属地部门!') } else if (!that.data.zyry) { that.Tap1('请输入作业人员!') } else if (!that.data.zynr) { that.Tap1('请输入作业内容!') } else if (!that.data.fxcs) { that.Tap1('请确认分析措施!') } else if (that.data.chosespr==true) { if(!that.data.spr1s||!that.data.spr2s){ that.Tap1('审批人未选择!') }else{ this.upimg(0, this.data.zyimg.length); } }else { this.upimg(0, this.data.zyimg.length); } }, Tap1: function (x) { wx.showModal({ title: "系统提示", content: x, showCancel: false, confirmText: "确定" }) }, //上传图片 upimg: function (x, y) { var that = this if (x < y) { wx.showLoading({ title: '上传现场图片' + (x + 1) + '....', }) if (that.data.zyimg[x].indexOf(that.data.serverUrl) == -1){ wx.uploadFile({ header: { 'content-type': 'application/json', // 默认值 'Cookie': getApp().globalData.sessionId, }, url: getApp().globalData.serverUrl + 'upfile', filePath: that.data.zyimg[x], name: 'upfile', success(res) { var obj = JSON.parse(res.data); that.data.zyimg[x] = obj['filepath'] x = x + 1 if (x < y) { that.upimg(x, y) } else { that.editzy() } } })}else{ that.data.zyimg[x].replace(that.data.serverUrl, "") var bl = that.data.zyimg[x].replace(that.data.serverUrl, "") that.data.zyimg[x] = bl x = x + 1 if (x < y) { that.upimg(x, y) } else { that.editzy() } } } else { that.editzy() } }, editzy: function () { // let fxcs = [] // let x = this.data.fxcslist // for (var i = 0, len = x.length; i < len; ++i) { // if (x[i].checked = true) { // fxcs.push(x[i].id) // } // } var zydata = { zyid:this.data.zyid, zylx:this.data.zylx, kssj: this.data.kssj, jssj: this.data.jssj, zyqy:this.data.zyqy, zydd: this.data.zydd, zynr: this.data.zynr, zyry: this.data.zyry, zyimg: this.data.zyimg, sdbm:this.data.sdbm, fxcs: this.data.fxcs, chosespr:this.data.chosespr, } if(this.data.chosespr){ zydata.spr1s = this.data.spr1s zydata.spr2s = this.data.spr2s zydata.chosespr = this.data.chosespr } //console.log(gcdata.unsafe) wx.showLoading({ title: '', }) wx.request({ url: getApp().globalData.serverUrl + 'api/operation?a=edit', header: { 'content-type': 'application/json', // 'Cookie': getApp().globalData.sessionId, }, method: 'POST', data: zydata, success: res => { if (res.statusCode === 200) { wx.hideLoading(); wx.navigateBack({ }) } } }); }, })