520 lines
14 KiB
JavaScript
520 lines
14 KiB
JavaScript
import config from '../../../config'
|
|
import {
|
|
getToken,
|
|
getUserInfo
|
|
} from '../../../utils/auth'
|
|
import {
|
|
findDictCache
|
|
} from '../../../api/publics'
|
|
import {
|
|
findProjectDeptUsers
|
|
} from '../../../api/project'
|
|
import {
|
|
findMyLastProblemmodify
|
|
} from '../../../api/problemmodify'
|
|
const app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
maxDate: new Date(2088, 1, 1).getTime(),
|
|
type:"",
|
|
typeName:"",
|
|
projectId:"",
|
|
projectName:"",
|
|
problemTypeList: [],
|
|
problemSubTypeList: [],
|
|
imageInfoData: [],
|
|
form:{
|
|
infoType:"",
|
|
problemType:"1",
|
|
dangerType:null,
|
|
nickedTime:"",
|
|
},
|
|
active: 0,
|
|
flowNodes:[{text:'开始'},{text:'提交隐患'},{text:'隐患整改'},{text:'隐患复检'},{text:'结束'}],
|
|
loginName: "",
|
|
userName: "",
|
|
rectifierData: [],
|
|
rectifierData2: [],
|
|
rectifierData3: [],
|
|
//验收时间
|
|
nickedTime: '',
|
|
loadShow: false,
|
|
lordSent: "",
|
|
lordSentUser: "",
|
|
copySend: "",
|
|
copySendUser: "",
|
|
recheckSend: "",
|
|
recheckSendUser: "",
|
|
workParts: "",
|
|
changeInfo: "",
|
|
dangerType: "1",
|
|
dangerTypeList: [],
|
|
selectValue: "",
|
|
selectIndex: "",
|
|
problemType: "1",
|
|
showHis: false,
|
|
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
if(!getToken()){
|
|
wx.redirectTo({
|
|
url: '../../login/login',
|
|
})
|
|
}
|
|
const proUserInfo = getUserInfo();
|
|
this.setData({
|
|
type:options.type,
|
|
typeName:options.type==1?"质量":"安全",
|
|
projectId:app.globalData.useProjectId,
|
|
projectName:app.globalData.useProjectName,
|
|
"form.infoType":options.type,
|
|
"form.recheckSend": proUserInfo.nickName,
|
|
"form.recheckSendUser": proUserInfo.userId
|
|
});
|
|
this.getDictCache();
|
|
this.getHisInfo(options.type);
|
|
this.getProjectUsers();
|
|
},
|
|
|
|
/**
|
|
* 获取字典缓存数据
|
|
*/
|
|
getDictCache(signId) {
|
|
// 初始化检查类型
|
|
findDictCache("ssp_proble_type").then(res => {
|
|
if (res.code == 200) {
|
|
let list = [];
|
|
res.data.forEach(item => {
|
|
list.push({
|
|
"id": item.dictValue,
|
|
"text": item.dictLabel
|
|
});
|
|
});
|
|
this.setData({
|
|
problemTypeList: list
|
|
});
|
|
}
|
|
});
|
|
|
|
//初始化隐患类型
|
|
findDictCache("ssp_proble_sub_type").then(res => {
|
|
if (res.code == 200) {
|
|
let list = [];
|
|
res.data.forEach(item => {
|
|
list.push({
|
|
"id": item.dictValue,
|
|
"text": item.dictLabel
|
|
});
|
|
});
|
|
this.setData({
|
|
problemSubTypeList: list
|
|
});
|
|
}
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 查询项目人员数据
|
|
* 获取项目所有人员,在页面组装数据...
|
|
*/
|
|
getProjectUsers() {
|
|
let params = "projectId="+app.globalData.useProjectId;
|
|
findProjectDeptUsers(params).then(res =>{
|
|
let _lordSentList = [];
|
|
let _copySendList = [];
|
|
let _checkUserList = [];
|
|
res.data.forEach(item =>{
|
|
//if(item.subDeptType!='1' && _lordSentList)
|
|
});
|
|
});
|
|
let that = this
|
|
wx.request({
|
|
url: app.globalData.reqUrl + '/wechat/projectuserinfo/queryAllProjectUserByParams',
|
|
method: "get",
|
|
data: {
|
|
projectId: that.data.projectId,
|
|
loginName: that.data.loginName
|
|
},
|
|
header: {
|
|
'content-type': 'application/x-www-form-urlencoded'
|
|
},
|
|
success(res) {
|
|
res = res.data
|
|
if (res.code == 200) {
|
|
that.setData({
|
|
rectifierData: res.data,
|
|
rectifierData3: res.data,
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|
|
wx.request({
|
|
url: app.globalData.reqUrl + '/wechat/projectuserinfo/queryAllProjectUserByParams',
|
|
method: "get",
|
|
data: {
|
|
projectId: that.data.projectId,
|
|
loginName: that.data.loginName,
|
|
selectMy: 'Y'
|
|
},
|
|
header: {
|
|
'content-type': 'application/x-www-form-urlencoded'
|
|
},
|
|
success(res) {
|
|
res = res.data;
|
|
if (res.code == 200) {
|
|
let findMy = false;
|
|
res.data.forEach(it => {
|
|
if (it.userinfoList.length > 0) {
|
|
it.userinfoList.forEach(u => {
|
|
if (that.data.loginName == u.phonenumber) {
|
|
findMy = true;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
if(!findMy){
|
|
res.data[0].userinfoList.push({state:false,nickName:that.data.userName,jobTypeName:'集团公司',phonenumber:that.data.loginName});
|
|
}
|
|
that.setData({
|
|
rectifierData2: res.data,
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 这里查询当前登录人上次提交隐患
|
|
* 自动填充整改人,复检人,抄送人
|
|
* @param {*} type
|
|
*/
|
|
getHisInfo(type) {
|
|
findMyLastProblemmodify(app.globalData.useProjectId,type).then(res => {
|
|
if(res.code==200 && res.data && res.data.length>0){
|
|
this.setData({
|
|
showHis: true,
|
|
"form.lordSent": res.data[0].lordSent,
|
|
"form.lordSentUser": res.data[0].lordSentUser,
|
|
"form.recheckSend": res.data[0].recheckSend,
|
|
"form.recheckSendUser": res.data[0].recheckSendUser,
|
|
"form.copySend": res.data[0].copySend,
|
|
"form.copySendUser": res.data[0].copySendUser
|
|
})
|
|
}
|
|
});
|
|
},
|
|
|
|
//隐患描述
|
|
onInputWorkParts(e) {
|
|
this.setData({
|
|
"form.workParts":e.detail.value
|
|
})
|
|
},
|
|
|
|
//整改要求
|
|
onInputChangeInfoValue(e) {
|
|
this.setData({
|
|
"form.changeInfo":e.detail.value
|
|
})
|
|
},
|
|
|
|
//验收时间
|
|
onInputTime(e) {
|
|
this.setData({
|
|
"form.nickedTime":e.detail
|
|
})
|
|
},
|
|
|
|
// 上传图片
|
|
onImagesArr(e) {
|
|
this.setData({
|
|
imageInfoData: e.detail
|
|
})
|
|
},
|
|
|
|
//添加整改人
|
|
onAddLordSent(e) {
|
|
if (e.detail.length > 0) {
|
|
this.setData({
|
|
lordSent: e.detail[0].userName,
|
|
lordSentUser: e.detail[0].phoneNumber
|
|
})
|
|
}
|
|
},
|
|
|
|
//添加抄送人
|
|
onAddCopySend(e) {
|
|
if (e.detail.length > 0) {
|
|
let phoneNumbers = "";
|
|
let userNames = "";
|
|
e.detail.forEach(it => {
|
|
phoneNumbers += "," + it.phoneNumber;
|
|
userNames += "," + it.userName;
|
|
});
|
|
this.setData({
|
|
copySend: userNames.substring(1),
|
|
copySendUser: phoneNumbers.substring(1)
|
|
})
|
|
} else {
|
|
this.setData({
|
|
copySend: "",
|
|
copySendUser: ""
|
|
})
|
|
}
|
|
},
|
|
|
|
//添加复检人
|
|
onAddRecheckSend(e) {
|
|
if (e.detail.length > 0) {
|
|
this.setData({
|
|
recheckSend: e.detail[0].userName,
|
|
recheckSendUser: e.detail[0].phoneNumber
|
|
})
|
|
}
|
|
},
|
|
|
|
//取消页面
|
|
cancelSaveView() {
|
|
this.returnToPage()
|
|
},
|
|
|
|
//保存
|
|
onProblemSubmitSave() {
|
|
this.setData({
|
|
loadShow: true
|
|
})
|
|
let that = this
|
|
let {
|
|
projectId,
|
|
projectName,
|
|
dangerType,
|
|
lordSent,
|
|
lordSentUser,
|
|
copySend,
|
|
copySendUser,
|
|
workParts,
|
|
changeInfo,
|
|
nickedTime,
|
|
recheckSend,
|
|
recheckSendUser,
|
|
imageInfoData,
|
|
loginName,
|
|
problemType,
|
|
userName
|
|
} = that.data;
|
|
//数据效验
|
|
if (projectId == "" || loginName == "") {
|
|
app.toast("数据异常,请刷新页面重试!")
|
|
that.setData({
|
|
loadShow: false
|
|
})
|
|
return;
|
|
}
|
|
if (imageInfoData.length == 0) {
|
|
app.toast("请上传隐患现场图片!")
|
|
that.setData({
|
|
loadShow: false
|
|
})
|
|
return;
|
|
}
|
|
if (problemType == "") {
|
|
app.toast("请选择检查类型!")
|
|
that.setData({
|
|
loadShow: false
|
|
})
|
|
return;
|
|
}
|
|
if (dangerType == "") {
|
|
app.toast("请选择隐患类型!")
|
|
that.setData({
|
|
loadShow: false
|
|
})
|
|
return;
|
|
}
|
|
if (workParts == "") {
|
|
app.toast("请填写隐患描述!")
|
|
that.setData({
|
|
loadShow: false
|
|
})
|
|
return;
|
|
}
|
|
if (changeInfo == "") {
|
|
app.toast("请填写隐患整改要求!")
|
|
that.setData({
|
|
loadShow: false
|
|
})
|
|
return;
|
|
}
|
|
if (nickedTime == "") {
|
|
app.toast("请选择整改截至时间!")
|
|
that.setData({
|
|
loadShow: false
|
|
})
|
|
return;
|
|
}
|
|
if (lordSent == "" || lordSentUser == "") {
|
|
app.toast("请选择整改人!")
|
|
that.setData({
|
|
loadShow: false
|
|
})
|
|
return;
|
|
}
|
|
if (recheckSend == "" || recheckSendUser == "") {
|
|
app.toast("请选择复检人!")
|
|
that.setData({
|
|
loadShow: false
|
|
})
|
|
return;
|
|
}
|
|
if (copySend == "" || copySendUser == "") {
|
|
app.toast("请选择抄送人!")
|
|
that.setData({
|
|
loadShow: false
|
|
})
|
|
return;
|
|
}
|
|
let pos = copySend.split(",");
|
|
pos.forEach(it => {
|
|
if (it == lordSent) {
|
|
app.toast("抄送人中不能包含整改人!")
|
|
that.setData({
|
|
loadShow: false
|
|
})
|
|
return;
|
|
}
|
|
});
|
|
let fileUrls = [];
|
|
imageInfoData.forEach(async (item) => {
|
|
let uploadUrl = app.globalData.uploadUrl + '/common/upload'
|
|
let name = "file"
|
|
//这里复杂的图片上传,改为同步上传,因为小程序只能上传一张图片
|
|
let obj = await that.syncUploadImage(uploadUrl, item, name);
|
|
fileUrls.push(obj.data.fileName);
|
|
//验证图片上传完毕
|
|
if (fileUrls.length == imageInfoData.length) {
|
|
let params = {
|
|
projectId,
|
|
infoType: "1",
|
|
problemArea: projectName,
|
|
problemType,
|
|
workParts,
|
|
changeInfo,
|
|
lordSent,
|
|
lordSentUser,
|
|
copySend,
|
|
copySendUser,
|
|
checkState: 0,
|
|
nickedTime: nickedTime + " 23:59:59",
|
|
smarkUrl: fileUrls.toString(),
|
|
createUser: loginName,
|
|
dangerType,
|
|
recheckSend,
|
|
recheckSendUser
|
|
}
|
|
wx.request({
|
|
url: app.globalData.reqUrl + '/wechat/projectProblemmodify/addQuality',
|
|
method: "POST",
|
|
data: params,
|
|
header: {
|
|
"Username": loginName,
|
|
"Content-Type": "application/json"
|
|
},
|
|
success(res) {
|
|
that.setData({
|
|
loadShow: false
|
|
})
|
|
res = res.data
|
|
if (res.code == 200) {
|
|
app.toast("添加成功!")
|
|
setTimeout(() => {
|
|
wx.redirectTo({
|
|
url: '../list/index',
|
|
})
|
|
}, 200)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
//选择检查类型
|
|
onSelectProblemType(e) {
|
|
this.setData({
|
|
"form.problemType": e.detail.id
|
|
})
|
|
},
|
|
|
|
//选择隐患类型
|
|
onSelectDangerType(e) {
|
|
this.setData({
|
|
"form.dangerType": e.detail.id
|
|
})
|
|
},
|
|
|
|
returnToPage: function () {
|
|
/*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
|
|
wx.redirectTo({
|
|
url: '../list/index',
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |