aqyj/pages/checkjob/job.js

350 lines
7.5 KiB
JavaScript

var util = require('../../utils/util.js')
Page({
/**
* 页面的初始数据
*/
data: {
serverUrl: getApp().globalData.serverUrl,
items: [
{ name: '1', value: '正在整改中'},
{ name: '2', value: '已整改完成' },
],
cjryname:"",
cjry:"",
yhtp1: [],
zghtp1: [],
},
bindjcwtInput: function (e) {
this.data.jcwt = e.detail.value
},
bindzgqkInput: function (e) {
this.data.zgqk = e.detail.value
},
bindcfnrInput: function (e) {
this.data.cfnr = e.detail.value
},
radioChange: function (e) {
this.data.jczt = e.detail.value
},
deleteImage: function (e) {
var that = this;
var yhtp1 = that.data.yhtp1;
var index = e.currentTarget.dataset.index; //获取当前长按图片下标
wx.showModal({
title: '系统提醒',
content: '确定要删除此图片吗?',
success: function (res) {
if (res.confirm) {
yhtp1.splice(index, 1);
} else if (res.cancel) {
return false;
}
that.setData({
yhtp1: yhtp1
});
}
})
},
chooseImage: function () {
var that = this
wx.chooseImage({
count: 9,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
console.log(that.data.yhtp1.concat(res.tempFilePaths))
that.setData({
yhtp1: that.data.yhtp1.concat(res.tempFilePaths)
})
}
})
},
previewImage: function (e) {
var current = e.target.dataset.src
wx.previewImage({
current: current,
urls: this.data.yhtp1
})
},
//上传图片
upimg:function(x,y){
var that=this
if(x<y){
wx.uploadFile({
header: {
'content-type': 'application/json', // 默认值
'Cookie': getApp().globalData.sessionId,
},
url: that.data.serverUrl + 'upfile',
filePath: that.data.yhtp1[x],
name: 'upfile',
success(res) {
var obj = JSON.parse(res.data);
that.data.yhtp1[x] = obj['filepath']
x = x + 1
if(x<y){
that.upimg(x, y)
}
}
})
}
},
deleteImages: function (e) {
var that = this;
var zghtp1 = that.data.zghtp1;
var index = e.currentTarget.dataset.index; //获取当前长按图片下标
wx.showModal({
title: '系统提醒',
content: '确定要删除此图片吗?',
success: function (res) {
if (res.confirm) {
zghtp1.splice(index, 1);
} else if (res.cancel) {
return false;
}
that.setData({
zghtp1: zghtp1
});
}
})
},
chooseImages: function () {
var that = this
wx.chooseImage({
count: 9,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
console.log(that.data.zghtp1.concat(res.tempFilePaths))
that.setData({
zghtp1: that.data.zghtp1.concat(res.tempFilePaths)
})
}
})
},
previewImages: function (e) {
var current = e.target.dataset.src
wx.previewImage({
current: current,
urls: this.data.zghtp1
})
},
//上传图片
upimgs:function(x,y){
var that=this
if(x<y){
wx.uploadFile({
header: {
'content-type': 'application/json', // 默认值
'Cookie': getApp().globalData.sessionId,
},
url: that.data.serverUrl + 'upfile',
filePath: that.data.zghtp1[x],
name: 'upfile',
success(res) {
var obj = JSON.parse(res.data);
that.data.zghtp1[x] = obj['filepath']
x = x + 1
if(x<y){
that.upimgs(x, y)
}
}
})
}
},
submit: function () {
if (!this.data.jcwt) {
this.Tap1('请填写检查问题!')
}
else if (!this.data.zgqk) {
this.Tap1('请填写整改情况!')
}
else if (!this.data.jczt) {
this.Tap1('请选择检查状态!')
}
else {
this.upimg(0, this.data.yhtp1.length)
this.upimgs(0, this.data.zghtp1.length)
this.addjob()
}
},
Tap1: function (x) {
wx.showModal({
title: "系统提示",
content: x,
showCancel: false,
confirmText: "确定"
})
},
addjob: function () {
var jobdata = {
checkquestion: this.data.jcwt,//检查问题
zgjg: this.data.zgqk,//整改情况
content: this.data.cfnr,//处罚内容
taskstate: this.data.jczt,//检查状态
participant: this.data.cjry,//处罚人
yhtp1:this.data.yhtp1,//问题图片
zghtp:this.data.zghtp1,//问题图片
}
console.log(jobdata)
wx.showModal({
title: '系统提示',
content: '确认提交!',
confirmText: "确定",
cancelText: "取消",
success: (res)=> {
if (res.confirm) {
wx.showLoading({
title: '正在提交...',
})
wx.request({
url: getApp().globalData.serverUrl + 'api/checkproject?a=addjob&jobid=' + this.data.jobid,
header: {
'content-type': 'application/json', //
'Cookie': getApp().globalData.sessionId,
},
method: 'POST',
data:jobdata ,
success: res => {
if (res.statusCode === 200) {
wx.hideLoading();
wx.navigateBack()
}
}
});
}
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var checkperson = true
this.getGcdetail(options.id);
this.setData({
jobid: options.id
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
this.setData({
cjryname: "",
cjry: "",
cjrs:0
}),
this.data.cfnr=""
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let lst = getApp().globalData.selectPeopleList
let nst = []
let nst1 = []
if (lst) {
for (var i = 0; i < lst.length; i++) {
nst.push(lst[i]['name'])
nst1.push(lst[i]['id'])
}
this.setData({
cjryname: nst.join(','),
cjry: nst1.join(','),
cjrs: nst1.length
})
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
getGcdetail: function (id) {
wx.showLoading({
title: '加载中',
}),
wx.request({
url: this.data.serverUrl + 'api/checkproject?a=checkjobdetail&id=' + id,
header: {
'content-type': 'application/json', // 默认值
'Cookie': getApp().globalData.sessionId,
},
data: {
},
success: res => {
wx.hideLoading();
console.log(res.data);
if (res.statusCode === 200) {
var data = res.data
//格式化观察信息
this.setData(data)
}
}
});
},
})