<template>
	<div class="jp-center">
		<h2 class="title">{{ title }}</h2>

		<el-tabs type="border-card" v-model="taskSelectedTab" @tab-click="onTabChange">
			<el-tab-pane label="表单信息" name="form-first">
				<component :formReadOnly="formReadOnly" v-if="formType === '2'" :class="formReadOnly ? 'readonly' : ''"
					ref="form" :businessId="businessId" :is="form" :status="status" @callBackFunc="callBackFunc"
					@changeLoading="changeLoading"></component>

				<PreviewForm v-if="formType !== '2'" :processDefinitionId="procDefId" :edit="true"
					:taskFormData="taskFormData" ref="form" />
			</el-tab-pane>
			<el-tab-pane label="流程信息" v-if="procInsId" name="form-second">
				<flow-time-line :historicTaskList="historicTaskList" />
			</el-tab-pane>
			<el-tab-pane label="流程图" name="form-third">
				<el-card class="box-card" shadow="hover">
					<template #header>
						<div class="card-header">
							<span>流程图</span>
						</div>
					</template>
					<flow-chart ref="chart1" v-if="procInsId" :processInstanceId="procInsId" />
					<flow-chart ref="chart2" v-if="!procInsId" :processDefId="procDefId" />
				</el-card>
			</el-tab-pane>
			<el-tab-pane label="流转记录" v-if="procInsId" name="form-forth">
				<flow-step :historicTaskList="historicTaskList" />
			</el-tab-pane>
			<el-tab-pane label="入库修改历史" v-if="commonJS.isNotEmpty(wareHouseId)" name="form-sixth">
				<vxe-table ref="wareHouseTable" border="inner" size="small" :key="222" max-height="1000px"
					class="vxe-table-element" :data="dataListHi">
					<vxe-column type="seq" width="60" title="序号"></vxe-column>
					<vxe-column min-width="120" align="center" title="修改类型" field="updateTradeType">
						<template #default="scope">
							<span v-if="commonJS.isNotEmpty(scope.row.updateTradeType)"> {{ scope.row.updateTradeType }}
							</span>
							<span v-else> -- </span>
						</template>
					</vxe-column>
					<vxe-column min-width="160" align="center" title="修改商品" field="updateTradeName">
						<template #default="scope">
							<span v-if="commonJS.isNotEmpty(scope.row.updateTradeName)"> {{ scope.row.updateTradeName }}
							</span>
							<span v-else> -- </span>
						</template>
					</vxe-column>
					<vxe-column min-width="160" align="center" title="修改人" field="updateUser">
						<template #default="scope">
							<span v-if="scope.row.endflag === '2'">(创建人) {{ scope.row.updateUser }} </span>
							<span v-else>{{ scope.row.updateUser }} </span>
						</template>
					</vxe-column>
					<vxe-column min-width="160" align="center" title="修改时间" field="createTime"></vxe-column>
					<vxe-column title="操作" width="150px" fixed="right" align="center">
						<template #default="scope">
							<el-button type="text" size="small" @click="hiDetail(scope.row)">修改详情</el-button>
						</template>
					</vxe-column>
				</vxe-table>
			</el-tab-pane>
			<el-tab-pane label="领用退回历史" v-if="returnId" name="form-seventh">
				<vxe-table ref="returnTable" border="inner" :key="111" size="small" class="vxe-table-element"
					max-height="1000px" :data="dataListHiCollect">
					<vxe-column type="seq" width="60" title="序号"></vxe-column>
					<vxe-column min-width="160" align="center" title="退回物品" field="returnGoods">
						<template #default="scope">
							<span v-if="commonJS.isNotEmpty(scope.row.returnGoods)"> {{ scope.row.returnGoods }} </span>
							<span v-else> -- </span>
						</template>
					</vxe-column>
					<vxe-column min-width="160" align="center" title="退回申请人" field="returnUserName"></vxe-column>
					<vxe-column min-width="160" align="center" title="退回时间" field="createTime"></vxe-column>
					<vxe-column title="操作" width="150px" fixed="right" align="center">
						<template #default="scope">
							<el-button type="text" size="small" @click="hiDetailCollect(scope.row)">退回详情</el-button>
						</template>
					</vxe-column>
				</vxe-table>
			</el-tab-pane>

			<el-tab-pane label="领用退回历史" v-if="psiReturnId" name="form-psi-return">
				<vxe-table ref="returnTable" border="inner" :key="111" size="small" class="vxe-table-element"
					max-height="1000px" :data="dataListHiCollect">
					<vxe-column type="seq" width="60" title="序号"></vxe-column>
					<vxe-column min-width="160" align="center" title="退回物品" field="returnGoods">
						<template #default="scope">
							<span v-if="commonJS.isNotEmpty(scope.row.returnGoods)"> {{ scope.row.returnGoods }} </span>
							<span v-else> -- </span>
						</template>
					</vxe-column>
					<vxe-column min-width="160" align="center" title="退回申请人" field="returnUserName"></vxe-column>
					<vxe-column min-width="160" align="center" title="退回时间" field="createTime"></vxe-column>
					<vxe-column title="操作" width="150px" fixed="right" align="center">
						<template #default="scope">
							<el-button type="text" size="small" @click="hiPsiDetailCollect(scope.row)">退回详情</el-button>
						</template>
					</vxe-column>
				</vxe-table>
			</el-tab-pane>

			<el-tab-pane label="归档历史" v-if="commonJS.isNotEmpty(cwArchiveHiFlag)" name="form-cwArchive">
				<vxe-table ref="wareHouseTable" border="inner" size="small" :key="222" max-height="1000px"
					class="vxe-table-element" :data="cwArchiveDataListHiCollect">
					<vxe-column type="seq" width="60" title="序号"></vxe-column>
					<vxe-column min-width="160" align="center" title="归档发起人" field="userName"></vxe-column>
					<vxe-column min-width="160" align="center" title="归档时间" field="auditDate"></vxe-column>
					<vxe-column min-width="160" align="center" title="归档状态" field="status">
						<template #default="scope">
							<el-button @click="detail(scope.row)" effect="dark"
								:type="$dictUtils.getDictLabel('cw_status_flag', scope.row.status, '-')">
								{{ $dictUtils.getDictLabel("cw_status", scope.row.status, '-') }}
							</el-button>
						</template>
					</vxe-column>
					<vxe-column title="操作" width="150px" fixed="right" align="center">
						<template #default="scope">
							<el-button type="text" size="small" @click="hiDetailCwArchive(scope.row)">归档详情</el-button>
						</template>
					</vxe-column>
				</vxe-table>
			</el-tab-pane>


		</el-tabs>

		<el-card style="margin-top: 10px; padding-bottom: 66px" v-if="!procInsId || taskId">
			<el-form :model="auditForm" ref="auditForm" v-loading="loading" label-width="120px">
				<el-row>
					<el-col :span="16">
						<!--						<el-form-item-->
						<!--							v-if="!procInsId"-->
						<!--							label="流程标题"-->
						<!--							prop="title"-->
						<!--						>-->
						<!--							<el-input-->
						<!--								placeholder="请输入流程标题"-->
						<!--								v-model="title"-->
						<!--							>-->
						<!--							</el-input>-->
						<!--						</el-form-item>-->
						<el-form-item v-if="taskId" label="审批信息" prop="message">
							<el-input type="textarea" :rows="3" placeholder="请输入审批意见" v-model="auditForm.message">
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="16">
						<el-form-item>
							<el-checkbox v-model="isCC">是否抄送</el-checkbox>
						</el-form-item>
					</el-col>
					<el-col :span="16">
						<el-form-item v-if="isCC" :rules="[
							{
								required: true,
								message: '用户不能为空',
								trigger: 'blur',
							},
						]" prop="userIds" label="抄送给">
							<user-select v-model="auditForm.userIds"></user-select>
						</el-form-item>
					</el-col>
					<!--<el-col :span="16">
						<el-form-item>
							<el-checkbox v-model="isAssign"
								>指定下一步处理者(不设置就使用默认处理人)</el-checkbox
							>
						</el-form-item>
					</el-col>-->
					<el-col :span="16">
						<el-form-item v-if="isAssign" :rules="[
							{
								required: true,
								message: '用户不能为空',
								trigger: 'blur',
							},
						]" prop="assignee" label="指定">
							<user-select :limit="1" v-model="auditForm.assignee"></user-select>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</el-card>

		<div class="FlowFormFooter">
			<template v-for="(button, index) in buttons">
				<template v-if="button.isHide === '0'">
					<el-button size="large" type="primary" v-if="button.code !== '_flow_print'" :key="index"
						@click="submit(button, buttons)" v-noMoreClick v-loading="loading" plain>{{ button.name
						}}</el-button>
					<el-button size="large" type="primary" v-if="button.code === '_flow_print'" @click="print"
						:key="index" v-noMoreClick v-loading="loading" plain>{{ button.name }}</el-button>
				</template>
			</template>
		</div>
		<task-back-nodes ref="taskBackNodes" @getBackTaskDefKey="back" />
		<user-select-dialog title="选择转办用户" ref="transferUserSelectDialog" :limit="1"
			@doSubmit="selectUsersToTransferTask"></user-select-dialog>
		<user-select-dialog title="选择委派用户" ref="delegateUserSelectDialog" :limit="1"
			@doSubmit="selectUsersToDelateTask"></user-select-dialog>
		<user-select-dialog title="选择加签用户" ref="addSignTaskUserSelectDialog"
			@doSubmit="selectUsersToAddSignTask"></user-select-dialog>
		<CollectReturnHi ref="collectReturnHi"></CollectReturnHi>
		<PsiCollectReturnHi ref="psiCollectReturnHi"></PsiCollectReturnHi>
		<WareHouseHi ref="wareHouseHi"></WareHouseHi>
		<ProjectReportArchiveForm ref="projectReportArchiveForm"></ProjectReportArchiveForm>
	</div>
