aqyj/pages/inspect/add.js

404 lines
10 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/inspect/check.js
Page({
/**
* 页面的初始数据
*/
data: {
items: [
{ name: '正常', value: '正常' },
{ name: '异常', value: '异常' },
],
serverUrl: getApp().globalData.serverUrl,
state:1,
selected:false,
        selected1:true,
csry:"",
todouser:"",
todouser_name:"请选择",
isok:true
        },
    selected:function(e){
        this.setData({
            selected1:false,
            selected:true
        })
    },
    selected1:function(e){
        this.setData({
            selected:false,
            selected1:true
        })
    },
/**
* 生命周期函数--监听页面加载
*/
radioChange: function (e) {
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
this.changeItems(this.data.jclx)
},
changeItems:function(val){
var x = []
for(var i=0;i<this.data.itemscheck0.length;i++){
if(this.data.itemscheck0[i].type == val){
x.push(this.data.itemscheck0[i])
}
}
this.setData({
itemscheck:x
})
},
cutArray(val){
var al = this.data.itemscheck0
for(var i=0;i<al.length;i++){
if(al[i].type != val){
al.splice(i,1)
}
}
return al
},
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 == '异常'){
this.setData({
isok:false
})
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 + '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,
//jclx: res.data[0].value//默认检查类型
})
}
}
});
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,
itemscheck0: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();
}
});
}
}
});
},
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 () {
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({
csryname: nst.join(','),
csry: nst1.join(','),
})
}
},
/**
* 生命周期函数--监听页面隐藏
*/
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
if(!that.data.jclx){
wx.showToast({
title: '请选择巡检类型!',
icon:'none'
})
return
}
for(var i=0;i<that.data.itemscheck.length;i++){
if(that.data.itemscheck[i].checked == undefined){
wx.showToast({
title: '有检查项未勾选!',
icon:'none'
})
return
}
}
let data1 = {
equipment: this.data.equipment.id,
state: 1,
type: this.data.jclx,
csry: this.data.csry
}
let data2 = that.data.itemscheck
for(var i=0;i<that.data.itemscheck.length;i++){
if (that.data.itemscheck[i].state == '异常待处理'){
if (that.data.itemscheck[i].img||that.data.itemscheck[i].desc){
}else{
wx.showToast({
title: '存在异常项目没有描述或图片!',
icon:'none'
})
return
}
}
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();
}
});
},
})