<template>
	<div class="recordsDetails" id='protectedItems'>
		<el-form label-width="120px" :rules="tableRules" ref="tableData" :model="tableData">
			<div id="pdfId">
				<div class="littleMsg" style="font-size: 18px;font-weight: 600;line-height: 40px;height: 40px;">
					<span style="float:left;font-size: 18px;">单位：</span>
					<span style="float:left;font-size: 18px;">{{tableData.orgName}}</span>
					<!-- <span style="float:right;">申请日期：{{tableData.gxspsj}}</span> -->
				</div>
				<div class="recordsTable">
					<table style="margin-bottom: 10px;">
						<tbody>
							<tr>
								<td colspan="1">
									<div style="min-width: 100px">
										熏蒸方案负责人
									</div>
								</td>
								<td colspan="1">
									<span>{{tableData.operationSupervisor}}</span>
								</td>
								<td colspan="1">联系电话</td>
								<td colspan="1">
									<span>{{tableData.contactPhone}}</span>
								</td>
								<td colspan="1">熏蒸方案起草人</td>
								<td colspan="1">
									<span>{{tableData.orgPerson}}</span>
								</td>
								<td colspan="1">联系电话</td>
								<td colspan="1">
									<span>{{tableData.orgPhone}}</span>
								</td>
								<td style="border: 0;"></td>
							</tr>
							<tr>
								<td colspan="1">作业地点</td>
								<td colspan="3">
									<span>{{tableData.operationLocaltion}}</span>
								</td>
								<td colspan="1">熏蒸作业施药开始时间</td>
								<td colspan="1">
									<el-date-picker v-show="isEdit" clearable class="dateInputCompatible" v-model="tableData.fumigationStart" type="date"
									 format="yyyy-MM-dd" value-format="yyyy-MM-dd"></el-date-picker>
									<span v-show="!isEdit">{{tableData.fumigationStart}}</span>
								</td>
								<td colspan="1">熏蒸作业施药结束时间</td>
								<td colspan="1">
									<el-date-picker v-show='isEdit' clearable v-model="tableData.fumigationEnd" type="date" format="yyyy-MM-dd"
									 value-format="yyyy-MM-dd"></el-date-picker>
									<span v-show="!isEdit">{{tableData.fumigationEnd}}</span>
								</td>
								<td style="border: 0;"></td>
							</tr>
							<tr>
								<td colspan="1">预计散气开始时间<span style="color: red;">*</span></td>
								<td colspan="1">
									<span v-show="!isEdit">{{tableData.gasStart}}</span>
								</td>
							  <td colspan="1">预计散气结束时间<span style="color: red;">*</span></td>
							  <td colspan="1">
							  		<span v-show="!isEdit">{{tableData.gasEnd}}</span>
							  </td>
							  <td colspan="1">预计残渣收集开始时间<span style="color: red;">*</span></td>
							  <td colspan="1">
							  		<span v-show="!isEdit">{{tableData.residueStart}}</span>
							  </td>
							  <td colspan="1">预计残渣收集结束时间<span style="color: red;">*</span></td>
							  <td colspan="1">
							  		<span v-show="!isEdit">{{tableData.residueEnd}}</span>
							  </td>
								<td style="border: 0;"></td>
							</tr>
						</tbody>
					</table>
				</div>
				<div>
					<el-row
					  v-for="(item, index) in fileList"
					  :key="index"
					>
					<a :href="`${fileDownload}?id=${item.id}`" style="color: blue;">{{
						 item.name
					  }}</a> 
					</el-row>
				</div>
				<div v-for="(val,indexs) in tableData.detailVOS" :key="indexs">
					<el-form-item v-show="isEdit" style="width: 80%;" label="选择熏蒸对象:">
						<el-select v-model="val.cfbh" style="width:180px;" @change="checkedIndex(val,indexs,'detailVOS')">
							<el-option v-for="item in cfOption" :key="item.cfbm" :label="item.cfmc" :disabled="item.disable" :value="item.cfbm"></el-option>
						</el-select>
					</el-form-item>
					<span style="line-height: 35px;height: 35px;font-size: 18px;font-weight: 600;" v-show="!isEdit">{{val.cfmc}}</span>
					<div v-show="val.checked || !isEdit">
						<el-table :data="val.data" border stripe tooltip-effect="dark" style="width: 100%">
							<el-table-column prop="kcsl" label="数量(吨)" align="center" show-overflow-tooltip>
							</el-table-column>
							<el-table-column prop="lspz" label="品种" align="center" show-overflow-tooltip>
							</el-table-column>
							<el-table-column prop="lsxz" label="粮油性质" align="center" show-overflow-tooltip>
							</el-table-column>
							<el-table-column prop="rksj" label="入库年月" align="center" show-overflow-tooltip>
							</el-table-column>
							<el-table-column prop="nd" label="生产年份" align="center" show-overflow-tooltip>
							</el-table-column>
							<el-table-column prop="" label="已熏蒸次数" align="center" show-overflow-tooltip>
								<template slot-scope="scope">
									<span>{{val.times}}</span>
								</template>
							</el-table-column>
							<el-table-column label="历史记录" align="center" width="100">
								<template slot-scope="scope">
									<el-tooltip class="item" effect="light" content="查看" placement="top">
										<el-button @click="checkDetail(scope.row.id,indexs)" type="primary" size="small" class="operate_show_btn iconfont iconchakan2"></el-button>
									</el-tooltip>
								</template>
							</el-table-column>
						</el-table>
						<div class="recordsTable">
							<table style="margin-top: 0;">
								<tbody>
									<tr>
										<td :rowspan="val.pestVOS.length+3" style="width: 150px;">

											害虫发生情况


										</td>
									<tr>
										<td colspan="3">害虫检测单号<span style="color: red;">*</span></td>
										<td colspan="6">
											<el-form-item label-width="0" :prop="'detailVOS.' + indexs + '.pestNo'" :rules="{
												required: true, message: '害虫检测单号不能为空', trigger: 'change'
											  }">
												<el-select clearable v-show="isEdit" v-model="val.pestNo" placeholder="请选择" @change="ChangePerCode($event,indexs)">
													<el-option v-for="item in val.lyxzOption" :key="item.hcjcdh" :label="item.hcjcdh" :value="item.hcjcdh"></el-option>
												</el-select>
											</el-form-item>
											<span v-show="!isEdit">{{val.pestNo}}</span>
										</td>
									</tr>
									<tr>
										<td colspan="1">害虫种类</td>
										<td colspan="1">发现时间</td>
										<td colspan="1">密度</td>
										<td colspan="1">发生部位</td>
										<td colspan="4">害虫抗药性分析</td>
									</tr>
									<tr v-for="(item,index) in val.pestVOS">
										<td colspan="1">{{item.hczl}}</td>
										<td colspan="1">{{item.vupdateTime}}</td>
										<td colspan="1">{{item.density}}</td>
										<td colspan="1">{{item.fsbw}}</td>
										<td colspan="4">{{item.hckyxfx}}</td>
									</tr>
									<tr>
										<td rowspan="3" style="width: 150px;">熏蒸设备配置<span style="color: red;">*</span></td>
									</tr>
									<tr>
										<td colspan="2">常规熏蒸</td>
										<td colspan="2">环流熏蒸</td>
										<td colspan="4">环流熏蒸与内环流技术结合</td>
									</tr>
									<tr>
										<td colspan="2" :class="{'errornull':val.istip}">
											<el-select clearable v-show="isEdit" v-model="val.convFumigation" placeholder="请选择" @change="cgChange('cg',indexs)">
												<el-option v-for="item in cgxzList" :key="item.value" :label="item.label" :value="item.value"></el-option>
											</el-select>
											<span v-show="val.istip" class="spanErrorTip">熏蒸设备三选一不能为空</span>
											<span v-show="!isEdit">{{getDictName('cgxzList',val.convFumigation)}}</span>
										</td>
										<td colspan="2" :class="{'errornull':val.istip}">
											<el-select clearable v-show="isEdit" v-model="val.recFumigation" placeholder="请选择" @change="cgChange('hl',indexs)">
												<el-option v-for="item in hlxzList" :key="item.value" :label="item.label" :value="item.value"></el-option>
											</el-select>
											<span v-show="val.istip" class="spanErrorTip">熏蒸设备三选一不能为空</span>
											<span v-show="!isEdit">{{getDictName('hlxzList',val.recFumigation)}}</span>
										</td>
										<td colspan="4" :class="{'errornull':val.istip}">
											<el-select clearable v-show="isEdit" v-model="val.recIcCombine" placeholder="请选择" @change="cgChange('hlnh',indexs)">
												<el-option v-for="item in hlnhjsList" :key="item.value" :label="item.label" :value="item.value"></el-option>
											</el-select>
											<span v-show="val.istip" class="spanErrorTip">熏蒸设备三选一不能为空</span>
											<span v-show="!isEdit">{{getDictName('hlnhjsList',val.recIcCombine)}}</span>
										</td>
									</tr>
									<tr>
										<td rowspan="6" style="width: 150px;">作业安排</td>
										<td colspan="2">药剂库位置<span style="color: red;">*</span></td>
										<td colspan="6">
											<!-- <el-form-item label-width="0" :prop="'detailVOS.' + indexs + '.drugNameCode'" :rules="{
												required: true, message: '药剂库位置不能为空', trigger: 'change'
												}"> -->
											
												<span>{{val.ypkwzname}}</span>
											<!-- </el-form-item> -->
										</td>
									</tr>
									<tr>
										<td colspan="2">药剂名称<span style="color: red;">*</span></td>
										<td colspan="2">剂型</td>
										<td colspan="2">浓度<span style="color: red;">*</span></td>
										<td colspan="2">施药方式<span style="color: red;">*</span></td>
									</tr>
									<tr>
										<td colspan="2">
											<!-- <el-form-item label-width="0" :prop="'detailVOS.' + indexs + '.drugNameCode'" :rules="{
												required: true, message: '药剂名称不能为空', trigger: 'change'
												}"> -->

												<span>{{val.drugCode}}</span>
											<!-- </el-form-item> -->

										</td>
										<td colspan="2">
											<!-- <el-form-item label-width="0"> -->
												<span>{{val.drugType}}</span>
											<!-- </el-form-item> -->
										</td>
										<td colspan="2">
											<!-- <el-form-item label-width="0" :prop="'detailVOS.' + indexs + '.drugConcentration'" :rules="{
												required: true, message: '浓度不能为空', trigger: 'blur'
												}"> -->
												<span>{{val.drugConcentration}}</span>
												<!-- <el-input :readonly="!isEdit" v-model="val.drugConcentration"></el-input> -->
											<!-- </el-form-item> -->
										</td>
										<td colspan="2">
											<!-- <el-form-item label-width="0" :prop="'detailVOS.' + indexs + '.applicationMethod'" :rules="{
												required: true, message: '施药方式不能为空', trigger: 'change'
												}"> -->
												<el-select clearable v-show="isEdit" v-model="val.applicationMethod" placeholder="请选择">
													<el-option v-for="item in yjfsList" :key="item.value" :label="item.label" :value="item.value"></el-option>
												</el-select>
												<span v-show="!isEdit">{{getDictName('cgxzList',val.applicationMethod)}}</span>
											<!-- </el-form-item> -->
										</td>
									</tr>
									<tr>
										<td colspan="2">领取数量<span style="color: red;">*</span>（kg）</td>
										<td colspan="2">粮堆单位用药量（g/m3）</td>
										<td colspan="2">空间单位用药量（g/m3）</td>
										<td colspan="2">总用药量<span style="color: red;">*</span>（kg）</td>
									</tr>
									<tr>
										<td colspan="2">
											<!-- <el-form-item label-width="0" :prop="'detailVOS.' + indexs + '.getNumber'" :rules="{
												required: true, message: '领取数量不能为空', trigger: 'blur'
												}"> -->
												<span>{{val.getNumber}}</span>
												<!-- <el-input :readonly="!isEdit" v-model="val.getNumber"></el-input> -->
											<!-- </el-form-item> -->
										</td>
										<td colspan="2">
											<!-- <el-form-item label-width="0"> -->
												<span>{{val.grainDosage}}</span>
												<!-- <el-input :readonly="!isEdit" v-model="val.grainDosage"></el-input> -->
											<!-- </el-form-item> -->
										</td>
										<td colspan="2">
											<!-- <el-form-item label-width="0"> -->
												<span>{{val.spaceDosage}}</span>
												<!-- <el-input :readonly="!isEdit" v-model="val.spaceDosage"></el-input> -->
											<!-- </el-form-item> -->
										</td>

										<td colspan="2">
											<!-- <el-form-item label-width="0" :prop="'detailVOS.' + indexs + '.totalDosage'" :rules="{
												required: true, message: '总用药量不能为空', trigger: 'blur'
												}"> -->
												<span>{{val.totalDosage}}</span>
												<!-- <el-input :readonly="!isEdit" v-model="val.totalDosage"></el-input> -->
											<!-- </el-form-item> -->
										</td>
									</tr>
								</tbody>
							</table>
							<table style="margin-top: 0;margin-bottom: 10px;" v-if="indexs == tableData.detailVOS.length-1">
								<tbody>
									<tr>
										<td></td>
										<!-- <td :rowspan="val.fumigationPersonnelList.length+3" style="width: 150px;">施药人员</td> -->
										<td colspan="">姓名<span style="color: red;">*</span></td>
										<td colspan="">资质情况</td>
										<td colspan="">资质情况审核</td>
										<td colspan="">工作任务</td>
										<td colspan="">是否为外请</td>
										<td style="width: 80px;" v-show='$route.query.type == "add" || $route.query.type == "edit"'>
											操作
										</td>
									</tr>
									<tr v-for="(info,indexvo) in val.fumigationPersonnelList.slice(0,1)">
										<td style="width: 150px;">作业负责人员</td>
									  <td colspan="">
									  	<span>{{info.personnelName}}</span>
									  </td>
									  <td colspan="">
									  	<span>{{info.professionalQualification}}</span>
									  	<!-- <el-input :readonly="!isEdit" v-model="info.professionalQualification"></el-input> -->
									  </td>
									  <td colspan="">
									  	<span>{{info.physicalCondition}}</span>
									  	<!-- <el-input :readonly="!isEdit" v-model="info.physicalCondition"></el-input> -->
									  </td>
									  <td colspan="">
									  	<span>{{info.workTask}}</span>
									  	<!-- <el-input :readonly="!isEdit" v-model="info.workTask"></el-input> -->
									  </td>
									  <td colspan="">
									  	<span>{{getDictName('outsideList',info.outside)}}</span>
									  	<!-- <el-input :disabled="!isEdit" v-model="info.outside"></el-input> -->
									  </td>
										<td colspan=""  v-show='$route.query.type == "add" || ($route.query.dataStatus == 0 && $route.query.type != "detail")'>

										</td>
									</tr>
									<tr>
										 <td :rowspan="val.fumigationPersonnelList.length" style="width: 150px;">熏蒸作业人员</td>
									    <tr v-for="(info,indexvo) in val.fumigationPersonnelList.slice(1,val.fumigationPersonnelList.length)">
									    	<td colspan="">
									    		<span>{{info.personnelName}}</span>
									    		<!-- <el-form-item label-width="0" :prop="'detailVOS.'+indexs+'fumigationPersonnelList.' + indexvo + '.personnelName'"
									    			:rules="{
									    			required: true, message: '姓名不能为空', trigger: 'blur'
									    			}"> -->
									    		<!-- <el-input @blur="blurinput($event,indexs,indexvo)" :readonly="!isEdit" v-model="info.personnelName"></el-input> -->
									    		<!-- <span v-show="info.isname" class="spanErrorTip">姓名不能为空</span> -->
									    		<!-- </el-form-item> -->
									    	</td>
									    	<td colspan="">
									    		<span>{{info.professionalQualification}}</span>
									    		<!-- <el-input :readonly="!isEdit" v-model="info.professionalQualification"></el-input> -->
									    	</td>
									    	<td colspan="">
									    		<span>{{info.physicalCondition}}</span>
									    		<!-- <el-input :readonly="!isEdit" v-model="info.physicalCondition"></el-input> -->
									    	</td>
									    	<td colspan="">
									    		<span>{{info.workTask}}</span>
									    		<!-- <el-input :readonly="!isEdit" v-model="info.workTask"></el-input> -->
									    	</td>
									    	<td colspan="">
									    		<!-- <el-select clearable v-show="isEdit" v-model="info.outside"
									    			placeholder="请选择">
									    			<el-option v-for="item in outsideList" :key="item.value"
									    				:label="item.label" :value="item.value"></el-option>
									    		</el-select> -->
									    		<span>{{getDictName('outsideList',info.outside)}}</span>
									    		<!-- <el-input :disabled="!isEdit" v-model="info.outside"></el-input> -->
									    	</td>
									    	<td colspan="" v-show='$route.query.type == "add" || $route.query.type == "edit"'>
									    		<div class="addrightboder" v-show='$route.query.type == "add" || $route.query.type == "edit"'>
									    			<span style="margin-left: 10px;" class="iconfont iconjianshao addradius minibtn" @click="removePersonnalVO(info,indexs)"></span>
									    		</div>
									    	</td>
									    </tr>
									</tr>
									
								</tbody>
							</table>
							<div class="miniaddrightboder" v-show='$route.query.type == "add" || $route.query.type == "edit"'>
								<span @click="addPersonnalVO(indexs)" class="iconfont iconzengjia addradius addminibtn">
								</span>
							</div>
                            <div style="float: right; width: 300px;margin-top: -120px;">
                                <div id="xzfzsqadd"></div>
                            </div>
						</div>
					</div>

					<!-- </el-row> -->
				</div>

				<div>
					<table>
						<tbody>
							<tr>
								<td rowspan="4" style="width: 150px;">
									购销公司审核
								</td>
							</tr>
							<tr>
								<td colspan="2">审核意见</td>
								<td colspan='6'>
									<el-radio-group :disabled="true" v-model="tableData.qyspjg">
										<el-radio :label="'1'">同意</el-radio>
										<el-radio :label="'0'">驳回</el-radio>
									</el-radio-group>
								</td>
							</tr>
							<tr>
								<td colspan="2">批复意见</td>
								<td colspan="6">
									<el-input type="textarea" :rows="3" :readonly="true" v-model="tableData.qyspyj" clearable placeholder="请输入购销公司意见"></el-input>
								</td>
							</tr>
							<tr>
								<td colspan="2">批准人</td>
								<td colspan="2">
									<el-input :readonly="true" v-model="tableData.qyspr"></el-input>
								</td>
								<td colspan="2">批准时间</td>
								<td colspan="2">
									<el-date-picker :readonly="true" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd" v-model="tableData.qyspsj"
									 placeholder="批准时间" clearable></el-date-picker>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
                <div v-show="$route.query.dataStatus == 12 || $route.query.dataStatus == 13 || $route.query.dataStatus == 7 || $route.query.dataStatus >= 5">
                    <table >
						<tbody>
							<tr>
								<td rowspan="4" style="width: 150px;">
									主管审核
								</td>
                            </tr>
							<tr>
								<td colspan="2">审核意见</td>
								<td colspan='6'>
									<el-radio-group :disabled="$route.query.dataStatus != '12'" v-model="tableData.zgldshjg">
										<el-radio :label="'1'">同意</el-radio>
										<el-radio :label="'0'">驳回</el-radio>
									</el-radio-group>
								</td>
							</tr>
							<tr>
								<td colspan="2">批复意见</td>
								<td colspan="6">
									<el-input type="textarea" :rows="3" :readonly="$route.query.dataStatus != '12'" v-model="tableData.zgldyj" clearable placeholder="请输入主管领导意见"></el-input>
								</td>
							</tr>
							<tr>
								<td colspan="2">批准人</td>
								<td colspan="2">
									<el-input :readonly="$route.query.dataStatus != '12'" v-model="tableData.zgldshr"></el-input>
								</td>
								<td colspan="2">批准时间</td>
								<td colspan="2">
									<el-date-picker :readonly="$route.query.dataStatus != '12'" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd" v-model="tableData.zgldshsj"
									 placeholder="批准时间" clearable></el-date-picker>
								</td>
							</tr>
						</tbody>
					</table>
					<div style="float: right;width: 300px;">
						<div id="fumigationSchemeDetail"></div>
					</div>
				</div>
				<div v-show='($route.query.dataStatus == 5 && $route.query.type !="look")|| $route.query.dataStatus == 6 || $route.query.dataStatus == 7' style="position: relative">
					<table>
						<tbody>
							<tr>
								<td rowspan="4" style="width: 150px;">
									区发改委审核
								</td>
							<tr>
								<td colspan="2">审核意见</td>
								<td colspan='6'>
									<el-radio-group :disabled="isLook" v-model="tableData.qfgwshjg">
										<el-radio :label="'1'">同意</el-radio>
										<el-radio :label="'0'">驳回</el-radio>
									</el-radio-group>
								</td>
							</tr>
							<tr>
								<td colspan="2">批复意见</td>
								<td colspan="6">
									<el-input type="textarea" :rows="3" :readonly="isLook" v-model="tableData.qfgwyj" clearable placeholder="请输入区发改委意见"></el-input>
								</td>
							</tr>
							<tr>
								<td colspan="2">审核人</td>
								<td colspan="2">
									<el-input :readonly="isLook" v-model="tableData.qfgwshr"></el-input>
								</td>
								<td colspan="2">批准时间</td>
								<td colspan="2">
									<el-date-picker :readonly="isLook" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd" v-model="tableData.qfgwsj"
									 placeholder="批准时间" clearable></el-date-picker>
								</td>
							</tr>
						</tbody>
					</table>
                    <div style="position: absolute; right: 300px; bottom: 150px;">
                        <div id="qfgwSchemeDetail"></div>
                    </div>
				</div>
			</div>
		</el-form>
		<el-dialog title="历史熏蒸情况" :visible.sync="dialogVisible" @close="closeDialog" :close-on-click-modal="false">
			<el-table :data="LsdataList" border stripe tooltip-effect="dark" style="width: 100%">
				<el-table-column width="60" type="index" label="序号" align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column prop="fumigationMethod" label="熏蒸方式" align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column prop="drugName" label="熏蒸药剂" align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column prop="totalDosage" label="用药量(g)" align="center" show-overflow-tooltip>
				</el-table-column>
				<el-table-column prop="fumigationDate" label="熏蒸日期" align="center" show-overflow-tooltip>
				</el-table-column>
			</el-table>
			<!-- <el-row> -->
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="pageForm.page"
			 :page-sizes="[10, 20, 30, 40]" :page-size="pageForm.size" layout="total, sizes, prev, pager, next, jumper" :total="pageForm.total"></el-pagination>
			<!-- </el-row> -->
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="dialogVisible=false" size="small" class="iconfont iconfanhui">返回
				</el-button>
			</span>
		</el-dialog>
		<div style="margin-top: 20px;text-align:center;">
			<el-button type="primary" @click="submitFun()" size="small" class="iconfont icontijiao" v-if="$route.query.type == 'audit'">提交</el-button>
			<!--            <el-button type="primary" v-if="$route.query.type == 'edit'" @click="confirmFun" size="small" class="iconfont iconqueren">确认</el-button>-->
			<el-button type="primary" :loading="stateLoading" @click="gaizhangFn" size="small" class="iconfont icongaizhang" v-if="$route.query.type == 'seal' && !isGzwc">盖章</el-button>
			<el-button type="primary" @click="bohuiFn" size="small" class="iconfont iconbohui" v-if="($route.query.type == 'seal' && !isGzwc) ||$route.query.type == 'audit'">驳回</el-button>
			<el-button type="primary" @click="exportFun" size="small" class="iconfont icondaochu11">导出</el-button>
			<el-button type="primary" @click="returnFun" size="small" class="iconfont iconfanhui">返回</el-button>
		</div>
		<!-- //签章弹窗组件 -->
		<sealDialog
		  ref="sealDialog"
		  sealId="qfgwSchemeDetail"
		  @sealTodo="sealTodo"
		  @sealError="sealError"
		></sealDialog>
	</div>