</template>

<script>
// import FlowChart from '../modeler/FlowChart'
import CollectReturnHi from '@/views/materialManagement/collect/CollectReturnHiForm'
import PsiCollectReturnHi from '@/views/psiManagement/collect/CollectReturnHiForm'
import WareHouseHi from '@/views/materialManagement/wareHouse/WareHouseHi'
import ProjectReportArchiveForm from '@/views/cw/projectReportArchive/ProjectReportArchiveForm'
import noticeService from '@/api/flowable/noticeService'
import useTabs from "@/utils/useTabs";
import UserSelect from "@/components/userSelect/index.vue";
import PreviewForm from "@/views/flowable/form/GenerateFlowableForm.vue";
import TaskBackNodes from "@/views/flowable/components/TaskBackNodes.vue";
import FlowStep from "@/views/flowable/components/FlowStep.vue";
import FlowTimeLine from "@/views/flowable/components/FlowTimeLine.vue";
import UserSelectDialog from "@/components/userSelect/UserSelectDialog.vue";
import taskService from "@/api/flowable/taskService.js";
import taskDefExtensionService from "@/api/flowable/taskDefExtensionService.js";
import formService from "@/api/flowable/formService.js";
import flowCopyService from "@/api/flowable/flowCopyService.js";
import processService from "@/api/flowable/processService.js";
import print2 from "@/utils/print.js";
import { shallowRef } from 'vue'
import CollectService from '@/api/materialManagement/CollectService'
import PsiCollectService from '@/api/psi/CollectService'
import WareHouseService from '@/api/materialManagement/WareHouseService'
import ProjectReportArchiveService from '@/api/cw/projectRecords/ProjectReportArchiveService'
import pick from "lodash.pick";
export default {
	collectService: null,
	psiCollectService: null,
	wareHouseService: null,
	projectReportArchiveService: null,
	beforeCreate() {
		this.collectService = new CollectService()
		this.psiCollectService = new PsiCollectService()
		this.wareHouseService = new WareHouseService()
		this.projectReportArchiveService = new ProjectReportArchiveService()
	},
	activated() {
		this.init();
		if (this.formType === "2") {
			// 读取外置表单
			if (this.formUrl === "/404") {
				this.form = null;
				this.$message.info("没有关联流程表单!");
			} else {
				const modules = import.meta.globEager("@/views/**/*.vue");
				Object.keys(modules).forEach((path) => {
					const dir = path.split("views")[1].split(".vue")[0];
					if (dir === this.formUrl) {
						this.form = shallowRef(modules[path].default);
					}
				});
			}
		} else {
			// 读取动态表单
			this.$nextTick(() => {
				if (this.formUrl === "/404") {
					this.$refs.form.createForm("");
				} else {
					this.$refs.form.createForm(this.formUrl);
				}
			});
			if (this.status === "start") {
				// 读取启动表单配置
				formService
					.getStartFormData({ processDefinitionId: this.procDefId })
					.then((data) => {
						this.taskFormData = data;
					});
			} else {
				// 读取任务表单配置
				formService
					.getTaskFormData({ taskId: this.taskId })
					.then((data) => {
						this.taskFormData = data;
					});
			}
		}
		// 读取按钮配置
		// 先清除缓存按钮
		this.buttons = null
		if (this.status === "start") {
			this.buttons = [{ code: "_flow_start", name: "启动", isHide: "0" }];
		} else if (this.status === 'startAndClose') { // 送审、关闭
			this.buttons = [{ code: '_flow_start', name: '送审', isHide: '0' }, { code: '_flow_close', name: '关闭', isHide: '0' }]
		} else if (this.status === 'reapplyFlag') { // 重新申请、流程终止、关闭
			this.buttons = [{ code: '_flow_reapply', name: '重新申请', isHide: '0' }, { code: '_flow_stop', name: '流程终止', isHide: '0' }, { code: '_flow_close', name: '关闭', isHide: '0' }]
		} else if (this.status === 'startAndHold') {  // 送审、暂存、关闭
			this.buttons = [{ code: '_flow_start', name: '送审', isHide: '0' }, { code: '_flow_save', name: '暂存', isHide: '0' }, { code: '_flow_close', name: '关闭', isHide: '0' }]
		} else if (this.status === 'startAndCloseFiled') { // 送审、关闭
			this.buttons = [{ code: '_flow_start', name: '送审', isHide: '0' }, { code: '_flow_close', name: '关闭', isHide: '0' }]
		} else if (this.status === 'startAndHoldFiled') {  // 送审、暂存、关闭
			this.buttons = [{ code: '_flow_start', name: '送审', isHide: '0' }, { code: '_flow_save', name: '暂存', isHide: '0' }, { code: '_flow_close', name: '关闭', isHide: '0' }]
		} else if (this.status === 'startAndCloseBorrow') {
			this.buttons = [{ code: '_flow_start', name: '送审', isHide: '0' }, { code: '_flow_close', name: '关闭', isHide: '0' }]
		} else if (this.status === 'reback') {
			this.buttons = [{ code: '_flow_reback', name: '撤回', isHide: '0' }]
		} else if (this.status === 'agreeAndReject') {
			this.buttons = [{ code: '_flow_agree', name: '同意', isHide: '0' }, { code: '_flow_reject', name: '驳回', isHide: '0' }]
			this.status = 'audit'
		} else if (this.procDefKey && this.taskDefKey) {
			// 读取按钮
			taskDefExtensionService
				.queryByDefIdAndTaskId({
					processDefId: this.procDefKey,
					taskDefId: this.taskDefKey,
				})
				.then((data) => {
					data.flowButtonList.forEach(item => {
						if (item.code === '_flow_agree') {
							this.status = 'audit'
						}
					})
					this.buttons = data.flowButtonList;
				});
		}
		// 读取历史任务列表
		if (this.procInsId) {
			taskService.historicTaskList(this.procInsId).then((data) => {
				this.historicTaskList = data;
			});
		}
	},
	components: {
		UserSelect,
		UserSelectDialog,
		PreviewForm,
		TaskBackNodes,
		FlowStep,
		FlowTimeLine,
		CollectReturnHi,
		PsiCollectReturnHi,
		ProjectReportArchiveForm,
		WareHouseHi
	},
	watch: {
		isAssign(val) {
			if (!val) {
				this.assignee = null;
			}
		},
		taskSelectedTab(val) {
			if (val === "form-third") {
				if (this.procInsId) {
					this.$refs.chart1.init();
				} else {
					this.$refs.chart2.init();
				}
			}
		},
	},
	methods: {
		changeBusiness() {
			this.$refs.form.close()
			this.businessId = 'false'
		},
		init() {
			this.cs = this.$route.query.cs;
			this.detail = this.$route.query.detail;
			this.taskSelectedTab = "form-first";
			this.procDefId = this.$route.query.procDefId;
			this.procDefKey = this.$route.query.procDefKey;
			this.formType = this.$route.query.formType;
			this.formUrl = this.$route.query.formUrl;
			this.taskId = this.$route.query.taskId;
			this.taskDefKey = this.$route.query.taskDefKey;
			this.status = this.$route.query.status;
			this.title = this.$route.query.formTitle;
			this.printObj.popTitle = this.title;
			this.businessId = this.$route.query.businessId;
			this.procInsId = this.$route.query.procInsId;
			this.formReadOnly =
				this.$route.query.formReadOnly !== undefined &&
				this.$route.query.formReadOnly !== "false" &&
				this.$route.query.formReadOnly !== false;
			this.isCC = false;
			this.isAssign = false;
			this.auditForm.assignee = null;
			this.auditForm.userIds = null;
			this.auditForm.message = "";
			this.cUser = this.commonJS.isEmpty(this.$route.query.cUser) ? false : this.$route.query.cUser
			this.contractTitle = this.$route.query.contractTitle
			this.statusFlag = this.$route.query.statusFlag
			this.wareHouseId = this.$route.query.wareHouseId
			this.cwArchiveId = this.$route.query.cwArchiveId
			this.cwArchiveHiFlag = ""
			this.returnId = this.$route.query.returnId
			this.psiReturnId = this.$route.query.psiReturnId
			if (this.commonJS.isEmpty(this.$route.query.isShow)) {
				this.isShow = 'true'
			} else {
				this.isShow = this.$route.query.isShow
			}
			let _this = this
			// this.$nextTick(() => {
			//   try {
			//     _this.$refs.form.getKeyWatch(Math.random().toString())
			//   } catch (e) {
			//     console.log(e)
			//   }
			// })
			setTimeout(function () {
				try {
					_this.$refs.form.getKeyWatch(Math.random().toString())
				} catch (e) {
					console.log(e)
				}
			}, 500)
			if (this.commonJS.isNotEmpty(this.cwArchiveId)) {
				this.projectReportArchiveService.findHiById(this.cwArchiveId).then((data) => {
					this.cwArchiveDataListHiCollect = data
					if (this.commonJS.isNotEmpty(data)) {
						this.cwArchiveHiFlag = true
					}
				})
			}
		},
		cc(procInsId) {
			if (this.isCC && this.auditForm.userIds) {
				this.$refs["auditForm"].validate((valid) => {
					if (valid) {
						flowCopyService.save({
							userIds: this.auditForm.userIds,
							procDefId: this.procDefId,
							procInsId: procInsId,
							procDefName: "",
							procInsName: this.title,
							taskName: "",
						});
					}
				});
			}
		},
		// 暂存草稿
		save() {
			if (this.formType === '2') { // 外置表单
				this.$refs.form.saveForm(() => {
					this.$message.success('操作成功')
					this.changeBusiness()
					useTabs.close()
					if (!this.commonJS.isEmpty(this.$route.query.routePath)) {
						this.$router.push({ path: this.$route.query.routePath })
					} else {
						this.$router.push({
							path: '/sys/dashboard/workBench/PendingList',
							query: {
								num: 3
							}
						})
					}
					// this.$router.push({path: this.$route.query.routePath})
				})
			}
		},
		print() {
			//直接传入REF或者querySelector
			print2(this.$refs.form);
		},
		// 启动流程
		start(vars) {
			if (this.formType === "2") {
				// 外置表单
				this.$refs.form.startForm(
					(businessTable, businessId, inputForm, recordType) => {
						vars = { ...vars, ...inputForm, recordType }
						console.log(vars)
						if (inputForm.procDefId) {
							this.procDefId = inputForm.procDefId
						}
						if (inputForm.procDefKey) {
							this.procDefId = inputForm.procDefKey
						}
						if (inputForm.title) {
							this.title = inputForm.title
						}
						if (inputForm.formTitle) {
							this.formTitle = inputForm.formTitle
						}
						console.log('recordType', recordType)
						if (recordType) {
							this.recordType = recordType
						}
						if (inputForm.days) {
							this.days = inputForm.days
						}
						console.log('this.recordType', this.recordType)
						let assignee = this.auditForm.assignee
						if (!this.commonJS.isEmpty(inputForm.assignee)) {
							assignee = inputForm.assignee
						}
						taskService
							.start({
								procDefId: this.procDefId,
								procDefKey: this.procDefKey,
								businessTable: businessTable,
								businessId: businessId,
								...vars,
								title: this.title,
								assignee: assignee,
								recordType: this.recordType,
								days: this.days,
							})
							.then((data) => {
								this.$message.success("启动成功");
								this.changeBusiness()
								useTabs.close();
								if (!this.commonJS.isEmpty(this.$route.query.routePath)) {
									this.$router.push({ path: this.$route.query.routePath })
								} else {
									this.$router.push({
										path: '/sys/dashboard/workBench/PendingList',
										query: {
											num: 3
										}
									})
								}
								this.cc(data);
							});
					}
				);
			} else {
				// 动态表单
				this.$refs.form.submitStartFormData(
					{
						processDefinitionId: this.procDefId,
						...vars,
						title: this.title,
						assignee: this.auditForm.assignee,
					},
					(data) => {
						this.changeBusiness()
						useTabs.close();
						if (!this.commonJS.isEmpty(this.$route.query.routePath)) {
							this.$router.push({ path: this.$route.query.routePath })
						} else {
							this.$router.push({
								path: '/sys/dashboard/workBench/PendingList',
								query: {
									num: 3
								}
							})
						}
						this.cc(data);
					}
				);
			}
		},
		// 同意
		agree(vars) {
			vars = { ...vars, agree: true }
			if (this.formType === '2') {
				this.commit(vars)
			}
		},
		// 重新申请
		reapply(vars) {
			vars = { ...vars, agree: true }
			if (this.formType === '2') { // 外置表单
				let param = {
					num: this.$route.query.num,
					taskId: this.taskId,
					taskDefKey: this.taskDefKey,
					procInsId: this.procInsId,
					procDefId: this.procDefId,
					vars: vars,
					comment: this.auditForm,
					assignee: this.auditForm.assignee,
					cope: {
						userIds: this.auditForm.userIds,
						procDefId: this.procDefId,
						procInsId: '',
						procDefName: '',
						procInsName: this.title,
						taskName: ''
					}
				}
				this.$refs.form.reapplyForm((businessTable, businessId, inputForm, recordType) => {
					vars = { ...vars, ...inputForm, recordType }
					if (inputForm.procDefId) {
						param.procDefId = inputForm.procDefId
					}
					let assignee = this.auditForm.assignee
					if (!this.commonJS.isEmpty(inputForm.assignee)) {
						assignee = inputForm.assignee
					}
					console.log('recordType', recordType)
					this.recordType = recordType
					if (!this.commonJS.isEmpty(inputForm.days)) {
						this.days = inputForm.days
					}
					console.log('this.recordType', this.recordType)
					taskService.audit({
						taskId: this.taskId,
						taskDefKey: this.taskDefKey,
						procInsId: this.procInsId,
						procDefId: this.procDefId,
						vars: vars,
						comment: this.auditForm,
						assignee: assignee,
						recordType: this.recordType,
						days: this.days
					}).then((data) => {
						this.$message.success('提交成功')
						this.changeBusiness()
						this.$refs.form.close()
						// 我的通知
						let createDate = ''
						this.myNotice(data, this.procDefId, this.title, vars.userName, createDate)
						useTabs.close()
						// this.$router.push({path: '/flowable/task/TodoList'})
						// this.cc(data)
						if (this.$route.query.routePath) {
							this.$router.push({ path: this.$route.query.routePath })
						} else {
							var num = this.$route.query.num
							if (num === '2') {
								this.$router.push({ path: '/sys/dashboard/workBench/Pending' })
								this.cc(data)
							} else if (num === '3') {
								this.$router.push({ path: '/sys/dashboard/workBench/PendingList' })
								this.cc(data)
							} else {
								this.$router.push({
									path: '/sys/dashboard/workBench/PendingList',
									query: {
										num: 3
									}
								})
								this.cc(data)
							}
						}
					})
				}, param)
			} else { // 动态表单
				this.$refs.form.submitTaskFormData(vars, this.procInsId, this.taskId, this.auditForm.assignee, this.auditForm, (data) => {
					this.changeBusiness()
					this.$refs.form.close()
					useTabs.close()
					// this.$router.push({path: '/flowable/task/TodoList'})
					// this.cc(data)
					if (this.$route.query.routePath) {
						this.$router.push({ path: this.$route.query.routePath })
					} else {
						var num = this.$route.query.num
						if (num === '2') {
							this.$router.push({ path: '/sys/dashboard/workBench/Pending' })
							this.cc(data)
						} else if (num === '3') {
							this.$router.push({ path: '/sys/dashboard/workBench/PendingList' })
							this.cc(data)
						} else {
							this.$router.push({
								path: '/sys/dashboard/workBench/PendingList',
								query: {
									num: 3
								}
							})
							this.cc(data)
						}
					}
				})
			}
		},
		// Process_1667978088459 客户修改
		// Process_1668394732246 项目登记
		// Process_1701829547130 报告归档权限申请
		// Process_1668503117077 报告质控管理员审核
		// Process_1669014216650 报告签章-公章
		// Process_1669087010742 报告签章-公章+执业章
		// Process_1668677901585 项目报告归档
		// Process_1670486210438 报告复核
		// Process_1670486210439 会计-报告号领取
		// Process_1668759076824 报告作废申请
		// Process_1670548572652 报告作废归档
		// Process_1670548572655 报告作废归档-苏州
		// Process_1669700915383 合同登记纸质归档
		// Process_1669271524486 报销审批
		// Process_1669271524487 财务-报销审批-电子发票
		// Process_1669275081328 发票申请
		// Process_1669275380218 发票作废
		// Process_1672738002595 发起通知
		// Process_1662628133027 评估-合同登记新建
		// Process_1663743217785 评估-合同登记归档
		// Process_1664370362499 评估-项目登记流程
		// Process_1666169509264 评估-项目一级校审
		// Process_1666266316011 评估-项目二级校审
		// Process_1666266494837 评估-项目三级校审
		// Process_1666331430821 评估-报告签发审批
		// Process_1666332258192 评估-项目登记归档
		// Process_1665383385070 评估-报销申请
		// Process_1665383385071 评估-报销申请-电子发票
		// Process_1665628043339 评估-发票作废
		// Process_1665458731435 评估-发票申请
		// Process_1669961023358 物资管理-采购申请
		// Process_1672729521837 物资管理-领用申请  Process_1673513775015
		// Process_1673332958749 财务-报告签章-实体章  Process_1673513595904
		// Process_1673514092406 物资管理-入库修改
		// Process_1673600899831 物资管理-合同
		// Process_1673924346231 中审-报销审批
		// Process_1673924346232 中审-报销审批-电子发票
		// Process_1667894339167 会计-合同登记
		// Process_1678692643340 会计-项目报告归档-苏州分部
		// Process_1683767097901 物资管理-领用退回申请
		// Process_1694762268070 报告-修改签字注师
		// Process_1694652340089 实习登记
		// Process_1694745513202 实习工作日志
		// Process_1695090819012 实习报销登记
		// Process_1695350752394 实习报销
		// Process_1696643627713 工资卡信息完善
		// Process_1696643401049 社保登记
		// Process_1695781849405 员工入职
		// Process_1698386333871 底稿归档检查
		// Process_1698981918212 离职交接
		// Process_1698387196829 电脑欠款回收
		// Process_1699256313120 应收账款检查
		// Process_1699321267272 社保账款检查
		// Process_1699926014064 备用金检查
		// Process_1698129477831 离职申请
		// Process_1701829547129 会计-复核及签章
		// Process_1702005929963 完善个人信息
		// Process_1702369424692 会计-报告号申请
		// Process_1702369424693 会计-报告号申请
		// Process_1670486210440 会计-报告号复核
		// Process_1704851888818 会计-所长报销
		// Process_1705370333755 会计-所长报销-电子发票
		// Process_1705389994103 中审-所长报销
		// Process_1705390592348 中审-所长报销-电子发票
		// Process_1705391439287 评估-所长报销
		// Process_1705391725816 评估-所长报销-电子发票
		// Process_1705454007925 项目-报销审批
		// Process_1705454863808 项目-报销审批-电子发票
		// Process_1706170102059 会计-总经办报销
		// Process_1706175399469 评估-总经办报销
		// Process_1706176397312 中审-总经办报销
		// Process_1706176397323 中审-苏州分公司-智永祥部门
		// Process_1706176937876 项目-总经办报销
		// Process_1706671221048 咨询-报销审批
		// Process_1706679472488 咨询-报销审批-电子发票
		// Process_1706680073642 咨询-总经办报销
		// Process_1706680331785 咨询-所长报销
		// Process_1706680660857 咨询-所长报销-电子发票
		// Process_1708926975266 会计-撤回签章
		// Process_1709102298565 盛所会计-报销申请
		// Process_1709104787957 盛所项目-报销申请
		// Process_1709605863764 财务-日常办公签章
		// Process_1709716622665 评估-日常办公签章
		// Process_1709606246355 财务-报告签章
		// Process_1709716869089 评估-报告签章
		// Process_1710204867282 评估-项目作废
		// Process_1711414021644 会计-预开票申请
		// Process_1711418224962 物资-项目报销
		// Process_1702534302878 日常办公-请假申请
		// Process_1713769833657 苏州-业务操作报销
		// Process_1722305645394 会计-报销文件补充
		// Process_1722389642543 评估-报销文件补充
		// Process_1722404901733 中审-报销文件补充
		// Process_1722412442950 项目-报销文件补充
		// Process_1722416114655 咨询-报销文件补充
		// Process_1723517404891 会议室预约
		// Process_1774937846626 进销存-采购申请
		// Process_1775006048278 进销存-入库修改
		// Process_1775013293806 进销存-领用申请
		// Process_1775013611447 进销存-领用退回申请
		// Process_1775549295075 进销存-报损申请
		// Process_1776049799724 进销存-食材采购统计
		// Process_1779092642832 景聚庭-折扣结账
		// 驳回
		reject(vars) {
			if (this.procDefId.includes('Process_1667978088459') ||
				this.procDefId.includes('Process_1668394732246') ||
				this.procDefId.includes('Process_1701829547130') ||
				this.procDefId.includes('Process_1668503117077') ||
				this.procDefId.includes('Process_1669014216650') ||
				this.procDefId.includes('Process_1669087010742') ||
				this.procDefId.includes('Process_1668677901585') ||
				this.procDefId.includes('Process_1670486210438') ||
				this.procDefId.includes('Process_1670486210439') ||
				this.procDefId.includes('Process_1668759076824') ||
				this.procDefId.includes('Process_1670548572652') ||
				this.procDefId.includes('Process_1670548572655') ||
				this.procDefId.includes('Process_1669700915383') ||
				this.procDefId.includes('Process_1669271524486') ||
				this.procDefId.includes('Process_1669271524487') ||
				this.procDefId.includes('Process_1669275081328') ||
				this.procDefId.includes('Process_1669275380218') ||
				this.procDefId.includes('Process_1672738002595') ||
				this.procDefId.includes('Process_1662628133027') ||
				this.procDefId.includes('Process_1663743217785') ||
				this.procDefId.includes('Process_1664370362499') ||
				this.procDefId.includes('Process_1666169509264') ||
				this.procDefId.includes('Process_1666266316011') ||
				this.procDefId.includes('Process_1666266494837') ||
				this.procDefId.includes('Process_1666331430821') ||
				this.procDefId.includes('Process_1666332258192') ||
				this.procDefId.includes('Process_1665383385070') ||
				this.procDefId.includes('Process_1665383385071') ||
				this.procDefId.includes('Process_1665628043339') ||
				this.procDefId.includes('Process_1665458731435') ||
				this.procDefId.includes('Process_1669961023358') ||
				this.procDefId.includes('Process_1673513775015') ||
				this.procDefId.includes('Process_1673513595904') ||
				this.procDefId.includes('Process_1673514092406') ||
				this.procDefId.includes('Process_1673600899831') ||
				this.procDefId.includes('Process_1673924346231') ||
				this.procDefId.includes('Process_1673924346232') ||
				this.procDefId.includes('Process_1667894339167') ||
				this.procDefId.includes('Process_1678692643340') ||
				this.procDefId.includes('Process_1683767097901') ||
				this.procDefId.includes('Process_1694762268070') ||
				this.procDefId.includes('Process_1694652340089') ||
				this.procDefId.includes('Process_1695090819012') ||
				this.procDefId.includes('Process_1695350752394') ||
				this.procDefId.includes('Process_1694745513202') ||
				this.procDefId.includes('Process_1696643627713') ||
				this.procDefId.includes('Process_1696643401049') ||
				this.procDefId.includes('Process_1695781849405') ||
				this.procDefId.includes('Process_1698386333871') ||
				this.procDefId.includes('Process_1698981918212') ||
				this.procDefId.includes('Process_1698387196829') ||
				this.procDefId.includes('Process_1699256313120') ||
				this.procDefId.includes('Process_1699321267272') ||
				this.procDefId.includes('Process_1699926014064') ||
				this.procDefId.includes('Process_1698129477831') ||
				this.procDefId.includes('Process_1701829547129') ||
				this.procDefId.includes('Process_1702005929963') ||
				this.procDefId.includes('Process_1702369424692') ||
				this.procDefId.includes('Process_1702369424693') ||
				this.procDefId.includes('Process_1670486210440') ||
				this.procDefId.includes('Process_1704851888818') ||
				this.procDefId.includes('Process_1705370333755') ||
				this.procDefId.includes('Process_1705389994103') ||
				this.procDefId.includes('Process_1705390592348') ||
				this.procDefId.includes('Process_1705391439287') ||
				this.procDefId.includes('Process_1705391725816') ||
				this.procDefId.includes('Process_1705454007925') ||
				this.procDefId.includes('Process_1705454863808') ||
				this.procDefId.includes('Process_1706170102059') ||
				this.procDefId.includes('Process_1706175399469') ||
				this.procDefId.includes('Process_1706176397312') ||
				this.procDefId.includes('Process_1706176397323') ||
				this.procDefId.includes('Process_1706176937876') ||
				this.procDefId.includes('Process_1706671221048') ||
				this.procDefId.includes('Process_1706679472488') ||
				this.procDefId.includes('Process_1706680073642') ||
				this.procDefId.includes('Process_1706680331785') ||
				this.procDefId.includes('Process_1706680660857') ||
				this.procDefId.includes('Process_1708926975266') ||
				this.procDefId.includes('Process_1709102298565') ||
				this.procDefId.includes('Process_1709104787957') ||
				this.procDefId.includes('Process_1709605863764') ||
				this.procDefId.includes('Process_1709606246355') ||
				this.procDefId.includes('Process_1709716622665') ||
				this.procDefId.includes('Process_1709716869089') ||
				this.procDefId.includes('Process_1710204867282') ||
				this.procDefId.includes('Process_1711414021644') ||
				this.procDefId.includes('Process_1711418224962') ||
				this.procDefId.includes('Process_1702534302878') ||
				this.procDefId.includes('Process_1713769833657') ||
				this.procDefId.includes('Process_1722305645394') ||
				this.procDefId.includes('Process_1722389642543') ||
				this.procDefId.includes('Process_1722404901733') ||
				this.procDefId.includes('Process_1722412442950') ||
				this.procDefId.includes('Process_1722416114655') ||
				this.procDefId.includes('Process_1723517404891') ||
				this.procDefId.includes('Process_1751269402209') ||
				this.procDefId.includes('Process_1774937846626') ||
				this.procDefId.includes('Process_1775006048278') ||
				this.procDefId.includes('Process_1775013293806') ||
				this.procDefId.includes('Process_1775013611447') ||
				this.procDefId.includes('Process_1775549295075') ||
				this.procDefId.includes('Process_1776049799724') ||
				this.procDefId.includes('Process_1779092642832')

			) {
				console.log('进入新版驳回')
				this.$confirm(`确定驳回流程吗?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(async () => {
					if (this.formType === '2') {
						vars = { ...vars, agree: false }
						// await this.commit(vars) // 驳回
						this.$refs.form.updateStatusById('reject', (assignee) => {
							if (this.commonJS.isEmpty(this.auditForm.assignee)) {
								this.auditForm.assignee = assignee
							}
							taskService.audit({
								taskId: this.taskId,
								taskDefKey: this.taskDefKey,
								procInsId: this.procInsId,
								procDefId: this.procDefId,
								vars: vars,
								comment: this.auditForm,
								assignee: this.auditForm.assignee
							}).then((data) => {
								this.$message.success('提交成功')
								this.changeBusiness()
								this.$refs.form.close()
								// 我的通知
								let createDate = ''
								this.myNotice(data, this.procDefId, this.title, vars.userName, createDate)
								useTabs.close()
								// this.$router.push({path: '/flowable/task/TodoList'})
								// this.cc(data)
								if (this.$route.query.routePath) {
									this.$router.push({ path: this.$route.query.routePath })
								} else {
									var num = this.$route.query.num
									if (num === '2') {
										this.$router.push({ path: '/sys/dashboard/workBench/Pending' })
										this.cc(data)
									} else if (num === '3') {
										this.$router.push({ path: '/sys/dashboard/workBench/PendingList' })
										this.cc(data)
									} else if (this.cs === 'cs') {
										this.$router.push({ path: '/dashboard/index' })
										this.cc(data)
									} else if (this.cs === 'cs2') {
										this.$router.push({ path: '/home' })
										this.cc(data)
									} else {
										this.$router.push({
											path: '/sys/dashboard/workBench/PendingList',
											query: {
												num: 3
											}
										})
										this.cc(data)
									}
								}
							})
						})
					}
				})
			} else {
				console.log('进入旧版驳回')
				this.$confirm(`确定驳回流程吗?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(async () => {
					if (this.formType === '2') {
						if (this.cUser === true || this.cUser === 'true') { // cUser为true则页面审核人为自定义多选，驳回时要将审核人重新定义一次
							await this.$refs.form.updateStatusById('reject', (businessTable, businessId, inputForm) => {
								this.auditForm.candidateUserList = inputForm.assignee
							})
							setTimeout(() => {
								taskService.backNodes(this.taskId).then((data) => {
									let backNodes = data
									if (backNodes.length > 0) {
										let backTaskDefKey = backNodes[backNodes.length - 1].taskDefKey
										this.back(backTaskDefKey)
									}
								})
							}, 100)
						} else {
							await this.$refs.form.updateStatusById('reject')
							taskService.backNodes(this.taskId).then((data) => {
								let backNodes = data
								if (backNodes.length > 0) {
									let backTaskDefKey = backNodes[backNodes.length - 1].taskDefKey
									this.back(backTaskDefKey)
								}
							})
						}
					}
				})
			}
		},
		reject2(vars) {
			if (this.procDefId.includes('Process_1667978088459') ||
				this.procDefId.includes('Process_1668394732246') ||
				this.procDefId.includes('Process_1701829547130') ||
				this.procDefId.includes('Process_1668503117077') ||
				this.procDefId.includes('Process_1669014216650') ||
				this.procDefId.includes('Process_1669087010742') ||
				this.procDefId.includes('Process_1668677901585') ||
				this.procDefId.includes('Process_1670486210438') ||
				this.procDefId.includes('Process_1670486210439') ||
				this.procDefId.includes('Process_1668759076824') ||
				this.procDefId.includes('Process_1670548572652') ||
				this.procDefId.includes('Process_1670548572655') ||
				this.procDefId.includes('Process_1669700915383') ||
				this.procDefId.includes('Process_1669271524486') ||
				this.procDefId.includes('Process_1669271524487') ||
				this.procDefId.includes('Process_1669275081328') ||
				this.procDefId.includes('Process_1669275380218') ||
				this.procDefId.includes('Process_1672738002595') ||
				this.procDefId.includes('Process_1662628133027') ||
				this.procDefId.includes('Process_1663743217785') ||
				this.procDefId.includes('Process_1664370362499') ||
				this.procDefId.includes('Process_1666169509264') ||
				this.procDefId.includes('Process_1666266316011') ||
				this.procDefId.includes('Process_1666266494837') ||
				this.procDefId.includes('Process_1666331430821') ||
				this.procDefId.includes('Process_1666332258192') ||
				this.procDefId.includes('Process_1665383385070') ||
				this.procDefId.includes('Process_1665383385071') ||
				this.procDefId.includes('Process_1665628043339') ||
				this.procDefId.includes('Process_1665458731435') ||
				this.procDefId.includes('Process_1669961023358') ||
				this.procDefId.includes('Process_1673513775015') ||
				this.procDefId.includes('Process_1673513595904') ||
				this.procDefId.includes('Process_1673514092406') ||
				this.procDefId.includes('Process_1673600899831') ||
				this.procDefId.includes('Process_1673924346231') ||
				this.procDefId.includes('Process_1673924346232') ||
				this.procDefId.includes('Process_1667894339167') ||
				this.procDefId.includes('Process_1678692643340') ||
				this.procDefId.includes('Process_1683767097901') ||
				this.procDefId.includes('Process_1694762268070') ||
				this.procDefId.includes('Process_1694652340089') ||
				this.procDefId.includes('Process_1695090819012') ||
				this.procDefId.includes('Process_1695350752394') ||
				this.procDefId.includes('Process_1694745513202') ||
				this.procDefId.includes('Process_1696643627713') ||
				this.procDefId.includes('Process_1696643401049') ||
				this.procDefId.includes('Process_1695781849405') ||
				this.procDefId.includes('Process_1698386333871') ||
				this.procDefId.includes('Process_1698981918212') ||
				this.procDefId.includes('Process_1698387196829') ||
				this.procDefId.includes('Process_1699256313120') ||
				this.procDefId.includes('Process_1699321267272') ||
				this.procDefId.includes('Process_1699926014064') ||
				this.procDefId.includes('Process_1698129477831') ||
				this.procDefId.includes('Process_1702534302878') ||
				this.procDefId.includes('Process_1774937846626') ||
				this.procDefId.includes('Process_1775006048278') ||
				this.procDefId.includes('Process_1775013293806') ||
				this.procDefId.includes('Process_1775013611447') ||
				this.procDefId.includes('Process_1775549295075') ||
				this.procDefId.includes('Process_1776049799724') ||
				this.procDefId.includes('Process_1779092642832')

			) {
				if (this.formType === '2') {
					vars = { ...vars, agree: false }
					// await this.commit(vars) // 驳回
					this.$refs.form.updateStatusById('reject', (assignee) => {
						if (this.commonJS.isEmpty(this.auditForm.assignee)) {
							this.auditForm.assignee = assignee
						}
						taskService.audit({
							taskId: this.taskId,
							taskDefKey: this.taskDefKey,
							procInsId: this.procInsId,
							procDefId: this.procDefId,
							vars: vars,
							comment: this.auditForm,
							assignee: this.auditForm.assignee
						}).then((data) => {
							this.$message.success('提交成功')
							this.changeBusiness()
							this.$refs.form.close()
							// 我的通知
							let createDate = ''
							this.myNotice(data, this.procDefId, this.title, vars.userName, createDate)
							useTabs.close()
							// this.$router.push({path: '/flowable/task/TodoList'})
							// this.cc(data)
							if (this.$route.query.routePath) {
								this.$router.push({ path: this.$route.query.routePath })
							} else {
								var num = this.$route.query.num
								if (num === '2') {
									this.$router.push({ path: '/sys/dashboard/workBench/Pending' })
									this.cc(data)
								} else if (num === '3') {
									this.$router.push({ path: '/sys/dashboard/workBench/PendingList' })
									this.cc(data)
								} else if (this.cs === 'cs') {
									this.$router.push({ path: '/dashboard/index' })
									this.cc(data)
								} else if (this.cs === 'cs2') {
									this.$router.push({ path: '/home' })
									this.cc(data)
								} else {
									this.$router.push({
										path: '/sys/dashboard/workBench/PendingList',
										query: {
											num: 3
										}
									})
									this.cc(data)
								}
							}
						})
					})
				}
			}
		},
		// 驳回至指定节点(节点是从0开始)
		rejectToPointNum(num) {
			this.$confirm(`确定驳回流程吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				taskService.backNodes(this.taskId).then((data) => {
					let backNodes = data
					if (backNodes.length > 0 && backNodes.length > num) {
						let backTaskDefKey = backNodes[num].taskDefKey
						this.back(backTaskDefKey)
					}
				})
			})
			if (this.formType === '2') {
				this.$refs.form.updateStatusById('reject')
			}
		},
		// 撤回
		reback() {
			this.$confirm(`确定撤回流程吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(async () => {
				await this.$refs.form.updateStatusById('reback')
				taskService.backNodes(this.taskId).then((data) => {
					let backNodes = data
					this.changeBusiness()
					// this.$router.push({path: this.$route.query.routePath})
					if (backNodes.length > 0) {
						let backTaskDefKey = backNodes[0].taskDefKey
						this.back(backTaskDefKey)
					} else {
						useTabs.close()
						if (!this.commonJS.isEmpty(this.$route.query.routePath)) {
							this.$router.push({ path: this.$route.query.routePath })
						} else {
							this.$router.push({
								path: '/sys/dashboard/workBench/PendingList',
								query: {
									num: 3
								}
							})
						}
					}
					// this.$refs.form.close()
				})
			})
		},
		// 驳回到任意节点
		turnBack() {
			this.$refs.taskBackNodes.init(this.taskId);
		},
		// 回退到任意节点
		back(backTaskDefKey) {
			taskService
				.back({
					taskId: this.taskId,
					backTaskDefKey: backTaskDefKey,
					...this.auditForm,
				})
				.then((data) => {
					this.$message.success("回退成功");
					this.changeBusiness()
					useTabs.close();
					var num = this.$route.query.num
					if (num === '2') {
						this.$router.push({ path: '/sys/dashboard/workBench/Pending' })
					} else if (num === '3') {
						this.$router.push({ path: '/sys/dashboard/workBench/PendingList' })
					} else {
						this.$router.push({
							path: '/sys/dashboard/workBench/PendingList',
							query: {
								num: 3
							}
						})
					}
					this.cc(data);
				});
		},
		// 加签
		addMultiInstance() {
			// this.$refs.addSignTaskUserSelectDialog.init()
		},
		selectUsersToAddSignTask(users) {
			let userIds = users
				.map((user) => {
					return user.id;
				})
				.join(",");
			taskService
				.addSignTask({
					taskId: this.taskId,
					userIds: JSON.stringify(userIds),
					comment: "",
					flag: false,
				})
				.then((data) => {
					this.$message.success(data);
				});
		},
		// 减签
		delMultiInstance() { },
		// 转办
		transfer() {
			this.$refs.transferUserSelectDialog.open();
		},
		selectUsersToTransferTask(user) {
			taskService.transfer(this.taskId, user[0].id).then((data) => {
				this.$message.success(data);
				this.$router.push({
					path: '/sys/dashboard/workBench/PendingList',
					query: {
						num: 3
					}
				})
			});
		},
		// 委托
		delegate() {
			this.$refs.delegateUserSelectDialog.open();
		},
		selectUsersToDelateTask(user) {
			taskService.delegate(this.taskId, user[0].id).then((data) => {
				this.$message.success(data);
				this.$router.push({
					path: '/sys/dashboard/workBench/PendingList',
					query: {
						num: 3
					}
				})
			});
		},
		// 终止
		stop() {
			this.$confirm(`确定终止流程吗?`, "提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "warning",
			}).then(() => {
				// 将数据状态更改为暂存状态
				this.$refs.form.updateStatusById('hold', () => {
					// this.auditForm.candidateUserList = inputForm.assignee
					processService.stop(this.procInsId, this.auditForm.message).then((data) => {
						this.$message.success(data)
						useTabs.close()
						// this.cc(data)
						if (this.$route.query.routePath) {
							this.$router.push({ path: this.$route.query.routePath })
						} else {
							var num = this.$route.query.num
							if (num === '2') {
								this.$router.push({ path: '/sys/dashboard/workBench/Pending' })
								this.cc(data)
							} else if (num === '3') {
								this.$router.push({ path: '/sys/dashboard/workBench/PendingList' })
								this.cc(data)
							} else {
								this.$router.push({
									path: '/sys/dashboard/workBench/PendingList',
									query: {
										num: 3
									}
								})
								this.cc(data)
							}
						}
					})
				})
			});
		},
		// 关闭
		close() {
			this.changeBusiness()
			useTabs.close()
			if (!this.commonJS.isEmpty(this.$route.query.routePath)) {
				this.$router.push({ path: this.$route.query.routePath })
			} else {
				this.$router.push({
					path: '/sys/dashboard/workBench/PendingList',
					query: {
						num: 3
					}
				})
			}
		},
		// 关闭
		cancel() {
			this.changeBusiness()
			useTabs.close()
			if (!this.commonJS.isEmpty(this.$route.query.routePath)) {
				this.$router.push({ path: this.$route.query.routePath })
			} else {
				this.$router.push({
					path: '/dashboard/index',
				})
			}
		},
		// 自定义按钮提交
		commit(vars) {
			if (this.formType === "2") {
				// 外置表单
				let param = {
					num: this.$route.query.num,
					taskId: this.taskId,
					taskDefKey: this.taskDefKey,
					procInsId: this.procInsId,
					procDefId: this.procDefId,
					vars: vars,
					comment: this.auditForm,
					assignee: this.auditForm.assignee,
					cope: {
						userIds: this.auditForm.userIds,
						procDefId: this.procDefId,
						procInsId: '',
						procDefName: '',
						procInsName: this.title,
						taskName: ''
					}
				}
				// eslint-disable-next-line no-unused-vars
				this.$refs.form.agreeForm(
					(businessTable, businessId, inputForm, recordType) => {
						if (this.commonJS.isNotEmpty(inputForm)) {
							if (this.commonJS.isNotEmpty(inputForm.assignee)) {
								this.auditForm.assignee = inputForm.assignee
								if (inputForm.imprestAmountArrears == 0) {
									this.reject2();
									return
								}
							}
							if (this.commonJS.isNotEmpty(inputForm.days)) {
								this.days = inputForm.days
							}
						}
						vars = { ...vars, ...inputForm, recordType }
						taskService
							.audit({
								taskId: this.taskId,
								taskDefKey: this.taskDefKey,
								procInsId: this.procInsId,
								procDefId: this.procDefId,
								comment: this.auditForm,
								assignee: this.auditForm.assignee,
								recordType: recordType,
								days: this.days,
								vars: vars
							})
							.then((data) => {
								this.$message.success("提交成功");
								useTabs.close();
								console.log("进入审核通过环节")
								console.log(this.title)
								// 我的通知
								let createDate = ''
								this.myNotice(data, this.procDefId, this.title, vars.userName, createDate)
								// this.$router.push({path: "/flowable/task/TodoList"});
								// this.cc(data);
								if (this.$route.query.routePath) {
									this.$router.push({ path: this.$route.query.routePath })
								} else {
									var num = this.$route.query.num
									if (num === '2') {
										this.$router.push({ path: '/sys/dashboard/workBench/Pending' })
										this.cc(data)
									} else if (num === '3') {
										this.$router.push({ path: '/sys/dashboard/workBench/PendingList' })
										this.cc(data)
									} else if (this.cs === 'cs') {
										this.$router.push({ path: '/dashboard/index' })
										this.cc(data)
									} else if (this.cs === 'cs2') {
										this.$router.push({ path: '/home' })
										this.cc(data)
									} else {
										this.$router.push({
											path: '/sys/dashboard/workBench/PendingList',
											query: {
												num: 3
											}
										})
										this.cc(data)
									}
								}
							});
					}, param
				);
			} else {
				// 动态表单
				this.$refs.form.submitTaskFormData(
					vars,
					this.procInsId,
					this.taskId,
					this.auditForm.assignee,
					this.auditForm,
					(data) => {
						this.changeBusiness()
						useTabs.close();
						// this.$router.push({path: "/flowable/task/TodoList"});
						// this.cc(data);
						if (this.$route.query.routePath) {
							this.$router.push({ path: this.$route.query.routePath })
						} else {
							var num = this.$route.query.num
							if (num === '2') {
								this.$router.push({ path: '/sys/dashboard/workBench/Pending' })
								this.cc(data)
							} else if (num === '3') {
								this.$router.push({ path: '/sys/dashboard/workBench/PendingList' })
								this.cc(data)
							} else {
								this.$router.push({
									path: '/sys/dashboard/workBench/PendingList',
									query: {
										num: 3
									}
								})
								this.cc(data)
							}
						}
					}
				);
			}
		},

		submit(currentBtn, buttons) {
			let vars = {}; // 存储流程变量

			// 把当前操作对应的自定义按钮(以_flow_开头的是系统按钮，排除在外）的编码，存储为对应的流程变量，值设置为true，其余自定义按钮编码对应的流程变量值为false。
			buttons.forEach((btn) => {
				if (btn.code && !btn.code.startsWith("_flow_")) {
					vars[btn.code] = false;
				}
			});
			if (currentBtn.code && !currentBtn.code.startsWith("_flow_")) {
				vars[currentBtn.code] = true;
			}
			vars.title = this.title; // 标题
			vars.assignee = this.auditForm.assignee; // 指定的下一步骤处理人
			this.auditForm.type = currentBtn.code; // 提交类型
			this.auditForm.status = currentBtn.name; // 按钮文字
			switch (currentBtn.code) {
				case "_flow_start": // 自动流程
					this.start(vars);
					break;
				case "_flow_save": // 草稿
					this.save();
					break;
				case "_flow_agree": // 同意
					this.agree();
					break;
				case "_flow_reject": // 驳回
					this.reject();
					break;
				case "_flow_back": // 驳回到任意步骤
					this.turnBack();
					break;
				case "_flow_add_multi_instance": // 加签
					this.addMultiInstance();
					break;
				case "_flow_del_multi_instance": // 减签
					this.delMultiInstance();
					break;
				case "_flow_transfer": // 转办
					this.transfer();
					break;
				case "_flow_delegate": // 外派
					this.delegate();
					break;
				case "_flow_stop": // 终止
					this.stop();
					break;
				case "_flow_print": // 打印
					this.print();
					break;
				case '_flow_reapply':// 重新申请
					this.reapply()
					break
				case '_flow_close':// 关闭
					this.close()
					break
				case '_flow_reback':// 撤回
					this.reback()
					break
				case '_fileApply':// 文件补充
					this.fileApply()
					break
				case '_cancel':// 关闭
					this.cancel()
					break
				default:
					this.commit(vars); // 自定义按钮提交
			}
		},

		//文件补充
		fileApply(vars) {
			let message = ""
			if (this.formType === "2") {
				// 外置表单
				this.$refs.form.fileApply(
					(businessTable, businessId, inputForm, recordType, createById, newTitle, title, procDefId, procDefKey, fileMessage) => {
						vars = { ...vars, ...inputForm, recordType }
						console.log(vars)
						if (procDefId) {
							this.procDefId = procDefId
						}
						if (procDefKey) {
							this.procDefKey = procDefKey
							inputForm.procDefKey = procDefKey
						}
						// if (newTitle) {
						// 	this.title = newTitle
						// }
						if (title) {
							this.formTitle = title
						}
						if (recordType) {
							this.recordType = recordType
						}
						if (inputForm.days) {
							this.days = inputForm.days
						}

						let assignee = createById
						if (!this.commonJS.isEmpty(createById)) {
							assignee = createById
						}
						message = fileMessage
						taskService
							.start({
								procDefId: this.procDefId,
								procDefKey: this.procDefKey,
								businessTable: businessTable,
								businessId: businessId,
								...vars,
								title: newTitle,
								assignee: assignee,
								recordType: this.recordType,
								days: this.days,
							})
							.then((data) => {
								this.$message.success(message);
								// this.changeBusiness()
								// useTabs.close();
								// if (!this.commonJS.isEmpty(this.$route.query.routePath)) {
								// 	this.$router.push({path: this.$route.query.routePath})
								// } else {
								// 	this.$router.push({
								// 		path: '/dashboard/index',
								// 	})
								// }
								// this.cc(data);
							});
					}
				);
			} else {
				// 动态表单
				this.$refs.form.submitStartFormData(
					{
						processDefinitionId: this.procDefId,
						...vars,
						title: this.title,
						assignee: this.auditForm.assignee,
					},
					(data) => {
						this.changeBusiness()
						useTabs.close();
						if (!this.commonJS.isEmpty(this.$route.query.routePath)) {
							this.$router.push({ path: this.$route.query.routePath })
						} else {
							this.$router.push({
								path: '/sys/dashboard/workBench/PendingList',
								query: {
									num: 3
								}
							})
						}
						this.cc(data);
					}
				);
			}

		},


		myNotice(taskId, proDefId, title, userName, createDate) {
			this.inputForm = {
				taskId: '',
				title: '',
				defId: '',
				taskName: '',
				createUser: '',
				createTime: '',
				noticeName: '',
				noticeId: ''
			}
			taskService.historicTaskList(taskId).then((data) => {
				if (data[data.length - 1].comment.status === '结束') {
					this.inputForm.taskId = taskId
					// 实例标题
					this.inputForm.title = title
					// 流程id
					this.inputForm.defId = proDefId
					// 流程名称
					processService.getById(proDefId).then((data) => {
						this.inputForm.taskName = data.name
					})
					// 流程发起人
					this.inputForm.createUser = data[0].assigneeName
					// 创建时间
					this.inputForm.createTime = data[0].histIns.endTime
					// 通知人
					this.inputForm.noticeName = data[0].assigneeName
					// 通知人Id
					this.inputForm.noticeId = data[0].assigneeId
					// noticeService.addInfo(this.inputForm)
				}
			})
		},
		callBackFunc(type) {
			// 隐藏同意按钮
			if (type === 'hide') {
				// 读取按钮
				taskDefExtensionService.queryByDefIdAndTaskId({
					processDefId: this.procDefKey,
					taskDefId: this.taskDefKey
				}).then((data) => {
					// console.log('buttons', data)
					data.flowButtonList.forEach(item => {
						if (item.code === '_flow_agree') {
							item.isHide = '1'
						}
					})
					this.buttons = data.flowButtonList
				})
			}
			// 展示同意按钮
			if (type === 'show') {
				// 读取按钮
				taskDefExtensionService.queryByDefIdAndTaskId({
					processDefId: this.procDefKey,
					taskDefId: this.taskDefKey
				}).then((data) => {
					// console.log('buttons', data)
					data.flowButtonList.forEach(item => {
						if (item.code === '_flow_agree') {
							item.isHide = '0'
						}
					})
					this.buttons = data.flowButtonList
				})
			}
		},
		// 开启/关闭taskForm页面的加载中状态
		changeLoading(loading) {
			if (this.commonJS.isNotEmpty(loading)) {
				this.loading = loading
			} else {
				this.loading = false
			}
		},
		onTabChange(event) {
			if (event.props.name === 'form-sixth') {
				if (this.commonJS.isNotEmpty(this.wareHouseId)) {
					this.wareHouseService.findHiById(this.wareHouseId).then((data) => {
						this.dataListHi = data
					})
				}
			}
			if (event.props.name === 'form-seventh') {
				if (this.commonJS.isNotEmpty(this.returnId)) {
					this.collectService.findByReturnId(this.returnId).then((data) => {
						this.collectService.findHiById(data.id).then((data) => {
							this.dataListHiCollect = data
						})
					})
				}
			}
			if (event.props.name === 'form-psi-return') {
				if (this.commonJS.isNotEmpty(this.psiReturnId)) {
					this.psiCollectService.findByReturnId(this.psiReturnId).then((data) => {
						this.psiCollectService.findHiById(data.id).then((data) => {
							this.dataListHiCollect = data
						})
					})
				}
			}

			/*if (event.props.name === 'form-cwArchive') {
				if (this.commonJS.isNotEmpty(this.cwArchiveId)) {
					this.projectReportArchiveService.findHiById(this.cwArchiveId).then((data) => {
						this.cwArchiveDataListHiCollect = data
					})
				}
			}*/
		},
		// 打开财务归档修改历史详情页
		hiDetailCwArchive(row) {
			if (this.commonJS.isNotEmpty(row.id)) {
				this.$refs.projectReportArchiveForm.init('view', row.id)
			}
		},
		// 打开入库修改历史详情页
		hiDetail(row) {
			if (this.commonJS.isNotEmpty(row.id)) {
				this.$refs.wareHouseHi.init(row.id)
			}
		},
		// 打开领用退回历史详情页
		hiDetailCollect(row) {
			if (this.commonJS.isNotEmpty(row.id)) {
				this.$refs.collectReturnHi.init(row.id)
			}
		},
		// 打开进销存领用退回历史详情页
		hiPsiDetailCollect(row) {
			if (this.commonJS.isNotEmpty(row.id)) {
				this.$refs.psiCollectReturnHi.init(row.id)
			}
		}
	},
	data() {
		return {
			cs: "",
			form: null,
			formType: "",
			formUrl: "",
			taskSelectedTab: "frist",
			historicTaskList: [],
			procDefId: "",
			procInsId: "",
			formReadOnly: false,
			procDefKey: "",
			taskId: "",
			taskFormData: [],
			taskDefKey: "",
			status: "",
			detail: "",
			title: "",
			businessId: "",
			buttons: [],
			isCC: false,
			isAssign: false,
			isShow: true,
			printObj: {
				id: "printForm",
				popTitle: "",
				extraCss: "",
				extraHead:
					'<meta http-equiv="Content-Language" content="zh-cn"/>',
			},
			auditForm: {
				message: "",
				type: "",
				status: "",
				userIds: null,
				assignee: null,
			},
			cUser: false,
			loading: false,
			wareHouseId: '',
			cwArchiveId: '',
			cwArchiveHiFlag: '',
			returnId: '',
			psiReturnId: '',
			dataListHi: [],
			dataListHiCollect: [],
			cwArchiveDataListHiCollect: [],
			recordType: ''
		};
	},
};
</script>
<style lang="less" scoped>
.jp-center {
	height: calc(100% - 34px);
	position: relative;
	padding: 10px;
}

.title {
	padding: 15px;
	text-align: center;
}

.FlowFormFooter {
	position: fixed;
	right: 0;
	bottom: 0;
	height: 66px;
	z-index: 999;
	/* margin-right: -20px;
    margin-left: -20px; */
	background: #fff;
	-webkit-box-shadow: 0 -3px 5px 0 rgba(0, 0, 0, 0.12);
	box-shadow: 0 -3px 5px 0 rgba(0, 0, 0, 0.12);
	flex-flow: row nowrap;
	justify-content: center;
	align-items: center;
	left: 0;
	display: flex;
	-webkit-transition: inline-block 0.3s, left 0.3s, width 0.3s,
		margin-left 0.3s, font-size 0.3s;
	transition: inline-block 0.3s, left 0.3s, width 0.3s, margin-left 0.3s,
		font-size 0.3s;
	/* right: 20.125px; */
}

.aminui-side-split+.aminui-side+.aminui-body.el-container {
	.FlowFormFooter {
		left: 275px;
	}
}

.aminui-side-split+.aminui-side.isCollapse+.aminui-body.el-container {
	.FlowFormFooter {
		left: 130px;
	}
}

.aminui-side+.aminui-body.el-container {
	.FlowFormFooter {
		left: 200px;
	}
}

.aminui-side.isCollapse+.aminui-body.el-container {
	.FlowFormFooter {
		left: 65px;
	}
}
</style>
