<template>
	<div class="page" >
		<el-form :inline="true" class="query-form" 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="no">
				<el-input v-model="searchForm.no" placeholder="请输入项目编号" clearable></el-input>
			</el-form-item>
			<el-form-item v-if="showHideItem" label="登记人" prop="createById">
				<UserSelect :limit='1' :readonly="true" :modelValue="searchForm.createById" @update:modelValue='(value) => {searchForm.createById = value}'></UserSelect>
			</el-form-item>
			<el-form-item v-if="showHideItem" label="项目负责人" prop="projectManagerName">
				<el-input v-model="searchForm.projectManagerName" placeholder="请输入项目负责人" clearable></el-input>
			</el-form-item>
			<el-form-item v-if="showHideItem" label="合同名称" prop="contractName">
				<el-input v-model="searchForm.contractName" placeholder="请输入合同名称" clearable></el-input>
			</el-form-item>
			<el-form-item v-if="showHideItem" label="委托方" prop="clientName">
				<el-input v-model="searchForm.clientName" placeholder="请输入委托方" clearable></el-input>
			</el-form-item>
			<el-form-item v-if="showHideItem" label="创建时间" prop="createDates">
				<el-date-picker
					placement="bottom-start"
					format="YYYY-MM-DD HH:mm:ss"
					value-format="YYYY-MM-DD HH:mm:ss"
					v-model="searchForm.createDates"
					type="datetimerange"
					range-separator="至"
					start-placeholder="开始日期"
					end-placeholder="结束日期">
				</el-date-picker>
			</el-form-item>
			<el-form-item v-if="showHideItem" label="状态" prop="status">
				<el-select v-model="searchForm.status" placeholder="请选择" style="width:100%;" clearable>
					<el-option
						v-for="item in $dictUtils.getDictList('program_project_list_info_status')"
						:key="item.value"
						:label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item v-if="showHideItem" label="一级校审状态" prop="status1">
				<el-select v-model="searchForm.status1" placeholder="请选择" style="width:100%;" clearable>
					<el-option
						v-for="item in $dictUtils.getDictList('program_project_list_info_status')"
						:key="item.value"
						:label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item v-if="showHideItem" label="二级校审状态" prop="status2">
				<el-select v-model="searchForm.status2" placeholder="请选择" style="width:100%;" clearable>
					<el-option
						v-for="item in $dictUtils.getDictList('program_project_list_info_status')"
						:key="item.value"
						:label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item v-if="showHideItem" label="三级校审状态" prop="status3">
				<el-select v-model="searchForm.status3" placeholder="请选择" style="width:100%;" clearable>
					<el-option
						v-for="item in $dictUtils.getDictList('program_project_list_info_status')"
						:key="item.value"
						:label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item v-if="showHideItem" label="签发单状态" prop="issuedStatus">
				<el-select v-model="searchForm.issuedStatus" placeholder="请选择" style="width:100%;" clearable>
					<el-option
						v-for="item in $dictUtils.getDictList('program_project_list_info_status')"
						:key="item.value"
						:label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item v-if="showHideItem" label="归档状态" prop="archiveStatus">
				<el-select v-model="searchForm.archiveStatus" placeholder="请选择" style="width:100%;" clearable>
					<el-option
						v-for="item in $dictUtils.getDictList('program_project_archive_list_info_status')"
						:key="item.value"
						:label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
			</el-form-item>

			<el-form-item>
				<el-button type="default" @click="showHide" :icon="showHideIcon">{{showHideName}}</el-button>
				<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" >
			<vxe-toolbar ref="toolbarRef" :refresh="{query: refreshList}" export custom>
				<template #buttons>
					<!--          <el-button v-if="hasPermission('program:registered:add')" type="primary" icon="el-icon-plus" @click="start()">新建</el-button>-->
					<el-button v-if="hasPermission('jy_project:info:add')" type="primary" icon="el-icon-plus" @click="start()">新建</el-button>
					<el-button v-if="hasPermission('jy_project:info:del')" type="danger"   icon="el-icon-delete" @click="deleteAll()" :disabled="$refs.typeDictTable && $refs.typeDictTable.getCheckboxRecords().length === 0" plain>删除</el-button>
				</template>
			</vxe-toolbar>
			<div class="jp-table-body">
				<vxe-table
					border="inner"
					auto-resize
					resizable
					height="auto"
					:loading="loading"
					size="small"
					ref="typeDictTable"
					show-header-overflow
					show-overflow
					highlight-hover-row
					:menu-config="{}"
					@sort-change="sortChangeHandle"
					:export-config="{
                    remote: true,
                    filename: `嘉溢项目数据${moment(new Date()).format('YYYY-MM-DD')}`,
                    sheetName: `嘉溢项目数据${moment(new Date()).format('YYYY-MM-DD')}`,
                    exportMethod: exportMethod,
                    types: ['xlsx'],
                    modes: ['current', 'selected', 'all']
                  }"
					:sort-config="{remote:true}"
					:data="dataList"
					:tree-config="{}"
					:checkbox-config="{}">
					<vxe-column type="seq" width="60" title="序号"></vxe-column>
					<vxe-column type="checkbox" width="50" ></vxe-column>
					<vxe-column min-width="170" align="center" title="项目名称" field="name" >
						<template #default="scope">
							<el-link  type="primary" :underline="false" v-if="hasPermission('jy_project:info:view')" @click="view(scope.row)">{{scope.row.name}}</el-link>
							<el-link  type="primary" :underline="false" v-else-if="hasPermission('jy_project:info:view')" @click="view(scope.row)">{{scope.row.name}}</el-link>
							<span v-else>{{scope.row.name}}</span>
						</template>
					</vxe-column>
					<vxe-column min-width="100" align="center" title="项目编号" field="no"></vxe-column>
					<vxe-column min-width="180" align="center" title="合同名称" field="contractName">
						<template #default="scope">
							<el-link  type="primary" :underline="false" v-if="hasPermission('jy_project:info:view')" @click="viewContract(scope.row.contractId)">{{scope.row.contractName}}</el-link>
							<el-link  type="primary" :underline="false" v-else-if="hasPermission('jy_project:info:view')" @click="viewContract(scope.row.contractId)">{{scope.row.contractName}}</el-link>
							<span v-else>{{scope.row.name}}</span>
						</template>
					</vxe-column>
					<vxe-column min-width="100" align="center" title="负责人" field="projectLeader"></vxe-column>
					<vxe-column min-width="180" align="center" title="主委托方" field="primaryLinkman"></vxe-column>
					<vxe-column min-width="100" align="center" title="创建人" field="createById"></vxe-column>
					<vxe-column min-width="120" align="center" title="创建日期" field="createTime"></vxe-column>

					<vxe-column  min-width="150px" align="center" title="登记状态" field="status" >
						<template #default="scope">
							<el-button @click="registeredDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.status, '')" effect="dark" >{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.status, '未登记')}} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="120" align="center" title="一级校审" field="firstInstanceStatus">
						<template #default="scope">
							<el-button  @click="firstAuditDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.firstInstanceStatus, '')" effect="dark" >{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.firstInstanceStatus, '未登记')}} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="120" align="center" title="二级校审" field="secondInstanceStatus">
						<template #default="scope">
							<el-button  @click="secondAuditDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.secondInstanceStatus, '')" effect="dark" >{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.secondInstanceStatus, '未登记')}} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="120" align="center" title="三级校审" field="thirdInstanceStatus">
						<template #default="scope">
							<el-button  @click="thirdAuditDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.thirdInstanceStatus, '')" effect="dark" >{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.thirdInstanceStatus, '未登记')}} </el-button>
						</template>
					</vxe-column>
					<vxe-column  min-width="150px" align="center" title="报告签发" field="reportIssuance" >
						<template #default="scope">
							<el-button  @click="issuedDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.reportIssuance, '')" effect="dark" >{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.reportIssuance, '未登记')}} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="120" align="center" title="项目归档" field="revicewStatus">
						<template #default="scope">
							<el-button @click="archiveDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.revicewStatus, '')" effect="dark" >{{$dictUtils.getDictLabel("program_project_archive_list_info_status", scope.row.revicewStatus, '未登记')}} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="120" align="center" title="外审" field="outInstance">
						<template #default="scope">
							<el-button @click="archiveDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.outInstance, '')" effect="dark" >{{$dictUtils.getDictLabel("program_project_archive_list_info_status", scope.row.outInstance, '未登记')}} </el-button>
						</template>
					</vxe-column>
					<vxe-column min-width="120" align="center" title="报批签发" field="reportsSubmit">
						<template #default="scope">
							<el-button @click="archiveDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.reportsSubmit, '')" effect="dark" >{{$dictUtils.getDictLabel("program_project_archive_list_info_status", scope.row.reportsSubmit, '未登记')}} </el-button>
						</template>
					</vxe-column>
					<vxe-column title="操作" min-width="200px" fixed="right" align="center">
						<template  #default="scope">
							<el-button v-if="hasPermission('program:registered:edit')&&(scope.row.status === '1' || scope.row.status === '3')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))" text type="primary"  @click="registeredPush(scope.row)">修改</el-button>
							<!--管理员角色登记完成后可修改-->
							<el-button v-if="hasPermission('jy_project:info:edit')&&scope.row.status === '5' && isAdmin" text type="primary"  @click="edit(scope.row.id)">修改</el-button>
							<!--项目负责人修改-->
							<el-button v-if="hasPermission('jy_project:info:edit')&&scope.row.status === '5' && scope.row.projectLeader === $store.state.user.id" text type="primary"  @click="edit(scope.row.id)">修改</el-button>
							<el-button v-if="hasPermission('jy_project:info:edit')&&scope.row.status === '2'&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))" text type="primary"  @click="registeredReback(scope.row)">撤回</el-button>
							<!--项目登记  审核-->
							<el-button v-if="scope.row.status==='2' && checkIsAudit(scope.row)" text type="primary"   @click="examine(scope.row)">登记审核</el-button>
							<!--项目登记  被驳回后当前申请人重新调整-->
							<el-button v-if="hasPermission('jy_project:info:edit')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.status === '4'" text type="primary"   @click="adjust(scope.row)">驳回调整</el-button>

							<el-button v-if="hasPermission('jy_project:info:del')&&(scope.row.status === '1' || scope.row.status === '3')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))" text type="primary"  @click="del(scope.row.id)">删除</el-button>
							<!--管理员角色登记完成后可删除-->
							<el-button v-if="hasPermission('jy_project:info:del')&&scope.row.status === '5' && isAdmin" text type="primary"  @click="del(scope.row.id)">删除</el-button>

							<!--              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.status === '5' && commonJS.isEmpty(scope.row.reportNo) && scope.row.createBy === $store.state.user.id" text type="primary"  @click="saveReportNo(scope.row.id)">生成报告号</el-button>-->