</template>

<script>
import { fileDownload } from "@/api";
import {
  getWareList,
  getByCreditCode,
  getPestOrderList,
  getPestInfoByOrder,
  getDrugList,
  getHistoryByStorageNo,
  getgationapplyadd,
  getDetailById,
  getupdateById,
  sinkpointList,
} from "@/api/grainReserves/zygl/index";
import { FileApi } from "@/api";
import htmlToPdf from "@/utils/htmlToPdf";
import sealDialog from "@/components/sealDialog/index.vue";
import { fileInfo } from "@/api/grainReserves/downWarehouse/warehouseAcceptance";

function checkPhone(rule, value, callback) {
  var val = value && value.trim();
  if (/^1\d{10}$/.test(val)) {
    callback();
  } else {
    callback(new Error("请按正确手机号码格式填写"));
  }
}

function checkCall(rule, value, callback) {
  var val = value && value.trim();
  if (/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(val)) {
    callback();
  } else {
    callback(new Error("请按正确电话号码格式填写"));
  }
}

function checkZNum(rule, value, callback) {
  if (/^(?:[1-9]\d*|0)$/.test(value) == false) {
    callback(new Error("请输入正整数"));
  } else {
    callback();
  }
}

function checkNum(rule, value, callback) {
  if (value && value != 0 && !Number(value)) {
    callback(new Error("请输入数字"));
  } else {
    callback();
  }
}
export default {
  name: "recordsDetails",
  components: {
    sealDialog,
  },
  data() {
    let self = this;
    return {
      ypknameList: [],
      fileDownload: `${fileDownload}`,
      fileList: [],
      stateLoading: false,
      pageForm: {
        page: 1,
        size: 10,
        total: 0,
      },
      outsideList: [
        {
          label: "否",
          value: "0",
        },
        {
          label: "是",
          value: "1",
        },
      ],
      cgxzList: [
        {
          label: "粮面潮解",
          value: "0",
        },
        {
          label: "布袋埋藏",
          value: "1",
        },
        {
          label: "探管",
          value: "2",
        },
        {
          label: "综合施药",
          value: "3",
        },
      ],
      hlxzList: [
        {
          label: "固定式布置形式",
          value: "0",
        },
        {
          label: "移动式布置形式",
          value: "1",
        },
      ],
      hlnhjsList: [
        {
          label: "分别使用_固定式",
          value: "0",
        },
        {
          label: "分别使用_移动式",
          value: "1",
        },
        {
          label: "二合一应用_单向控制",
          value: "2",
        },
        {
          label: "二合一应用_双向控制",
          value: "3",
        },
      ],
      yjfsList: [
        {
          label: "潮解法",
          value: "0",
        },
        {
          label: "仓外发生器",
          value: "1",
        },
        {
          label: "钢瓶气",
          value: "2",
        },
      ],
      // yjnameList:[

      // ],

      LsdataList: [
        // {
        // 	sys_type:'10',
        // 	upload_time:'2020-02-03',
        // 	upload_user:'fsda'
        // },
        // {
        // 	sys_type:'10',
        // 	upload_time:'dsfad单方事故',
        // 	upload_user:'fsda'
        // }
      ],
      dialogVisible: false,
      isLook: false,
      isEdit: false,
      isGz: false,
      tableData: {
        operationLocaltion: "",
        qyspjg: "1",
        qyspr: "",
        qyspsj: "",
        xzqygz: "",
        qlbgz: "",
        qlbspsj: "",
        qlbspr: "",
        // qlbspjg: '',
        // xzqygz: '',
        // qlbgz: '',
        // 主管
        zgldshjg: "1",
        zgldyj: "",
        zgldshr: "",
        zgldshsj: "",
        // 区发改委
        qfgwshjg: '',
        qfgwshr: '',
        qfgwsj: '',
        qfgwyj: '',
        detailVOS: [
          {
            times: "",
            lyxzOption: [],
            grainNature: "",
            yjnameList: [],
            drugCode: "",
            totalDosage: "",
            spaceDosage: "",
            grainDosage: "",
            getNumber: "",
            applicationMethod: "",
            drugConcentration: "",
            drugType: "",
            recIcCombine: "",
            recFumigation: "",
            convFumigation: "",
            pestNo: "",
            checked: false,
            cfbh: "",
            hlnhdisabled: false,
            cgdisabled: false,
            hldisabled: false,
            data: [],
            pestVOS: [
              {
                pestType: "",
                discoveryTime: "",
                density: "",
                happenPosition: "",
                pestResistance: "",
              },
            ],
            fumigationPersonnelList: [
              {
                personnelName: "",
                professionalQualification: "",
                physicalCondition: "",
                workTask: "",
                outside: "",
              },
            ],
          },
        ],
      },
      isGzwc: false,
      rules: {
        qlbspjg: [
          {
            required: true,
            message: "请选择审核意见",
            trigger: "change",
          },
        ],
        // qyfzr:[{
        // 	required: true,
        // 	message: '请输入单位负责人',
        // 	trigger: 'change'
        // }],
        qlbspjg: [
          {
            required: true,
            message: "请填写退回原因",
            trigger: "blur",
          },
        ],
      },
      cfOption: [],
      tableRules: {
        orgPhone: [
          {
            validator: checkPhone,
          },
        ],
        contactPhone: [
          {
            validator: checkPhone,
          },
        ],
        funigaPhone: [
          {
            validator: checkPhone,
          },
        ],
        fumigationNumber: [
          {
            validator: checkZNum,
          },
        ],
        drugPurity: [
          {
            validator: checkNum,
          },
        ],
      },
      //用来选择 开始与结束的时间段
      selectStartTime: {
        disabledDate(time) {
          if (!self.tableData.fumigationEnd) return false;
          return (
            new Date(time).getTime() >=
            new Date(self.tableData.fumigationEnd).getTime()
          );
        },
      },
      selectEndTime: {
        disabledDate(time) {
          if (!self.tableData.fumigationStart) return false;
          return (
            new Date(time).getTime() <=
            new Date(self.tableData.fumigationStart).getTime()
          );
        },
      },
    };
  },
  methods: {
    // 获取库点列表
    async getStoreHouses(type) {
      let res = await sinkpointList();
      if (res && res.infoCode === 200) {
        this.ypknameList = res.data;
        if (type == "check") {
        } else {
          this.getInfo();
        }
        return;
      }
      this.$message.error(res.msg || "获取库点名称列表失败");
    },
    getDictName(key, value) {
      let name = "";
      if (value) {
        this[key].forEach((item) => {
          value.split(",").forEach((val) => {
            if (item.value == val) {
              name += item.label + ",";
            }
          });
        });
      }
      if (name) {
        return name.substring(0, name.length - 1);
      } else {
        return "";
      }
    },
    handleSizeChange(val) {
      this.pageForm.size = val;
      this.GetHistoryStorage(this.indexs);
    },
    handleCurrentChange(val) {
      this.pageForm.page = val;
      this.GetHistoryStorage(this.indexs);
    },
    //关闭弹窗
    closeDialog() {},
    //查看历史记录
    checkDetail(id, index) {
      this.dialogVisible = true;
      this.GetHistoryStorage(index);
    },
    //获取历史记录列表
    GetHistoryStorage(index) {
      this.indexs = index;
      getHistoryByStorageNo(
        this.pageForm,
        this.tableData.detailVOS[index].cfbh
      ).then((res) => {
        if (res.infoCode == 200) {
          this.LsdataList = res.data.items;
          this.pageForm.total = res.data.total;
          this.$set(this.tableData.detailVOS[index], "times", res.data.total);
        }
      });
    },
    //选择熏蒸对象
    checkedIndex(item, index, key) {
      this.getdrugList(index);
      this.GetHistoryStorage(index);
      let arr = [];
      this.tableData[key].forEach((item, index) => {
        arr.push(item.cfbh);
      });
      for (let i = 0; i < this.cfOption.length; i++) {
        this.$set(this.cfOption[i], "disable", false);
      }
      for (let i = 0; i < this.cfOption.length; i++) {
        for (let j = 0; j < arr.length; j++) {
          if (this.cfOption[i].cfbm == arr[j]) {
            this.$set(this.cfOption[i], "disable", true);
          }
        }
      }
      getByCreditCode(sessionStorage.getItem("tyshxydm"))
        .then((res) => {
          if (res.infoCode == 200) {
            this.tableData.detailVOS[index].data = res.data;
          }
          var datas = {
            cfbh: item.cfbh,
            tyshxydm: sessionStorage.getItem("tyshxydm"),
          };
          this.getPestList(datas, index);
        })
        .catch();
    },
    //获取虫害检测单号
    getPestList(data, index) {
      getPestOrderList(data).then((res) => {
        if (res.infoCode == 200) {
          this.tableData.detailVOS[index].lyxzOption = res.data;
        }
      });
    },
    //通过虫害单号获取虫害信息
    ChangePerCode(e, index) {
      getPestInfoByOrder(e).then((res) => {
        this.tableData.detailVOS[index].pestVOS = res.data;
      });
    },
    //获取药剂名称，药剂剂型
    getdrugList(index) {
      getDrugList().then((res) => {
        if (res.infoCode == 200) {
          this.tableData.detailVOS[index].yjnameList = res.data;
        }
      });
    },
    //选择药剂名称，显示剂型
    Drugchange(e, index) {
      this.tableData.detailVOS[index].yjnameList.forEach((val, k) => {
        if (e == val.drugName) {
          this.tableData.detailVOS[index].drugType = val.drugType;
        }
      });
    },
    //选择熏蒸设备配置
    cgChange(type, index) {
      if (type == "cg" && this.tableData.detailVOS[index].convFumigation) {
        this.tableData.detailVOS[index].cgdisabled = false;
        this.tableData.detailVOS[index].hldisabled = true;
        this.tableData.detailVOS[index].hlnhdisabled = true;
      } else if (
        type == "hl" &&
        this.tableData.detailVOS[index].recFumigation
      ) {
        this.tableData.detailVOS[index].cgdisabled = true;
        this.tableData.detailVOS[index].hldisabled = false;
        this.tableData.detailVOS[index].hlnhdisabled = true;
      } else if (
        type == "hlnh" &&
        this.tableData.detailVOS[index].recIcCombine
      ) {
        this.tableData.detailVOS[index].cgdisabled = true;
        this.tableData.detailVOS[index].hldisabled = true;
        this.tableData.detailVOS[index].hlnhdisabled = false;
      } else {
        this.tableData.detailVOS[index].cgdisabled = false;
        this.tableData.detailVOS[index].hldisabled = false;
        this.tableData.detailVOS[index].hlnhdisabled = false;
      }
    },
    getDictionaryList() {
      //仓房或选择熏蒸对象
      getWareList({
        kddm: sessionStorage.getItem("tyshxydm") + "001",
      })
        .then((res) => {
          this.cfOption = res.data;
        })
        .catch();
    },
    //提交
    submitFun(succInfo, errInfo) {
      //同意后状态成为 2 企业待盖章
      //驳回后状态成为 0 待提交
      if (succInfo) {
        let params = this.tableData;
        params.dataStatus = 7;
        getupdateById(params)
          .then((res) => {
            if (res.infoCode && res.infoCode == 200) {
              this.$message.success(succInfo);
              this.$router.go(-1);
            } else {
              this.$message.error(errInfo);
            }
          })
          .catch();
      } else {
        // this.$refs.spData.validate((valid, dom) => {
        // 	if (valid) {
        if (this.tableData.qlbspjg == "0" && this.tableData.qlbspjg == "") {
          this.$message.error("请填写申请企业意见");
          return;
        }
        this.$confirm("是否确认提交?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            // this.tableData.qlbspr = sessionStorage.getItem('userName')
            // this.tableData.qlbspsj = this.formatDateTime(new Date());
            let params = this.tableData;
            if (this.tableData.qfgwshjg == "1") {
              params.dataStatus = 6; //区粮办待盖章
            } else {
              params.dataStatus = 13; // 企业待盖章
              params.qfgwyj = "";
              params.qfgwshjg = "";
              params.qfgwshr = "";
              params.qfgwsj = "";
            }
            getupdateById(params)
              .then((res) => {
                if (res.infoCode && res.infoCode == 200) {
                  this.$message.success("提交成功");
                  this.$router.go(-1);
                } else {
                  this.$message.error("提交失败");
                }
              })
              .catch();
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消提交",
            });
          });
      }
    },
    //驳回
    bohuiFn() {
      this.$confirm("是否确认驳回?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let params = this.tableData;
          if (params.dataStatus == '5') {
              params.dataStatus = 13;
          } else if (params.dataStatus == '6') {
              params.dataStatus = 5;
              params.qfgwyj = "";
              params.qfgwshjg = "";
              params.qfgwshr = "";
              params.qfgwsj = "";
          }
          getupdateById(params)
            .then((res) => {
              if (res.infoCode && res.infoCode == 200) {
                this.$message.success("驳回成功");
                this.$router.go(-1);
              } else {
                this.$message.error("驳回失败");
              }
            })
            .catch();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消驳回",
          });
        });
    },
    //盖章
    gaizhangFn() {
      this.$confirm("是否确认盖章？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.stateLoading = true;
          this.$refs.sealDialog.getData();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消盖章",
          });
        });
    },
    sealTodo(sealData) {
      // new签章
      var sh = `newSeal${sealData}`;
      this.tableData.qfgwgz = sh;
      this.submitFun("盖章成功！", "盖章失败！");
    },
    sealError() {
      this.stateLoading = false;
    },
	//导出
	exportFun() {
	  this.printType = false;
	  let _this = this;
	  setTimeout(function () {
	    htmlToPdf.downloadPDF(
	      document.querySelector("#pdfId"),
	      "天津市粮油仓储单位熏蒸作业备案表.pdf"
	    );
	    _this.printType = true;
	  }, 100);
	},
    //取消
    returnFun() {
      this.$router.go(-1);
    },

    getInfo() {
      // let params = {
      // 	id: this.$route.query.id
      // }
      getDetailById(this.$route.query.id)
        .then((res) => {
          if (res.infoCode && res.infoCode == 200) {
            this.tableData = res.data;
            // this.tableData.qlbspr = sessionStorage.getItem('userName')
            // this.tableData.qlbspsj = this.formatDateTime(new Date());
            this.tableData.qlbspr = this.tableData.qlbspr
              ? this.tableData.qlbspr
              : sessionStorage.getItem("userName");
            this.tableData.qlbspsj = this.tableData.qlbspsj
              ? this.tableData.qlbspsj
              : this.formatDateTime(new Date());
            if (!res.data.qfgwshjg) {
              this.tableData.qfgwshjg = "1";
            }
			this.tableData.detailVOS.forEach((items) =>{
			    var arrfzr=[]
			    var arrxzfzr=[]
			    items.fumigationPersonnelList.forEach((vals,i) =>{
			      if(vals.sffzr == 1){
			        arrfzr.push(vals)
			        // items.fzPersonnelList=items.fumigationPersonnelList.slice(i,1)
			      }else{
			        arrxzfzr.push(vals)
			        // items.xzzyPersonnelList=items.fumigationPersonnelList.slice(1,items.fumigationPersonnelList.length)
			      }
			    })
				if(arrfzr.length){
					
				}else{
					items.fumigationPersonnelList.unshift({
					  isname: false,
					  personnelName: "",
					  professionalQualification: "",
					  physicalCondition: "",
					  workTask: "",
					  outside: "",
					  sffzr:1
					})
				}
			  })
            res.data.detailVOS.forEach((item, index) => {
              this.ypknameList.forEach((val) => {
                if (item.ypkwz == val.kddm) {
                  item.ypkwzname = val.kdmc;
                }
              });
              item.data = [];
              var datas = {
                cfmc: item.cfmc,
                kcsl: item.kcsl,
                lspz: item.lspz,
                lsxz: item.lsxz,
                rksj: item.rksj,
                nd: item.scnf,
                lsxzCode: item.lsxzCode,
                lspzCode: item.lspzCode,
                cfbm: item.cfbm,
              };
              item.data.push(datas);
              // this.checkedIndex(item, index, 'detailVOS')
              // this.cgChange()
              item.checked = true;
              console.log(index, "gggggggggggg");
              this.GetHistoryStorage(index);
            });
            if (res.data.fumigationAttach) {
              fileInfo(res.data.fumigationAttach).then((res) => {
                this.fileList = res.data;
              });
            }
            this.tableData = res.data;
            if (this.tableData.xzqygz) {
              if (this.tableData.xzqygz.indexOf("newSeal") == -1) {
                this.$nextTick(() => {
                  this.$ShowSeal("xzfzsqadd", 1);
                  this.$SetSealData(this.tableData.xzqygz, 0, "lingdao", 1);
                });
              } else {
                this.$signatureOnload(
                  "xzfzsqadd",
                  this.tableData.xzqygz.substring(7)
                );
              }
            }
            if (this.tableData.qlbgz) {
              if (this.tableData.qlbgz.indexOf("newSeal") == -1) {
                this.$nextTick(() => {
                  this.$ShowSeal("fumigationSchemeDetail", 1);
                  this.$SetSealData(this.tableData.qlbgz, 0, "lingdao", 1);
                });
              } else {
                this.$signatureOnload(
                  "fumigationSchemeDetail",
                  this.tableData.qlbgz.substring(7)
                );
              }
            }
            if (this.tableData.qfgwgz) {
              if (this.tableData.qfgwgz.indexOf("newSeal") == -1) {
                this.$nextTick(() => {
                  this.$ShowSeal("qfgwSchemeDetail", 1);
                  this.$SetSealData(this.tableData.qfgwgz, 0, "lingdao", 1);
                });
              } else {
                this.$signatureOnload(
                  "qfgwSchemeDetail",
                  this.tableData.qfgwgz.substring(7)
                );
              }
            }
          }
        })
        .catch();
    },
    //转时间方法
    formatDateTime(date) {
      let y = date.getFullYear();
      let m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      let h = date.getHours();
      h = h < 10 ? "0" + h : h;
      let minute = date.getMinutes();
      minute = minute < 10 ? "0" + minute : minute;
      let second = date.getSeconds();
      second = second < 10 ? "0" + second : second;
      return y + "-" + m + "-" + d;
      // return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
    },
  },
  created() {
    this.getDictionaryList();
    this.getStoreHouses();
    if (this.$route.query.type == "look" || this.$route.query.dataStatus == 6) {
      this.isLook = true;
    } else if (this.$route.query.type == "seal") {
      this.isGz = true;
    } else if (this.$route.query.type == "edit") {
      this.isEdit = true;
    } else if (this.$route.query.type == "add") {
      this.isEdit = true;
      this.tableData.orgName = sessionStorage.getItem("orgName");
      this.tableData.orgCode = sessionStorage.getItem("orgCode");
      this.tableData.tyshxydm = sessionStorage.getItem("tyshxydm");
      this.tableData.gxspr = sessionStorage.getItem("userName");
      this.tableData.gxspsj = this.formatDateTime(new Date());
      return;
    }
    this.getInfo();
  },
};
</script>

