<template>
    <div class="flex-container">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <!-- 搜索区域 -->
            <a-form layout="inline">
                <a-row :gutter="24">
                    <a-col :md="6" :sm="12">
                        <a-form-item label="时间选择：">
                            <a-range-picker @change="onChange"/>
                        </a-form-item>
                    </a-col>
                    <span class="table-page-search-submitButtons" style="float: left; overflow: hidden;">
            <a-col :md="4" :sm="24">
              <a-button @click="search()" type="primary">查询</a-button>
              <a-button v-show="!callback" @click="handleSubmit" style="margin-left: 10px">导出</a-button>
              <a-button v-show="callback" style="margin-left: 10px">
                导出中
                <a-spin style="margin-left: 5px" size="small"/>
              </a-button>
            </a-col>
          </span>
                </a-row>
            </a-form>
        </div>

        <!--列表-->
        <s-table
                :columns="columns"
                :data="rowdata"
                bordered
                ref="table"
                size="small"
                class="flex-filling"
                :locale="emptyText"
        ></s-table>
    </div>
</template>

<script>
    import STable from "@/components/table";
    import {reportList, reportDownload} from "../../../api/school-center/orderConversion/orderConversionAPI";
    import {cloneObject, exportFile} from "@/utils/util";
    import moment from "moment";
    export default {
        name: "kdOrderConversionXX",
        components: {
            STable
        },
        data() {
            return {
                emptyText: {emptyText: '暂无数据'},
                callback: false,
                Formtable: this.$form.createForm(this),
                queryParam: {
                    startTime: "",
                    endTime: "",
                    conversionType:"10"
                },
                columns: [
                    {title: "县分", dataIndex: "sub_name", width: 50},
                    {title: "学校名称", dataIndex: "school", width: 200},
                    {title: "成功单总数", dataIndex: "orderCount", width: 75},
                    {title: "单宽", children: [
                        {title: "订单总量", dataIndex: "status_5_1", width: 75},
                        {title: "已完成", dataIndex: "status_5_2", width: 75},
                        {title: "异常单", dataIndex: "status_5_3", width: 75},
                        ]
                    },
                    {title: "融合", children: [
                        {title: "订单总量", dataIndex: "status_3_1", width: 75},
                        {title: "已完成", dataIndex: "status_3_2", width: 75},
                        {title: "异常单", dataIndex: "status_3_3", width: 75},
                      ]
                    },
                    {title: "单宽进融", children: [
                        {title: "订单总量", dataIndex: "status_10_1", width: 75},
                        {title: "已完成", dataIndex: "status_10_2", width: 75},
                        {title: "异常单", dataIndex: "status_10_3", width: 75},
                      ]
                    }
                ],
                rowdata: parameter => {
                    let params = {
                        pageNo: parameter.pageNo,
                        pageSize: parameter.pageSize
                    };
                    let obj = cloneObject(this.queryParam);
                    //表示
                    return reportList(Object.assign(params, obj)).then(res => {
                        console.log(res);
                        let data = {};
                        if (res.state !== "success") {
                            this.$message.error("查询失败！", 5);
                            this.emptyText.emptyText = '查询失败！'
                            data = {
                                data: []
                            };
                        } else {
                            data = {
                                data: res.data
                            };
                        }
                        return data;
                    });
                }
            };
        },
        methods: {
            moment,
            search() {
                this.$refs.table.refresh({search: true});
            },
            //时间事件
            onChange(date, dateString) {
                if (dateString.length == 0) {
                    this.queryParam.startTime = "";
                    this.queryParam.endTime = "";
                } else {
                    this.queryParam.startTime = dateString[0];
                    this.queryParam.endTime = dateString[1];
                }
            },
            handleSubmit() {
                this.callback = true;
                let today = new Date();
                today.setTime(today.getTime());
                let s2 = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate();
                exportFile(
                    reportDownload(this.queryParam),
                    "一人一码宽带报表（学校）" + s2 + ".xlsx",
                    this.downloadstatu
                );
            },
            downloadstatu() {
                this.callback = false;
            }
        }
    };
</script>

<style scoped>
</style>