336 lines
8.4 KiB
JavaScript
336 lines
8.4 KiB
JavaScript
// pages/inspect/check.js
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
items: [
|
||
{ name: '正常', value: '正常' },
|
||
{ name: '异常', value: '异常' },
|
||
],
|
||
serverUrl: getApp().globalData.serverUrl,
|
||
state:1,
|
||
selected:false,
|
||
selected1:true
|
||
},
|
||
selected:function(e){
|
||
this.setData({
|
||
selected1:false,
|
||
selected:true
|
||
})
|
||
},
|
||
selected1:function(e){
|
||
this.setData({
|
||
selected:false,
|
||
selected1:true
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
radioChange: function (e) {
|
||
console.log('radio发生change事件,携带value值为:', e.detail.value);
|
||
this.setData({
|
||
state: e.detail.value,
|
||
});
|
||
},
|
||
bindjclxChange: function (e) {
|
||
this.setData({
|
||
jclxIndex: e.detail.value,
|
||
})
|
||
this.data.jclx = this.data.jclxArray[e.detail.value].value
|
||
},
|
||
radioChange2: function (e) {
|
||
var that = this
|
||
that.data.itemscheck[e.currentTarget.dataset.index].checked = true
|
||
if (e.detail.value=='正常'){
|
||
that.data.itemscheck[e.currentTarget.dataset.index].state = '正常'
|
||
}
|
||
else if (e.detail.value == '异常'){
|
||
that.data.itemscheck[e.currentTarget.dataset.index].state = '异常待处理'
|
||
}
|
||
that.setData({
|
||
itemscheck:that.data.itemscheck
|
||
})
|
||
},
|
||
bindcontentInput: function (e) {
|
||
this.data.content = e.detail.value
|
||
},
|
||
onLoad: function (options) {
|
||
let id = options.id
|
||
wx.request({
|
||
url: this.data.serverUrl + 'api/equipment?a=detail&id=' + id,
|
||
header: {
|
||
'content-type': 'application/json', // 默认值
|
||
'Cookie': getApp().globalData.sessionId,
|
||
},
|
||
success: res => {
|
||
if (res.statusCode === 200) {
|
||
console.log(res.data)
|
||
this.setData({
|
||
equipment:res.data
|
||
})
|
||
wx.request({
|
||
url: this.data.serverUrl + 'api/equipmentcheckform/'+res.data.checkform,
|
||
header: {
|
||
'content-type': 'application/json', // 默认值
|
||
'Cookie': getApp().globalData.sessionId,
|
||
},
|
||
success: res => {
|
||
if (res.statusCode === 200) {
|
||
this.setData({
|
||
itemscheck:res.data.items
|
||
})
|
||
}
|
||
wx.hideLoading();
|
||
}
|
||
});
|
||
wx.request({
|
||
url: this.data.serverUrl + 'api/risk?a=steps&type=equipment',
|
||
header: {
|
||
'content-type': 'application/json', // 默认值
|
||
'Cookie': getApp().globalData.sessionId,
|
||
},
|
||
method:'post',
|
||
data:{'name':res.data.name,'id':res.data.id,'areaid':res.data.area__id},
|
||
success: res => {
|
||
if (res.statusCode === 200) {
|
||
if(res.data.code==1){
|
||
this.setData({
|
||
steps:res.data.steps
|
||
})
|
||
}
|
||
}
|
||
wx.hideLoading();
|
||
}
|
||
});
|
||
}
|
||
}
|
||
});
|
||
//获取巡检类型
|
||
wx.request({
|
||
url: this.data.serverUrl + 'getdickey?dicclass=57&a=combobox',
|
||
header: {
|
||
'content-type': 'application/json', // 默认值
|
||
'Cookie': getApp().globalData.sessionId,
|
||
},
|
||
data: {},
|
||
success: res => {
|
||
if (res.statusCode === 200) {
|
||
this.data.jclxArray = res.data;
|
||
this.setData({
|
||
jclxArray: res.data,
|
||
jclxIndex: 0,
|
||
jclx: res.data[0].value//默认检查类型
|
||
})
|
||
}
|
||
}
|
||
});
|
||
},
|
||
submit:function(){
|
||
let data={
|
||
equipment:this.data.equipment.id,
|
||
state:this.data.state,
|
||
content:this.data.content
|
||
}
|
||
wx.showLoading({
|
||
title: '提交中',
|
||
})
|
||
wx.request({
|
||
url: this.data.serverUrl + 'api/inspect?a=add',
|
||
header: {
|
||
'content-type': 'application/json', // 默认值
|
||
'Cookie': getApp().globalData.sessionId,
|
||
},
|
||
method:'POST',
|
||
data:data,
|
||
success: res => {
|
||
if (res.statusCode === 200) {
|
||
console.log(res.data)
|
||
wx.navigateBack({
|
||
|
||
})
|
||
}
|
||
wx.hideLoading();
|
||
}
|
||
});
|
||
},
|
||
submit2: function () {
|
||
wx.navigateTo({
|
||
url: '/pages/trouble/addtrouble?type=inspect',
|
||
})
|
||
},
|
||
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage: function () {
|
||
|
||
},
|
||
chooseImage: function (e) {
|
||
var that = this
|
||
wx.chooseImage({
|
||
count: 1,
|
||
sizeType: ['original', 'compressed'],
|
||
sourceType: ['album', 'camera'],
|
||
success: function (res) {
|
||
wx.showLoading({
|
||
title: '上传图片..',
|
||
mask:true
|
||
})
|
||
wx.uploadFile({
|
||
header: {
|
||
'content-type': 'application/json', // 默认值
|
||
'Cookie': getApp().globalData.sessionId,
|
||
},
|
||
url: getApp().globalData.serverUrl + 'upfile',
|
||
filePath: res.tempFilePaths[0],
|
||
name: 'upfile',
|
||
success(res) {
|
||
wx.hideLoading()
|
||
var obj = JSON.parse(res.data);
|
||
that.data.itemscheck[e.currentTarget.dataset.index].img = getApp().globalData.serverUrl + obj['filepath']
|
||
that.setData({
|
||
itemscheck:that.data.itemscheck
|
||
})
|
||
|
||
},
|
||
complete: function (res) {
|
||
wx.hideLoading()
|
||
}
|
||
})
|
||
}
|
||
})
|
||
},
|
||
previewImage: function (e) {
|
||
console.log(e)
|
||
var current = e.target.dataset.src
|
||
wx.previewImage({
|
||
current: current,
|
||
urls: [current]
|
||
})
|
||
},
|
||
deleteImage: function (e) {
|
||
var that = this;
|
||
var index = e.currentTarget.dataset.index; //获取当前长按图片下标
|
||
wx.showModal({
|
||
title: '系统提醒',
|
||
content: '确定要删除此图片吗?',
|
||
success: function (res) {
|
||
if (res.confirm) {
|
||
that.data.itemscheck[index].img = null
|
||
} else if (res.cancel) {
|
||
return false
|
||
}
|
||
that.setData({
|
||
itemscheck: that.data.itemscheck
|
||
});
|
||
}
|
||
})
|
||
},
|
||
descChange: function(e){
|
||
var that = this
|
||
that.data.itemscheck[e.currentTarget.dataset.index].desc=e.detail.value
|
||
},
|
||
submit3: function () {
|
||
var that = this
|
||
let data1 = {
|
||
equipment: this.data.equipment.id,
|
||
state: 1,
|
||
type: this.data.jclx
|
||
}
|
||
let data2 = that.data.itemscheck
|
||
for(var i=0;i<that.data.itemscheck.length;i++){
|
||
if (that.data.itemscheck[i].state == '异常待处理' || that.data.itemscheck[i].state == '异常已处理'){
|
||
data1.state = 0
|
||
}
|
||
if (that.data.itemscheck[i].img && that.data.itemscheck[i].img.indexOf(getApp().globalData.serverUrl)!=-1){
|
||
data2[i].img = data2[i].img.replace(getApp().globalData.serverUrl,'')
|
||
}
|
||
}
|
||
console.log(data1,data2)
|
||
|
||
wx.showLoading({
|
||
title: '提交中',
|
||
})
|
||
wx.request({
|
||
url: getApp().globalData.serverUrl + 'api/inspect?a=add',
|
||
header: {
|
||
'content-type': 'application/json', // 默认值
|
||
'Cookie': getApp().globalData.sessionId,
|
||
},
|
||
method: 'POST',
|
||
data: data1,
|
||
success: res => {
|
||
if (res.statusCode === 200) {
|
||
wx.request({
|
||
url: getApp().globalData.serverUrl + 'api/inspectitem?a=adds',
|
||
header: {
|
||
'content-type': 'application/json', // 默认值
|
||
'Cookie': getApp().globalData.sessionId,
|
||
},
|
||
method: 'POST',
|
||
data: {
|
||
'inspect':res.data.inspect,
|
||
'items':data2
|
||
},
|
||
success: res => {
|
||
if (res.statusCode === 200) {
|
||
wx.redirectTo({
|
||
url: '/pages/inspect/index',
|
||
})
|
||
}
|
||
wx.hideLoading();
|
||
}
|
||
});
|
||
}
|
||
wx.hideLoading();
|
||
}
|
||
});
|
||
},
|
||
}) |