<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-input v-model="formInline.kdmc" clearable style="width:180px;"></el-input>
                </el-form-item>
                <el-form-item label="通风开始结束时间:">
                  <el-date-picker
                    style="width:250px"
                    v-model="formInline.time"
                    type="daterange"
                    value-format="yyyy-MM-dd"
                    range-separator="至"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                  ></el-date-picker>
                </el-form-item>
                <el-form-item label="仓房名称:" label-width="80px">
                    <el-input v-model="formInline.warehouseName" clearable style="width:180px;"></el-input>
                </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="kdmc" label="库点名称" align="center" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="warehouseName" label="仓房名称" align="center" :show-overflow-tooltip="true" width="260px"></el-table-column>
                    <el-table-column prop="tfkssj" label="通风开始时间" align="center" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            {{/\d{4}-\d{1,2}-\d{1,2}/g.exec(scope.row.tfkssj).toString()}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="tfjssj" label="通风结束时间" align="center" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            {{/\d{4}-\d{1,2}-\d{1,2}/g.exec(scope.row.tfjssj).toString()}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="tfzyfzr" label="通风作业负责人" align="center" :show-overflow-tooltip="true">
                        <!-- <template slot-scope="scope">
                            {{getDictName('xzfsOption',scope.row.fumigationType)}}
                        </template> -->
                    </el-table-column>
                    <el-table-column label="操作" align="center" width="120">
                        <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="lookFun(scope.row)"
                                ></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 {
        tfListPageGet
    } 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 {
                temp:[{
                    a:123,
                    b:123,
                    c:123,
                    d:123,
                    e:123
                }],
                searchShowMoreBool: false,
                zts: [5,6,7],
                formInline: {
                    cfmc: '',
                    time: [],
                },
                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: 0,
                    //     label: '待提交',
                    // },
                    // {
                    //     value: 1,
                    //     label: '企业待审核',
                    // },
                    // {
                    //     value: 2,
                    //     label: '企业待盖章',
                    // },
                    // {
                    //     value: 3,
                    //     label: '购销公司待审核',
                    // },
                    // {
                    //     value: 4,
                    //     label: '购销公司待盖章',
                    // },
                    {
                        value: 5,
                        label: '区粮办待审核',
                    },
                    {
                        value: 6,
                        label: '区粮办待盖章',
                    },
                    {
                        value: 7,
                        label: '已备案',
                    },
                    // {
                    //     value: 11,
                    //     label: '已退回',
                    // },
                ],
                pzOption: [],
                yjOption: [],
                xzfsOption: [],
            };
        },
        watch: {
            // "formInline.dataStatus" (newV,oldV) {
            //     if(newV === 0 || newV){
            //         this.formInline.zts = [newV]
            //     }else{
            //         this.formInline.zts = this.zts
            //     }
            // },
        },
        created() {
            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");
                });
            },
            //获取列表
            getList(type) {

                let data = {
                    pageNum: this.pageInfo.pageNum,
                    pageSize: this.pageInfo.pageSize,
                    kdmc: this.formInline.kdmc, 
                    warehouseName: this.formInline.warehouseName,
                    tfjssj:this.formInline.time&&this.formInline.time.length?this.formInline.time[1]:'',
                    tfkssj:this.formInline.time&&this.formInline.time.length?this.formInline.time[0]:'',
                    time:this.formInline.time
                }
                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,["kdmc","time"])
                        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')))
                tfListPageGet(JSON.parse(sessionStorage.getItem('searchData'))).then((res)=>{
                    // console.log("res",res)
                    if(res.code && res.code == 200){
                        this.tableList = res.data.list;
                        this.$set(this.pageInfo,"total", res.data.total)
                    }
                }).catch(error=>{
                })
            },
            //查询
            queryFun() {
                //查询
                this.handleCurrentChange(1);
            },
            //重置
            resetFun() {
                //重置
                this.formInline = {
                    cfmc: '',
                    time:[]
                }
                this.pageInfo = {
                    pageNum: 1,
                    pageSize: 10,
                    total: 0
                }
                this.queryFun();
            },
            //查看
            lookFun(row){
                this.$router.push({
                    path: "ventilationDetail",
                    query: {
                        id: row.tfzyid,
                        name:row.kdmc
                    }
                });
            },
            handleSizeChange(val) {
                //条数改变
                this.pageInfo.pageSize = val;
                this.getList();
            },
            handleCurrentChange(val) {
                //页数改变
                this.pageInfo.pageNum = val;
                this.getList();
            },
        }
    };
</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>
