<template>
	<div class="detail-main">
		<el-form class="content-main" label-width="150px" ref="formQuery" :model="formQuery">
			<el-row>
				<el-col :span="8">
					<el-form-item label="单位名称">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.dwmc"></el-input>
						<!-- <el-select v-model="formQuery.dwmc" :disabled="isView">
							<el-option v-for="item in companies" :key="item.kddm" :value="item.kdmc" :label="item.kdmc"></el-option>
						</el-select>-->
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="经营地址:" prop="jydz">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.jydz"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="企业性质:" prop="qyxz">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.qyxz"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item label="主要仓储业务类型" prop="zyccywlx">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.zyccywlx"></el-input>
						<!-- <el-select v-model="formQuery.zyccywlx" :disabled="isView">
							<el-option v-for="item in companies" :key="item.kddm" :value="item.kdmc" :label="item.kdmc"></el-option>
						</el-select>-->
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="库区个数:" prop="kqgs">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.kqgs"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="占地面积:" prop="zdmj">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.zdmj"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item label="总仓容" prop="zcr">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.zcr"></el-input>
						<!-- <el-select v-model="formQuery.dwmc" :disabled="isView">
							<el-option v-for="item in companies" :key="item.kddm" :value="item.kdmc" :label="item.kdmc"></el-option>
						</el-select>-->
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="完好仓容:" prop="whcr">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.whcr"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="简易仓容:" prop="jycr">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.jycr"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item label="总罐容" prop="zgr">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.zgr"></el-input>
						<!-- <el-select v-model="formQuery.dwmc" :disabled="isView">
							<el-option v-for="item in companies" :key="item.kddm" :value="item.kdmc" :label="item.kdmc"></el-option>
						</el-select>-->
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="油罐个数:" prop="yggs">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.yggs"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="储粮罩棚:" prop="clzp">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.clzp"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item label="烘干设施:" prop="hgss">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.hgss"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="烘干能力" prop="hgnl">
						<!-- <el-select v-model="formQuery.dwmc" :disabled="isView">
							<el-option v-for="item in companies" :key="item.kddm" :value="item.kdmc" :label="item.kdmc"></el-option>
						</el-select>-->
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.hgnl"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="日出库能力:" prop="rcknl">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.rcknl"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item label="应用环流熏蒸仓容:" prop="yyhlxzcr">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.yyhlxzcr"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="应用粮情测控仓容" prop="yylqckcr">
						<!-- <el-select v-model="formQuery.dwmc" :disabled="isView">
							<el-option v-for="item in companies" :key="item.kddm" :value="item.kdmc" :label="item.kdmc"></el-option>
						</el-select>-->
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.yylqckcr"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="应用机械通风仓容:" prop="yyjxtfcr">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.yyjxtfcr"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item label="实现气调储粮仓容:" prop="sxqdclcr">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.sxqtclcr"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="保管员" prop="bgr">
						<!-- <el-select v-model="formQuery.dwmc" :disabled="isView">
							<el-option v-for="item in companies" :key="item.kddm" :value="item.kdmc" :label="item.kdmc"></el-option>
						</el-select>-->
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.bgy"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="质量检验员:" prop="zljyr">
						<el-input clearable class="inputWidth" :disabled="showLock" v-model="formQuery.zljyy"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<!-- 
			<hr style="margin-bottom:10px;" />-->
			<div class="sub_title">审核</div>
			<el-row v-show="shenh1">
				<el-col :span="8">
					<el-form-item label="审核部门:" prop="qyshbmmc">
						<el-input clearable class="inputWidth" v-model="formQuery.qxshbmmc" :disabled="true"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="审核人:" prop="qyshr">
						<el-input clearable class="inputWidth" v-model="formQuery.qxshr"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="审核结果" prop="qxshjg">
						<el-radio-group v-model="formQuery.qxshjg">
							<el-radio :label="1">通过</el-radio>
							<el-radio :label="2">驳回</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row v-if="shenh1">
				<el-col :span="8">
					<el-form-item label="审核日期:" prop="qxshsj">
						<el-date-picker
							type="date"
							v-model="formQuery.qxshsj"
							format="yyyy-MM-dd"
							value-format="yyyy-MM-dd"
						></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="审核结果:" prop="qyshyj">
						<el-input clearable class="inputWidth" v-model="formQuery.qxshyj"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<!-- <hr style="margin-bottom:10px;" /> -->
			<el-row v-if="shenh2">
				<el-col :span="8">
					<el-form-item label="审核部门:" prop="msshbmmc">
						<el-input clearable class="inputWidth" v-model="formQuery.msshbmmc" :disabled="true"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="审核人:" prop="mshrshr">
						<el-input clearable class="inputWidth" v-model="formQuery.mshrshr"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="审核结果" prop="mshjgshjg">
						<el-radio-group v-model="formQuery.mshjgshjg">
							<el-radio :label="1">通过</el-radio>
							<el-radio :label="2">驳回</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row v-if="shenh2">
				<el-col :span="8">
					<el-form-item label="审核日期:" prop="mshjgshjgshsj">
						<el-date-picker
							type="date"
							v-model="formQuery.mshjgshjgshsj"
							format="yyyy-MM-dd"
							value-format="yyyy-MM-dd"
						></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="审核结果:" prop="msshyj">
						<el-input clearable class="inputWidth" v-model="formQuery.msshyj"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<!-- <hr style="margin-bottom:10px;" /> -->
			<el-row v-if="shenh3">
				<el-col :span="8">
					<el-form-item label="审核部门:" prop="zzqshbmmc">
						<el-input clearable class="inputWidth" v-model="formQuery.zzqshbmmc" :disabled="true"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="审核人:" prop="zzqshr">
						<el-input clearable class="inputWidth" v-model="formQuery.zzqshr"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="审核结果" prop="zzqshjg">
						<el-radio-group v-model="formQuery.zzqshjg">
							<el-radio :label="1">通过</el-radio>
							<el-radio :label="2">驳回</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row v-if="shenh3">
				<el-col :span="8">
					<el-form-item label="审核日期:" prop="zzqshsj">
						<el-date-picker
							type="date"
							v-model="formQuery.zzqshsj"
							format="yyyy-MM-dd"
							value-format="yyyy-MM-dd"
						></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="审核结果:" prop="zzqshyj">
						<el-input clearable class="inputWidth" v-model="formQuery.zzqshyj"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>

		<!-- <el-table
      v-if="showorfalse"
      :data="tableDatas"
      stripe
      border
      fit
      highlight-current-row
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column align="center" label="序号" width="70">
        <template slot-scope="scope">
          <span>{{scope.$index+1}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="shbm" label="审核部门"></el-table-column>
      <el-table-column align="center" prop="shr" label="审核人"></el-table-column>
      <el-table-column align="center" prop="shjg" label="审核结果">
        <template slot-scope="scope">
          <el-radio-group v-model="scope.row.sflh">
            <el-radio label="1">通过</el-radio>
            <el-radio label="2">驳回</el-radio>
          </el-radio-group>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="shrq" label="审核日期" show-overflow-tooltip width="120px;"></el-table-column>
      <el-table-column align="center" prop="shyj" label="审核意见" show-overflow-tooltip width="120px;"></el-table-column>
		</el-table>-->
		<el-row class="footer">
			<el-button
				type="primary"
				v-if="isView"
				size="small"
				@click="handleSave"
				class="iconfont iconzancun"
			>保存</el-button>
			<el-button type="primary" size="small" @click="cancel" class="iconfont iconfanhui">返回</el-button>
		</el-row>
	</div>
</template>

<script>
import {
	getList,
	saves,
	findLis,
	uodate,
	shenhe
} from '@/api/grainCoManage/warehousingLogistics/recordAudit/index.js'
export default {
	//   components: {
	//     VueEditor
	//   },
	data() {
		return {
			shenh1: false,
			shenh2: false,
			shenh3: false,
			showorfalse: false,
			tableDatas: [],
			tableDataspush: [],
			selectListData: [],
			formQuery: {
				qyshbmmc: '旗县粮食局',
				qyshr: '张峰',
				zzqshbmmc: '自治区粮食和物资储备处',
				zzqshr: '立码付',
				msshbmmc: '盟市粮食局',
				mshrshr: '张罗'
			},
			planData: {
				pzbm: '',
				dwbm: '',
				lssl: '',
				scnd: '',
				sfbg: '',
				remark: '',
				sjlx: 0, // 安排0, 货源1
				wtbm: '',
				jylx: ''
			},
			tableData: [],
			rowData: {},
			showLock: true,
			companies: [],
			variety: [],
			form: {
				apzt: '',
				apztmc: '',
				wtbm: ''
			},
			isAdd: false,
			isView: true,
			taskId: '',
			babm: ''
		}
	},
	created() {
		if (this.$route.query.type == 'shows') {
			this.isView = false
			this.shenh1 = true
			this.shenh2 = true
			this.shenh3 = true
			// if (this.taskId == '旗县粮食局审核') {
			// 	this.formQuery.qyshbmmc = '旗县粮食局审核'
			// 	this.shenh1 = true
			// }
			// if (this.taskId == '盟市粮食局审核') {
			// 	this.msshbmmc = this.taskId
			// 	this.shenh2 = true
			// }
			// if (this.taskId == '自治区粮食和物资储备处审核') {
			// 	this.shenh3 = true
			// 	this.zzqshbmmc = this.taskId
			// }
			this.scalePlanDetails(this.$route.query.babm)
		}
		if (this.$route.query.type == 'edits') {
			this.showorfalse = true
			this.taskId = this.$route.query.taskId
			this.babm = this.$route.query.babm
			console.log(this.taskId, '88888')
			if (this.taskId == '旗县粮食局审核') {
				this.formQuery.qyshbmmc = this.taskId
				this.shenh1 = true
			}
			if (this.taskId == '盟市粮食局审核') {
				this.shenh2 = true
			}
			if (this.taskId == '自治区粮食和物资储备处审核') {
				this.shenh3 = true
			}
			this.scalePlanDetails(this.$route.query.babm)
		}
	},
	methods: {
		handleSelectionChange(val) {
			this.selectListData = val
		},
		//查看详情
		scalePlanDetails(babm) {
			let data = {
				babm: babm
			}
			findLis(data).then((res) => {
				if (res.infoCode == '200') {
					this.formQuery = res.data
					this.formQuery.qyshbmmc = '旗县粮食局审核'
					this.formQuery.msshbmmc = '盟市粮食局审核'
					this.formQuery.zzqshbmmc = '自治区粮食和物资储备处审核'
				}
			})
		},
		cancel() {
			this.$router.push({
				path: '/grainCoManage/warehousingLogistics/recordAudit/index'
			})
		},
		handleSave() {
			if (this.taskId == '旗县粮食局审核') {
				let data = {
					qyshbmmc: '旗县粮食局审核',
					babm: this.$route.query.babm,
					taskId: this.$route.query.taskId,
					userId: sessionStorage.getItem('userCode'),
					message: this.formQuery.qyshyj,
					processId: this.formQuery.lcid,
					status: this.formQuery.qxshjg,
					statusKey: 'status'
				}
				shenhe(data).then((res) => {
					if (res.infoCode === 200) {
						this.$message.success('审核成功')
						this.formQuery = res.data
						this.$router.push('index')
					} else {
						this.$message.error('审核失败')
					}
				})
			}
			if (this.taskId == '盟市粮食局审核') {
				let data = {
					babm: this.$route.query.babm,
					taskId: this.$route.query.taskId,
					userId: sessionStorage.getItem('userCode'),
					message: this.formQuery.msshyj,
					processId: this.formQuery.lcid,
					status: this.formQuery.mshjgshjg,
					statusKey: 'status'
				}
				shenhe(data).then((res) => {
					if (res.infoCode === 200) {
						this.$message.success('审核成功')
						this.$router.push('index')
						this.formQuery = res.data
					} else {
						this.$message.error('审核失败')
					}
				})
			}
			if (this.taskId == '自治区粮食和物资储备处审核') {
				let data = {
					babm: this.$route.query.babm,
					taskId: this.$route.query.taskId,
					userId: sessionStorage.getItem('userCode'),
					message: this.formQuery.zzqshyj,
					processId: this.formQuery.lcid,
					status: this.formQuery.zzqshjg,
					statusKey: 'status'
				}
				shenhe(data).then((res) => {
					if (res.infoCode === 200) {
						this.$message.success('审核成功')
						this.$router.push('index')
						this.formQuery = res.data
					} else {
						this.$message.error('审核失败')
					}
				})
			}
		},
		insert() {
			insert({
				details: this.tableData,
				entryAndExitOrderVO: this.form
			}).then((res) => {
				if (res.infoCode === 200) {
					this.$message.success(res.msg)
					this.$router.push('index')
					return
				}
				this.$message.error(res.msg)
			})
		},
		update() {
			update({
				details: this.tableData,
				entryAndExitOrderVO: this.form
			}).then((res) => {
				if (res.infoCode === 200) {
					this.$message.success(res.msg)
					this.$router.push('index')
					return
				}
				this.$message.error(res.msg)
			})
		},
		handleCompanyChange(val, index) {
			let cur = this.companies.filter((item) => item.kdmc == val)[0]
			this.tableData[index].dwbm = cur.kddm
		},
		handleVarietyChange(val, index) {
			let cur = this.variety.filter((item) => item.dictName == val)[0]
			this.tableData[index].pzbm = cur.dictCode
		},
		handleAddRow() {
			if (this.tableData.length < 1) {
				this.tableData.push({
					...this.planData
				})
			} else {
				this.tableData.push({
					// ...this.planData
					pzbm: '',
					dwbm: '',
					lssl: '',
					scnd: '',
					sfbg: '',
					remark: '',
					sjlx: 0, // 安排0, 货源1
					wtbm: '',
					jylx: ''
				})
			}
		},
		handleDelRow(index) {
			this.tableData.splice(index, 1)
		},
		getCompanies() {
			companies().then((res) => {
				this.companies = res.data
			})
		},
		getTypes() {
			varietys(11).then((res) => {
				this.variety = res.data
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.detail-main {
	width: 100%;
	padding: 20px 0;

	.add-table-item {
		text-align: right;
		margin-right: 36px;

		.iconfont {
			font-size: 20px;
			font-weight: bold;
			cursor: pointer;
		}
	}

	.footer {
		text-align: center;
		margin: 20px 0;
	}
}
.sub_title{
    height: 2.5em;
    line-height: 2.5em;
    color: white;
    text-align: center;
    margin: 20px auto;
    width: 100%;
    background-color: #49a2fa;
}
</style>