<style scoped lang="scss">
.recordsDetails {
  background-color: #fff;
  font-size: 14px;
  padding-bottom: 20px;

  #pdfId {
    padding: 20px;
  }

  .littleMsg {
    height: 17px;
  }

  .title {
    font-size: 26px;
    font-weight: 500;
    text-align: center;
  }

  .recordsTable {
    width: 100%;
  }

  table {
    width: 100%;
    // margin: 10px 0;
    margin-top: 10px;
    font-size: 14px;
    border-collapse: collapse;
    color: #525357;
  }

  th {
    font-weight: 700;
    font-size: 18px;
  }

  td,
  th {
    text-align: center;
    border: 1px solid #eaeaea;
    word-wrap: break-word;
    height: 40px;
    line-height: 40px;
  }
  span,
  .el-input,
  .el-textarea {
    font-size: 12px;
  }
}

.addradius {
  border-radius: 50px !important;
}

.addrightboder {
  float: right;
  margin-right: 10px;
}

.addrightboder span,
.miniaddrightboder span {
  font-size: 20px;
  font-weight: bold;
  color: #4588db;
  cursor: pointer;
}

.miniaddrightboder {
  margin-top: -46px;
  float: right;
  margin-right: 40px;
}

.minibtn {
  height: auto !important;
  padding: 5px !important;
}

.addminibtn {
  height: auto !important;
  padding: 5px !important;
}

.el-button--danger {
  padding: 10px;
}

.spanErrorTip {
  color: #f56c6c;
  font-size: 12px;
  padding-top: 4px;
  line-height: 1;
  padding: 4px 0;
  float: left;
}
</style>
<style>
.el-radio__label {
  font-size: 12px !important;
}
#xzfzsqadd {
  position: relative !important;
}

#xzfzsqadd > div {
  left: 0px !important;
  top: -40px !important;
}

#xzfzsq {
  left: 0px !important;
  top: -40px !important;
}

#gxxzbaInfoApply {
  position: relative !important;
}

#gxxzbaInfoApply > div {
  left: 0px !important;
  top: -160px !important;
}

#gxxzbaInfoApplySign {
  left: 0px !important;
  top: -160px !important;
}

#fumigationSchemeDetail {
  position: relative !important;
}

#fumigationSchemeDetail > div {
  left: 0px !important;
  top: -160px !important;
}

#fumigationScheme {
  left: 0px !important;
  top: -160px !important;
}

el-dialog {
  width: 1000px !important;
}
</style>
