jhwxapp/miniprogram/pages/project_flowable/initTask/index.js

646 lines
18 KiB
JavaScript
Raw Normal View History

2024-05-03 10:37:27 +08:00
import {
getDictCache
} from '../../../api/publics'
2023-09-17 02:08:35 +08:00
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
2024-03-17 16:19:31 +08:00
maxDate: new Date(2088, 1, 1).getTime(),
2024-05-03 10:37:27 +08:00
minDate: new Date(2001, 1, 1).getTime(),
2024-03-17 16:19:31 +08:00
deptId: "",
deptName: "",
userId: "",
nickName: "",
loginName: "",
projectId: "",
projectName: "",
remark: "",
filesData: [],
2024-05-03 10:37:27 +08:00
limit: 30,
2024-03-17 16:19:31 +08:00
fileType: ["pdf", "png", "jpg", "jpeg"],
procDefId: "",
approveTitle: "",
deploymentId: "",
activeName: "",
flowNodeList: [],
flowNodes: [],
isFiles: false,
2024-03-25 01:40:33 +08:00
imageInfoData: [],
2024-04-14 21:28:11 +08:00
active: 0,
2024-05-03 10:37:27 +08:00
fbAptitude: false,
subDeptType: "",
subDeptTypes: [],
subDeptScope: "",
subDeptScopes: [],
subDeptName: "",
subDeptAptitude: "",
subDeptChairman: "",
subDeptSafetyCertificate: "",
subDeptCustodian: "",
subDeptCustodianCardId: "",
subDeptApproachDate: "",
2024-07-09 21:42:49 +08:00
persChange1: false,
persChange2: false,
2023-09-17 02:08:35 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
2024-03-17 16:19:31 +08:00
let {
procDefId,
approveTitle,
2024-05-03 10:37:27 +08:00
deploymentId,
procDefKey
2024-03-17 16:19:31 +08:00
} = options
2024-05-03 10:37:27 +08:00
if (procDefKey == "flow_fbzzsp_fbszzsp") {
this.getDicts();
this.setData({
fbAptitude: true
})
}
2024-07-09 21:42:49 +08:00
if (procDefKey == "flow_xmglzdl_xmzbdwrybg" || procDefKey == "flow_xmglzdl_xmjldwrybg") {
this.setData({
persChange1: true
})
}
if (procDefKey == "flow_xmglzdl_xmjlzjrybg" || procDefKey == "flow_xmglzdl_xmzbjlrybg") {
this.setData({
persChange2: true
})
}
2023-09-17 02:08:35 +08:00
//获取缓存数据
wx.getStorage({
2024-03-17 16:19:31 +08:00
key: 'userinfo',
success: res => {
this.setData({
projectId: app.globalData.projectId,
projectName: app.globalData.projectName,
procDefId,
approveTitle,
deploymentId,
deptId: res.data.deptId,
deptName: res.data.deptName,
userId: res.data.userId,
nickName: res.data.nickName,
loginName: res.data.loginName
})
this.getFlowNodes();
}
})
2023-09-17 02:08:35 +08:00
},
//取消页面
2024-03-17 16:19:31 +08:00
cancelSaveView() {
/*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
wx.redirectTo({
2023-09-17 02:08:35 +08:00
url: '../myFlowDefinition/index'
})
},
2024-05-03 10:37:27 +08:00
//获取字典信息
getDicts() {
let that = this;
/*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
getDictCache('flow_sub_dept_type').then(res => {
if (res.code == 200) {
let typeList = [];
res.data.forEach(item => {
typeList.push({
"id": item.dictValue,
"text": item.dictLabel
});
})
that.setData({
subDeptTypes: typeList,
subDeptType: typeList[0].id,
})
}
});
getDictCache('flow_sub_dept_scope').then(res => {
if (res.code == 200) {
let scopeList = [];
res.data.forEach(item => {
scopeList.push({
"id": item.dictValue,
"text": item.dictLabel
});
})
that.setData({
subDeptScopes: scopeList,
subDeptScope: scopeList[0].id,
})
}
});
},
//选择分包类型
onSelectSubDeptTypes(e) {
this.setData({
subDeptType: e.detail.id
})
},
//选择分包范围
onSelectSubDeptScopes(e) {
let list = [];
e.detail.forEach(it =>{
if(it.id){
list.push(it.id)
}
})
this.setData({
subDeptScope: list.toString()
})
},
//输入分包单位名称
inputSubDeptName(e) {
this.setData({
subDeptName: e.detail.value
})
},
//输入分包单位资质
inputSubDeptAptitude(e) {
this.setData({
subDeptAptitude: e.detail.value
})
},
//输入分包单位法人代表
inputSubDeptChairman(e) {
this.setData({
subDeptChairman: e.detail.value
})
},
//输入分包单位安全证书
inputSubDeptSafetyCertificate(e) {
this.setData({
subDeptSafetyCertificate: e.detail.value
})
},
//输入分包单位项目经理
inputSubDeptCustodian(e) {
this.setData({
subDeptCustodian: e.detail.value
})
},
//输入分包单位名称
inputSubDeptCustodianCardId(e) {
this.setData({
subDeptCustodianCardId: e.detail.value
})
},
//选择分包进场时间
inputSubDeptApproachDate(e) {
this.setData({
subDeptApproachDate: e.detail
})
},
/**
* 获取流程节点
* @param {*} val
*/
2024-03-17 16:19:31 +08:00
getFlowNode(val) {
2023-09-17 02:08:35 +08:00
let flowNodeList = this.data.flowNodeList;
2024-03-17 16:19:31 +08:00
for (let i = 0; i < flowNodeList.length; i++) {
if (flowNodeList[i].id == val) {
2023-09-17 02:08:35 +08:00
let list = this.data.flowNodes;
2024-03-17 16:19:31 +08:00
list.push({
id: flowNodeList[i].id,
2024-03-25 01:40:33 +08:00
name: flowNodeList[i].name,
text: flowNodeList[i].name.length > 4 ? flowNodeList[i].name.substring(0, 4) : flowNodeList[i].name
2024-03-17 16:19:31 +08:00
});
2023-09-17 02:08:35 +08:00
this.setData({
2024-03-17 16:19:31 +08:00
flowNodes: list
2023-09-17 02:08:35 +08:00
})
2024-03-17 16:19:31 +08:00
if (flowNodeList[i].outgoingFlows && flowNodeList[i].outgoingFlows.length > 0) {
2023-09-17 02:08:35 +08:00
return this.getFlowNode(flowNodeList[i].outgoingFlows[0].targetRef);
}
}
}
},
//查询工作流节点
2024-03-17 16:19:31 +08:00
getFlowNodes() {
2023-09-17 02:08:35 +08:00
let that = this;
wx.request({
2024-03-17 16:19:31 +08:00
url: app.globalData.reqUrl + '/wechat/flowTask/readNotes/' + this.data.deploymentId,
method: "get",
data: {},
2023-09-17 02:08:35 +08:00
header: {
"Content-Type": "application/json"
},
2024-03-17 16:19:31 +08:00
success(res) {
2023-09-17 02:08:35 +08:00
res = res.data
2024-03-17 16:19:31 +08:00
if (res.code == 200) {
2023-09-17 02:08:35 +08:00
that.setData({
2024-03-17 16:19:31 +08:00
flowNodeList: res.data
2023-09-17 02:08:35 +08:00
})
2024-03-17 16:19:31 +08:00
if (res.data.length > 0) {
2023-09-17 02:08:35 +08:00
let list = that.data.flowNodes;
2024-03-17 16:19:31 +08:00
list.push({
id: res.data[0].id,
2024-03-25 01:40:33 +08:00
name: res.data[0].name,
text: res.data[0].name
2024-03-17 16:19:31 +08:00
});
2023-09-17 02:08:35 +08:00
that.setData({
2024-03-17 16:19:31 +08:00
flowNodes: list
2023-09-17 02:08:35 +08:00
})
return that.getFlowNode(res.data[0].outgoingFlows[0].targetRef);
}
2024-03-17 16:19:31 +08:00
} else {
2023-09-17 02:08:35 +08:00
app.toast(res.msg);
}
}
})
},
//保存
2024-03-17 16:19:31 +08:00
onSave() {
2023-09-17 02:08:35 +08:00
this.setData({
2024-03-17 16:19:31 +08:00
loadShow: true
2023-09-17 02:08:35 +08:00
})
2024-03-17 16:19:31 +08:00
let {
procDefId,
projectId,
userId,
loginName,
remark,
2024-05-03 10:37:27 +08:00
filesData,
fbAptitude,
subDeptType,
subDeptScope,
subDeptName,
subDeptAptitude,
subDeptChairman,
subDeptSafetyCertificate,
subDeptCustodian,
subDeptCustodianCardId,
subDeptApproachDate
2024-03-17 16:19:31 +08:00
} = this.data;
2023-09-17 02:08:35 +08:00
//数据效验
2024-03-17 16:19:31 +08:00
if (projectId == "" || loginName == "" || userId == "" || procDefId == "") {
2023-09-17 02:08:35 +08:00
app.toast("数据异常,请刷新页面重试!")
this.setData({
2024-03-17 16:19:31 +08:00
loadShow: false
2023-09-17 02:08:35 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
//分包资质审批数据效验
if (fbAptitude) {
if (subDeptType == "") {
app.toast("请选择分包类型!")
this.setData({
loadShow: false
})
return;
}
if (subDeptScope == "") {
app.toast("请选择分包范围!")
this.setData({
loadShow: false
})
return;
}
if (subDeptName == "") {
app.toast("请填写分包单位名称!")
this.setData({
loadShow: false
})
return;
}
if (subDeptAptitude == "") {
app.toast("请填写分包单位资质!")
this.setData({
loadShow: false
})
return;
}
if (subDeptChairman == "") {
app.toast("请填写分包单位法人代表!")
this.setData({
loadShow: false
})
return;
}
if (subDeptSafetyCertificate == "") {
app.toast("请填写分包单位安全生产许可证!")
this.setData({
loadShow: false
})
return;
}
if (subDeptCustodian == "") {
app.toast("请填写分包单位项目经理!")
this.setData({
loadShow: false
})
return;
}
if (subDeptCustodianCardId == "") {
app.toast("请填写分包单位项目经理身份证号!")
this.setData({
loadShow: false
})
return;
}
if (subDeptApproachDate == "") {
app.toast("请选择分包单位进场时间!")
this.setData({
loadShow: false
})
return;
}
2023-09-17 02:08:35 +08:00
}
2024-03-17 16:19:31 +08:00
if (filesData.length == 0 && this.data.imageInfoData.length == 0) {
2023-09-17 02:08:35 +08:00
app.toast("请上传审批内容!")
this.setData({
2024-03-17 16:19:31 +08:00
loadShow: false
2023-09-17 02:08:35 +08:00
});
return;
}
2024-05-03 10:37:27 +08:00
if (remark == "") {
app.toast("请填写申请说明!")
this.setData({
loadShow: false
})
return;
}
2024-03-17 16:19:31 +08:00
for (let i = 0; i < filesData.length; i++) {
2023-09-17 02:08:35 +08:00
let _fileType = filesData[0].path.split('.');
2024-03-17 16:19:31 +08:00
_fileType = _fileType[_fileType.length - 1].toLowerCase();
2023-09-17 02:08:35 +08:00
//判断附件类型,如果是图片直接展示,非图片则显示附件
2024-03-17 16:19:31 +08:00
if (this.data.fileType.indexOf(_fileType) == -1) {
app.toast("申批内容不支持 [ " + _fileType + " ] 格式请上传PDF文件。")
2023-09-17 02:08:35 +08:00
this.setData({
2024-03-17 16:19:31 +08:00
loadShow: false
2023-09-17 02:08:35 +08:00
});
return;
}
}
let that = this;
wx.showModal({
title: '提示',
2024-03-17 16:19:31 +08:00
content: '是否确定提交' + this.data.approveTitle + '',
2023-09-17 02:08:35 +08:00
success: function (sm) {
2024-03-17 16:19:31 +08:00
if (sm.confirm) {
// 用户点击了确定 可以调用了
that.submit()
2023-09-17 02:08:35 +08:00
} else if (sm.cancel) {
that.setData({
2024-03-17 16:19:31 +08:00
loadShow: false
2023-09-17 02:08:35 +08:00
});
2024-03-17 16:19:31 +08:00
console.log('用户点击取消');
2023-09-17 02:08:35 +08:00
}
2024-03-17 16:19:31 +08:00
}
})
2023-09-17 02:08:35 +08:00
},
2024-03-17 16:19:31 +08:00
submit() {
2023-09-17 02:08:35 +08:00
let that = this
2024-03-17 16:19:31 +08:00
let {
procDefId,
projectId,
projectName,
userId,
loginName,
nickName,
remark,
filesData,
2024-05-03 10:37:27 +08:00
imageInfoData,
fbAptitude,
subDeptType,
subDeptScope,
subDeptName,
subDeptAptitude,
subDeptChairman,
subDeptSafetyCertificate,
subDeptCustodian,
subDeptCustodianCardId,
subDeptApproachDate
2024-03-17 16:19:31 +08:00
} = that.data;
2023-09-17 02:08:35 +08:00
let fileUrls = [];
2024-03-25 01:40:33 +08:00
filesData.forEach(f => {
2024-03-17 16:19:31 +08:00
imageInfoData.push(f.path);
});
imageInfoData.forEach(async (item) => {
let uploadUrl = app.globalData.uploadUrl + '/common/upload'
let name = "file"
2023-09-17 02:08:35 +08:00
//这里复杂的图片上传,改为同步上传,因为小程序只能上传一张图片
2024-03-17 16:19:31 +08:00
let obj = await that.syncUploadImage(uploadUrl, item, name);
2023-09-17 02:08:35 +08:00
fileUrls.push(obj.data.fileName);
//验证图片上传完毕
2024-03-17 16:19:31 +08:00
if (fileUrls.length == imageInfoData.length) {
2024-05-03 10:37:27 +08:00
//分包单位资质审批参数
let fbAptitudeParams = {};
if(fbAptitude){
fbAptitudeParams = {
subDeptType,
subDeptScope,
subDeptName,
subDeptAptitude,
subDeptChairman,
subDeptSafetyCertificate,
subDeptCustodian,
subDeptCustodianCardId,
subDeptApproachDate
}
}
2023-09-17 02:08:35 +08:00
let params = {
procDefId,
userId,
2024-03-17 16:19:31 +08:00
userName: loginName,
2023-09-17 02:08:35 +08:00
nickName,
2024-03-17 16:19:31 +08:00
variables: {
businessKey: projectId,
2023-09-17 02:08:35 +08:00
projectName,
2024-03-17 16:19:31 +08:00
files: fileUrls.toString(),
2023-09-17 02:08:35 +08:00
remark,
2024-05-03 10:37:27 +08:00
...fbAptitudeParams
2023-09-17 02:08:35 +08:00
}
}
wx.request({
url: app.globalData.reqUrl + '/wechat/flowTask/startProcessInstance',
2024-03-17 16:19:31 +08:00
method: "POST",
data: params,
2023-09-17 02:08:35 +08:00
header: {
"Username": loginName,
"Content-Type": "application/json"
},
2024-03-17 16:19:31 +08:00
success(res) {
2023-09-17 02:08:35 +08:00
that.setData({
2024-03-17 16:19:31 +08:00
loadShow: false
2023-09-17 02:08:35 +08:00
})
2024-03-17 16:19:31 +08:00
res = res.data
if (res.code == 200) {
2023-09-17 02:08:35 +08:00
app.toast("提交申请成功!")
2024-03-17 16:19:31 +08:00
setTimeout(() => {
wx.redirectTo({
url: '../myProcessIns/index',
})
}, 200)
} else {
2023-09-17 02:08:35 +08:00
app.toast(res.msg);
}
}
})
2024-03-17 16:19:31 +08:00
}
2023-09-17 02:08:35 +08:00
})
},
/**
* 这里考虑上传图片异步问题封装为同步
*/
2024-03-17 16:19:31 +08:00
syncUploadImage(url, uploadFile, name) {
2023-09-17 02:08:35 +08:00
return new Promise((resolve, reject) => {
wx.uploadFile({
2024-03-17 16:19:31 +08:00
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)
}
2023-09-17 02:08:35 +08:00
});
})
},
//申请说明
remarkblur: function (options) {
this.data.remark = options.detail.value;
},
2024-03-17 16:19:31 +08:00
/**
* 上传文件
* @param {*} options
*/
fileUpload(options) {
let file = options.detail;
2023-09-17 02:08:35 +08:00
this.setData({
filesData: file
});
},
2024-03-17 16:19:31 +08:00
// list 上传图片
onImagesArr(e) {
var data = this.data.imageInfoData
data = e.detail
this.setData({
imageInfoData: data
})
},
// 手风琴
onChange(event) {
this.setData({
activeName: event.detail,
});
},
/**
* 切换上传文件类型
* @param {*} e
*/
switchFiles(e) {
this.setData({
isFiles: !this.data.isFiles,
});
2024-03-25 01:40:33 +08:00
if (this.data.isFiles) {
if (this.data.filesData.length == 0) {
2024-03-17 16:19:31 +08:00
let myImages = this.selectComponent("#myImage");
myImages.upload();
}
2024-03-25 01:40:33 +08:00
} else {
if (this.data.imageInfoData.length == 0) {
2024-03-17 16:19:31 +08:00
let myFiles = this.selectComponent("#myFiles");
myFiles.upload();
}
}
},
2023-09-17 02:08:35 +08:00
returnToPage: function () {
/*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
wx.redirectTo({
url: '../myFlowDefinition/index',
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})