<!--							&lt;!&ndash; 一级校审  发起&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:edit')&&scope.row.status === '5' &&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&(scope.row.status1 === '0'||scope.row.status1 === '1'||scope.row.status1 === '3')" text type="primary"  @click="firstAuditPush(scope.row)">一级校审</el-button>-->
<!--							&lt;!&ndash; 一级校审  撤回&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:edit')&&scope.row.status1 === '2' &&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))" text type="primary"  @click="firstAuditReback(scope.row)">校审撤回</el-button>-->
<!--							&lt;!&ndash; 一级校审  审核&ndash;&gt;-->
<!--							<el-button v-if="scope.row.status1==='2' && checkIsAuditFirst(scope.row)" text type="primary"   @click="examineFirst(scope.row)">一级校审审核</el-button>-->
<!--							&lt;!&ndash; 一级校审  被驳回后当前申请人重新调整&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:edit')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.status1 === '4'" text type="primary"   @click="adjustFirst(scope.row)">驳回调整</el-button>-->

<!--							&lt;!&ndash; 二级校审  发起&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:edit')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.status1 === '5'&&(scope.row.status2 === '0'||scope.row.status2 === '1'||scope.row.status2 === '3')" text type="primary"  @click="secondAuditPush(scope.row)">二级校审</el-button>-->
<!--							&lt;!&ndash; 二级校审  撤回&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:edit')&&scope.row.status2 === '2'&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))" type="text"  @click="secondAuditReback(scope.row)">校审撤回</el-button>-->
<!--							&lt;!&ndash; 二级校审  审核&ndash;&gt;-->
<!--							<el-button v-if="scope.row.status2==='2' && checkIsAuditSecond(scope.row)" text type="primary"  @click="examineSecond(scope.row)">二级校审审核</el-button>-->
<!--							&lt;!&ndash; 二级校审  被驳回后当前申请人重新调整&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:edit')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.status2 === '4'" text type="primary"  @click="adjustSecond(scope.row)">驳回调整</el-button>-->

