<template>
	<div class="page">
		<el-form :inline="true" class="query-form m-b-10" ref="searchForm" :model="searchForm"
			@keyup.enter.native="refreshList()" @submit.native.prevent>
			<!-- 搜索框-->
			<el-form-item label="姓名" prop="name">
				<el-input v-model="searchForm.name" placeholder="请输入姓名" clearable></el-input>
			</el-form-item>
			<el-form-item label="归属部门" prop="department">
				<SelectTree ref="officeTree" :props="{
					value: 'id',             // ID字段名
					label: 'name',         // 显示名称
					children: 'children'    // 子级字段名
				}" :url="`/system-server/sys/office/treeData?type=2`" :value="searchForm.department" :clearable="true"
					:accordion="true" size="default" @getValue="(value, label) => { searchForm.department = value }" />
			</el-form-item>
			<el-form-item label="联系电话" prop="mobile">
				<el-input v-model="searchForm.mobile" placeholder="请输入联系电话" clearable></el-input>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" @click="refreshList()" icon="el-icon-search">查询</el-button>
				<el-button @click="resetSearch()" icon="el-icon-refresh-right">重置</el-button>
			</el-form-item>
		</el-form>
		<div class="jp-table top" style="">
			<vxe-toolbar :refresh="{ query: refreshList }" ref="toolbarRef" export custom>
				<template #buttons>
					<!--          <el-button v-if="!haveComplete" type="primary" icon="el-icon-plus" @click="start()">新建</el-button>-->
					<el-button v-if="!haveComplete" type="primary" icon="el-icon-plus" @click="start()">新建</el-button>
					<span v-if="haveComplete" style="color: red">已存在离职申请，无法多次提交</span>
				</template>
			</vxe-toolbar>
			<div style="height: calc(100% - 90px)">
				<vxe-table border="inner" auto-resize resizable height="auto" :loading="loading" ref="clientTable"
					show-header-overflow show-overflow highlight-hover-row :print-config="{}" :export-config="{
						remote: true,
						filename: `入职登记信息${moment(new Date()).format('YYYY-MM-DD')}`,
						sheetName: '入职登记信息',
						exportMethod: exportMethod,
						types: ['xlsx'],
						modes: ['current', 'selected', 'all']
					}" :menu-config="{}" @sort-change="sortChangeHandle" :sort-config="{ remote: true }" :data="dataList"
					:checkbox-config="{}">
					<vxe-column type="seq" width="60" title="序号"></vxe-column>
					<vxe-column min-width="160" align="center" title="姓名" field="name">
						<template #default="scope">
							<el-link type="primary" :underline="false" v-if="hasPermission('depart:view')"
								@click="view(scope.row.id)">{{ scope.row.name }}</el-link>
							<span v-else>{{ scope.row.name }}</span>
						</template>
					</vxe-column>
					<vxe-column min-width="160" align="center" title="联系电话" field="mobile"></vxe-column>
					<vxe-column min-width="160" align="center" title="所属部门" field="departmentName"></vxe-column>
					<vxe-column min-width="100" title="状态" fixed="right" align="center" field="type">
						<template #default="scope">
							<el-button @click="detail(scope.row)"
								:type="$dictUtils.getDictLabel('status_info', scope.row.type, '')" effect="dark">{{
									$dictUtils.getDictLabel("status", scope.row.type, '未开始') }} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="100" title="交接状态" fixed="right" align="center" field="handoverType">
						<template #default="scope">
							<el-button @click="handoverDetail(scope.row)"
								:type="$dictUtils.getDictLabel('status_info', scope.row.handoverType, '')"
								effect="dark">
								{{ $dictUtils.getDictLabel("status", scope.row.handoverType, '未开始') }} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="100" title="电脑款项状态" fixed="right" align="center" field="computerType">
						<template #default="scope">
							<el-button @click="computerHandoverDetail(scope.row)"
								:type="$dictUtils.getDictLabel('status_info', scope.row.computerType, '')"
								effect="dark">
								{{ $dictUtils.getDictLabel("status", scope.row.computerType, '未开始') }} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="100" title="应收账款状态" fixed="right" align="center" field="accountsType">
						<template #default="scope">
							<el-button @click="accountsHandoverDetail(scope.row)"
								:type="$dictUtils.getDictLabel('status_info', scope.row.accountsType, '')"
								effect="dark">
								{{ $dictUtils.getDictLabel("status", scope.row.accountsType, '未开始') }} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="100" title="社保账款状态" fixed="right" align="center" field="securityType">
						<template #default="scope">
							<el-button @click="securityHandoverDetail(scope.row)"
								:type="$dictUtils.getDictLabel('status_info', scope.row.securityType, '')"
								effect="dark">
								{{ $dictUtils.getDictLabel("status", scope.row.securityType, '未开始') }} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="100" title="备用金状态" fixed="right" align="center" field="imprestType">
						<template #default="scope">
							<el-button @click="imprestHandoverDetail(scope.row)"
								:type="$dictUtils.getDictLabel('status_info', scope.row.imprestType, '')" effect="dark">
								{{ $dictUtils.getDictLabel("status", scope.row.imprestType, '未开始') }} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="100" title="底稿归档状态" fixed="right" align="center" field="draftType">
						<template #default="scope">
							<el-button @click="draftHandoverDetail(scope.row)"
								:type="$dictUtils.getDictLabel('status_info', scope.row.draftType, '')" effect="dark">
								{{ $dictUtils.getDictLabel("status", scope.row.draftType, '未开始') }} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="100" title="门卡回收状态" fixed="right" align="center" field="recoveryType">
						<template #default="scope">
							<el-button @click="recoveryHandoverDetail(scope.row)"
								:type="$dictUtils.getDictLabel('status_info', scope.row.recoveryType, '')"
								effect="dark">
								{{ $dictUtils.getDictLabel("status", scope.row.recoveryType, '未开始') }} </el-button>
						</template>
					</vxe-column>

					<vxe-column title="操作" width="200px" fixed="right" align="center">
						<template #default="scope">
							<div v-if="isAdmin">
								<el-button v-if="
									scope.row.type === '5' || scope.row.type === '4' || scope.row.type === '3'" text type="primary"
									@click="edit(scope.row.id)">修改</el-button>
								<el-button v-if="
									scope.row.type === '5' || scope.row.type === '4' || scope.row.type === '3'" text type="primary"
									@click="del(scope.row.id)">删除</el-button>
							</div>
							<div v-else>
								<el-button
									v-if="hasPermission('depart:edit') && scope.row.createById === $store.state.user.id && (scope.row.type === '1' || scope.row.type === '3')"
									text type="primary" @click="editForm(scope.row)">修改</el-button>
								<el-button
									v-if="hasPermission('depart:edit') && scope.row.createById === $store.state.user.id && (scope.row.type === '2')"
									text type="primary" @click="reback(scope.row)">撤回</el-button>
								<el-button
									v-if="hasPermission('depart:del') && scope.row.createById === $store.state.user.id && (scope.row.type === '1' || scope.row.type === '3' || scope.row.type === undefined || scope.row.type === '0')"
									text type="primary" @click="del(scope.row.id)">删除</el-button>
								<!--              审核-->
								<el-button v-if="scope.row.type === '2' && checkIsAudit(scope.row)" text type="primary"
									@click="examine(scope.row)">审核</el-button>
								<!--              被驳回后当前申请人重新调整-->
								<el-button
									v-if="scope.row.createById === $store.state.user.id && scope.row.type === '4'" text
									type="primary" @click="adjust(scope.row)">驳回调整</el-button>
								<el-button
									v-if="(scope.row.createById === $store.state.user.id) && scope.row.type === '5' && (scope.row.handoverType === undefined || scope.row.handoverType === '0' || scope.row.handoverType === '1' || scope.row.handoverType === '3')"
									text type="primary" @click="handover(scope.row)">离职交接</el-button>
								<!--离职交接撤回-->
								<el-button
									v-if="scope.row.type === '5' && scope.row.handoverType === '2' && (scope.row.createById === $store.state.user.id)"
									text type="primary" @click="rebackHandover(scope.row)">撤回离职交接</el-button>
								<el-button
									v-if="scope.row.createById === $store.state.user.id && scope.row.type === '5' && scope.row.handoverType === '4'"
									text type="primary" @click="adjustHandover(scope.row)">驳回调整</el-button>


								<el-button
									v-if="scope.row.recoveryType === '5' && (scope.row.createById === $store.state.user.id)"
									text type="primary" @click="toHref(scope.row)">离职证明下载</el-button>

							</div>
						</template>
					</vxe-column>
				</vxe-table>
				<vxe-pager background :current-page="tablePage.currentPage" :page-size="tablePage.pageSize"
					:total="tablePage.total" :page-sizes="[10, 20, 100, 1000, { label: '全量数据', value: 1000000 }]"
					:layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
					@page-change="currentChangeHandle">
				</vxe-pager>
			</div>
		</div>
		<DepartRegistrationEditForm ref="departRegistrationEditForm" @refreshList="refreshList">
		</DepartRegistrationEditForm>
	</div>
