422 lines
11 KiB
JavaScript
422 lines
11 KiB
JavaScript
import config from '../../../config'
|
||
import {
|
||
getToken,
|
||
getUserInfo
|
||
} from '../../../utils/auth'
|
||
import {
|
||
findDictCache
|
||
} from '../../../api/publics'
|
||
import {
|
||
findProjectDeptUsers
|
||
} from '../../../api/project'
|
||
import {
|
||
add,
|
||
findMyLastProblemmodify
|
||
} from '../../../api/problemmodify'
|
||
const app = getApp()
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
maxDate: new Date(2088, 1, 1).getTime(),
|
||
minDate: new Date().getTime()+(3600*48*1000),
|
||
type: "",
|
||
typeName: "",
|
||
problemTypeList: [],
|
||
problemSubTypeList: [],
|
||
imageInfoData: [],
|
||
form: {
|
||
projectId: "",
|
||
projectName: "",
|
||
infoType: "",
|
||
problemType: "1",
|
||
dangerType: "1",
|
||
workParts: "",
|
||
changeInfo: "",
|
||
nickedTime: "",
|
||
lordSent: "",
|
||
lordSentUser: "",
|
||
recheckSend: "",
|
||
recheckSendUser: "",
|
||
copySend: "",
|
||
copySendUser: ""
|
||
},
|
||
active: 1,
|
||
flowNodes: [{
|
||
text: '开始'
|
||
}, {
|
||
text: '提交隐患'
|
||
}, {
|
||
text: '隐患整改'
|
||
}, {
|
||
text: '隐患复检'
|
||
}, {
|
||
text: '结束'
|
||
}],
|
||
lordSentList: [],
|
||
copySendList: [],
|
||
checkUserList: [],
|
||
loadShow: false,
|
||
showHis: false,
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
if (!getToken()) {
|
||
wx.redirectTo({
|
||
url: '../../../login/login',
|
||
})
|
||
}
|
||
const proUserInfo = getUserInfo();
|
||
this.setData({
|
||
type: options.type,
|
||
typeName: options.type == 1 ? "质量" : "安全",
|
||
"form.comId": proUserInfo.projectUserInfo.comId,
|
||
"form.projectId": app.globalData.useProjectId,
|
||
"form.projectName": app.globalData.useProjectName,
|
||
"form.infoType": options.type,
|
||
"form.recheckSend": proUserInfo.userId,
|
||
"form.recheckSendUser": proUserInfo.nickName
|
||
});
|
||
this.getDictCache();
|
||
this.getHisInfo(options.type);
|
||
this.getProjectUsers();
|
||
},
|
||
|
||
/**
|
||
* 获取字典缓存数据
|
||
*/
|
||
getDictCache() {
|
||
// 初始化检查类型
|
||
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() {
|
||
findProjectDeptUsers(app.globalData.useProjectId).then(res => {
|
||
if (res.code == 200) {
|
||
this.setData({
|
||
lordSentList: res.data.lordSentList,
|
||
copySendList: res.data.copySendList,
|
||
checkUserList: res.data.checkUserList,
|
||
});
|
||
}
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 这里查询当前登录人上次提交隐患
|
||
* 自动填充整改人,复检人,抄送人
|
||
* @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({
|
||
"form.lordSent": e.detail[0].userId,
|
||
"form.lordSentUser": e.detail[0].userName
|
||
})
|
||
}
|
||
},
|
||
|
||
//添加抄送人
|
||
onAddCopySend(e) {
|
||
if (e.detail.length > 0) {
|
||
let _userIds = "";
|
||
let _userNames = "";
|
||
e.detail.forEach(it => {
|
||
_userIds += "," + it.userId;
|
||
_userNames += "," + it.userName;
|
||
});
|
||
this.setData({
|
||
"form.copySend": _userIds.substring(1),
|
||
"form.copySendUser": _userNames.substring(1)
|
||
})
|
||
} else {
|
||
this.setData({
|
||
"form.copySend": "",
|
||
"form.copySendUser": ""
|
||
})
|
||
}
|
||
},
|
||
|
||
//添加复检人
|
||
onAddRecheckSend(e) {
|
||
if (e.detail.length > 0) {
|
||
this.setData({
|
||
"form.recheckSend": e.detail[0].userId,
|
||
"form.recheckSendUser": e.detail[0].userName
|
||
})
|
||
}
|
||
},
|
||
|
||
//取消页面
|
||
cancelSaveView() {
|
||
this.returnToPage()
|
||
},
|
||
|
||
/**
|
||
* 数据保存
|
||
*/
|
||
submitSave() {
|
||
let _form = {
|
||
...this.data.form
|
||
};
|
||
let {
|
||
imageInfoData
|
||
} = this.data
|
||
//数据效验
|
||
if (!_form.comId || !_form.projectId) {
|
||
app.toast("数据异常,请刷新页面重试!")
|
||
return false;
|
||
}
|
||
if (imageInfoData.length == 0) {
|
||
app.toast("请上传隐患现场图片!")
|
||
return false;
|
||
}
|
||
if (!_form.problemType) {
|
||
app.toast("请选择检查类型!")
|
||
return false;
|
||
}
|
||
if (!_form.dangerType) {
|
||
app.toast("请选择隐患类型!")
|
||
return false;
|
||
}
|
||
if (!_form.workParts) {
|
||
app.toast("请填写隐患描述!")
|
||
return false;
|
||
}
|
||
if (!_form.changeInfo) {
|
||
app.toast("请填写隐患整改要求!")
|
||
return false;
|
||
}
|
||
if (!_form.nickedTime) {
|
||
app.toast("请选择整改截至时间!")
|
||
return false;
|
||
}
|
||
if (!_form.lordSent || !_form.lordSentUser) {
|
||
app.toast("请选择整改人!")
|
||
return false;
|
||
}
|
||
if (!_form.recheckSend || !_form.recheckSendUser) {
|
||
app.toast("请选择复检人!")
|
||
return false;
|
||
}
|
||
if (!_form.copySend || !_form.copySendUser) {
|
||
app.toast("请选择抄送人!")
|
||
return false;
|
||
}
|
||
let fileUrls = [];
|
||
this.setData({
|
||
loadShow: true
|
||
});
|
||
let that = this;
|
||
imageInfoData.forEach(async (item) => {
|
||
//这里复杂的图片上传,改为同步上传,因为小程序只能上传一张图片
|
||
let obj = await that.syncUploadImage(item);
|
||
fileUrls.push(obj.data.data.url);
|
||
//验证图片上传完毕
|
||
if (fileUrls.length == imageInfoData.length) {
|
||
_form.smarkUrl = fileUrls.toString();
|
||
add(_form).then(res => {
|
||
this.setData({
|
||
loadShow: false
|
||
});
|
||
if (res.code == 200) {
|
||
app.toast("新增数据成功!")
|
||
setTimeout(() => {
|
||
wx.redirectTo({
|
||
url: `../list/index?type=${this.data.type}`,
|
||
})
|
||
}, 200)
|
||
}
|
||
});
|
||
}
|
||
})
|
||
},
|
||
|
||
//选择检查类型
|
||
onSelectProblemType(e) {
|
||
this.setData({
|
||
"form.problemType": e.detail.id
|
||
})
|
||
},
|
||
|
||
//选择隐患类型
|
||
onSelectDangerType(e) {
|
||
this.setData({
|
||
"form.dangerType": e.detail.id
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 这里考虑上传图片异步问题,封装为同步
|
||
*/
|
||
syncUploadImage(file) {
|
||
let _baseUrl = config.baseUrl;
|
||
return new Promise((resolve, reject) => {
|
||
wx.uploadFile({
|
||
url: _baseUrl + "/file/upload", // 上传的服务器接口地址
|
||
filePath: file,
|
||
header: {
|
||
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
||
'Authorization': 'Bearer ' + getToken()
|
||
},
|
||
name: "file", //上传的所需字段,后端提供
|
||
formData: {},
|
||
success: (res) => {
|
||
// 上传完成操作
|
||
const data = JSON.parse(res.data)
|
||
resolve({
|
||
data: data
|
||
})
|
||
},
|
||
fail: (err) => {
|
||
//上传失败:修改pedding为reject
|
||
console.log("访问接口失败", err);
|
||
wx.showToast({
|
||
title: "网络出错,上传失败",
|
||
icon: 'none',
|
||
duration: 1000
|
||
});
|
||
reject(err)
|
||
}
|
||
});
|
||
})
|
||
},
|
||
|
||
returnToPage: function () {
|
||
wx.redirectTo({
|
||
url: `../list/index?type=${this.data.type}`
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage() {
|
||
|
||
}
|
||
}) |