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

613 lines
20 KiB
JavaScript
Raw Normal View History

2024-03-17 16:19:31 +08:00
import config from '../../../config'
2023-09-17 02:08:35 +08:00
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
2024-03-25 01:40:33 +08:00
maxDate: new Date(2088, 1, 1).getTime(),
deptName: "",
userId: "",
myUserId: "",
nickName: "",
loginName: "",
projectId: "",
projectName: "",
procInsId: "",
infoData: {},
procDefName: "",
deployId: "",
activeName: "",
flowNodeList: [],
flowNodes: [],
imageList: [],
filesData: [],
taskId: "",
taskName: "",
passState: true,
backName: "",
stopShow: false,
deleteShow: false,
revocationShow: false,
finishTime: "",
ret: "",
comment: "",
stopBtnShow: false,
imageType: ["png", "jpg", "jpeg"],
2024-04-14 21:28:11 +08:00
taskComType:"",
2024-03-25 01:40:33 +08:00
fileType: ["pdf"],
2024-04-14 21:28:11 +08:00
active: 100,
rejectNode:false
2023-09-17 02:08:35 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
2024-03-25 01:40:33 +08:00
let {
deployId,
procInsId,
procDefName,
deptName,
nickName,
taskId,
taskName,
projectName,
userId,
finishTime,
2024-04-14 21:28:11 +08:00
ret,
taskComType
2024-03-25 01:40:33 +08:00
} = options
2023-09-17 02:08:35 +08:00
//获取缓存数据
wx.getStorage({
2024-03-25 01:40:33 +08:00
key: 'userinfo',
success: res => {
this.setData({
projectId: app.globalData.projectId,
projectName,
procInsId,
procDefName,
deployId,
deptName,
nickName,
taskId,
taskName,
userId,
finishTime,
ret,
2024-04-14 21:28:11 +08:00
taskComType,
2024-03-25 01:40:33 +08:00
myUserId: res.data.userId,
loginName: res.data.loginName,
})
this.getFlowRecordList();
2024-04-14 21:28:11 +08:00
this.getFlowNodes();
2024-03-25 01:40:33 +08:00
this.getFormDatasList();
}
})
2023-09-17 02:08:35 +08:00
},
2024-03-25 01:40:33 +08:00
getFlowNode(val) {
2023-09-17 02:08:35 +08:00
let flowNodeList = this.data.flowNodeList;
2024-03-25 01:40:33 +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-04-14 21:28:11 +08:00
let actNv = this.data.active;
if(flowNodeList[i].name==this.data.taskName){
if(this.data.taskComType=="2" || this.data.taskComType=="3"){
actNv = list.length-1;
}else{
actNv = list.length;
2023-09-17 02:08:35 +08:00
}
}
2024-04-14 21:28:11 +08:00
list.push({
id: flowNodeList[i].id,
name: flowNodeList[i].name,
text: flowNodeList[i].name.length > 4 ? flowNodeList[i].name.substring(0, 4) : flowNodeList[i].name
});
2023-09-17 02:08:35 +08:00
this.setData({
2024-04-14 21:28:11 +08:00
active:actNv,
2024-03-25 01:40:33 +08:00
flowNodes: list
2023-09-17 02:08:35 +08:00
})
2024-03-25 01:40:33 +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-25 01:40:33 +08:00
getFlowNodes() {
2023-09-17 02:08:35 +08:00
let that = this;
wx.request({
2024-03-25 01:40:33 +08:00
url: app.globalData.reqUrl + '/wechat/flowTask/readNotes/' + that.data.deployId,
method: "get",
data: {},
2023-09-17 02:08:35 +08:00
header: {
"Content-Type": "application/json"
},
2024-03-25 01:40:33 +08:00
success(res) {
2023-09-17 02:08:35 +08:00
res = res.data
2024-03-25 01:40:33 +08:00
if (res.code == 200) {
2023-09-17 02:08:35 +08:00
that.setData({
2024-03-25 01:40:33 +08:00
flowNodeList: res.data
2023-09-17 02:08:35 +08:00
})
2024-03-25 01:40:33 +08:00
if (res.data.length > 0) {
2023-09-17 02:08:35 +08:00
let list = that.data.flowNodes;
2024-03-25 01:40:33 +08:00
list.push({
id: res.data[0].id,
name: res.data[0].name,
2024-04-14 21:28:11 +08:00
text: res.data[0].name
2024-03-25 01:40:33 +08:00
});
2023-09-17 02:08:35 +08:00
that.setData({
2024-03-25 01:40:33 +08:00
flowNodes: list
2023-09-17 02:08:35 +08:00
})
return that.getFlowNode(res.data[0].outgoingFlows[0].targetRef);
}
2024-03-25 01:40:33 +08:00
} else {
2023-09-17 02:08:35 +08:00
app.toast(res.msg);
}
}
})
},
//查询审批日志
2024-03-25 01:40:33 +08:00
getFlowRecordList() {
2023-09-17 02:08:35 +08:00
let that = this;
wx.request({
url: app.globalData.reqUrl + '/wechat/flowTask/findCommentByProcInsId',
2024-03-25 01:40:33 +08:00
method: "get",
data: {
procInsId: this.data.procInsId
2023-09-17 02:08:35 +08:00
},
header: {
"Content-Type": "application/json"
},
2024-03-25 01:40:33 +08:00
success(res) {
2023-09-17 02:08:35 +08:00
res = res.data
2024-03-25 01:40:33 +08:00
if (res.code == 200) {
2023-09-17 02:08:35 +08:00
that.setData({
2024-03-25 01:40:33 +08:00
flowRecordList: res.data
2023-09-17 02:08:35 +08:00
})
2024-03-25 01:40:33 +08:00
let list = [];
2024-04-14 21:28:11 +08:00
res.data.forEach((item,idx)=>{
if(idx==1 && (item.commentType=="3" || item.commentType=="2")){
that.setData({
rejectNode:true
})
}
2024-03-25 01:40:33 +08:00
if (item.deleteReason) {
item.deleteReason = that.getDeleteReason(item.deleteReason);
2023-09-17 02:08:35 +08:00
}
2024-03-25 01:40:33 +08:00
if (item.duration) {
item.duration = that.getDurationDate(item.duration);
2023-09-17 02:08:35 +08:00
}
list.push(item);
})
that.setData({
2024-03-25 01:40:33 +08:00
flowRecordList: list
2023-09-17 02:08:35 +08:00
})
2024-03-25 01:40:33 +08:00
} else {
2023-09-17 02:08:35 +08:00
app.toast(res.msg);
}
}
})
},
//查询审批表单参数
2024-03-25 01:40:33 +08:00
getFormDatasList() {
2023-09-17 02:08:35 +08:00
let that = this;
wx.request({
url: app.globalData.reqUrl + '/wechat/flowTask/findFormDatasByProcInsId',
2024-03-25 01:40:33 +08:00
method: "get",
data: {
procInsId: this.data.procInsId
2023-09-17 02:08:35 +08:00
},
header: {
"Content-Type": "application/json"
},
2024-03-25 01:40:33 +08:00
success(res) {
2023-09-17 02:08:35 +08:00
res = res.data
2024-03-25 01:40:33 +08:00
if (res.code == 200) {
2023-09-17 02:08:35 +08:00
that.setData({
2024-03-25 01:40:33 +08:00
infoData: res.data
2023-09-17 02:08:35 +08:00
})
2024-03-17 16:19:31 +08:00
let filesData = [];
let imageList = [];
2023-09-17 02:08:35 +08:00
//判断附件
2024-03-25 01:40:33 +08:00
if (res.data.files) {
res.data.files.split(',').forEach(element => {
let ft = element.split('.');
if (that.data.imageType.indexOf(ft[ft.length - 1].toLowerCase()) > -1) {
imageList.push({
2024-04-14 21:28:11 +08:00
minPath: config.baseUrl + element + '.min.jpg',
path: config.baseUrl + element
2024-03-25 01:40:33 +08:00
});
} else {
let it = element.split('/');
filesData.push({
name: it[it.length - 1],
path: element
});
}
});
2023-09-17 02:08:35 +08:00
}
that.setData({
2024-03-17 16:19:31 +08:00
filesData,
imageList,
2024-03-25 01:40:33 +08:00
stopShow: !that.data.finishTime && that.data.userId == that.myUserId,
deleteShow: !that.data.finishTime && that.data.userId == that.myUserId,
revocationShow: !that.data.finishTime
2023-09-17 02:08:35 +08:00
})
2024-03-25 01:40:33 +08:00
} else {
2023-09-17 02:08:35 +08:00
app.toast(res.msg);
}
}
})
},
2024-03-25 01:40:33 +08:00
//退回
onStop() {
if (!this.data.stopBtnShow) {
2023-09-17 02:08:35 +08:00
app.toast("请填写终止原因!")
this.setData({
2024-03-25 01:40:33 +08:00
stopBtnShow: true
2023-09-17 02:08:35 +08:00
})
return;
2024-03-25 01:40:33 +08:00
} else {
if (this.data.comment == "") {
app.toast("请填写终止原因!")
this.setData({
stopBtnShow: true
})
return;
}
2023-09-17 02:08:35 +08:00
}
2024-03-25 01:40:33 +08:00
this.setData({
loadShow: true
})
let that = this
let params = {
instanceId: this.data.procInsId,
comment: this.data.comment,
userId: this.data.myUserId,
taskId: this.data.taskId
}
//弹出确认
wx.showModal({
title: '提示',
content: '是否终止当前流程申请?',
success: function (sm) {
if (sm.confirm) {
wx.request({
url: app.globalData.reqUrl + '/wechat/flowTask/stopProcess',
method: "POST",
data: params,
header: {
"Username": that.data.loginName,
"Content-Type": "application/json"
},
success(res) {
that.setData({
loadShow: false
})
res = res.data
if (res.code == 200) {
app.toast("终止流程申请成功!")
if (that.data.ret == "finished") {
setTimeout(() => {
wx.redirectTo({
url: '../finished/index',
})
}, 200)
} else {
setTimeout(() => {
wx.redirectTo({
url: '../myProcessIns/index',
})
}, 200)
}
} else {
app.toast(res.msg);
}
}
})
} else if (sm.cancel) {
2023-09-17 02:08:35 +08:00
that.setData({
2024-03-25 01:40:33 +08:00
loadShow: false
2023-09-17 02:08:35 +08:00
})
2024-03-25 01:40:33 +08:00
console.log('用户点击取消');
2023-09-17 02:08:35 +08:00
}
}
2024-03-25 01:40:33 +08:00
})
2023-09-17 02:08:35 +08:00
},
//通过
2024-03-25 01:40:33 +08:00
onDelete() {
this.setData({
loadShow: true
})
let that = this
//弹出确认
wx.showModal({
title: '提示',
content: '是否确认删除流程申请?',
success: function (sm) {
if (sm.confirm) {
wx.request({
url: app.globalData.reqUrl + '/wechat/flowTask/delete/' + that.data.procInsId,
method: "delete",
data: {},
header: {
"Username": that.data.loginName,
"Content-Type": "application/json"
},
success(res) {
that.setData({
loadShow: false
})
res = res.data
if (res.code == 200) {
app.toast("删除流程申请成功!")
if (that.data.ret == "finished") {
setTimeout(() => {
wx.redirectTo({
url: '../finished/index',
})
}, 200)
} else {
setTimeout(() => {
wx.redirectTo({
url: '../myProcessIns/index',
})
}, 200)
}
} else {
app.toast(res.msg);
}
}
})
} else if (sm.cancel) {
2023-09-17 02:08:35 +08:00
that.setData({
2024-03-25 01:40:33 +08:00
loadShow: false
2023-09-17 02:08:35 +08:00
})
2024-03-25 01:40:33 +08:00
console.log('用户点击取消');
2023-09-17 02:08:35 +08:00
}
}
2024-03-25 01:40:33 +08:00
})
2023-09-17 02:08:35 +08:00
},
//撤回
2024-03-25 01:40:33 +08:00
onRevocation() {
2023-09-17 02:08:35 +08:00
this.setData({
2024-03-25 01:40:33 +08:00
loadShow: true
2023-09-17 02:08:35 +08:00
})
let that = this
let params = {
procInsId: this.data.procInsId,
instanceId: this.data.procInsId,
2024-03-25 01:40:33 +08:00
taskId: this.data.taskId,
userId: this.data.myUserId,
assignee: this.data.nickName
2023-09-17 02:08:35 +08:00
}
//弹出确认
wx.showModal({
title: '提示',
content: '是否确认撤回当前任务流程?',
success: function (sm) {
2024-03-25 01:40:33 +08:00
if (sm.confirm) {
wx.request({
url: app.globalData.reqUrl + '/wechat/flowTask/revokeProcess',
method: "POST",
data: params,
header: {
"Username": that.data.loginName,
"Content-Type": "application/json"
},
success(res) {
that.setData({
loadShow: false
})
res = res.data
if (res.code == 200) {
app.toast("撤回流程申请成功!")
if (that.data.ret == "finished") {
setTimeout(() => {
wx.redirectTo({
url: '../finished/index',
})
}, 200)
} else {
setTimeout(() => {
wx.redirectTo({
url: '../myProcessIns/index',
})
}, 200)
}
} else {
app.toast(res.msg);
2023-09-17 02:08:35 +08:00
}
}
2024-03-25 01:40:33 +08:00
})
2023-09-17 02:08:35 +08:00
} else if (sm.cancel) {
that.setData({
2024-03-25 01:40:33 +08:00
loadShow: false
})
console.log('用户点击取消');
2023-09-17 02:08:35 +08:00
}
}
})
2024-03-25 01:40:33 +08:00
},
2023-09-17 02:08:35 +08:00
2024-03-25 01:40:33 +08:00
// 手风琴
onChange(event) {
this.setData({
activeName: event.detail,
});
},
2023-09-17 02:08:35 +08:00
2024-03-25 01:40:33 +08:00
getDeleteReason(val) {
val = val.replace("Change activity to ", "");
let flowRecordList = this.data.flowRecordList;
for (let i = 0; i < flowRecordList.length; i++) {
if (flowRecordList[i].taskDefKey == val) {
return "驳回至" + flowRecordList[i].taskName;
}
}
},
2023-09-17 02:08:35 +08:00
2024-03-25 01:40:33 +08:00
getDurationDate(val) {
// 计算出相差天数
let days = Math.floor(val / (24 * 3600 * 1000))
// 计算出小时数
let leave1 = val % (24 * 3600 * 1000) // 计算天数后剩余的毫秒数
let hours = Math.floor(leave1 / (3600 * 1000))
// 计算相差分钟数
let leave2 = leave1 % (3600 * 1000) // 计算小时数后剩余的毫秒数
let minutes = Math.floor(leave2 / (60 * 1000))
// 计算相差秒数
let leave3 = leave2 % (60 * 1000) // 计算分钟数后剩余的毫秒数
let seconds = Math.round(leave3 / 1000)
if (days > 0) {
if (days < 10) days = "0" + days;
if (hours < 10) hours = "0" + hours;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
return days + '天' + hours + '小时' + minutes + '分钟' + seconds + '秒';
}
if (hours > 0) {
if (hours < 10) hours = "0" + hours;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
return hours + '小时' + minutes + '分钟' + seconds + '秒';
}
if (minutes > 0) {
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
return minutes + '分钟' + seconds + '秒';
}
if (seconds > 0) {
if (seconds < 10) seconds = "0" + seconds;
return seconds + '秒';
}
},
2023-09-17 02:08:35 +08:00
//选择退回节点
2024-03-25 01:40:33 +08:00
onSelectTargetKey(e) {
2023-09-17 02:08:35 +08:00
this.setData({
2024-03-25 01:40:33 +08:00
targetKey: e.detail.id,
backName: e.detail.name
2023-09-17 02:08:35 +08:00
})
},
2024-03-25 01:40:33 +08:00
2023-09-17 02:08:35 +08:00
returnToPage: function () {
/*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
2024-03-25 01:40:33 +08:00
if (this.data.ret == "finished") {
2023-09-17 02:08:35 +08:00
wx.redirectTo({
url: '../finished/index',
})
2024-03-25 01:40:33 +08:00
} else {
2023-09-17 02:08:35 +08:00
wx.redirectTo({
url: '../myProcessIns/index',
})
}
},
2024-03-25 01:40:33 +08:00
//展示图片详细
showImg: function (e) {
let {
path
} = e.currentTarget.dataset.set
2024-04-14 21:28:11 +08:00
let images = [];
this.data.imageList.forEach(img =>{
images.push(img.path);
});
2024-03-25 01:40:33 +08:00
wx.previewImage({
2024-04-14 21:28:11 +08:00
urls: images,
2024-03-25 01:40:33 +08:00
current: path
})
},
2024-03-17 16:19:31 +08:00
2024-03-25 01:40:33 +08:00
/**
* 下载并打开文档
* @param {*} e
*/
downFile: function (e) {
let {
path
} = e.currentTarget.dataset.set
2023-09-17 18:10:31 +08:00
wx.downloadFile({
2024-03-25 01:40:33 +08:00
// 示例 url并非真实存在
url: app.globalData.uploadUrl + '/common/download/resource?resource=' + path,
success: function (res) {
const filePath = res.tempFilePath
let fpt = filePath.split(".");
wx.openDocument({
filePath: filePath,
fileType: fpt[fpt.length - 1],
success: function (res) {
console.log('打开文档成功')
},
fail: function (res) {
console.log(res)
}
})
}
})
//app.toast("暂不支持下载!如需下载请前往后台管理系统!!")
},
2023-09-17 18:10:31 +08:00
2023-09-17 02:08:35 +08:00
//终止原因
commentblur: function (options) {
this.data.comment = options.detail.value;
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})