</template>

<script>
import enrollmentRegistrationService from '@/api/human/enrollment/EnrollmentRegistrationService'
import SelectTree from '@/components/treeSelect/treeSelect.vue'
import handoverService from '@/api/human/depart/HandoverService'
import departRegistrationService from '@/api/human/depart/DepartRegistrationService'
import processService from '@/api/flowable/ProcessService'
import userService from '@/api/sys/UserService'
import taskService from '@/api/flowable/TaskService'
import DepartRegistrationEditForm from "./DepartRegistrationEditForm";
import OSSSerivce, {
	toHrefByUrlAndName
} from '@/api/sys/OSSService'
import pick from "lodash.pick";
export default {
	data() {
		return {
			haveComplete: false,
			num: 0,
			searchForm: {
				name: '',
				department: '',
				mobile: '',
			},
			dataList: [],
			tablePage: {
				total: 0,
				currentPage: 1,
				pageSize: 10,
				orders: []
			},
			tableKey: '',
			loading: false,
			processDefinitionAuditId: '',
			procDefAuditKey: '',
			handoverDefId: '',
			handoverDefAuditKey: '',
			isAdmin: false,
			create: ''
		}
	},
	created() {
		this.ossService = new OSSSerivce()
	},
	components: {
		SelectTree,
		DepartRegistrationEditForm
	},
	computed: {
		userName() {
			return this.$store.state.user.name
		},
		user() {
			this.createName = this.$store.state.user.name
			return this.$store.state.user
		}
	},
	mounted() {
		this.$nextTick(() => {
			//将表格和工具栏进行关联
			const $table = this.$refs.clientTable;
			const $toolbar = this.$refs.toolbarRef;
			$table.connect($toolbar);
		})
		this.refreshList()

	},
	activated() {
		this.refreshList()
	},
	methods: {
		// 查看
		view(id) {
			this.$refs.departRegistrationEditForm.init('view', id)
		},
		// 新增
		add() {
		},
		toHref(row) {
			toHrefByUrlAndName(row.dimissionProveUrl, row.name + "离职证明")
		},
		// 修改
		edit(id) {
			id = id || this.$refs.clientTable.getCheckboxRecords().map(item => {
				return item.id
			})[0]
			this.$refs.departRegistrationEditForm.init('edit', id)
		},
		// 查询当前用户是否是管理员用户
		checkIsAdmin() {
			userService.is().then((data) => {
				this.isAdmin = data
			})
		},
		// 获取数据列表
		refreshList() {
			this.loading = true
			departRegistrationService.list({
				'current': this.tablePage.currentPage,
				'size': this.tablePage.pageSize,
				'orders': this.tablePage.orders,
				...this.searchForm
			}).then((data) => {
				this.dataList = data.records
				this.tablePage.total = data.total
				this.tableKey = Math.random()
				this.loading = false
			})
			this.checkIsAdmin()
			processService.getByName('离职申请').then((data) => {
				if (!this.commonJS.isEmpty(data.id)) {
					this.processDefinitionAuditId = data.id
					this.procDefAuditKey = data.key
				}
			})
			processService.getByName('离职交接申请').then((data) => {
				if (!this.commonJS.isEmpty(data.id)) {
					this.handoverDefId = data.id
					this.handoverDefAuditKey = data.key
				}
			})
			departRegistrationService.selectComplete().then((data) => {
				this.haveComplete = data
			})
		},
		// 当前页
		currentChangeHandle({ currentPage, pageSize }) {
			this.tablePage.currentPage = currentPage
			this.tablePage.pageSize = pageSize
			this.refreshList()
		},
		// 排序
		sortChangeHandle(column) {
			this.tablePage.orders = []
			if (column.order != null) {
				this.tablePage.orders.push({ column: this.$utils.toLine(column.property), asc: column.order === 'asc' })
			}
			this.refreshList()
		},
		resetSearch() {
			this.$refs.searchForm.resetFields()
			this.refreshList()
		},
		start() {
			//发起流程前判断是否已经完善了个人信息 及 入住登记表中是否有当然登录人的信息
			var userId = this.$store.state.user.id
			enrollmentRegistrationService.findByUserId(userId).then((data) => {
				if (data == 0) {
					this.$message.error('请先完善个人信息再发起离职申请!')
					throw new Error('请先完善个人信息再发起离职申请!')
				} else {
					// 读取流程表单
					let tabTitle = `发起流程【离职申请】`
					let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了 [离职申请]`
					taskService.getTaskDef({
						procDefId: this.processDefinitionAuditId,
						status: 'startAndHold'
					}).then((data) => {
						this.$router.push({
							path: '/flowable/task/TaskForm',
							query: {
								...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
								procDefId: this.processDefinitionAuditId,
								procDefKey: this.procDefKey,
								status: 'startAndHold',
								title: tabTitle,
								formType: data.formType,
								formUrl: data.formUrl,
								formTitle: processTitle,
								businessId: 'false',
								isShow: false,
								routePath: '/human/depart/registration/DepartRegistrationList'
							}
						})
					})
				}
			})
		},
		editForm(row) {
			// 暂存修改
			let status = ''
			if (row.type === '1') {
				status = 'startAndHold'
			}
			// 撤回或者驳回修改
			if (row.type === '3') {
				status = 'startAndClose'
			} else if (row.status === '4') {
				status = 'reapplyFlag'
			}
			// 读取流程表单
			let tabTitle = `发起流程【离职申请】`
			let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了 [离职申请]`
			taskService.getTaskDef({
				procDefId: this.processDefinitionAuditId,
				businessId: row.id,
				businessTable: 'human_resources_depart_registration',
				status: status
			}).then((data) => {
				this.$router.push({
					path: '/flowable/task/TaskForm',
					query: {
						...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
						procDefId: this.processDefinitionAuditId,
						procDefKey: this.procDefKey,
						status: status,
						title: tabTitle,
						formType: data.formType,
						formUrl: data.formUrl,
						formTitle: processTitle,
						businessTable: 'human_resources_depart_registration',
						businessId: row.id,
						isShow: false,
						routePath: '/human/depart/registration/DepartRegistrationList'
					}
				})
			})
		},
		// 查看离职申请流程结果
		detail(row) {
			if (row.type !== '0' && row.type !== '1') {
				// eslint-disable-next-line eqeqeq
				taskService.getTaskDef({
					procInsId: row.procInsId,
					procDefId: this.processDefinitionAuditId
				}).then((data) => {
					this.$router.push({
						path: '/flowable/task/TaskFormDetail',
						query: {
							...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
							isShow: 'false',
							readOnly: true,
							title: '离职申请' + '流程详情',
							formTitle: '离职申请' + '流程详情',
							businessId: row.id,
							status: 'reback'
						}
					})
				})
			}
		},
		// 查看离职交接流程结果
		handoverDetail(row) {
			if (row.handoverType !== '0' && row.handoverType !== '1') {
				// eslint-disable-next-line eqeqeq
				taskService.getTaskDef({
					procInsId: row.handoverProcInsId,
					procDefId: this.handoverDefId
				}).then((data) => {
					this.$router.push({
						path: '/flowable/task/TaskFormDetail',
						query: {
							...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
							isShow: 'false',
							readOnly: true,
							title: '离职申请' + '流程详情',
							formTitle: '离职申请' + '流程详情',
							businessId: row.handoverId,
							status: 'reback'
						}
					})
				})
			}
		},
		// 查看备用金流程结果
		imprestHandoverDetail(row) {
			if (row.imprestType !== '0' && row.imprestType !== '1') {
				// eslint-disable-next-line eqeqeq
				taskService.getTaskDef({
					procInsId: row.imprestProcInsId,
					procDefId: row.imprestProcDefId
				}).then((data) => {
					this.$router.push({
						path: '/flowable/task/TaskFormDetail',
						query: {
							...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
							isShow: 'false',
							readOnly: true,
							title: '备用金检查' + '流程详情',
							formTitle: '备用金检查' + '流程详情',
							businessId: row.imprestId,
							status: 'reback'
						}
					})
				})
			}
		},
		// 查看底稿归档流程结果
		draftHandoverDetail(row) {
			if (row.draftType !== '0' && row.draftType !== '1') {
				// eslint-disable-next-line eqeqeq
				taskService.getTaskDef({
					procInsId: row.draftProcInsId,
					procDefId: row.draftProcDefId
				}).then((data) => {
					this.$router.push({
						path: '/flowable/task/TaskFormDetail',
						query: {
							...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
							isShow: 'false',
							readOnly: true,
							title: '底稿归档检查' + '流程详情',
							formTitle: '底稿归档检查' + '流程详情',
							businessId: row.draftId,
							status: 'reback'
						}
					})
				})
			}
		},
		// 查看门卡回收流程结果
		recoveryHandoverDetail(row) {
			if (row.recoveryType !== '0' && row.recoveryType !== '1') {
				// eslint-disable-next-line eqeqeq
				taskService.getTaskDef({
					procInsId: row.recoveryProcInsId,
					procDefId: row.recoveryProcDefId
				}).then((data) => {
					this.$router.push({
						path: '/flowable/task/TaskFormDetail',
						query: {
							...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
							isShow: 'false',
							readOnly: true,
							title: '门卡回收' + '流程详情',
							formTitle: '门卡回收' + '流程详情',
							businessId: row.recoveryId,
							status: 'reback'
						}
					})
				})
			}
		},
		// 查看电脑款项流程结果
		computerHandoverDetail(row) {
			if (row.computerType !== '0' && row.computerType !== '1') {
				// eslint-disable-next-line eqeqeq
				taskService.getTaskDef({
					procInsId: row.computerProcInsId,
					procDefId: row.computerProcDefId
				}).then((data) => {
					this.$router.push({
						path: '/flowable/task/TaskFormDetail',
						query: {
							...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
							isShow: 'false',
							readOnly: true,
							title: '电脑款项检查' + '流程详情',
							formTitle: '电脑款项检查' + '流程详情',
							businessId: row.computerId,
							status: 'reback'
						}
					})
				})
			}
		},
		// 查看应收账款流程结果
		accountsHandoverDetail(row) {
			if (row.accountsType !== '0' && row.accountsType !== '1') {
				// eslint-disable-next-line eqeqeq
				taskService.getTaskDef({
					procInsId: row.accountsProcInsId,
					procDefId: row.accountsProcDefId
				}).then((data) => {
					this.$router.push({
						path: '/flowable/task/TaskFormDetail',
						query: {
							...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
							isShow: 'false',
							readOnly: true,
							title: '应收账款检查' + '流程详情',
							formTitle: '应收账款检查' + '流程详情',
							businessId: row.accountsId,
							status: 'reback'
						}
					})
				})
			}
		},
		// 查看社保账款流程结果
		securityHandoverDetail(row) {
			if (row.securityType !== '0' && row.securityType !== '1') {
				// eslint-disable-next-line eqeqeq
				taskService.getTaskDef({
					procInsId: row.securityProcInsId,
					procDefId: row.securityProcDefId
				}).then((data) => {
					this.$router.push({
						path: '/flowable/task/TaskFormDetail',
						query: {
							...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
							isShow: 'false',
							readOnly: true,
							title: '社保账款检查' + '流程详情',
							formTitle: '社保账款检查' + '流程详情',
							businessId: row.securityId,
							status: 'reback'
						}
					})
				})
			}
		},
		// 自定义服务端导出
		exportMethod({ options }) {
			// 传给服务端的参数
			const params = {
				'current': this.tablePage.currentPage,
				'size': this.tablePage.pageSize,
				'orders': this.tablePage.orders,
				...this.searchForm,
				filename: options.filename,
				sheetName: options.sheetName,
				isHeader: options.isHeader,
				original: options.original,
				mode: options.mode,
				selectIds: options.mode === 'selected' ? options.map(item => item.id) : [],
				exportFields: options.columns.map(column => column.property)
			}
			return departRegistrationService.exportExcel(params).then((res) => {
				// 将二进制流文件写入excel表，以下为重要步骤
				this.$utils.downloadExcel(res, options.filename)
			}).catch(function (err) {
				if (err.response) {
					// console.log(err.response)
				}
			})
		},
		// 删除
		del(id) {
			let ids = id || this.$refs.clientTable.getCheckboxRecords().map(item => {
				return item.id
			}).join(',')
			this.$confirm(`确定删除所选项吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				this.loading = true
				departRegistrationService.remove(ids).then((data) => {
					this.$message.success(data)
					this.refreshList()
					this.loading = false
				})
			})
		},
		// 撤回
		reback(row) {
			this.$confirm(`确定撤回流程吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				processService.revokeProcIns(row.procInsId).then((data) => {
					let param = { type: '3', id: row.id }
					departRegistrationService.updateStatusById(param)
					this.$message.success('回退成功')
					this.refreshList()
				})
			})
		},
		// 审核
		examine(row) {
			departRegistrationService.findById(row.id).then((data) => {
				if (data.type !== '2') { // status的值不等于“审核中”，就弹出提示
					this.$message.error('数据已发生改变或不存在，请刷新数据')
					this.refreshList()
				} else {
					this.todo(row)
				}
			})
		},
		// 审核或重新调整跳转
		todo(row) {
			let cUser = false
			taskService.getTaskDefInfo({
				taskId: row.taskId
			}).then((data) => {
				this.$router.push({
					path: '/flowable/task/TaskForm',
					query: {
						...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title', 'businessId'),
						isShow: false,
						formReadOnly: true,
						formTitle: `${data.taskName}`,
						cUser: cUser,
						title: `审批【${data.taskName || ''}】`,
						routePath: '/human/depart/registration/DepartRegistrationList'   // 数据处理后需要跳转的页面路径
					}
				})
			})
		},
		// 驳回后调整
		adjust(row) {
			departRegistrationService.findById(row.id).then((data) => {
				console.log('data', data)
				if (data.type !== '4') { // status的值不等于“驳回”，就弹出提示
					this.$message.error('数据已发生改变或不存在，请刷新数据')
					this.refreshList()
				} else {
					this.todo(row)
				}
			})
		},
		// 查询当前登录人是否是数据的审核人
		checkIsAudit(row) {
			let loginUserId = this.$store.state.user.id  // 获取当前登录用户id
			if (this.commonJS.isNotEmpty(row.auditUserIds)) {
				for (const userId of row.auditUserIds) {
					if (userId === loginUserId) {  // 当数据的审核人中包含当前登录人id时，返回true
						return true
					}
				}
			}
			return false
		},
		handover(row) {
			// 读取流程表单
			let tabTitle = `发起流程【离职交接】`
			let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了 [离职交接]`
			let businessId = ''
			if (this.commonJS.isNotEmpty(row.handoverId)) {
				businessId = row.handoverId
			} else {
				businessId = row.id
			}
			console.log(businessId);

			taskService.getTaskDef({
				procDefId: this.handoverDefId,
				status: 'startAndHold'
			}).then((data) => {
				console.log(data);
				this.$router.push({
					path: '/flowable/task/TaskForm',
					query: {
						...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
						procDefId: this.handoverDefId,
						procDefKey: this.handoverDefAuditKey,
						status: 'startAndHold',
						title: tabTitle,
						formType: data.formType,
						formUrl: data.formUrl,
						formTitle: processTitle,
						businessId: businessId,
						isShow: false,
						routePath: '/human/depart/registration/DepartRegistrationList'
					}
				})
			})
		},
		// 撤回离职交接
		rebackHandover(row) {
			this.$confirm(`确定要撤回该申请吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(async () => {
				await handoverService.findById(row.handoverId).then((data) => {
					if (data.type !== '2') { // status的值不等于“审核中”，就弹出提示
						this.$message.error('数据已发生改变或不存在，请刷新数据')
						this.refreshList()
					} else {
						processService.revokeProcIns(row.handoverProcInsId).then((data) => {
							let form = { type: '3', id: row.handoverId }
							handoverService.updateStatusById(form)
							this.$message.success(data)
							this.refreshList()
						})
					}
				})
			})
		},
		adjustHandover(row) {
			handoverService.findById(row.handoverId).then((data) => {
				if (data.type !== '4') { // status的值不等于“驳回”，就弹出提示
					this.$message.error('数据已发生改变或不存在，请刷新数据')
					this.refreshList()
				} else {
					row.id = row.handoverId
					this.handover(row)
				}
			})
		},
	}
}
</script>
