<template>
	<div class="content-main fumigationRecordPage">
		<el-form ref="formInline" :model="formInline" class="search-bm-boder" inline>
			<el-row>
				<!-- <el-form-item label="粮食品种:" label-width="80px">
					<el-cascader
					  style="width: 190px"
					  :options="pzOption"
					  :props="pzProps"
					  clearable
					  :show-all-levels="false"
					  v-model="formInline.lspz"
					  placeholder="请选择品种"
					></el-cascader>
                </el-form-item> -->
				<el-form-item label="承储库名称:" label-width="100px">
					<el-input v-model="formInline.orgName" clearable style="width:180px;"></el-input>
				</el-form-item>
				<el-form-item label="作业时间:" label-width="80px">
					<el-date-picker class="dateInputCompatible" clearable v-model="formInline.issueTime" type="daterange"
					 range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"></el-date-picker>
				</el-form-item>
				<el-form-item label="状态:" label-width="80px">
					<el-select v-model="formInline.dataStatus" clearable style="width:180px;">
						<el-option v-for="item in dataStatusList" :key="item.value" :label="item.label" :value="item.value"></el-option>
					</el-select>
				</el-form-item>

				<el-form-item>
					<div class="search-button">
						<span class="search-line"></span>
						<el-button type="primary" @click="queryFun" size="small" class="iconfont iconchaxun">查询</el-button>
						<el-button type="primary" @click="resetFun" size="small" class="iconfont iconzhongzhi">重置</el-button>
					</div>
				</el-form-item>
			</el-row>
		</el-form>
		<el-row>
			<el-col :span="24">
				<el-table :data="tableList" v-loading="loading" border stripe highlight-current-row>
					<el-table-column align="center" label="序号" width="60">
						<template slot-scope="scope">
							<span>{{ scope.$index + 1 }}</span>
						</template>
					</el-table-column>
					<el-table-column prop="orgName" label="承储库名称" align="center" :show-overflow-tooltip="true" width="260px"></el-table-column>
					<el-table-column prop="id" label="熏蒸编号" align="center" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column prop="ch" label="仓号" align="center" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column prop="fumigationStart" label="作业时间" align="center" :show-overflow-tooltip="true">
						<!-- <template slot-scope="scope">
                        {{formatDateTimes(new Date(scope.row.fumigationStart))}}
                      </template> -->
					</el-table-column>
					<el-table-column prop="dataStatus" label="状态" align="center" :show-overflow-tooltip="true">
						<template slot-scope="scope">
							<span v-if="scope.row.dataStatus == 0">待提交</span>
							<span v-if="scope.row.dataStatus == 1">企业待审核</span>
							<span v-if="scope.row.dataStatus == 2">企业待盖章</span>
							<span v-if="scope.row.dataStatus == 3">购销公司待审核</span>
							<span v-if="scope.row.dataStatus == 4">购销公司待盖章</span>
							<span v-if="scope.row.dataStatus == 5">区粮办待审核</span>
							<span v-if="scope.row.dataStatus == 6">区粮办待盖章</span>
							<span v-if="scope.row.dataStatus == 7">已备案</span>
							<span v-if="scope.row.dataStatus == 9">资料上传</span>
                            <span v-if="scope.row.dataStatus == 12">主管待审核</span>
                            <span v-if="scope.row.dataStatus == 13">购销公司待盖章</span>
						</template>
					</el-table-column>
					<el-table-column label="操作" align="center" width="160">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="light" content="查看" placement="top">
								<el-button type="primary" size="small" class="iconfont operate_show_btn iconchakan2" @click.stop="recordsFun(scope.row,'look')"></el-button>
							</el-tooltip>
							
							<el-tooltip class="item" effect="light" content="审核" placement="top" v-if="buttonNameList.indexOf('审核') > -1 && scope.row.dataStatus == '5'">
								<el-button type="primary" size="small" class="iconfont operate_edit_btn iconshenhe" @click.stop="recordsFun(scope.row,'audit')">
								</el-button>
							</el-tooltip>
							<el-tooltip class="item" effect="light" content="盖章" placement="top" v-if="buttonNameList.indexOf('盖章') > -1 && scope.row.dataStatus == 6">
								<el-button type="primary" size="small" class="operate_edit_btn iconfont icongaizhang" @click.stop="recordsFun(scope.row,'seal')">
								</el-button>
							</el-tooltip>
							<el-tooltip class="item" effect="light" content="导出" placement="top">
								<el-button type="primary" size="small" class="iconfont operate_show_btn icondaochu11" @click.stop="recordsFun(scope.row,'look')"></el-button>
							</el-tooltip>
						</template>
					</el-table-column>
				</el-table>
				<div class="pag-right clearFix">
					<el-pagination class="right" @size-change="handleSizeChange" @current-change="handleCurrentChange"
					 :current-page.sync="pageInfo.pageNum" :page-sizes="[10, 20, 30, 40]" :page-size="pageInfo.pageSize" layout="total, sizes, prev, pager, next, jumper"
					 :total="pageInfo.total"></el-pagination>
				</div>
			</el-col>
		</el-row>
	</div>
