<template>
	<div>
		<SearchBox ref="SearchBoxRef" formName="inputQuery" :formData="query" @PopupNo="PopupNo" @reset="reset">
		</SearchBox>

		<ButtonBar @search="handleSearch" @handleExportBatch="handleExportBatch" @handleExportAll="handleExportAll"></ButtonBar>

		<el-card :body-style="cardBodyStyle">
			<el-table :data="tableData" border highlight-current-row @selection-change="handleSelectionChange"
				height="63vh">
				<el-table-column type="selection" fixed></el-table-column>
				<el-table-column type="index" label="序号" align="center" width="60" fixed>
					<template #default="scope">
						<span>{{ scope.$index + (currentPage - 1) * pageSize + 1 }}</span>
					</template>
				</el-table-column>
				<el-table-column v-if="true" prop="contrNo" label="合同编号" width="150" header-align="center"
					align="center" show-overflow-tooltip fixed>
				</el-table-column>
				<el-table-column v-if="true" prop="contrNm" label="合同名称" width="180" header-align="center"
					align="center" show-overflow-tooltip  fixed>
				</el-table-column>
				<el-table-column v-if="true" prop="supplierNm" label="交易方名称" width="250" header-align="center"
					align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column v-if="true" prop="contrTy" label="合同类型" width="100" header-align="center"
					align="center" show-overflow-tooltip :formatter="formatter">
				</el-table-column>
				<el-table-column v-if="true" prop="conSts" label="合同状态" width="120" header-align="center" align="center"
					show-overflow-tooltip :formatter="formatter">
				</el-table-column>
				<el-table-column v-if="true" prop="khContrNo" label="对方合同编号" width="150" header-align="center"
					align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column v-if="true" prop="approveDt" label="审批结束时间" width="150" header-align="center"
					align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column v-if="true" prop="delvDate" label="预计交货日期" width="120" header-align="center"
					align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column v-if="true" prop="invMth" label="结算方式" width="100" header-align="center" align="center"
					show-overflow-tooltip :formatter="formatter">
				</el-table-column>
				<el-table-column v-if="true" prop="analyDataAccord" label="化验结算依据" width="120" header-align="center"
					align="center" show-overflow-tooltip :formatter="formatter">
				</el-table-column>
				<el-table-column v-if="true" prop="weightDataAccord" label="计量结算依据" width="120" header-align="center"
					align="center" show-overflow-tooltip :formatter="formatter">
				</el-table-column>
				<el-table-column v-if="true" prop="priceDcnMth" label="定价方式" width="100" header-align="center"
					align="center" show-overflow-tooltip :formatter="formatter">
				</el-table-column>
				<el-table-column v-if="true" prop="delvMth" label="交货方式" width="100" header-align="center"
					align="center" show-overflow-tooltip :formatter="formatter">
				</el-table-column>
				<el-table-column v-if="true" prop="delvPlace" label="交货地点" width="120" header-align="center"
					align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column v-if="true" prop="ifAnnual" label="是否长协" width="100" header-align="center"
					align="center" show-overflow-tooltip :formatter="formatter">
				</el-table-column>
				<el-table-column v-if="true" prop="ifBid" label="是否招投标" width="100" header-align="center" align="center"
					show-overflow-tooltip :formatter="formatter">
				</el-table-column>
				<el-table-column v-if="false" prop="salMth" label="销售方式" width="100" header-align="center" align="center"
					show-overflow-tooltip :formatter="formatter">
				</el-table-column>
				<el-table-column v-if="true" prop="signReqNo" label="签约请示" width="120" header-align="center"
					align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column v-if="true" prop="totalAmt" label="合同金额" width="100" header-align="center"
					align="right" show-overflow-tooltip>
				</el-table-column>
				<el-table-column v-if="true" prop="qty" label="重量" width="120" header-align="center" align="right"
					show-overflow-tooltip>
				</el-table-column>
				<el-table-column v-if="true" prop="contrReq" label="合同要求" width="100" header-align="center"
					align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column v-if="true" prop="contrDt" label="合同日期" width="120" header-align="center"
					align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column v-if="true" prop="checkYn" label="争议所在地法院" width="150" header-align="center"
					align="center" show-overflow-tooltip :formatter="formatter">
				</el-table-column>
				<el-table-column v-if="true" prop="riskInfo" label="风险提示" width="100" header-align="center"
					align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column v-if="true" prop="tempNm" label="合同模板名称" width="120" header-align="center"
					align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column v-if="true" prop="addTime" label="录入日期" width="120" header-align="center"
					align="center" show-overflow-tooltip :formatter="formatter">
				</el-table-column>
				<el-table-column v-if="true" prop="addName" label="录入人" width="100" header-align="center" align="center"
					show-overflow-tooltip>
				</el-table-column>
				<el-table-column label="操作" header-align="center" align="center" width="200px" fixed="right">
					<template #default="{ row }">
						<el-button plain type="primary" @click="handleDetail(row)" v-if="row.workId !== ''">详情</el-button>
						<el-button plain type="primary" @click="handleDetail1(row)" v-else>详情</el-button>
					</template>
				</el-table-column>
			</el-table>
		</el-card>

		<el-card :body-style="cardBodyStyle">
			<el-pagination :current-page="currentPage" :page-size="pageSize" :page-sizes="pageSizes" :total="totalRows"
				background="background" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
				@current-change="handleCurrentChange">
			</el-pagination>
		</el-card>

		<el-dialog fullscreen :close-on-click-modal="false" draggable :title="title" v-model="dialogVisibleSal"
			top="5vh" @open="openDialog" @close="closeDialog">
			<el-form :model="form" label-width="120px" label-position="right" inline ref="ruleFormRef" :rules="rules">
				<el-form-item label="合同类型" prop="contrTy">
					<el-select v-model="form.contrTy" :placeholder="form.contrTy" clearable style="width: 200px;"
						class="dicSelect" disabled>
						<el-option v-for="item in dicList.CONTRACT_TYPE" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="合同编号">
					<el-input v-model="form.contrNo" clearable style="width: 200px" disabled></el-input>
				</el-form-item>
				<el-form-item label="合同名称" prop="contrNm">
					<el-input v-model="form.contrNm" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="交易方名称" prop="supplierNm">
					<el-input v-model="form.supplierNm" clearable readonly style="width: 200px;">
						<template #append>
							<el-button :icon="Search" @click="handleSearchSupplier" disabled />
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="对方合同编号">
					<el-input v-model="form.khContrNo" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="合同状态">
					<el-select v-model="form.conSts" placeholder="" clearable style="width: 200px" class="dicSelect"
						disabled>
						<el-option v-for="item in dicList.contrSts" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="审批结束时间">
					<el-date-picker v-model="form.approveDt" type="datetime" style="width: 200px;"
						value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss" disabled></el-date-picker>
				</el-form-item>
				<el-form-item label="预计交货日期">
					<el-date-picker v-model="form.delvDate" type="date" style="width: 200px;" value-format="YYYY-MM-DD"
						format="YYYY-MM-DD" readonly></el-date-picker>
				</el-form-item>
				<el-form-item label="结算方式">
					<el-select v-model="form.invMth" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.SAL_INV_MTH" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="定价方式">
					<el-select v-model="form.priceDcnMth" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.PRICE_DCN_MTH" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="交货方式">
					<el-select v-model="form.delvMth" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.DELV_MTH" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="交货地点">
					<el-input v-model="form.delvPlace" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="是否长协" prop="ifAnnual">
					<el-select v-model="form.ifAnnual" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.COM_YN" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="是否招投标">
					<el-select v-model="form.ifBid" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.COM_YN" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="签约请示">
					<el-input v-model="form.signReqNo" clearable style="width: 200px" readonly>
						<template #append>
							<el-button :icon="Search" @click="handleSearchSignRequest" diabled />
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="合同金额">
					<el-input-number v-model="form.totalAmt" :precision="2" :step="0.1" controls-position="right"
						clearable style="width: 200px" disabled></el-input-number>
				</el-form-item>
				<el-form-item label="重量">
					<el-input-number v-model="form.qty" :precision="2" :step="0.1" controls-position="right" clearable
						style="width: 200px" disabled></el-input-number>
				</el-form-item>
				<el-form-item label="合同要求">
					<el-input v-model="form.contrReq" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="合同日期">
					<el-date-picker v-model="form.contrDt" type="date" style="width: 200px;" value-format="YYYY-MM-DD"
						format="YYYY-MM-DD" @change="handleContrDt" readonly></el-date-picker>
				</el-form-item>
				<el-form-item label="终止日期" :error="endDtError">
					<el-date-picker v-model="form.endDt" type="date" style="width: 200px;" value-format="YYYY-MM-DD"
						format="YYYY-MM-DD" :disabled-date="disabledDate" @change="handleEndDt"
						readonly></el-date-picker>
				</el-form-item>
				<el-form-item label="争议所在地法院">
					<el-select v-model="form.checkYn" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.CHECK_YN" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="风险提示">
					<el-input v-model="form.riskInfo" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="合同模板名称">
					<el-input v-model="form.tempNm" clearable style="width: 200px" readonly>
						<template #append>
							<el-button :icon="Search" @click="handleSearchCotTmp" disabled />
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="录入日期">
					<el-date-picker v-model="form.addTime" type="date" style="width: 200px;" value-format="YYYY-MM-DD"
						format="YYYY-MM-DD" disabled></el-date-picker>
				</el-form-item>
				<el-form-item label="录入人">
					<el-input v-model="form.addName" clearable style="width: 200px" disabled></el-input>
				</el-form-item>
				<el-form-item label="是否补录">
                <el-checkbox v-model="ifSupplemental" disabled/>
            </el-form-item>
			</el-form>

			<template #footer>
				<el-button type="info" @click="handleCancelSave">关闭</el-button>
			</template>

			<el-tabs v-model="activeName" @tab-click="handleClick">
				<el-tab-pane label="合同行" name="first">
					<addLineVue :cotHead="form" :readonly="readonly"></addLineVue>
				</el-tab-pane>
				<el-tab-pane label="收付款方式" name="second">
					<addVue :cotHead="form" :readonly="readonly" @receive-from-child="retuScales"></addVue>
				</el-tab-pane>
				<el-tab-pane label="文件上传" name="third">
					<el-card :body-style="cardBodyStyle">
						
						<Attachment ref="AttachmentRefManual" :fId="fId" :uploadButton="!readonly"></Attachment>
					</el-card>
				</el-tab-pane>
				<el-tab-pane label="合同条款" name="fourth">
					<addHouse :cotHead="form"></addHouse>
				</el-tab-pane>
			</el-tabs>
		</el-dialog>

		<el-dialog fullscreen :close-on-click-modal="false" draggable :title="title" v-model="dialogVisiblePur"
			top="5vh" @open="openDialog" @close="closeDialog">
			<el-form :model="form" label-width="120px" label-position="right" inline ref="ruleFormRef" :rules="rules">
				<el-form-item label="合同类型" prop="contrTy">
					<el-select v-model="form.contrTy" :placeholder="form.contrTy" clearable style="width: 200px;"
						disabled>
						<el-option v-for="item in dicList.CONTRACT_TYPE" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="合同编号">
					<el-input v-model="form.contrNo" clearable style="width: 200px" disabled></el-input>
				</el-form-item>
				<el-form-item label="合同名称" prop="contrNm">
					<el-input v-model="form.contrNm" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="交易方名称" prop="supplierNm">
					<el-input v-model="form.supplierNm" clearable style="width: 200px;" readonly>
						<template #append>
							<el-button :icon="Search" disabled />
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="对方合同编号">
					<el-input v-model="form.khContrNo" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="合同状态">
					<el-select v-model="form.conSts" placeholder="" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.contrSts" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="审批结束时间">
					<el-date-picker v-model="form.approveDt" type="datetime" style="width: 200px;"
						value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss" disabled></el-date-picker>
				</el-form-item>
				<el-form-item label="预计交货日期">
					<el-date-picker v-model="form.delvDate" type="date" style="width: 200px;" value-format="YYYY-MM-DD"
						format="YYYY-MM-DD" readonly></el-date-picker>
				</el-form-item>
				<el-form-item label="结算方式">
					<el-select v-model="form.invMth" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.SAL_INV_MTH" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="化验结算依据">
					<el-select v-model="form.analyDataAccord" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.ANALY_DATA_ACCORD" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="计量结算依据">
					<el-select v-model="form.weightDataAccord" placeholder="请选择" clearable style="width: 200px"
						disabled>
						<el-option v-for="item in dicList.WEIGHT_DATA_ACCORD" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="定价方式">
					<el-select v-model="form.priceDcnMth" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.PRICE_DCN_MTH" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="交货方式">
					<el-select v-model="form.delvMth" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.DELV_MTH" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="交货地点">
					<el-input v-model="form.delvPlace" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="到达地">
					<el-input v-model="form.toPlace" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="出发地">
					<el-input v-model="form.fromPlace" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="是否长协" prop="ifAnnual">
					<el-select v-model="form.ifAnnual" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.COM_YN" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="是否招投标">
					<el-select v-model="form.ifBid" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.COM_YN" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="是否内部生产" prop="internalProduction">
					<el-select v-model="form.internalProduction" placeholder="请选择" clearable style="width: 200px">
						<el-option v-for="item in dicList.COM_YN" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<!-- <el-form-item label="是否采购备件" prop="purTy">
					<el-select v-model="form.purTy" placeholder="请选择" clearable style="width: 200px">
						<el-option v-for="item in dicList.COM_YN" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item> -->
				<el-form-item label="签约请示">
					<el-input v-model="form.signReqNo" clearable style="width: 200px" readonly>
						<template #append>
							<el-button :icon="Search" disabled />
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="合同金额">
					<el-input-number v-model="form.totalAmt" :precision="2" :step="0.1" controls-position="right"
						clearable style="width: 200px" disabled></el-input-number>
				</el-form-item>
				<el-form-item label="重量">
					<el-input-number v-model="form.qty" :precision="2" :step="0.1" controls-position="right" clearable
						style="width: 200px" disabled></el-input-number>
				</el-form-item>
				<el-form-item label="合同要求">
					<el-input v-model="form.contrReq" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="合同日期">
					<el-date-picker v-model="form.contrDt" type="date" style="width: 200px;" value-format="YYYY-MM-DD"
						format="YYYY-MM-DD" readonly></el-date-picker>
				</el-form-item>
				<el-form-item label="终止日期">
					<el-date-picker v-model="form.endDt" type="date" style="width: 200px;" value-format="YYYY-MM-DD"
						format="YYYY-MM-DD" readonly></el-date-picker>
				</el-form-item>
				<el-form-item label="争议所在地法院">
					<el-select v-model="form.checkYn" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.CHECK_YN" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="风险提示">
					<el-input v-model="form.riskInfo" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="合同模板名称">
					<el-input v-model="form.tempNm" clearable style="width: 200px" readonly>
						<template #append>
							<el-button :icon="Search" disabled />
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="录入日期">
					<el-date-picker v-model="form.addTime" type="date" style="width: 200px;" value-format="YYYY-MM-DD"
						format="YYYY-MM-DD" disabled></el-date-picker>
				</el-form-item>
				<el-form-item label="录入人">
					<el-input v-model="form.addName" clearable style="width: 200px" disabled></el-input>
				</el-form-item>
				<el-form-item label="是否补录">
                <el-checkbox v-model="ifSupplemental" disabled/>
            </el-form-item>
			</el-form>

			<template #footer>
				<el-button plain type="info" @click="handleCancelSave">关闭</el-button>
			</template>

			<el-tabs v-model="activeName" @tab-click="handleClick">
				<el-tab-pane label="合同行" name="first">
					<addLineVue :cotHead="form" :readonly="readonly"></addLineVue>
				</el-tab-pane>
				<el-tab-pane label="收付款方式" name="second">
					<addVue :cotHead="form" :readonly="readonly" @receive-from-child="retuScales"></addVue>
				</el-tab-pane>
				<el-tab-pane label="文件上传" name="third">
					<el-card :body-style="cardBodyStyle">
						
						<Attachment ref="AttachmentRefManual" :fId="fId" :uploadButton="!readonly"></Attachment>
					</el-card>
				</el-tab-pane>

				<el-tab-pane label="合同条款" name="fourth">
					<addHouse :cotHead="form"></addHouse>
				</el-tab-pane>
			</el-tabs>
		</el-dialog>

		<el-dialog fullscreen :close-on-click-modal="false" draggable :title="title" v-model="dialogVisibleService"
			top="5vh" @open="openDialog" @close="closeDialog">
			<el-form :model="form" label-width="120px" label-position="right" inline ref="ruleFormRef" :rules="rules">
				<el-form-item label="合同类型" prop="contrTy">
					<el-select v-model="form.contrTy" :placeholder="form.contrTy" clearable style="width: 200px;"
						class="dicSelect" disabled>
						<el-option v-for="item in dicList.CONTRACT_TYPE" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="合同编号">
					<el-input v-model="form.contrNo" clearable style="width: 200px" disabled></el-input>
				</el-form-item>
				<el-form-item label="合同名称" prop="contrNm">
					<el-input v-model="form.contrNm" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="交易方名称" prop="supplierNm">
					<el-input v-model="form.supplierNm" clearable readonly style="width: 200px;">
						<template #append>
							<el-button :icon="Search" @click="handleSearchSupplier" disabled />
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="对方合同编号">
					<el-input v-model="form.khContrNo" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="合同状态">
					<el-select v-model="form.conSts" placeholder="" clearable style="width: 200px" class="dicSelect"
						disabled>
						<el-option v-for="item in dicList.contrSts" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="审批结束时间">
					<el-date-picker v-model="form.approveDt" type="datetime" style="width: 200px;"
						value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss" disabled></el-date-picker>
				</el-form-item>
				<el-form-item label="预计交货日期">
					<el-date-picker v-model="form.delvDate" type="date" style="width: 200px;" value-format="YYYY-MM-DD"
						format="YYYY-MM-DD" readonly></el-date-picker>
				</el-form-item>
				<el-form-item label="结算方式">
					<el-select v-model="form.invMth" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.SAL_INV_MTH" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="化验结算依据">
					<el-select v-model="form.analyDataAccord" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.ANALY_DATA_ACCORD" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="计量结算依据">
					<el-select v-model="form.weightDataAccord" placeholder="请选择" clearable style="width: 200px"
						disabled>
						<el-option v-for="item in dicList.WEIGHT_DATA_ACCORD" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="定价方式">
					<el-select v-model="form.priceDcnMth" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.PRICE_DCN_MTH" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="交货方式">
					<el-select v-model="form.delvMth" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.DELV_MTH" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="交货地点">
					<el-input v-model="form.delvPlace" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="到达地">
					<el-input v-model="form.toPlace" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="出发地">
					<el-input v-model="form.fromPlace" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="是否长协" prop="ifAnnual">
					<el-select v-model="form.ifAnnual" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.COM_YN" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="是否招投标">
					<el-select v-model="form.ifBid" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.COM_YN" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<!-- <el-form-item label="销售方式">
					<el-select v-model="form.salMth" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.SAL_SAL_MTH" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item> -->
				<el-form-item label="质量要求">
					<el-input v-model="form.qualityReq" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="签约请示">
					<el-input v-model="form.signReqNo" clearable style="width: 200px" readonly>
						<template #append>
							<el-button :icon="Search" @click="handleSearchSignRequest" diabled />
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="合同金额">
					<el-input-number v-model="form.totalAmt" :precision="2" :step="0.1" controls-position="right"
						clearable style="width: 200px" disabled></el-input-number>
				</el-form-item>
				<el-form-item label="重量">
					<el-input-number v-model="form.qty" :precision="2" :step="0.1" controls-position="right" clearable
						style="width: 200px" disabled></el-input-number>
				</el-form-item>
				<el-form-item label="合同要求">
					<el-input v-model="form.contrReq" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="合同日期">
					<el-date-picker v-model="form.contrDt" type="date" style="width: 200px;" value-format="YYYY-MM-DD"
						format="YYYY-MM-DD" @change="handleContrDt" readonly></el-date-picker>
				</el-form-item>
				<el-form-item label="终止日期" :error="endDtError">
					<el-date-picker v-model="form.endDt" type="date" style="width: 200px;" value-format="YYYY-MM-DD"
						format="YYYY-MM-DD" :disabled-date="disabledDate" @change="handleEndDt"
						readonly></el-date-picker>
				</el-form-item>
				<el-form-item label="争议所在地法院">
					<el-select v-model="form.checkYn" placeholder="请选择" clearable style="width: 200px" disabled>
						<el-option v-for="item in dicList.CHECK_YN" :key="item.dicCode" :label="item.dicName"
							:value="item.dicCode" />
					</el-select>
				</el-form-item>
				<el-form-item label="风险提示">
					<el-input v-model="form.riskInfo" clearable style="width: 200px" readonly></el-input>
				</el-form-item>
				<el-form-item label="合同模板名称">
					<el-input v-model="form.tempNm" clearable style="width: 200px" readonly>
						<template #append>
							<el-button :icon="Search" @click="handleSearchCotTmp" disabled />
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="录入日期">
					<el-date-picker v-model="form.addTime" type="date" style="width: 200px;" value-format="YYYY-MM-DD"
						format="YYYY-MM-DD" disabled></el-date-picker>
				</el-form-item>
				<el-form-item label="录入人">
					<el-input v-model="form.addName" clearable style="width: 200px" disabled></el-input>
				</el-form-item>
				<el-form-item label="是否补录">
                <el-checkbox v-model="ifSupplemental" disabled/>
            </el-form-item>
			</el-form>

			<template #footer>
				<el-button plain type="info" @click="handleCancelSave">关闭</el-button>
			</template>

			<el-tabs v-model="activeName" @tab-click="handleClick">
				<el-tab-pane label="合同行" name="first">
					<addLineVue :cotHead="form" :readonly="readonly"></addLineVue>
				</el-tab-pane>
				<el-tab-pane label="收付款方式" name="second">
					<addVue :cotHead="form" :readonly="readonly" @receive-from-child="retuScales"></addVue>
				</el-tab-pane>
				<el-tab-pane label="文件上传" name="third">
					<el-card :body-style="cardBodyStyle">
						
						<Attachment ref="AttachmentRefManual" :fId="fId" :uploadButton="!readonly"></Attachment>
					</el-card>
				</el-tab-pane>

				<el-tab-pane label="合同条款" name="fourth">
					<addHouse :cotHead="form"></addHouse>
				</el-tab-pane>
			</el-tabs>
		</el-dialog>
	</div>
