<template>
    <!--粮食应急加工企业报表-->
    <div class="content-main">
        <el-row class="search-bm-boder">
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
                <h3 style="text-align: center;font-size: 20px;">粮食应急加工企业</h3>
                <el-form-item label="所在区:">
                	<el-select
                	  clearable
                	  class="inputCompatible"
                	  v-model="formInline.location"
                	  placeholder="请选择"
                	>
                	  <el-option
                	    v-for="item in countyOptions"
                	    :key="item.dictCode"
                	    :label="item.dictName"
                	    :value="item.dictName"
                	  ></el-option>
                	</el-select>
                </el-form-item>
                <el-form-item>
                  <div class="search-button">
                    <span class="search-line"></span>
                    <el-button
                      type="primary"
                      size="small"
                      class="iconfont iconchaxun"
                      @click="getList"
                      >查询</el-button
                    >
                    <el-button
                      type="primary"
                      @click="
                        formInline = { };
                        doSearch();
                      "
                      size="small"
                      class="iconfont iconzhongzhi"
                      >重置</el-button
                    >
                  </div>
                </el-form-item>
			</el-form>
        </el-row>
        <el-row class="addBtnBg">
            <el-upload style="display: inline-block" :show-file-list="false" :action="actionUrl" :headers="uploadHeader"
                       class="daoru" :on-success="handleSuccess" :on-change="changeFj"
                       accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel">
                <el-button type="primary" class="iconfont icondaoru1" size="small">导入</el-button>
            </el-upload>
            <el-button type="primary" class="iconfont icondaochu11" size="small" @click="exportSubmit">下载模板</el-button>
			<el-button type="primary" class="iconfont icondaochu11" size="small" @click="exportExcel">导出</el-button>
        </el-row>
        <el-row>
            <h3 style="float: right;">更新时间: <span>{{ newdate }}</span></h3>
            <el-table :data="tableData" stripe border fit highlight-current-row style="width: 100%">
                <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" label="所在区" prop="location" show-overflow-tooltip></el-table-column>
                <el-table-column align="center" label="企业名称" prop="businessname" show-overflow-tooltip></el-table-column>
                <el-table-column align="center" label="统一社会信用代码" prop="creditcode" show-overflow-tooltip></el-table-column>
                <el-table-column align="center" label="地址" prop="address" show-overflow-tooltip></el-table-column>
                <el-table-column align="center" label="联系人姓名" prop="contactname" show-overflow-tooltip></el-table-column>
                <el-table-column align="center" label="联系人联系方式(座机/手机)" prop="contactphone" show-overflow-tooltip></el-table-column>
                <el-table-column align="center" label="日加工能力(吨)" show-overflow-tooltip>
                    <el-table-column align="center" label="小麦日加工能力" prop="wheat" show-overflow-tooltip></el-table-column>
                    <el-table-column align="center" label="稻谷日加工能力" prop="paddy" show-overflow-tooltip></el-table-column>
                    <el-table-column align="center" label="油脂精炼日加工能力" prop="oiltreatment" show-overflow-tooltip></el-table-column>
                </el-table-column>
            </el-table>
        </el-row>
        <el-row>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="pageForm.pageNum"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="pageForm.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pageForm.total">
            </el-pagination>
        </el-row>
    </div>
</template>

<script>
	import { dqTree } from "@/api/jdjcbb/inspectionWork"
    import {getEmergency, exportByObject,exportEmergency} from "@/api/bordereaux/emergency/getEmergency";
    import {file, irpt} from '@/api';

    export default {
        data() {
            return {
				countyOptions:[],
				formInline:{
					location:'',
				},
                tableData: [],
                // 更新时间
                newdate: '',
                pageForm: {
                    pageNum: 1,
                    pageSize: 10,
                    total: 0,
                },
                // 导入URL
                actionUrl: irpt + "/emergency/uploadEmergency",
                // 导入
                uploadHeader: {
                    token: sessionStorage.getItem('TOKENL')
                },
            }
        },
        created() {
			dqTree().then(res => {
			    this.countyOptions = res.data.subDataDictionarys
			})
            // 初始化列表
            this.getList();
        },
        methods: {
			//导出列表
			exportExcel(){
				var data={
					...this.pageForm,
					...this.formInline
				}
				exportEmergency(data).then(res => {
				    let blob = new Blob([res], {type: 'application/vnd.ms-excel;charset=utf-8'});
					const link = document.createElement('a');
					link.style.display = 'none';
					link.href = URL.createObjectURL(blob);
					link.setAttribute('download', '粮食应急加工企业报表');
					document.body.appendChild(link);
					link.click();
					document.body.removeChild(link);
				}).catch((err) => {
				    this.$message.error(err);
				});
			},
			doSearch(){
				this.getList();
			},
            // 分页列表
            getList() {
				var data={
					...this.pageForm,
					...this.formInline
				}
                getEmergency(data).then(res => {
                    console.log("res:", res);
                    if (res.infoCode === 200) {
                        this.tableData = res.data.list;
                        if (this.tableData.length > 0) {
                            this.newdate = this.tableData[0].newdate;
                        }
                        this.pageForm.total = res.data.total;
                    } else {
                        this.$message.error(res.msg);
                    }
                }).catch((err) => {
                    this.$message.error(err);
                });
            },
            //附件上传
            changeFj(file, fileList) {
                console.log('changeFj|file=', file);
                console.log('changeFj|fileList=', fileList);
            },
            //导入
            handleSuccess(response) {
                // console.log('handleSuccess=', response);
                if (response.infoCode === 200) {
                    this.$message.success(response.msg);
                    this.getList();
                } else {
                    this.$message.error(response.msg);
                }
            },
            // 下载模板
            exportSubmit() {
                exportByObject("52887322190016").then(res => {
                    let blob = new Blob([res], {type: 'application/vnd.ms-excel;charset=utf-8'});
                    if (!!window.ActiveXObject || "ActiveXObject" in window) {
                        window.navigator.msSaveOrOpenBlob(blob, '粮食应急加工企业报表.xlsx');
                    } else {
                        const link = document.createElement('a');
                        link.style.display = 'none';
                        link.href = URL.createObjectURL(blob);
                        link.setAttribute('download', '粮食应急加工企业报表.xlsx');
                        document.body.appendChild(link);
                        link.click();
                        document.body.removeChild(link);
                    }
                }).catch((err) => {
                    this.$message.error(err);
                });
            },
            // 分页
            handleSizeChange(val) {
                this.pageForm.pageSize = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.pageForm.pageNum = val;
                this.getList();
            },
        }
    }
</script>

<style scoped>

</style>