<!--							&lt;!&ndash; 三级校审  发起&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:edit')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.status2 === '5' &&(scope.row.status3 === '0'||scope.row.status3 === '1'||scope.row.status3 === '3')" text type="primary"  @click="thirdAuditPush(scope.row)">三级校审</el-button>-->
<!--							&lt;!&ndash; 三级校审  撤回&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:edit')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.status3 === '2'" text type="primary"  @click="thirdAuditReback(scope.row)">校审撤回</el-button>-->
<!--							&lt;!&ndash; 三级校审  审核&ndash;&gt;-->
<!--							<el-button v-if="scope.row.status3==='2' && checkIsAuditThird(scope.row)" text type="primary"   @click="examineThird(scope.row)">三级校审审核</el-button>-->
<!--							&lt;!&ndash; 三级校审  被驳回后当前申请人重新调整&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:edit')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.status3 === '4'" text type="primary"   @click="adjustThird(scope.row)">驳回调整</el-button>-->

<!--							&lt;!&ndash;三神结束后，评估报告签发前进行资产评估项目（校对）&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:proo')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.status3 === '5'&&scope.row.issuedStatus === '0'" text type="primary"  @click="proofread(scope.row.id)">校对</el-button>-->
<!--							&lt;!&ndash;报告签发&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:browse')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id)) &&scope.row.status3 === '5' && (scope.row.issuedStatus === null ||scope.row.issuedStatus === undefined ||scope.row.issuedStatus === '' ||scope.row.issuedStatus === '0' || scope.row.issuedStatus === '1' || scope.row.issuedStatus === '3')" text type="primary"  @click="issued(scope.row)">签发</el-button>-->
<!--							&lt;!&ndash;报告签发撤回&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:browse')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id)) && scope.row.issuedStatus === '2'" text type="primary"  @click="issuedReback(scope.row)">签发撤回</el-button>-->
<!--							&lt;!&ndash; 报告签发  审核&ndash;&gt;-->
<!--							<el-button v-if="scope.row.issuedStatus==='2' && checkIsAuditIssued(scope.row)" text type="primary"  @click="examineIssued(scope.row)">签发审核</el-button>-->
<!--							&lt;!&ndash; 报告签发  被驳回后当前申请人重新调整&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:browse')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.issuedStatus === '4'" text type="primary"  @click="adjustIssued(scope.row)">驳回调整</el-button>-->