</template>
<script>
	import {
		getManageList,
		getList,
		getDictionaryList,
		getPzOptions
	} from "@/api/grainReserves/zygl/index";
	import * as validate from "@/directives/validate";
	import {
		getParameter
	} from "@/utils/index";
	import {
		authorityControl
	} from "@/api/menuList";

	export default {
		data() {
			return {
				pzProps: {
					label: "dictName",
					value: "dictCode",
					children: "subDataDictionarys",
					// checkStrictly: true,

					emitPath: false,
				},
				searchShowMoreBool: false,
				status: '',
				formInline: {
					orgName: '',
					issueTime: [],
					dataStatus: '',
					status: ''
				},
				breedNameList: [{
						value: '0',
						label: '玉米',
					},
					{
						value: '1',
						label: '小麦',
					},
					{
						value: '2',
						label: '大豆',
					},
					{
						value: '3',
						label: '稻谷',
					},
					{
						value: '4',
						label: '其他',
					},
				],
				fumigationTypeList: [{
						value: '0',
						label: '常规熏蒸',
					},
					{
						value: '1',
						label: '整仓环流熏蒸',
					},
					{
						value: '2',
						label: '膜下环流熏蒸',
					},
					{
						value: '3',
						label: '其他熏蒸方式',
					},
				],
				curId: "", //该条数据的id
				typeZgData: [],
				paginationShow: true,
				tableList: [],
				loading: false,
				pageInfo: {
					pageNum: 1,
					pageSize: 10,
					total: 0
				},
				buttonNameList: [],
				dataStatusList: [{
						value: 5,
						label: '区粮办待审核',
					},
					{
						value: 6,
						label: '区粮办待盖章',
					},
					{
						value: 7,
						label: '已备案',
					},
				],
				pzOption: [],
				yjOption: [],
				xzfsOption: [],
			};
		},
		watch: {
			"formInline.dataStatus"(newV, oldV) {
				if (newV === 0 || newV) {
					this.formInline.status = newV
				} else {
					this.formInline.status = this.status
				}
			},
		},
		created() {
			if (sessionStorage.getItem('orgCode').length == 5) {
				this.status = 7
				this.formInline.status = 7
			} else {
				this.status = ''
				this.formInline.status = ''
			}
			this.getSinkpointList()
			this.getDictionaryList()
			this.getButtonList();
		},
		methods: {
			//获取按钮
			getButtonList() {
				let codeData = {
					resourceCode: sessionStorage.getItem("resourceCode"),
					userId: sessionStorage.getItem("userCode")
				};
				authorityControl(codeData).then(res => {
					res.data.forEach(item => {
						this.buttonNameList.push(item.resourceName);
					});
					this.getList("start");
				});
			},
			getDictName(key, value) {
				let name = ''
				if (value && this[key].length) {
					this[key].forEach(item => {
						value.split(',').forEach(val => {
							if (item.dictCode == val) {
								name += item.dictName + ','
							}
						})
					})
				}
				if (name) {
					return name.substring(0, name.length - 1)
				} else {
					return ''
				}
			},
			async getSinkpointList() {
				console.log('品种ffffffffff')
				let res = await getPzOptions();
				this.pzOption = res.data;
			},
			getDictionaryList() {
				//品种
				// getDictionaryList({groupId: 'KJPZ'}).then(res=>{
				//     this.pzOption = res.data
				// }).catch()
				//药剂
				getDictionaryList({
					groupId: 'KJYJ'
				}).then(res => {
					this.yjOption = res.data
				}).catch()
				//熏蒸方式
				getDictionaryList({
					groupId: 'KJXZ'
				}).then(res => {
					this.xzfsOption = res.data
				}).catch()
			},
			//获取列表
			getList(type) {
				console.log('lkkkkkkkwwwwwwwwwww')
				console.log(this.formInline.issueTime)
				let data = {
					pageNum: this.pageInfo.pageNum,
					pageSize: this.pageInfo.pageSize,
					issueTime: this.formInline.issueTime,
					endTime: this.formInline.issueTime ? this.formInline.issueTime[1] : undefined,
					startTime: this.formInline.issueTime ? this.formInline.issueTime[0] : undefined,
					dataStatus: this.formInline.dataStatus,
					orgName: this.formInline.orgName,
					status: this.formInline.status
				}
				if (type != "start") { //非初始化调用：查询、分页
					sessionStorage.setItem('searchData', JSON.stringify(data))
				} else { //初始化分两种情况，详情页等返回后的初始化，以及第一次进入此菜单的初始化
					if (JSON.parse(sessionStorage.getItem('searchData')) && sessionStorage.getItem('searchData') != "{}") { //详情页返回后，将对应查询条件和分页的字段赋值，页面回显参数
						let searchData = JSON.parse(sessionStorage.getItem('searchData'))
						this.formInline = getParameter(searchData, ["orgName", "status", "issueTime", "dataStatus"])
						this.pageInfo = getParameter(searchData, ["pageNum", "pageSize"])
					} else { //第一次进去此菜单时，保存上方默认的data
						sessionStorage.setItem('searchData', JSON.stringify(data))
					}
				}

				console.log('this.formInline', this.formInline)
				console.log('JSON.parse(sessionStorage.getItem(\'searchData\'))', JSON.parse(sessionStorage.getItem('searchData')))
				getManageList(JSON.parse(sessionStorage.getItem('searchData'))).then((res) => {
					// console.log("res",res)
					if (res.infoCode && res.infoCode == 200) {
						this.tableList = res.data.items;
						this.$set(this.pageInfo, "total", res.data.total)
					}
				}).catch(error => {})
			},
			//查询
			queryFun() {
				//查询
				this.handleCurrentChange(1);
			},
			//重置
			resetFun() {
				//重置
				this.formInline = {
					status: this.status
				}
				this.pageInfo = {
					pageNum: 1,
					pageSize: 10,
					total: 0
				}
				this.queryFun();
			},
			//查看
			//备案
			recordsFun(row,type) {
				this.$router.push({
					path: "schemeDetail",
					query: {
						id: row.id,
						type: type,
						dataStatus:row.dataStatus
					}
				});
			},
			handleSizeChange(val) {
				//条数改变
				this.pageInfo.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				//页数改变
				this.pageInfo.pageNum = val;
				this.getList();
			},
			formatDateTimes(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 + " " + h + ":" + minute + ":" + second;
			},
		}
	};
</script>
<style lang="scss">
	.fumigationRecordPage {
		.el-select {
			width: 100%;
		}

		.itemStyle .el-form-item__label {
			line-height: 20px;
		}

		.el-dialog__body {
			padding-bottom: 0px;
		}

		.curStyle .el-form-item__label {
			line-height: 20px;
		}
	}
</style>
