<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
	<div>
		<el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method === 'view' ? 'readonly' : ''"
			:disabled="(status === 'audit' || status === 'taskFormDetail')" label-width="100px" @submit.native.prevent>

			<el-divider content-position="left"><i class="el-icon-document"></i> 离职交接信息</el-divider>
			<el-row :gutter="26">
				<el-col :span="12">
					<el-form-item label="姓名" prop="name"
						:rules="[{ required: true, message: '姓名不能为空', trigger: 'blur' }]">
						<el-input v-model="inputForm.name" :disabled="true"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="所属部门" prop="department" :rules="[
						{ required: true, message: '请选择所属部门', trigger: 'blur' }
					]">
						<SelectTree ref="officeTree" :props="{
							value: 'id',             // ID字段名
							label: 'name',         // 显示名称
							children: 'children'    // 子级字段名
						}" :url="`/system-server/sys/office/treeData?type=2`" :value="inputForm.department" :accordion="true"
							size="large" :disabled="true" @getValue="(value) => { inputForm.department = value }" />
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="项目经理" prop="realProjectManager" :rules="[
						{ required: true, message: '项目经理不能为空', trigger: 'change' }
					]">
						<!--						<UserSelectSignatory style="width: 100%" ref="userSelect1"-->
						<!--											 :readonly="true" :limit='1' :modelValue="inputForm.projectManager"-->
						<!--											 @update:modelValue='(value, label) => {inputForm.projectManager = value}'></UserSelectSignatory>-->
						<!-- <UserSelect2 :limit='1' :modelValue="inputForm.projectManager"
							@update:modelValue='(value, label) => { inputForm.projectManager = value }'></UserSelect2> -->
						<el-input @focus="openUserDia3" v-model="inputForm.realProjectManager" placeholder="请选择项目经理">
							<template #suffix>
								<el-button style="background-color: white;color: #1b1e25;border-color: white;"
									type="primary" slot="append" icon="el-icon-search" @click="openUserDia3">
								</el-button>
							</template>
						</el-input>
					</el-form-item>
				</el-col>
				<!--				<el-col :span="12">-->
				<!--					<el-form-item label="底稿管理员" prop="draftAdministrator"-->
				<!--								  :rules="[-->
				<!--								  	{required: true, message: '底稿管理员不能为空', trigger: 'change'}-->
				<!--                   ]">-->
				<!--						<UserSelectAll size="medium" :limit='1' :modelValue="inputForm.draftAdministrator" @update:modelValue='(value) => {inputForm.draftAdministrator = value}'></UserSelectAll>-->
				<!--					</el-form-item>-->
				<!--				</el-col>-->
			</el-row>
			<el-row :gutter="26">
				<el-col :span="24">
					<el-form-item label="备注" prop="remarks" :rules="[]">
						<el-input :rows="5" type="textarea" v-model="inputForm.remarks"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-divider content-position="left"><i class="el-icon-document"></i> 未完成归档的项目信息</el-divider>
			<el-row>
				<el-col :span="24">
					<div style="height:500px;padding-bottom: 50px;">
						<vxe-table border="inner" align="center" auto-resize resizable height="auto"
							:loading="tableLoading" size="small" ref="todoTable" show-header-overflow show-overflow
							highlight-hover-row :menu-config="{}" :print-config="{}" :import-config="{}"
							:export-config="{}" :data="dataList" header-align="center" :checkbox-config="{}">
							<vxe-column title="项目编号" field="projectNumber">
								<template #default="scope">
									<el-link type="primary" :underline="false"
										v-if="hasPermission('cwProjectRecords:view')"
										@click="view(scope.row.projectId)">{{
											scope.row.projectNumber }}</el-link>
									<span v-else>{{ scope.row.projectName }}</span>
								</template>
							</vxe-column>
							<vxe-column title="项目名称" field="projectName"></vxe-column>
							<vxe-column title="报告号" field="reportNo"></vxe-column>
							<vxe-column title="创建人" field="userName"></vxe-column>
							<vxe-column title="创建时间" field="createTime"></vxe-column>
							<vxe-column title="当前所处节点" field="nodeLocation">
								<template #default="scope">
									<div v-if="inputForm.type != '5'">
										<div v-if="scope.row.applyStatus != 5">
											<el-tag v-if="scope.row.applyStatus !== '0'"
												:type="$dictUtils.getDictLabel('cw_status_flag', scope.row.applyStatus, '-')">
												{{ $dictUtils.getDictLabel("cw_status", scope.row.applyStatus, '-') }}
											</el-tag>
											<el-tag type="warning" v-else-if="scope.row.reviewStatus === '0'">
												报告号申请
											</el-tag>
										</div>
										<div v-else>
											<el-tag v-if="scope.row.reviewStatus != 0"
												:type="$dictUtils.getDictLabel('cw_status_flag', scope.row.reviewStatus, '-')">
												{{ $dictUtils.getDictLabel("cw_status", scope.row.reviewStatus, '-') }}
											</el-tag>

											<el-tag v-if="scope.row.signatureType === '1' && scope.row.newType === '0'"
												:type="$dictUtils.getDictLabel('cw_status_flag', scope.row.status1, '-')">
												{{ scope.row.status1 === '5' ? '电子章已完成' :
													$dictUtils.getDictLabel("cw_status", scope.row.status1, '-') }}
											</el-tag>
											<el-tag
												v-else-if="scope.row.signatureType === '2' && scope.row.newType === '0'"
												@click="detailS2(scope.row)" effect="dark"
												:type="$dictUtils.getDictLabel('cw_project_report_sign_status_flag', scope.row.status2, '-')">
												{{ $dictUtils.getDictLabel("cw_project_report_sign_status",
													scope.row.status2, '-') }}
											</el-tag>
											<el-tag
												v-else-if="scope.row.signatureType === '3' && scope.row.newType === '0'"
												@click="detailS3(scope.row)" effect="dark"
												:type="$dictUtils.getDictLabel('cw_status_flag', scope.row.status3, '-')">
												{{ scope.row.status3 === '5' ? '实体章已完成' :
													$dictUtils.getDictLabel("cw_status", scope.row.status3, '-') }}
											</el-tag>
											<el-tag type="warning" v-else-if="scope.row.newType === '0'">
												复合签章
											</el-tag>
											<el-tag v-else-if="scope.row.reviewStatus == 0" type="warning">
												复合签章
											</el-tag>
										</div>
									</div>
									<div v-else>
										<el-tag type="warning">
											{{ scope.row.nodeLocation }}
										</el-tag>
									</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>
				</el-col>
			</el-row>
			<el-divider content-position="left"><i class="el-icon-document"></i> 近一个月内完成归档的项目信息</el-divider>
			<el-row>
				<el-col :span="24">
					<div style="height:500px;padding-bottom: 50px;">
						<vxe-table border="inner" auto-resize resizable height="auto" :loading="tableLoading1"
							size="small" ref="todoTable" show-header-overflow show-overflow highlight-hover-row
							:menu-config="{}" align="center" :print-config="{}" :import-config="{}" :export-config="{}"
							:data="dataList1" header-align="center" :checkbox-config="{}">
							<vxe-column title="项目编号" field="projectNumber">
								<template #default="scope">
									<el-link type="primary" :underline="false"
										v-if="hasPermission('cwProjectRecords:view')"
										@click="view(scope.row.projectId)">{{
											scope.row.projectNumber }}</el-link>
									<span v-else>{{ scope.row.projectName }}</span>
								</template>
							</vxe-column>
							<vxe-column title="项目名称" field="projectName"></vxe-column>
							<vxe-column title="报告号" field="reportNo"></vxe-column>
							<vxe-column title="创建人" field="createName"></vxe-column>
							<vxe-column title="创建时间" field="createTime"></vxe-column>
							<vxe-column title="当前所处节点" field="nodeLocation">
								<template #default="scope">
									<div v-if="inputForm.type == '5'">
										<el-tag type="success">{{ scope.row.nodeLocation }}</el-tag>
									</div>
									<div v-else>
										<el-tag type="success" v-if="scope.row.archiveSta === '已按时归档'">已按时归档</el-tag>
										<el-tag type="success" v-if="scope.row.archiveSta === '已超期归档'">已超期归档</el-tag>
									</div>
								</template>
							</vxe-column>
						</vxe-table>
						<vxe-pager background :current-page="tablePage1.currentPage" :page-size="tablePage1.pageSize"
							:total="tablePage1.total"
							:page-sizes="[10, 20, 100, 1000, { label: '全量数据', value: 1000000 }]"
							:layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
							@page-change="currentChangeHandle1">
						</vxe-pager>
					</div>
				</el-col>
			</el-row>
			<el-divider content-position="left"><i class="el-icon-document"></i> 作废报告归档未完成的项目信息</el-divider>
			<el-row>
				<el-col :span="24">
					<div style="height:250px;padding-bottom: 50px;">
						<vxe-table border="inner" auto-resize resizable height="auto" :loading="tableLoading2"
							size="small" ref="todoTable" show-header-overflow show-overflow highlight-hover-row
							:menu-config="{}" :print-config="{}" :import-config="{}" :export-config="{}"
							:data="dataList2" align="center" header-align="center" :checkbox-config="{}">
							<vxe-column title="项目编号" field="projectNumber">
								<template #default="scope">
									<el-link type="primary" :underline="false"
										v-if="hasPermission('cwProjectRecords:view')"
										@click="view(scope.row.projectId)">{{
											scope.row.projectNumber }}</el-link>
									<span v-else>{{ scope.row.projectName }}</span>
								</template>
							</vxe-column>
							<vxe-column title="项目名称" field="projectName"></vxe-column>
							<vxe-column title="报告号" field="reportNo"></vxe-column>
							<vxe-column title="创建人" field="userName"></vxe-column>
							<vxe-column title="创建时间" field="createTime"></vxe-column>
							<vxe-column title="当前所处节点" field="">
								<template #default="scope">
									<el-tag type="warning">报告作废{{ $dictUtils.getDictLabel("filed_type",
										scope.row.applyFileType, '-') }}</el-tag>

								</template>
							</vxe-column>
						</vxe-table>
						<vxe-pager background :current-page="tablePage2.currentPage" :page-size="tablePage2.pageSize"
							:total="tablePage2.total"
							:page-sizes="[10, 20, 100, 1000, { label: '全量数据', value: 1000000 }]"
							:layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
							@page-change="currentChangeHandle2">
						</vxe-pager>
					</div>
				</el-col>
			</el-row>
			<el-col :span="24">
				<UpLoadComponent ref="uploadComponent"></UpLoadComponent>
			</el-col>
		</el-form>
		<user-select3 ref="userSelect3" @doSubmit="selectUser3"></user-select3>
		<ProjectRecordsForm ref="projectRecordsForm" @refreshList="refreshList"></ProjectRecordsForm>
	</div>