<!--							&lt;!&ndash;评估报告装订后的审核&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:browse')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.issuedStatus === '5'&&scope.row.archiveStatus === '0'" text type="primary" @click="browse(scope.row.id)">装订自校</el-button>-->

<!--							&lt;!&ndash; 项目归档&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:edit')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.issuedStatus === '5' &&(scope.row.archiveStatus === '0'||scope.row.archiveStatus === '1'||scope.row.archiveStatus === '3'||scope.row.archiveStatus === '6')" text type="primary" @click="archivePush(scope.row)">项目归档</el-button>-->
<!--							&lt;!&ndash; 项目归档撤回&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:edit')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.archiveStatus === '2'" text type="primary" @click="archiveReback(scope.row)">项目归档撤回</el-button>-->
<!--							&lt;!&ndash; 项目归档  审核&ndash;&gt;-->
<!--							<el-button v-if="scope.row.archiveStatus==='2' && checkIsAuditArchive(scope.row)" text type="primary"  @click="examineArchive(scope.row)">归档审核</el-button>-->
<!--							&lt;!&ndash; 项目归档  被驳回后当前申请人重新调整&ndash;&gt;-->
<!--							<el-button v-if="hasPermission('program:registered:edit')&&(scope.row.createBy === $store.state.user.id||haveProjectIds.includes(scope.row.id))&&scope.row.archiveStatus === '4'" text type="primary"  @click="adjustArchive(scope.row)">驳回调整</el-button>-->

							<!--一级校审ftl文件下载-->
							<!--              <el-button v-if="hasPermission('program:registered:edit')" text type="primary"  icon="el-icon-circle-check"  @click="downloadFirstAuditTpl(scope.row)">一级校审下载</el-button>-->
							<!--              <el-button v-if="hasPermission('program:registered:edit')" text type="primary"  icon="el-icon-circle-check"  @click="downloadSecondAuditTpl(scope.row)">二级校审下载</el-button>-->
							<!--              <el-button v-if="hasPermission('program:registered:edit')" text type="primary"  icon="el-icon-circle-check"  @click="downloadThirdlyAuditTpl(scope.row)">三级校审下载</el-button>-->

							<!--自校功能ftl文件下载-->
							<!--              <el-button v-if="hasPermission('program:registered:edit')" text type="primary"  icon="el-icon-circle-check"  @click="downloadProofreadAuditTpl(scope.row)">校对审核</el-button>-->
							<!--              <el-button v-if="hasPermission('program:registered:edit')" text type="primary"  icon="el-icon-circle-check"  @click="downloadAuditRecordFormAfterBindingTpl(scope.row)">评估报告装订后</el-button>-->

							<!--报告签发单-->
							<!--              <el-button v-if="hasPermission('program:registered:edit')" text type="primary"  icon="el-icon-circle-check"  @click="downloadReportAusstellungTpl(scope.row)">报告签发单</el-button>-->

						</template>
					</vxe-column>
				</vxe-table>
				<vxe-pager
					background
					size="small"
					: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>
		<ProjectDia  ref="projectDia" @refreshDataList="refreshList"></ProjectDia>
		<ProjectFormUpdate ref="projectFormUpdate" @refreshDataList="refreshList"></ProjectFormUpdate>
		<ProofreadForm  ref="proofreadForm" @refreshDataList="refreshList"></ProofreadForm>
		<ProofreadBrowseForm  ref="proofreadBrowseForm" @refreshDataList="refreshList"></ProofreadBrowseForm>
		<ContractAddForm ref="contractAddForm"></ContractAddForm>
	</div>
