<!--
 * @Author: ysh
 * @Date: 2024-04-26 17:01:15
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-05-10 15:36:52
-->
<template>
  <div class="app-container">
    <nav-header :taskForm="taskForm" :taskName="taskName" :startUser="startUser"
      :flowRecordList="flowRecordList"></nav-header>
    <borrow-form :taskForm="taskForm" :taskName="taskName" @goBack="goBack"></borrow-form>
  </div>
</template>

<script>
import { flowRecord } from "@/api/flowable/finished";
import { getProcessVariables, flowXmlAndNode, definitionStart } from "@/api/flowable/definition";
import { complete, rejectTask, returnList, returnTask, getNextFlowNode, delegate, flowTaskForm } from "@/api/flowable/todo";
import BorrowForm from '@/views/flowable/form/finance/borrowForm.vue';
import navHeader from './components/navHeader.vue'
export default {
  components: {
    navHeader,
    BorrowForm
  },
  data() {
    return {
      taskForm: {
        returnTaskShow: false, // 是否展示回退表单
        delegateTaskShow: false, // 是否展示回退表单
        defaultTaskShow: true, // 默认处理
        comment: "", // 意见内容
        procInsId: "", // 流程实例编号
        instanceId: "", // 流程实例编号
        deployId: "",  // 流程定义编号
        taskId: "",// 流程任务编号
        procDefId: "",  // 流程编号
        targetKey: "",
        variables: {
          variables: {}
        },
      },
      startUser: null, // 发起人信息,
      taskName: null, // 任务节点
      flowRecordList: []
    }
  },
  created() {
    if (this.$route.query) {
      this.taskName = this.$route.query.taskName;
      this.startUser = this.$route.query.startUser;
      this.taskForm.deployId = this.$route.query.deployId;
      this.taskForm.taskId = this.$route.query.taskId;
      this.taskForm.procInsId = this.$route.query.procInsId;
      this.taskForm.executionId = this.$route.query.executionId;
      this.taskForm.instanceId = this.$route.query.procInsId;
      this.taskForm.formId = this.$route.query.formId;
      this.taskForm.procDefName = this.$route.query.procDefName;
      // 流程任务获取变量信息
      if (this.taskForm.taskId) {
        this.processVariables(this.taskForm.taskId)
        this.getFlowTaskForm(this.taskForm.taskId)
      }
      this.getFlowRecordList(this.taskForm.procInsId, this.taskForm.deployId);
    }
  },
  methods: {
    /** 获取流程变量内容 */
    processVariables(taskId) {
      if (taskId) {
        // 提交流程申请时填写的表单存入了流程变量中后续任务处理时需要展示
        getProcessVariables(taskId).then(res => {
        });
      }
    },
    /** 流程节点表单 */
    getFlowTaskForm(taskId) {
      if (taskId) {
        // 提交流程申请时填写的表单存入了流程变量中后续任务处理时需要展示
        flowTaskForm({ taskId: taskId }).then(res => {
          this.taskForm.variables = res.data.formData;
        });
      }
    },
    /** 流程流转记录 */
    getFlowRecordList(procInsId, deployId) {
      const that = this
      const params = { procInsId: procInsId, deployId: deployId }
      flowRecord(params).then(res => {
        that.flowRecordList = res.data.flowList;
      }).catch(res => {
        this.goBack();
      })
    },
    goBack() {
      // 关闭当前标签页并返回上个页面
      const obj = this.$route;
      this.$tab.closeOpenPage(obj);
      this.$router.go(-1);
    }
  }

}
</script>

<style lang="scss" scoped></style>