</template>

<script>
import SelectTree from '@/components/treeSelect/treeSelect.vue'
import handoverService from '@/api/human/depart/HandoverService'
import CommonApi from '@/api/cw/common/CommonApi'
import UserSelectAll from '@/components/userSelectAll'
import UserSelect2 from '@/components/userSelect'
import projectReportService from '@/api/cw/reportManagement/ProjectReportService'
import ProjectReportArchiveService from '@/api/cw/projectRecords/ProjectReportArchiveService'
import ReportCancellApplyArchivedService from '@/api/cw/reportCancellApplyArchived/ReportCancellApplyArchivedService'
import UpLoadComponent from '@/views/common/HandoverUpLoadComponent'
import OSSSerivce from '@/api/sys/OSSService'
import UserSelect3 from '@/views/utils/UserTreeSelectToResign'
import ProjectRecordsForm from '@/views/cw/projectRecords/projectRecordsForm'
export default {
	props: {
		businessId: {
			type: String,
			default: ''
		},
		formReadOnly: {
			type: Boolean,
			default: false
		},
		status: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			title: '',
			method: '',
			visible: false,
			loading: false,
			inputForm: {
				userId: '',
				name: '',
				procInsId: '',
				department: '',
				projectManager: '',
				draftAdministrator: '',
				remarks: '',
				registrationId: '',
				type: '',
				workAttachments: [],
				realProjectManager: ''
			},
			keyWatch: '',
			haveProjectIds: '',
			// 获取1个月内完成的项目接口的参数
			tableLoading: false,
			dataList: [],
			searchForm: {
				reviewStatus: '',
				status1: '',
				applyStatus: '',	//报告号申请
				createBy: '',
			},
			tablePage: {
				total: 0,
				currentPage: 1,
				pageSize: 10,
				orders: []
			},
			// 获取1个月内完成的项目接口的参数
			tablePage1: {
				total: 0,
				currentPage: 1,
				pageSize: 10,
				orders: []
			},
			dataList1: [],
			tableLoading1: false,
			searchForm1: {
				cwProjectRecordsDTO: {
					projectName: '',
					projectMasterName: '',
					realHeaderName: ''
				},
				name: '',
				year: '',
				number: '',
				auditDates: [],
				status: '',
				createBy: {
					name: ''
				},
				createDates: [],
				reportNo: '',
				fileNumber: '',
				archiveSta: ''
			},
			// 作废报告接口参数
			tablePage2: {
				total: 0,
				currentPage: 1,
				pageSize: 10,
				orders: []
			},
			dataList2: [],
			tableLoading2: false,
			searchForm: {
				projectNumber: '',
				applyFileType: '',
				projectName: '',
				projectMasterId: '',
				projectMaster2Id: '',
				createBy: '',
				contractDates: [],
				projectMasterName: '', // 项目经理1
				projectMaster2Name: '' // 项目经理2
			},
			dataList: []
		}
	},
	commonApi: null,
	projectReportArchiveService: null,
	reportCancellApplyArchivedService: null,
	ossService: null,
	created() {
		this.commonApi = new CommonApi()
		this.projectReportArchiveService = new ProjectReportArchiveService()
		this.reportCancellApplyArchivedService = new ReportCancellApplyArchivedService()
		this.ossService = new OSSSerivce()
	},
	components: {
		SelectTree,
		UserSelectAll,
		UserSelect2,
		UserSelect3,
		UpLoadComponent,
		ProjectRecordsForm
	},
	computed: {
		bus: {
			get() {
				return this.businessId
			},
			set(val) {
				this.businessId = val
			}
		},
		name() {
			return this.$store.state.user.name
		},
		userId() {
			return this.$store.state.user.id
		}
	},
	watch: {
		'keyWatch': {
			handler(newVal) {
				if (this.commonJS.isNotEmpty(this.bus)) {
					this.init('', this.bus)
				} else {
					this.$nextTick(() => {
						this.$refs.inputForm.resetFields()
					})
				}
			}
		},
		'loading': {
			handler(newVal) {
				this.$emit('changeLoading', newVal)
			}
		}
	},
	methods: {
		// 获取未完成数据列表
		getNotCompProjectInfo() {
			this.tableLoading = true
			projectReportService.findNotCompletedList({
				'current': this.tablePage.currentPage,
				'size': this.tablePage.pageSize,
				'orders': this.tablePage.orders,
				...this.searchForm,
				applyStatus: "-1",
				reviewStatus: "-1",
				createBy: this.inputForm.name
			}).then((data) => {
				this.dataList = data.records
				this.tablePage.total = data.total
				this.tableLoading = false
			})
		},
		// 当前页
		currentChangeHandle({ currentPage, pageSize }) {
			this.tablePage.currentPage = currentPage;
			this.tablePage.pageSize = pageSize;
			if (this.inputForm.type == 5) {
				this.getProjectInfo1()
			} else {
				this.getNotCompProjectInfo();
			}
		},
		// 获取一个月内完成的数据列表
		getCompProjectInfo() {
			// 生成归档日期的起始日期(1个月前)
			let dateLastMonth = this.moment().startOf('day').subtract(1, 'month').format('YYYY-MM-DD HH:mm:ss');
			//当前日期
			let date = this.moment().startOf('day').format('YYYY-MM-DD HH:mm:ss');
			this.tableLoading1 = true
			this.projectReportArchiveService.findCompletedList({
				'current': this.tablePage1.currentPage,
				'size': this.tablePage1.pageSize,
				'orders': this.tablePage1.orders,
				...this.searchForm1,
				auditDates: [dateLastMonth, date],
				archiveSta: "-1",
				createBy: {
					name: this.inputForm.name
				}
			}).then((data) => {
				this.dataList1 = data.records
				this.tablePage1.total = data.total
				this.tableLoading1 = false
			})
		},

		// 当前页
		currentChangeHandle1({ currentPage, pageSize }) {
			this.tablePage1.currentPage = currentPage
			this.tablePage1.pageSize = pageSize
			if (this.inputForm.type == 5) {
				this.getProjectInfo2()
			} else {
				this.getCompProjectInfo()
			}
		},
		// 获取作废报告归档未完成信息
		getCancelProjectInfo() {
			this.tableLoading2 = true
			this.reportCancellApplyArchivedService.findNotCompList({
				'current': this.tablePage2.currentPage,
				'size': this.tablePage2.pageSize,
				'orders': this.tablePage2.orders,
				...this.searchForm2,
				createBy: this.inputForm.name,
				applyFileType: '-1'
			}).then((data) => {
				this.dataList2 = data.records
				this.tablePage2.total = data.total
				this.tableLoading2 = false
			})
		},
		// 当前页
		currentChangeHandle2({ currentPage, pageSize }) {
			this.tablePage2.currentPage = currentPage
			this.tablePage2.pageSize = pageSize
			this.getCancelProjectInfo()
		},
		getKeyWatch(keyWatch) {
			this.keyWatch = keyWatch
		},
		async init(method, id) {
			this.dataList = []
			// await this.ossService.findFileList(id).then((data) => {
			// 	data.forEach((item) => {
			// 		item.name = item.attachmentName
			// 		this.dataList.push(item)
			// 	})
			// })
			this.method = method

			this.inputForm = {
				userId: '',
				name: '',
				procInsId: '',
				department: '',
				projectManager: '',
				draftAdministrator: '',
				remarks: '',
				registrationId: '',
				type: '',
				workAttachments: []
			}
			if (method === 'add') {
				this.title = `新建离职申请`
			} else if (method === 'edit') {
				this.title = '修改离职申请信息'
			}
			this.inputForm.id = id
			this.visible = true
			this.loading = false
			this.$nextTick(() => {
				this.loading = true
				this.$refs.uploadComponent.clearUpload()
				handoverService.findById(this.inputForm.id).then((data) => {
					console.log(data)
					this.fileList = []
					this.fileList2 = []
					if (this.status === 'audit' || this.status === 'taskFormDetail') {
						method = 'view'
					}
					if (data) {
						this.inputForm = this.recover(this.inputForm, data)
						this.inputForm.realProjectManager = data.projectManagerName
					}
					this.inputForm = JSON.parse(JSON.stringify(this.inputForm))

					if (this.commonJS.isEmpty(this.inputForm.name)) {
						this.inputForm.name = this.$store.state.user.name
					}
					if (this.commonJS.isEmpty(this.inputForm.department)) {
						this.inputForm.department = this.$store.state.user.office.id
					}
					if (this.inputForm.workAttachments && this.inputForm.workAttachments.length > 0) {
						// this.dataList = this.inputForm.workAttachments.map(item => {
						// 	return {
						// 		...item,
						// 		name: item.attachmentName
						// 	}
						// })
						this.$refs.uploadComponent.newUpload(method, this.inputForm.workAttachments, 'handover', 300, "交接资料附件上传")
					}


					if (this.inputForm.type != 5) {
						this.getNotCompProjectInfo()
						this.getCompProjectInfo()
					} else {
						this.getProjectInfo1()
						this.getProjectInfo2()
					}
					// 获取未完成数据列表
					this.getCancelProjectInfo()
					this.loading = false
				})
			})
		},
		getProjectInfo1() {
			this.tableLoading = true;
			handoverService.findProjectList({
				current: this.tablePage.currentPage,
				size: this.tablePage.pageSize,
				orders: this.tablePage.orders,
				id: this.inputForm.id,
				type: 0
			}).then(data => {
				this.dataList = data.records.map(item => {
					return {
						...item,
						userName: item.createName,
						reportNo: item.reportCode
					}
				})
				this.tablePage.total = data.total
				this.tableLoading = false;
			}).catch(err => {
				this.tableLoading = false;

			})
		},
		getProjectInfo2() {
			this.tableLoading1 = true;
			handoverService.findProjectList({
				current: this.tablePage1.currentPage,
				size: this.tablePage1.pageSize,
				orders: this.tablePage1.orders,
				id: this.inputForm.id,
				type: 1
			}).then(data => {
				this.dataList1 = data.records.map(item => {
					return {
						...item,
						userName: item.createName,
						reportNo: item.reportCode
					}
				})
				this.tablePage1.total = data.total
				this.tableLoading1 = false;
			}).catch(err => {
				this.tableLoading1 = false;

			})
		},
		// 表单提交
		doSubmit() {
			this.$refs['inputForm'].validate((valid) => {
				if (valid) {
					this.loading = true
					if (this.commonJS.isEmpty(this.inputForm.files)) {
						this.inputForm.files = []
					}
					this.inputForm.workAttachments = this.$refs.uploadComponent.getDataList()
					// this.$refs.uploadComponent.getDataList().forEach((item) => {
					// 	if (item.id === null || item.id === undefined || item.id === '') {
					// 		item.url = item.raw.url
					// 	}
					// 	item.attachmentFlag = 'workClient'
					// 	item.fileSize = item.size
					// 	item.attachmentName = item.name
					// 	item.createBy = null
					// 	this.inputForm.workAttachments.push(item)
					// })
					this.inputForm.id = this.businessId
					handoverService.save(this.inputForm).then((data) => {
						this.close()
						this.$message.success(data)
						this.$emit('refreshDataList')
						this.loading = false
					}).catch(() => {
						this.loading = false
					})
				}
			})
		},
		close() {
			this.$refs.inputForm.resetFields()
			this.fileList = []
			this.fileList2 = []
			this.visible = false
		},
		reapplyForm(callback) {
			this.loading = true
			handoverService.findById(this.inputForm.id).then((data) => {
				if (data.type !== '4') { // 审核状态不是“驳回”，就弹出提示
					this.loading = false
					this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
					throw new Error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
				} else {
					this.startForm(callback)
				}
			})
		},
		//暂存
		saveForm(callback) {
			// 暂存
			this.loading = true
			this.inputForm.type = '1'
			if (this.commonJS.isEmpty(this.inputForm.registrationId)) {
				this.inputForm.registrationId = this.businessId
			}


			handoverService.save(this.inputForm).then((data) => {
				callback(data.businessTable, data.businessId, this.inputForm)
				this.loading = false
			}).catch(() => {
				this.loading = false
			})
		},
		// 送审
		async startForm(callback) {
			if (this.$refs.uploadComponent.checkProgress()) {
				this.loading = false
				return
			}
			this.$refs['inputForm'].validate(async (valid) => {
				if (valid) {
					this.loading = true
					this.inputForm.type = '2'
					if (this.commonJS.isEmpty(this.inputForm.registrationId)) {
						this.inputForm.registrationId = this.businessId
					}
					this.inputForm.workAttachments = this.$refs.uploadComponent.getDataList()

					// this.$refs.uploadComponent.getDataList().forEach((item) => {
					// 	if (item.id === null || item.id === undefined || item.id === '') {
					// 		item.url = item.raw.url
					// 	}
					// 	item.attachmentFlag = 'workClient'
					// 	item.fileSize = item.size
					// 	item.attachmentName = item.name
					// 	item.createBy = null
					// 	this.inputForm.workAttachments.push(item)
					// })

					handoverService.save(this.inputForm).then((data) => {
						this.inputForm.title = `${this.$store.state.user.name} 发起了 [离职交接]`
						this.inputForm.id = data.businessId
						this.inputForm.assignee = this.inputForm.projectManager
						callback(data.businessTable, data.businessId, this.inputForm)
						this.$refs.inputForm.resetFields()
						this.loading = false
					}).catch(() => {
						this.$refs.inputForm.resetFields()
						this.loading = false
					})
				} else {
					this.loading = false
				}
			})
		},
		getTagText(scopeRow) {
			const dictUtils = this.$dictUtils;

			if (scopeRow.applyStatus != 5) {
				if (scopeRow.applyStatus !== '0') {
					return dictUtils.getDictLabel("cw_status", scopeRow.applyStatus, '-');
				}
				if (scopeRow.applyStatus === '0' && scopeRow.reviewStatus === '0') {
					return '报告号申请未发起';
				}
				return dictUtils.getDictLabel("cw_status", scopeRow.applyReviewStatus, '-');
			} else {
				if (scopeRow.reviewStatus != 0) {
					return dictUtils.getDictLabel("cw_status", scopeRow.reviewStatus, '-');
				}

				if (scopeRow.signatureType === '1' && scopeRow.newType === '0') {
					return scopeRow.status1 === '5' ? '电子章已完成' : dictUtils.getDictLabel("cw_status", scopeRow.status1, '-');
				}
				if (scopeRow.signatureType === '2' && scopeRow.newType === '0') {
					return dictUtils.getDictLabel("cw_project_report_sign_status", scopeRow.status2, '-');
				}
				if (scopeRow.signatureType === '3' && scopeRow.newType === '0') {
					return scopeRow.status3 === '5' ? '实体章已完成' : dictUtils.getDictLabel("cw_status", scopeRow.status3, '-');
				}
				if (scopeRow.newType === '0' || scopeRow.reviewStatus == 0) {
					return '复合签章未发起';
				}
			}

			return '-'; // 默认返回
		},
		saveProjectList() {
			let projectList = []
			projectReportService.findNotCompletedList({
				'current': 1,
				'size': 10000,
				'orders': this.tablePage.orders,
				...this.searchForm,
				applyStatus: "-1",
				reviewStatus: "-1",
				createBy: this.inputForm.name
			}).then((data) => {
				data.records.forEach(item => {
					projectList.push({
						projectNumber: item.projectNumber,
						projectName: item.projectName,
						reportCode: item.reportNo,
						nodeLocation: this.getTagText(item),
						type: "0",
						handoverId: this.inputForm.id,
						createProjectUserId: item.createById
					})
				})
				// 生成归档日期的起始日期(1个月前)
				let dateLastMonth = this.moment().startOf('day').subtract(6, 'month').format('YYYY-MM-DD HH:mm:ss');
				//当前日期
				let date = this.moment().startOf('day').format('YYYY-MM-DD HH:mm:ss');
				this.projectReportArchiveService.findCompletedList({
					'current': 1,
					'size': 100000,
					'orders': this.tablePage1.orders,
					...this.searchForm1,
					auditDates: [dateLastMonth, date],
					archiveSta: "-1",
					createBy: {
						name: this.inputForm.name
					}
				}).then((data1) => {
					data1.records.forEach(item1 => {
						let text = ""
						if (item1.archiveSta === '已按时归档') {
							text = '已按时归档';
						}
						if (item1.archiveSta === '已超期归档') {
							text = '已超期归档';
						}
						projectList.push({
							projectId: item1.projectId,
							projectNumber: item1.projectNumber,
							projectName: item1.projectName,
							reportCode: item1.reportNo,
							nodeLocation: text,
							type: "1",
							handoverId: this.inputForm.id,
							createProjectUserId: item1.createBy.id
						})
					})
					// 保存
					handoverService.saveProject(projectList)
				})
			})

		},
		// 通过
		async agreeForm(callback) {
			if (this.$refs.uploadComponent.checkProgress()) {
				this.loading = false
				return
			}
			this.loading = true
			handoverService.findById(this.inputForm.id).then((data) => {
				if (data.type !== '2') { // 审核状态不是“审核中”，就弹出提示
					this.loading = false
					this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
					throw new Error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
				} else {
					this.$refs['inputForm'].validate(async (valid) => {
						if (valid) {
							this.loading = true

							this.commonApi.getTaskNameByProcInsId(this.inputForm.procInsId).then((data) => {
								if (this.commonJS.isNotEmpty(data)) {
									if (data === '部门主任审批') {
										this.inputForm.type = '5'
										// 将项目信息固定保存
										this.saveProjectList()
										console.log("部门主任审批添加项目");

									}
								}
								handoverService.save(this.inputForm).then((data) => {
									callback(data.businessTable, data.businessId, this.inputForm)
									this.loading = false
								}).catch(() => {
									this.loading = false
								})
							})

						} else {
							this.loading = false
						}
					})
				}
			})
		},
		// 修改状态
		updateStatusById(type, callback) {
			if (type === 'reject') {
				this.loading = true
				handoverService.findById(this.inputForm.id).then((data) => {
					console.log('进入了驳回')
					if (data.type !== '2') { // 审核状态不是“审核中”，就弹出提示
						this.loading = false
						this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
						throw new Error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
					} else {
						this.commonApi.getTaskNameByProcInsId(this.inputForm.procInsId).then((name) => {
							if (this.commonJS.isNotEmpty(name)) {
								if (name === '项目经理审批' || name === '项目经理重新审批') {
									this.inputForm.type = '4'
								}
							}
							handoverService.updateStatusById(this.inputForm).then(() => {
								this.loading = false
								callback()
							})
						})
					}
				})
			} else if (type === 'hold') {
				this.loading = true
				handoverService.findById(this.inputForm.id).then((data) => {
					if (data.type !== '4') { // 审核状态不是“驳回”，就弹出提示
						this.loading = false
						this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
						throw new Error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
					} else {
						this.inputForm.type = '1'
						handoverService.updateStatusById(this.inputForm).then(() => {
							this.loading = false
							callback()
						})
					}
				})
			}
		},
		openUserDia3() {
			let userInfo = JSON.parse(localStorage.getItem("USER_INFO"))
			this.$refs.userSelect3.init(userInfo.tenantDTO.id)
			// this.$refs.userSelect3.setSelectRow(userInfo.companyDTO.id)
		},
		selectUser3(user) {
			this.inputForm.projectManager = user[0].id
			this.inputForm.realProjectManager = user[0].name
			console.log(user);
		},
		view(id) {
			console.log(id)
			this.$refs.projectRecordsForm.init('view', id)
		},
	}
}
</script>
