diff --git a/app/service/task.js b/app/service/task.js index 0b56a7a..e65fb0e 100644 --- a/app/service/task.js +++ b/app/service/task.js @@ -57,15 +57,13 @@ class TaskService extends Service { } async buildNext({ taskData, type }) { - const { userId, username } = this.ctx.userInfo; - - const { taskId, workflowConfig, taskConfigId, taskEditUserList, taskEditedUserList } = taskData; + const { taskId, taskWorkflow, taskConfigId, taskEditUserList, taskEditedUserList } = taskData; var updateTaskData = null var historyInsertData = [] var noticeInsertData = [] - var curNode = workflowConfig.nodeList.find(node => node.id == taskConfigId) + var curNode = taskWorkflow.nodeList.find(node => node.id == taskConfigId) var taskStatus = "running" // 1、更新task状态 @@ -87,8 +85,8 @@ class TaskService extends Service { } else {// 流转搭配下一节点 // 找下一个节点 - var nextNode = await this.getNextNode(workflowConfig, curNode) - var nextLine = workflowConfig.lineList.find(line => line.sourceNodeId == nextNode.id) + var nextNode = await this.getNextNode(taskWorkflow, curNode) + var nextLine = taskWorkflow.lineList.find(line => line.sourceNodeId == nextNode.id) // 下一个节点是审批节点 if (nextNode.properties.type === "approvalTask") { @@ -106,17 +104,17 @@ class TaskService extends Service { noticeInsertData.push({ noticeId: await idGenerateUtil.uuid(), noticeName: "通知-审批-" + taskId, - noticeContent: '{}', + noticeContent: nextNode.properties.userIdList.join(','), pushContent: '{}', pushStatus: "success", pushAt: dayjs().format("YYYY-MM-DD HH:mm:ss") }) historyInsertData.push(await this.createTaskHistory({ taskData, taskStatus, type })) - nextNode = await this.getNextNode(workflowConfig, curNode) + nextNode = await this.getNextNode(taskWorkflow, curNode) taskData = { ...taskData, taskConfigId: nextNode.id, - taskEditUserList: null, + // taskEditUserList: nextNode.properties.userIdList.join(','), taskEditedUserList: null, taskComment: null, operationAt: dayjs().format("YYYY-MM-DD HH:mm:ss") @@ -165,8 +163,9 @@ class TaskService extends Service { } async getNextNode(workflow, curNode) { - var line = workflow.lineList.find(l => l.sourceNodeId == curNode.id) - var nextNode = workflow.nodeList.find(n => n.id == line.targetNodeId) + const { lineList, nodeList } = workflow + var line = lineList.find(l => l.sourceNodeId == curNode.id), + nextNode = nodeList.find(n => n.id == line.targetNodeId); if (nextNode.properties.type === "conditionTask") { nextNode = this.getNextNode(workflow, nextNode) @@ -176,25 +175,96 @@ class TaskService extends Service { } async createTaskHistory({ taskData, taskStatus, type }) { + const { userId, username } = this.ctx.userInfo; + + // 解构 taskData 对象以简化访问 + const { taskId, taskFormInput, taskConfigId, taskNextConfigList, + taskLineType, taskEditUserList, taskViewUserList, + taskComment, taskWorkflow, operationAt } = taskData; + + // 计算任务持续时间 + const taskCostDuration = Math.round(dayjs().diff(dayjs(operationAt)) / 1000); + return { - taskId: taskData.taskId, - taskStatus: taskStatus, - taskTitle: taskData.taskTitle, - taskFormInput: JSON.stringify(taskData.taskFormInput), - taskConfigId: taskData.taskConfigId, - taskNextConfigList: taskData.taskNextConfigList, - taskLineTypeList: taskData.taskLineType, - taskInitUser: taskData.taskInitUser, - taskEditUserList: taskData.taskEditUserList, - taskViewUserList: taskData.taskViewUserList, - taskComment: taskData.taskComment, - workflowConfig: JSON.stringify(taskData.taskWorkflow), + taskId, + taskStatus, + taskFormInput: JSON.stringify(taskFormInput), + taskConfigId, + taskNextConfigList, + taskLineTypeList: taskLineType, + taskEditUserList, + taskViewUserList, + taskComment, + taskWorkflow: JSON.stringify(taskWorkflow), taskExplain: type, taskHandleDesc: type, - taskCostDuration: Math.round(dayjs().diff(dayjs(taskData.operationAt)) / 1000) + taskCostDuration, + createHistoryBy: userId, + createHistoryAt: dayjs().format('YYYY-MM-DD HH:mm:ss') } } + + async getTaskWorkflow() { + const { jianghuKnex } = this.app; + const { userId } = this.ctx.userInfo; + const { taskId } = this.ctx.request.body.appData.actionData; + + // 获取当前审批 + const task = await jianghuKnex('task').where({ taskId }).first(); + const { taskWorkflow, taskConfigId } = task + + // 获取审批流历史 + const taskHistory = await jianghuKnex('task_history').where({ taskId }).select(); + // 获取人员 + const userList = await jianghuKnex('enterprise_user').select() + + var workflowHistory = JSON.parse(taskWorkflow).nodeList.filter(n => !['start', 'end', 'conditionTask'].includes(n.properties.type)) + .map(node => { + const { id, label, userIdList, approvalType } = node.properties + + const userConfig = userIdList?.map(appUserId => { + var username = userList.find(u => u.userId == appUserId)?.username, + historyRecord = taskHistory.find(h => h.taskConfigId == node.id && h.createHistoryBy == appUserId); + + if (historyRecord) { + const { taskComment, taskHandleDesc, createHistoryAt, taskStatus } = historyRecord + + return { + userId: userId, + username: username, + comment: taskComment, + handleDesc: taskHandleDesc, + createHistoryAt: dayjs(createHistoryAt || '').format('YYYY-MM-DD HH:mm:ss'), + taskStatus: taskStatus, + } + } else { + return { + userId: userId, + username: username, + } + } + }) + + var nodeStatus = '审批中' + if (approvalType == "或签") { + nodeStatus = _.some(userConfig, ['handleDesc', '拒绝']) ? '已拒绝' : _.some(userConfig, ['handleDesc', '同意']) ? '已同意' : '审批中' + } else { + var nodeStatus = _.some(userConfig, ['handleDesc', '拒绝']) ? '已拒绝' : _.every(userConfig, ['handleDesc', '同意']) ? '已同意' : '审批中' + } + + return { + id, + label, + approvalType: approvalType, // 是审批节点就取审批形式 + userList: userConfig, + nodeStatus: nodeStatus + } + }) + + return workflowHistory + + } } module.exports = TaskService; diff --git a/app/view/component/taskHistory.html b/app/view/component/taskHistory.html index 713e8ac..e4ac6f7 100644 --- a/app/view/component/taskHistory.html +++ b/app/view/component/taskHistory.html @@ -1,41 +1,55 @@ @@ -49,17 +63,21 @@ type: String, default: '', }, + taskConfigId: { + type: String, + default: '', + }, + workflowConfig: { + type: Object, + default: ()=>{ + return {} + }, + }, }, data() { return { isTableLoading: false, - headers: [ - {text: "名称", value: "taskTitle", width: 230, class: 'fixed', cellClass: 'fixed'}, - {text: "节点说明", value: "taskHandleDesc", width: 120}, - {text: "操作人", value: "operationByUser", width: 120}, - {text: "操作时间", value: "operationAt", width: 250}, - ], - tableData: [], + workflowHistory: [], }; }, watch: { @@ -75,21 +93,16 @@ // ---------- 获取列表 >>>>>>>>>> -------- async getTableData() { this.isTableLoading = true; - const result = await window.jianghuAxios({ + const resultData = (await window.jianghuAxios({ data: { appData: { pageId: 'todo', - actionId: 'getTaskHistory', + actionId: 'getTaskWorkflow', actionData: {taskId: this.taskId}, } } - }) - const {taskHistoryList, lineTypeList} = result.data.appData.resultData; - taskHistoryList.forEach(task => { - task.operationAt = task.taskStatus != 'end' ? dayjs(task.operationAt).format('YYYY-MM-DD HH:mm:ss') : '' - }) - this.tableData = taskHistoryList; - this.$emit('line-type-list', lineTypeList); + })).data.appData.resultData + this.workflowHistory = resultData this.isTableLoading = false; }, // ---------- <<<<<<<<<< 获取列表 -------- @@ -98,5 +111,40 @@ diff --git a/app/view/page/todo.html b/app/view/page/todo.html index 5153133..ab52c1a 100644 --- a/app/view/page/todo.html +++ b/app/view/page/todo.html @@ -110,40 +110,45 @@ - - - - - 审核信息 - - - - - {{ lineTypeItem.type }} - - - - + + + + 审核信息【{{updateItemId}}】 + + - - - - - + + + + + {{ index + 1 }}. {{ formItem.statement }}* + + + + + + + - 备注 - + 审批意见 + - + + + + {{ lineTypeItem.text }} + + + + + - 审核历史 - + 审批流程 + @@ -186,7 +191,7 @@ {% block vueScript %} -{% include 'component/formItem.html' %} +{% include 'component/tpl/formComponentList.html' %} {% include 'component/taskHistory.html' %} {% include 'common/jianghuJs/fixedTableHeightV4.html' %} @@ -213,17 +218,29 @@ tableData: [], historyData: [], headers: [ - { text: "审批项", value: "taskTitle" }, - { text: "操作者", value: "operationByUser", width: 120 }, - { text: "操作时间", value: "operationAt", width: 250 }, + { text: "审批ID", value: "taskId", width: 120 }, + { text: "分组", value: "taskTemplateGroup", width: 120 }, + { text: "审批项", value: "taskTitle", width: 200 }, + { text: "创建者", value: "taskInitUser", width: 120 }, + { text: "创建时间", value: "taskCreateAt", width: 150 }, + { text: "结束时间", value: "taskFinishAt", width: 150 }, {text: '操作', value: 'action', align: 'center', sortable: false, width: 80, class: 'fixed', cellClass: 'fixed'}, ], isSubmitDrawerShown: false, - updateItem: {}, workflowType: 'todo', // todo, history - lineTypeList: [], - userId: '<$ ctx.userInfo.userId $>' + lineTypeList: [{ + text: "同意", + value: "同意", + },{ + text: "拒绝", + value: "拒绝", + }], + userId: '<$ ctx.userInfo.userId $>', + + updateItem: {}, + updateItemId: null, + }, // 计算 computed: { @@ -245,14 +262,12 @@ case 'getHistoryData': await this.getHistoryData(); break; - case 'openDataPicker': - await this.openDataPicker(uiActionData); - break; case 'startUpdateItem': await this.prepareUpdateFormData(uiActionData); await this.openUpdateDrawer(); break; case 'submitNode': + await this.prepareSubmitValidate(); await this.confirmSubmitDialog(); await this.submitForReview(uiActionData); await this.closeSubmitDrawer(); @@ -279,13 +294,10 @@ } } }); - const rows = result.data.appData.resultData.rows; - rows.forEach(row => { - row.taskFormInput = JSON.parse(row.taskFormInput); - row.operationAt = dayjs(row.operationAt).format('YYYY-MM-DD HH:mm:ss'); - }); + this.tableData = rows.filter(item => !item.taskEditedUserList || !item.taskEditedUserList.includes(this.userId)); + this.isTableLoading = false; }, async getHistoryData() { @@ -296,8 +308,7 @@ pageId: 'todo', actionId: 'selectHistoryList', actionData: {}, - where: { taskStatus: 'running' }, - whereLike: { taskEditUserList: '<$ ctx.userInfo.userId $>', taskConfigId: 'userTask-' }, + whereLike: { taskEditUserList: '<$ ctx.userInfo.userId $>', taskConfigId: 'approvalTask-' }, orderBy: [{ column: 'id', order: 'desc' }] } } @@ -305,26 +316,31 @@ const rows = result.data.appData.resultData.rows; rows.forEach(row => { - row.taskFormInput = JSON.parse(row.taskFormInput); row.operationAt = dayjs(row.operationAt).format('YYYY-MM-DD HH:mm:ss'); }); this.historyData = rows; }, // ---------- 审核、查看 uiAction >>>>>>>>>>>> -------- async prepareUpdateFormData(funObj) { + this.updateItem = _.cloneDeep(funObj); - this.updateItem.workflowConfig = JSON.parse(funObj.workflowConfig); - this.updateItem.currentNode = this.updateItem.workflowConfig.nodeList.find(e => e.id === this.updateItem.taskConfigId); - this.updateItem.readonlyFormIdList = this.updateItem.taskFormInput.formList.map(form => form.id).filter(formId => (this.updateItem.currentNode.formIdEdit || '').indexOf(formId) === -1); - this.updateItem.taskHistoryList = []; // 审核历史 + this.updateItemId = this.updateItem.taskId + this.updateItem.taskWorkflow = JSON.parse(funObj.taskWorkflow); + this.updateItem.taskFormInput = JSON.parse(funObj.taskFormInput); this.updateItem.taskComment = ''; // 备注 - this.lineTypeList = []; // 所有操作按钮 }, async openUpdateDrawer() { this.isSubmitDrawerShown = true; }, + prepareSubmitValidate(){ + if(this.updateItem.taskComment.length > 250){ + window.vtoast.fail("审批意见不能超过250个字!") + throw new Error("审批意见不能超过250个字!") + } + }, + async confirmSubmitDialog() { if (await window.confirmDialog({ title: "审核", content: "确定提交审核吗?" }) === false) { throw new Error("[confirmSubmitDialog] 否"); @@ -338,7 +354,10 @@ appData: { pageId: 'todo', actionId: 'submitNode', - actionData: { type: lineType, id: this.updateItem.id, taskId: this.updateItem.taskId, taskComment: this.updateItem.taskComment, taskFormInput: JSON.stringify(this.updateItem.taskFormInput) } + actionData: { + updateItem: this.updateItem, + type: lineType + } } } }) @@ -347,9 +366,7 @@ async closeSubmitDrawer() { this.isSubmitDrawerShown = false; this.updateItem = {}; - }, - setLineTypeList(lineTypeList) { - this.lineTypeList = _.uniqBy((lineTypeList || '').split(",").map(lineType => ({ type: lineType, label: lineType })), 'type'); + this.updateItemId = null; }, // ---------- <<<<<<<<<<< 审核、查看 uiAction -------- }