</template>

<script setup>
import ButtonBar from '@/components/ButtonBar.vue'
import addLineVue from '@/views/cot/input/line.vue'
import addVue from '@/views/cot/input/invtype.vue'
import addHouse from '@/views/cot/input/house.vue'

import {
	ref,
	reactive,
	onMounted,
	getCurrentInstance
} from 'vue'
import { Search } from '@element-plus/icons-vue'

const {
	proxy
} = getCurrentInstance()

import tools from '@/tools'

const cardBodyStyle = ref(tools.style.card)
const inputStyle = ref(tools.style.input)

import Attachment from '@/components/Attachment.vue'
import { ElMessage } from 'element-plus';
const activeName = ref('first')


onMounted(() => {
	// getMenuTable()
	getDictList()
	handleSearch()
})

/**
 * 查询表格字段
 */
// const column = ref([])
// const getMenuTable = () => {
// 	var url = 'framework/MenuTable/queryMenuTable'
// 	var param = {
// 		menuId: localStorage.getItem('menuId'),
// 		tName: 'tableDate'
// 	}
// 	proxy.$axios.post(url, param).then(response => {
// 		if (response.data.code == '0') {
// 			column.value = response.data.data
// 		} else {
// 			ElMessage({
// 				type: 'error',
// 				message: '操作失败' + response.data.msg,
// 			});
// 		}
// 	});
// }
/**
 * 查询表格
 */


