<template>
    <div class="ele-body">
        <a-card :bordered="false">
            <!-- 搜索表单 -->
            <a-form
                :model="where"
                layout="vertical"
                :label-col="{ md: { span: 6 }, sm: { span: 24 } }"
                :wrapper-col="{ md: { span: 18 }, sm: { span: 24 } }"
            >
                <a-row>
                    <a-col :lg="6" :md="12" :sm="24" :xs="24">
                        <a-form-item label="时间范围:">
                            <a-date-picker v-model:value="where.time" />
                        </a-form-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col :lg="24" :md="24" :sm="24" :xs="24">
                        <a-space>
                            <a-button type="primary" @click="reload">查询</a-button>
                            <a-button @click="reset">重置</a-button>
                            <a-button @click="exportFile">导出Excel</a-button>
                        </a-space>
                    </a-col>
                </a-row>
            </a-form>
            <!-- 表格 -->
            <ele-pro-table
                v-model:selection="selectionList"
                ref="table"
                row-key="ambientAirId"
                :datasource="url"
                :columns="columns"
                :where="where"
                :scroll="{ x: 'max-content' }"
                :need-page="false"
                @done="(d) => (data = d.data)"
            >

            </ele-pro-table>
        </a-card>
    </div>
    <!-- 编辑弹窗 -->
</template>

<script>
// import _ from "lodash";
import XLSX from "xlsx";
import {airDayRankUrl} from "@/api/ecology/atmosphere/air";
import locale from "ant-design-vue/es/date-picker/locale/zh_CN";
import moment from "moment";
//   import utils from "./utils";
export default {
    name: "AirDayRanking",
    components: {},
    data() {
        return {
            data: [],
            locale,
            bill: {},
            // 表格数据接口
            url: airDayRankUrl,
            selection: [],
            // 表格列配置
            columns: [
                {title: "排名",dataIndex: "rankNumber",},
                {title: "省份",dataIndex: "province",},
                {title: "城市",dataIndex: "city",},
                {title: "AQI",dataIndex: "aqi",},
                {title: "空气质量",dataIndex: "airQuality",},
                {title: "PM2.5浓度/(ug/m3)",dataIndex: "pm25",},
                {title: "首要污染物",dataIndex: "primaryPollutant",},
            ],
            placeOptions:[],
            time: undefined,
            // 表格搜索条件
            where: {
            },
            // 表格选中数据
            selectionList: [],
        };
    },
    mounted() {
    },
    methods: {

        /* 刷新表格 */
        reload() {

            this.$refs.table.reload({
                where: this.where,
            });
        },
        /* 重置搜索 */
        reset() {

            this.reload();
        },
        exportFile() {

            const columns = [
                {
                    title: "监测日期",
                    dataIndex: "monitorTime",
                    sorter: true,
                    customRender: ({text}) => moment(text).format("YYYY-MM-DD HH:mm")
                },
                {
                    title: "城市",
                    dataIndex: "city",
                    sorter: true,
                },
                {
                    title: "测点名称",
                    dataIndex: "place",
                    sorter: true,
                },
                {
                    title: "SO2/(μg/m3)",
                    dataIndex: "so2",
                    sorter: true,
                },
                {
                    title: "NO2/(μg/m3)",
                    dataIndex: "no2",
                    sorter: true,
                },
                {
                    title: "PM10/(μg/m3)",
                    dataIndex: "pm10",
                    sorter: true,
                },
                {
                    title: "CO/(mg/m3)",
                    dataIndex: "co",
                    sorter: true,
                },
                {
                    title: "臭氧（O3）最大8小时滑动平均浓度/(μg/m3)",
                    dataIndex: "o3",
                    sorter: true,
                },
                {
                    title: "PM2.5",
                    dataIndex: "pm25",
                    sorter: true,
                },
                {
                    title: "空气质量指数AQI",
                    dataIndex: "aqi",
                    sorter: true,
                },
                {
                    title: "首要污染物",
                    dataIndex: "primaryPollutant",
                    sorter: true,
                },
                {
                    title: "空气质量指数级别",
                    dataIndex: "aqiLevel",
                    sorter: true,
                },
                {
                    title: "空气质量状况",
                    dataIndex: "airQualityStatus",
                    sorter: true,
                },
                {
                    title: "备注",
                    dataIndex: "remark",
                    sorter: true,
                },
                {
                    title: "创建人",
                    dataIndex: "username",
                    sorter: true,
                },
            ];
            const arr = [];
            const th = columns.map((item) => item.title);
            arr.push(th);
            this.data.forEach((d) => {
                const td = columns.map((item) => d[item.dataIndex]);
                arr.push(td);
            });
            let sheet = XLSX.utils.aoa_to_sheet(arr);
            this.$util.exportSheet(XLSX, sheet, new Date().getTime().toString());

        },
    },
};
</script>

<style scoped lang="less">
</style>