Browse Source

feat: 行政审批打印增加审批记录

liujt 1 tuần trước cách đây
mục cha
commit
4e45eb1f71
1 tập tin đã thay đổi với 85 bổ sung3 xóa
  1. 85 3
      src/views/bpm/collaborative/detail.vue

+ 85 - 3
src/views/bpm/collaborative/detail.vue

@@ -242,6 +242,8 @@ import purchaseRequisitionComponent from '@/BIZComponents/processSubmitDialog/co
 import businessTripComponent from '@/BIZComponents/processSubmitDialog/components/businessTripComponent.vue';
 import { getGroupUserTree, getProduceTreeByCode } from '@/api/main';
 import { listOrganizations, getUserPage } from '@/api/system/organization';
+import { getTaskListByProcessInstanceId } from '@/api/bpm/task';
+import store from '@/store';
 
 export default {
   name: 'formDetailDialog',
@@ -277,7 +279,8 @@ export default {
       isRight: false,
       previewDialog: false,
       previewHtml: '',
-      remoteOptionsCache: {}
+      remoteOptionsCache: {},
+      tasks: []
     };
   },
   computed: {
@@ -306,12 +309,23 @@ export default {
     }
   },
   methods: {
+    getChildren(data) {
+      const arr = [];
+      (data || []).forEach((item) => {
+        if (item.children && item.children.length > 0) {
+          arr.push(...this.getChildren(item.children));
+        }
+        arr.push(item);
+      });
+      return arr;
+    },
     open(row) {
       this.form = _.cloneDeep(row);
       if (this.form.id) {
         storageApi.getInfoBySourceBizNo(this.form.id).then((res) => {
           this.outgoingData = res;
         });
+        this.getTaskList();
       }
       this.jsonData = JSON.parse(this.form.formJson.makingJson);
       this.jsonData.config.dataSource &&
@@ -327,6 +341,35 @@ export default {
       });
     },
 
+    // 获取流程审批记录
+    getTaskList() {
+      getTaskListByProcessInstanceId(this.form.id).then((response) => {
+          // 审批记录
+          this.tasks = [];
+          // console.log(response,'response')
+          // 移除已取消的审批
+          response.forEach((task) => {
+            // if (task.result !== 4) {
+            this.tasks.push(...this.getChildren([task]));
+            // }
+          });
+
+          // 需要审核的记录
+          const userId = store.getters.userId;
+          this.tasks.forEach((task) => {
+            if (task.result !== 1 && task.result !== 6) {
+              // 只有待处理才需要
+              return;
+            }
+            if (!task.assigneeUser || task.assigneeUser.id !== userId) {
+              // 自己不是处理人
+              return;
+            }
+          });
+          console.log(this.tasks,'this.tasks')
+        });
+    },
+
     async ensureRemoteData(makingJson) {
       if (!makingJson || !makingJson.list) return;
       const tasks = [];
@@ -665,10 +708,49 @@ export default {
         + '.pf-blank-title{font-weight:600;margin-bottom:6px;color:#333;font-size:14px;word-break:break-word;white-space:normal} '
         + 'a{color:#1890ff} '
         + '.pf-table{width:100%;border-collapse:collapse;margin-top:6px} '
-        + '.pf-table th,.pf-table td{border:1px solid #e8e8e8;padding:6px;text-align:left} ';
+        + '.pf-table th,.pf-table td{border:1px solid #e8e8e8;padding:6px;text-align:left} '
+        + '.pf-tasks-title{font-size:16px;font-weight:600;margin-top:24px;margin-bottom:8px} '
+        + '@media print{.pf-table thead{display:table-row-group}.pf-table tr{page-break-inside:avoid}}';
 
       return '<!doctype html><html><head><meta charset="utf-8" /><title>' + title + '</title><style>' + style + '</style></head><body>'
-        + '<div class="pf-container"><div class="pf-title">' + title + '</div>' + rows.join('\n') + '</div></body></html>';
+        + '<div class="pf-container"><div class="pf-title">' + title + '</div>' + rows.join('\n') + this.generateTasksPrintHtml() + '</div></body></html>';
+    },
+
+    // 将流程审批记录(tasks)拼接为可打印的表格 HTML
+    generateTasksPrintHtml() {
+      if (!this.tasks || this.tasks.length === 0) return '';
+      const trs = this.tasks
+        .map((item, index) => {
+          const nickname =
+            item.assigneeUser && item.assigneeUser.nickname
+              ? item.assigneeUser.nickname
+              : '';
+          const deptName =
+            item.assigneeUser && item.assigneeUser.deptName
+              ? item.assigneeUser.deptName
+              : '';
+          return '<tr>'
+            + '<td style="text-align:center">' + (index + 1) + '</td>'
+            + '<td>' + this.escapeHtml(item.name) + '</td>'
+            + '<td>' + this.escapeHtml(nickname) + '</td>'
+            + '<td>' + this.escapeHtml(deptName) + '</td>'
+            + '<td>' + this.escapeHtml(item.createTime) + '</td>'
+            + '<td>' + this.escapeHtml(item.endTime) + '</td>'
+            + '<td>' + this.escapeHtml(item.reason) + '</td>'
+            + '</tr>';
+        })
+        .join('');
+
+      return '<div class="pf-tasks-title">审批记录</div>'
+        + '<table class="pf-table"><thead><tr>'
+        + '<th style="text-align:center">序号</th>'
+        + '<th>任务</th>'
+        + '<th>发起人/审批人</th>'
+        + '<th>部门</th>'
+        + '<th>创建时间</th>'
+        + '<th>审批时间</th>'
+        + '<th>审批意见</th>'
+        + '</tr></thead><tbody>' + trs + '</tbody></table>';
     },
 
     escapeHtml(str) {