/**
 *  查询字典
 */
const dicList = ref({
	CONTRACT_TYPE: [],
	contrSts: [],
	SAL_INV_MTH: [],
	PRICE_DCN_MTH: [],
	DELV_MTH: [],
	TMS_FTRANTYPE: [],
	WEIGHT_DATA_ACCORD: [],
	ANALY_DATA_ACCORD: [],
	SAL_SAL_MTH: [],
	COM_YN: [],
	CHECK_YN: []
})
const getDictList = () => {
	var url = 'framework/Common/querySelectorList'
	var param = {
		type: JSON.stringify(['CONTRACT_TYPE', 'contrSts', 'SAL_INV_MTH', 'PRICE_DCN_MTH', 'DELV_MTH', 'TMS_FTRANTYPE', 'WEIGHT_DATA_ACCORD', 'ANALY_DATA_ACCORD', 'SAL_SAL_MTH', 'COM_YN', 'CHECK_YN'])
	}
	proxy.$axios.get(url, param).then(response => {
		if (response.data.code == '0') {
			dicList.value = response.data.data
		} else {
			ElMessage.error('操作失败！' + response.data.msg)
		}
	})
}
const formatter = (row, column, cellValue, index) => {
	if (!cellValue || cellValue == null || cellValue == '') {
		return cellValue
	}
	switch (column.property) {
		case 'contrTy':
			cellValue = dicList.value.CONTRACT_TYPE.find(item => item.dicCode == cellValue)?.dicName
			break
		case 'conSts':
			cellValue = dicList.value.contrSts.find(item => item.dicCode == cellValue)?.dicName
			break
		case 'invMth':
			cellValue = dicList.value.SAL_INV_MTH.find(item => item.dicCode == cellValue)?.dicName
			break
		case 'priceDcnMth':
			cellValue = dicList.value.PRICE_DCN_MTH.find(item => item.dicCode == cellValue)?.dicName
			break
		case 'delvMth':
			cellValue = dicList.value.DELV_MTH.find(item => item.dicCode == cellValue)?.dicName
			break
		case 'weightDataAccord':
			cellValue = dicList.value.WEIGHT_DATA_ACCORD.find(item => item.dicCode == cellValue)?.dicName
			break
		case 'analyDataAccord':
			cellValue = dicList.value.ANALY_DATA_ACCORD.find(item => item.dicCode == cellValue)?.dicName
			break
		case 'salMth':
			cellValue = dicList.value.SAL_SAL_MTH.find(item => item.dicCode == cellValue)?.dicName
			break
		case 'ifAnnual':
			cellValue = dicList.value.COM_YN.find(item => item.dicCode == cellValue)?.dicName
			break
		case 'ifBid':
			cellValue = dicList.value.COM_YN.find(item => item.dicCode == cellValue)?.dicName
			break
		case 'checkYn':
			cellValue = dicList.value.CHECK_YN.find(item => item.dicCode == cellValue)?.dicName
			break
		case 'addTime':
			cellValue = cellValue.split(' ')[0]
			break
	}

	return cellValue
}
/**
 *  查询字典
 */

