585 lines
16 KiB
JavaScript
585 lines
16 KiB
JavaScript
// pageage/safetyManagement/addSafetyInspect/index.js
|
||
const app = getApp()
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
maxDate: new Date(2088, 1, 1).getTime(),
|
||
currentDate: new Date().getTime(),
|
||
deptId: "",
|
||
projectId: "",
|
||
projectName: "",
|
||
loginName: "",
|
||
rectifierData: [],
|
||
rectifierData2: [],
|
||
imageInfoData: [],
|
||
loadShow: false,
|
||
measureType: "1",
|
||
measureTypeList: [],
|
||
measureInfo: "1",
|
||
infoTypeList: [],
|
||
measureInfoTypeList: [],
|
||
measurePosition: "",
|
||
measurePointPosition: "",
|
||
qualityUser: "",
|
||
qualityUserName: "",
|
||
superviseUser: "",
|
||
superviseUserName: "",
|
||
//验收时间
|
||
measureTime: '',
|
||
measureResult: "1",
|
||
limit: 9,
|
||
measureFiles: [],
|
||
resultList: [{
|
||
id: 1,
|
||
text: "合格"
|
||
}, {
|
||
id: 2,
|
||
text: "不合格"
|
||
}],
|
||
fileType: ["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf", "png", "jpg", "jpeg"]
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
let {
|
||
projectId,
|
||
projectName
|
||
} = options
|
||
//获取缓存数据
|
||
wx.getStorage({
|
||
key: 'userinfo',
|
||
success: res => {
|
||
this.setData({
|
||
projectId,
|
||
projectName,
|
||
deptId: res.data.deptId,
|
||
loginName: res.data.loginName
|
||
})
|
||
this.getProjectUserData();
|
||
this.getMeasureTypeList();
|
||
this.getMeasureInfoTypeList();
|
||
}
|
||
})
|
||
},
|
||
|
||
//查询项目人员数据
|
||
getProjectUserData() {
|
||
let that = this
|
||
wx.request({
|
||
url: app.globalData.reqUrl + '/wechat/projectuserinfo/selectProjectUnitUser',
|
||
method: "get",
|
||
data: {
|
||
unitType: "4",
|
||
projectId: that.data.projectId
|
||
},
|
||
header: {
|
||
'content-type': 'application/x-www-form-urlencoded'
|
||
},
|
||
success(res) {
|
||
res = res.data
|
||
if (res.code == 200) {
|
||
that.setData({
|
||
rectifierData: res.data,
|
||
})
|
||
}
|
||
}
|
||
})
|
||
|
||
wx.request({
|
||
url: app.globalData.reqUrl + '/wechat/projectuserinfo/selectProjectUnitUser',
|
||
method: "get",
|
||
data: {
|
||
unitType: "2",
|
||
projectId: that.data.projectId
|
||
},
|
||
header: {
|
||
'content-type': 'application/x-www-form-urlencoded'
|
||
},
|
||
success(res) {
|
||
res = res.data
|
||
if (res.code == 200) {
|
||
that.setData({
|
||
rectifierData2: res.data,
|
||
})
|
||
}
|
||
}
|
||
})
|
||
},
|
||
|
||
getMeasureTypeList() {
|
||
let that = this
|
||
wx.request({
|
||
url: app.globalData.reqUrl + '/wechat/projectMeasure/queryDictType',
|
||
method: "get",
|
||
data: {
|
||
type: 'project_measure_type'
|
||
},
|
||
header: {
|
||
'content-type': 'application/x-www-form-urlencoded'
|
||
},
|
||
success(res) {
|
||
res = res.data
|
||
if (res.code == 200) {
|
||
let list = [];
|
||
res.data.forEach(it => {
|
||
list.push({
|
||
"id": it.dictValue,
|
||
"text": it.dictLabel
|
||
});
|
||
})
|
||
that.setData({
|
||
measureTypeList: list
|
||
})
|
||
}
|
||
}
|
||
})
|
||
},
|
||
|
||
getMeasureInfoTypeList() {
|
||
let that = this
|
||
wx.request({
|
||
url: app.globalData.reqUrl + '/wechat/projectMeasure/queryDictType',
|
||
method: "get",
|
||
data: {
|
||
type: 'project_measure_info_type'
|
||
},
|
||
header: {
|
||
'content-type': 'application/x-www-form-urlencoded'
|
||
},
|
||
success(res) {
|
||
res = res.data
|
||
if (res.code == 200) {
|
||
let list = [];
|
||
res.data.forEach(it => {
|
||
if (!it.remark) {
|
||
list.push({
|
||
"id": it.dictValue,
|
||
"text": it.dictLabel
|
||
});
|
||
}
|
||
})
|
||
that.setData({
|
||
infoTypeList: res.data,
|
||
measureInfoTypeList: list
|
||
})
|
||
}
|
||
}
|
||
})
|
||
},
|
||
|
||
//测量部位
|
||
onInputMeasurePosition(e) {
|
||
let measurePosition = e.detail.value
|
||
this.setData({
|
||
measurePosition
|
||
})
|
||
},
|
||
|
||
//测量点位
|
||
onInputMeasurePointPosition(e) {
|
||
let measurePointPosition = e.detail.value
|
||
this.setData({
|
||
measurePointPosition
|
||
})
|
||
},
|
||
|
||
//验收时间
|
||
onInputTime(e) {
|
||
let measureTime = e.detail
|
||
this.setData({
|
||
measureTime
|
||
})
|
||
},
|
||
|
||
// list 上传图片
|
||
onImagesArr(e) {
|
||
var data = this.data.imageInfoData
|
||
data = e.detail
|
||
this.setData({
|
||
imageInfoData: data
|
||
})
|
||
},
|
||
|
||
//添加质量专员
|
||
onAddQualityUser(e) {
|
||
if (e.detail.length > 0) {
|
||
this.setData({
|
||
qualityUser: e.detail[0].phoneNumber,
|
||
qualityUserName: e.detail[0].userName
|
||
})
|
||
}
|
||
},
|
||
|
||
//添加监理专员
|
||
onAddSuperviseUser(e) {
|
||
if (e.detail.length > 0) {
|
||
this.setData({
|
||
superviseUser: e.detail[0].phoneNumber,
|
||
superviseUserName: e.detail[0].userName
|
||
})
|
||
}
|
||
},
|
||
|
||
//切换测量结果
|
||
onSelectType(e) {
|
||
this.setData({
|
||
measureResult: e.detail.id
|
||
})
|
||
},
|
||
|
||
//取消页面
|
||
cancelSaveView() {
|
||
this.returnToPage()
|
||
},
|
||
|
||
//保存
|
||
onSave() {
|
||
this.setData({
|
||
loadShow: true
|
||
})
|
||
let that = this
|
||
let {
|
||
projectId,
|
||
loginName,
|
||
deptId,
|
||
measureType,
|
||
measureInfo,
|
||
measurePosition,
|
||
measurePointPosition,
|
||
qualityUser,
|
||
qualityUserName,
|
||
superviseUser,
|
||
superviseUserName,
|
||
measureTime,
|
||
measureResult,
|
||
imageInfoData,
|
||
measureFiles
|
||
} = that.data;
|
||
//数据效验
|
||
if (projectId == "" || loginName == "" || deptId == "") {
|
||
app.toast("数据异常,请刷新页面重试!")
|
||
that.setData({
|
||
loadShow: false
|
||
})
|
||
return;
|
||
}
|
||
if (imageInfoData.length == 0) {
|
||
app.toast("请上传测量现场图片!")
|
||
that.setData({
|
||
loadShow: false
|
||
})
|
||
return;
|
||
}
|
||
if (measureType == "") {
|
||
app.toast("请选择测量类型!")
|
||
that.setData({
|
||
loadShow: false
|
||
})
|
||
return;
|
||
}
|
||
if (measureInfo == "") {
|
||
app.toast("请选择测量内容!")
|
||
that.setData({
|
||
loadShow: false
|
||
})
|
||
return;
|
||
}
|
||
if (measurePosition == "") {
|
||
app.toast("请填写测量部位!")
|
||
that.setData({
|
||
loadShow: false
|
||
})
|
||
return;
|
||
}
|
||
if (measurePointPosition == "") {
|
||
app.toast("请填写测量点位!")
|
||
that.setData({
|
||
loadShow: false
|
||
})
|
||
return;
|
||
}
|
||
if (qualityUser == "" || qualityUserName == "") {
|
||
app.toast("请选择质量专员!")
|
||
that.setData({
|
||
loadShow: false
|
||
})
|
||
return;
|
||
}
|
||
if (superviseUser == "" || superviseUserName == "") {
|
||
app.toast("请选择监理专员!")
|
||
that.setData({
|
||
loadShow: false
|
||
})
|
||
return;
|
||
}
|
||
if (measureTime == "") {
|
||
app.toast("请选择测量时间!")
|
||
that.setData({
|
||
loadShow: false
|
||
})
|
||
return;
|
||
}
|
||
// if(measureResult==""){
|
||
// app.toast("请选择测量结果!")
|
||
// that.setData({
|
||
// loadShow:false
|
||
// })
|
||
// return;
|
||
// }
|
||
if (superviseUser == qualityUser) {
|
||
app.toast("质量专员和监理专员不能是同一人!")
|
||
that.setData({
|
||
loadShow: false
|
||
})
|
||
return;
|
||
}
|
||
|
||
if (measureFiles.length > 0) {
|
||
for (let i = 0; i < measureFiles.length; i++) {
|
||
let _fileType = measureFiles[i].path.split('.');
|
||
_fileType = _fileType[_fileType.length - 1].toLowerCase();
|
||
//判断附件类型,如果是图片直接展示,非图片则显示附件
|
||
if (this.data.fileType.indexOf(_fileType) == -1) {
|
||
app.toast("当前 [ " + _fileType + " ] 文件不支持上传!")
|
||
that.setData({
|
||
loadShow: false
|
||
});
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
let fileUrls = [];
|
||
let _measureFiles = [];
|
||
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) {
|
||
if(measureFiles.length>0){
|
||
measureFiles.forEach(async (_file) => {
|
||
let uploadUrl = app.globalData.uploadUrl + '/common/upload'
|
||
let name = "file"
|
||
//这里复杂的图片上传,改为同步上传,因为小程序只能上传一张图片
|
||
let obj = await that.syncUploadImage(uploadUrl, _file.path, name);
|
||
_measureFiles.push(obj.data.fileName);
|
||
if (_measureFiles.length == measureFiles.length) {
|
||
this.submitFroms(fileUrls,_measureFiles);
|
||
}
|
||
});
|
||
}else{
|
||
//不传入附件信息
|
||
this.submitFroms(fileUrls,"");
|
||
}
|
||
}
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 表单提交
|
||
* @param {*} fileUrls
|
||
* @param {*} measureFiles
|
||
*/
|
||
submitFroms(fileUrls,measureFiles){
|
||
let that = this
|
||
let {
|
||
projectId,
|
||
loginName,
|
||
deptId,
|
||
measureType,
|
||
measureInfo,
|
||
measurePosition,
|
||
measurePointPosition,
|
||
qualityUser,
|
||
qualityUserName,
|
||
superviseUser,
|
||
superviseUserName,
|
||
measureTime,
|
||
} = that.data;
|
||
let params = {
|
||
projectId,
|
||
deptId,
|
||
imageUrls: fileUrls.toString(),
|
||
measureFiles: measureFiles.toString(),
|
||
measureType,
|
||
measureInfo,
|
||
measurePosition,
|
||
measurePointPosition,
|
||
qualityUser,
|
||
qualityUserName,
|
||
superviseUser,
|
||
superviseUserName,
|
||
measureTime: measureTime+":00",
|
||
approveStatus: "1",
|
||
createBy: loginName
|
||
}
|
||
wx.request({
|
||
url: app.globalData.reqUrl + '/wechat/projectMeasure/add',
|
||
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)
|
||
}
|
||
}
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 这里考虑上传图片异步问题,封装为同步
|
||
*/
|
||
syncUploadImage(url, uploadFile, name) {
|
||
return new Promise((resolve, reject) => {
|
||
wx.uploadFile({
|
||
url, // 上传的服务器接口地址
|
||
filePath: uploadFile,
|
||
header: {
|
||
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
|
||
},
|
||
name, //上传的所需字段,后端提供
|
||
formData: {
|
||
user: 'test'
|
||
},
|
||
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)
|
||
}
|
||
});
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 文件上传
|
||
* @param {*} e
|
||
*/
|
||
fileUpload(e) {
|
||
this.setData({
|
||
measureFiles: e.detail
|
||
});
|
||
},
|
||
|
||
//选择测量类型
|
||
onSelectMeasureType(e) {
|
||
let list = [];
|
||
if (e.detail.id == 6) {
|
||
this.data.infoTypeList.forEach(item => {
|
||
if (item.remark == "gjgc") {
|
||
list.push({
|
||
"id": item.dictValue,
|
||
"text": item.dictLabel
|
||
});
|
||
}
|
||
})
|
||
} else {
|
||
this.data.infoTypeList.forEach(item => {
|
||
if (!item.remark) {
|
||
list.push({
|
||
"id": item.dictValue,
|
||
"text": item.dictLabel
|
||
});
|
||
}
|
||
})
|
||
}
|
||
this.setData({
|
||
measureType: e.detail.id,
|
||
measureInfo: list[0].id,
|
||
measureInfoTypeList: list
|
||
})
|
||
},
|
||
|
||
//选择测量内容
|
||
onSelectMeasureInfo(e) {
|
||
this.setData({
|
||
measureInfo: e.detail.id
|
||
})
|
||
},
|
||
|
||
returnToPage: function () {
|
||
/*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
|
||
wx.redirectTo({
|
||
url: '../list/index',
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage() {
|
||
|
||
}
|
||
}) |