</template>

<script>
	import taskService from '@/api/flowable/taskService'
	import ProjectInfoService from "@/api/jy/ProjectInfoService";
	import userService from '@/api/sys/userService'
	import processService from '@/api/flowable/processService'
	import pick from 'lodash.pick'
	import ProjectDia from './ProjectDia'
	import ContractAddForm from '../workContractInfo/ContractAddForm'
export default {
	data(){
		return {
			applyUserName: '',
			showHideItem: false,
			showHideIcon: 'el-icon-arrow-down',
			showHideName: '展示',
			searchForm: {
				name: '',
				no: '',
				createById: '',
				primaryLinkman: '',//委托方
				contractName: '',
				projectLeader:'',//项目负责人
				createDates: [],
				status: '',
				firstInstance: '',  // 一级校审状态
				secondInstance: '',	// 二级校审状态
				thirdInstance: '',	// 三级校审状态
				reportIssuance: '',	// 报告签发
				outIssuance:'',//外审
				reportsSubmit:'',//报批签发
				reviewStatus:'',//归档状态
			},
			dataList: [],
			tablePage: {
				total: 0,
				currentPage: 1,
				pageSize: 10,
				orders: []
			},
			createName: '',
			loading: false,
			isAdmin: false,
			processDefinitionId:'',
			procDefKey:'',
			haveProjectIds:''
		}
	},
	ProjectInfoService:null,
	created(){
		this.projectInfoService=new ProjectInfoService()
	},
	components:{
		ProjectDia,
		ContractAddForm
	},
	mounted(){
		this.$nextTick(() => {
			// 将表格和工具栏进行关联
			const $table = this.$refs.typeDictTable;
			const $toolbar = this.$refs.toolbarRef;
			$table.connect($toolbar);
		});
		this.refreshList();
	},
	activated(){
		this.is()
		this.refreshList()
	},
	computed:{
		userName () {
			return this.$store.state.user.name
		},
		user () {
			this.createName = this.$store.state.user.name
			return this.$store.state.user
		}
	},
	methods:{
		showHide () {
			if (this.showHideItem === false) {
				this.showHideItem = true
				this.showHideIcon = 'el-icon-arrow-up'
				this.showHideName = '隐藏'
			} else {
				this.showHideItem = false
				this.showHideIcon = 'el-icon-arrow-down'
				this.showHideName = '展示'
			}
		},
		// 新增
		add () {
			this.$refs.projectForm.init('add', '')
		},
		// 修改
		edit (id) {
			id = id || this.$refs.typeDictTable.getCheckboxRecords().map(item => {
				return item.id
			})[0]
			this.$refs.projectFormUpdate.init('edit', id)
		},
		// 查看
		view (row) {
			this.$refs.projectDia.init('view', row.id)
		},
		// 获取数据列表
		refreshList () {
			this.loading = true
			this.createName = this.$store.state.user.name
			this.projectInfoService.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.loading = false
			})
			// 获取当前登录人的所属项目id集合
			this.projectInfoService.getHaveProjectIds().then((data) => {
				if (this.commonJS.isNotEmpty(data)) {
					this.haveProjectIds = data.map(i => {
						if (this.commonJS.isNotEmpty(i)) {
							return i
						}
					}).join(',')
				}
			})
			processService.getByName('嘉溢-项目登记').then((data) => {
				if (!this.commonJS.isEmpty(data.id)) {
					this.processDefinitionId = data.id
					this.procDefKey = data.key
				}
			})
		},
		// 当前页
		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()
		},
		// 删除
		deleteAll (id) {
			let ids = id || this.$refs.typeDictTable.getCheckboxRecords().map(item => {
				return item.id
			}).join(',')
			this.$confirm(`确定删除所选项吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				this.loading = true
				this.projectInfoService.deleteAll(ids).then((data) => {
					this.$message.success(data)
					this.refreshList()
					this.loading = false
				})
			})
		},
		// 删除
		del (id) {
			let ids = id || this.$refs.typeDictTable.getCheckboxRecords().map(item => {
				return item.id
			}).join(',')
			this.$confirm(`确定删除所选项吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				this.loading = true
				this.projectInfoService.delete(ids).then((data) => {
					this.$message.success(data)
					this.refreshList()
					this.loading = false
				})
			})
		},
		resetSearch () {
			this.searchForm.createById = ''
			this.applyUserName = ''
			this.$refs.searchForm.resetFields()
			this.refreshList()
		},
		// 查询当前登录人是否是数据的审核人
		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
		},
		is () {
			userService.is().then((data) => {
				this.isAdmin = data
			})
			console.log('is',this.isAdmin)
		},
		// 发起项目登记审批
		// registeredPush (row) {
		// 	// 读取流程表单
		// 	let title = `发起流程【项目登记审批】`
		// 	let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了[项目登记审批]`
		// 	let status = 'startAndHold'
		// 	if (row.status === '3') {
		// 		status = 'startAndClose'
		// 	} else if (row.status === '4') {
		// 		status = 'reapplyFlag'
		// 	}
		// 	taskService.getTaskDef({ procDefId: this.processDefinitionAuditId,
		// 		businessId: row.id,
		// 		businessTable: 'program_project_list_info'}).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.procDefAuditKey,
		// 				title: title,
		// 				formType: data.formType,
		// 				formUrl: data.formUrl,
		// 				formTitle: processTitle,
		// 				businessTable: 'program_project_list_info',
		// 				businessId: row.id,
		// 				isShow: 'false',
		// 				status: status,
		// 				routePath: '/program/registered/ProjectList'
		// 			}
		// 		})
		// 	})
		// },
		// // 查看项目登记审批流程结果
		registeredDetail (row) {
			if (row.status !== '0' && row.status !== '1') {
				this.projectInfoService.findById(row.id).then((data)=>{
					console.log('data',data)
					// eslint-disable-next-line eqeqeq
					taskService.getTaskDef({
						procInsId: data.procInsId,
						procDefId: data.processDefinitionId
					}).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',
								method: 'view'
							}
						})
					})
				})

			}
		},
		// // 撤回项目登记审批
		registeredReback (row) {
			this.$confirm(`确定要撤回该申请吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(async () => {
				await this.projectInfoService.findById(row.id).then((data) => {
					if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
						this.$message.error('数据已发生改变或不存在，请刷新数据')
						this.refreshList()
					} else {
						processService.revokeProcIns(row.procInsId).then((data) => {
							let form = {status: '3', id: row.id}
							this.projectInfoService.updateStatusById(form)
							this.$message.success(data)
							this.refreshList()
						})
					}
				})
			})
		},
		start () {
			// 读取流程表单
			let tabTitle = `发起流程【嘉溢-项目登记】`
			let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了 [嘉溢-项目登记]`
			taskService.getTaskDef({ procDefId: this.processDefinitionId,
				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.processDefinitionId,
						procDefKey: this.procDefKey,
						status: 'startAndHold',
						title: tabTitle,
						formType: data.formType,
						formUrl: data.formUrl,
						formTitle: processTitle,
						businessId: 'false',
						isShow: false,
						routePath: '/jy/project/ProjectList'
					}
				})
			})
		},
		// 审核
		examine (row) {
			this.projectInfoService.findById(row.id).then((data) => {
				if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
					this.$message.error('数据已发生改变或不存在，请刷新数据')
					this.refreshList()
				} else {
					this.todo(row)
				}
			})
		},
		// 驳回后调整
		adjust (row) {
			this.projectInfoService.findById(row.id).then((data) => {
				if (data.status !== '4') { // 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: '/jy/project/ProjectList'   // 数据处理后需要跳转的页面路径
					}
				})
			})
		},
		viewContract (id) {
			this.$refs.contractAddForm.init('view', id)
		},
	}
}
</script>