const query = ref({
	contrTy: '',
	contrNo: '',
	contrNm: '',
	khContrNo: '',
	supplierNm: '',
	contrDt: '',
})
const tableData = ref([])
const handleSearch = () => {
	currentPage.value = 1
	getTableData()
}

const getTableData = () => {
	var url = 'cot/Head/query'
	var param = {
		page: currentPage.value,
		rows: pageSize.value,
		params: JSON.stringify(query.value)
	}
	proxy.$axios.get(url, param).then(response => {
		if (response.data.code == '0') {
			tableData.value = response.data.data.records
			totalRows.value = response.data.data.total
		} else {
			ElMessage.error('操作失败！' + response.data.msg)
		}
	})
}
/**
 *   查询
 */

/**
 * 分页
 */
const currentPage = ref(1)
const totalRows = ref(0)
const pageSizes = ref([5, 10, 20, 30, 40])
const pageSize = ref(10)
const handleSizeChange = (val) => {
	pageSize.value = val
	getTableData()
}
const handleCurrentChange = (val) => {
	currentPage.value = val
	getTableData()
}
/**
 * 分页
 */


/**
 * 新增
 */
const title = ref('')
const readonly = ref(false)
const dialogVisible = ref(false)
const form = ref({
	id: '',
	contrTy: '',
	contrNo: '',
	dataAccord: '',
	approveDt: '',
	checkYn: '',
	riskInfo: '',
	conSts: '',
	signReqNo: '',
	delvDays: '',
	delvDate: '',
	priceDcnMth: '',
	signReqId: '',
	ifAnnual: '',
	delvMth: '',
	contrForm: '',
	processInstanceStatus: '',
	processInstanceId: '',
	ifBid: '',
	tempNm: '',
	invMth: '',
	toPlace: '',
	fromPlace: '',
	tempId: '',
	totalAmt: null,
	qty: null,
	conSts: '',
	remark: '',
	contrReq: '',
	delvPlace: '',
	trsMth: '',
	salMth: '',
	contrDt: '',
	compCd: '',
	deptNm: '',
	deptCd: '',
	supplierNm: '',
	supplierCd: '',
	supplierId: '',
	contrNm: '',
	khContrNo: '',
	addId: '',
	addCode: '',
	addName: '',
	addDeptId: '',
	addDeptCode: '',
	addDeptName: '',
	addTime: '',
	analyDataAccord: '',
	weightDataAccord: '',
})
const ruleFormRef = ref()
const rules = reactive({
	contrNm: [{
		required: true,
		message: '请输入合同名称',
		trigger: 'change' | 'blur'
	}],
	ifAnnual: [{
		required: true,
		message: '请输入是否为长协合同',
		trigger: 'change' | 'blur'
	}],
})

const dialogVisibleSal = ref(false)
const dialogVisiblePur = ref(false)
const dialogVisibleService = ref(false)
/**
 * 新增
 */


/**
 * 保存、修改、删除
 */
const fId = ref('')
const AttachmentRefManual = ref(null)
const ifSupplemental = ref(false)
const closeDialog = () => {
	fId.value = ''
	activeName.value = 'first'
}
const handleCancelSave = () => {
	dialogVisible.value = false
	dialogVisibleSal.value = false
	dialogVisiblePur.value = false
	dialogVisibleService.value = false
}
const handleDetail1 = (row) => {
	if (ruleFormRef.value) {
		ruleFormRef.value.resetFields();
	}

	title.value = '详情'
	fId.value = row.id
	form.value = { ...row }
	ifSupplemental.value = form.value.ifSupplemental === '1'
	readonly.value = true
	switch (form.value.contrTy) {
		case '10':
			dialogVisibleSal.value = true
			break
		case '20':
			dialogVisiblePur.value = true
			break
		case '30':
			dialogVisibleService.value = true
			break
	}
}


/**
 * 保存、修改、删除
 */
const multipleSelection = ref([])
const handleSelectionChange = (val) => {
	multipleSelection.value = val
}
// 批量导出
const handleExportBatch = () => {
	if (multipleSelection.value.length < 1) {
		ElMessage({
			type: 'warning',
			message: '请选择要导出的数据!'
		})
		return
	}

	var ids = []
	multipleSelection.value.forEach((item, index) => {
		ids.push(item.id)
	})
	location.href = import.meta.env.VITE_BASE_API +
		'/cot/Head/exportBatch?ids=' + encodeURIComponent(JSON.stringify(ids))
}

// 全部导出
const handleExportAll = () => {
	location.href = import.meta.env.VITE_BASE_API +
		'/cot/Head/exportAll?params=' + encodeURIComponent(JSON.stringify(query.value))
}

/**
 * 工作流相关
 */
const flowId = ref('')
const handleDetail = (row) => {
	switch (row.contrTy) {
		case '10':
			flowId.value = 'salContract'
			break
		case '20':
			flowId.value = 'purContract'
			break
		case '30':
			flowId.value = 'serviceContract'
			break
	}

	if (row.workId === null) {
		ElMessage({
			type: 'info',
			message: '无法查看',
		})
	} else {

		sessionStorage.setItem('workflowQuery', JSON.stringify({
			flowId: flowId.value,
			workId: row.workId,
			trackId: row.trackId,
			date: new Date().getTime()
		}))

		proxy.$router.push({
			path: '/workflow/detail',
		})
	}
}
</script>


<style scoped>
::v-deep .dicSelect .el-select__wrapper .el-select__selected-item {
	color: #a8abb2;
}
</style>