<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: "orderConversionXF",
        components: {
            STable
        },
        data() {
            return {
                emptyText: {emptyText: '暂无数据'},
                callback: false,
                Formtable: this.$form.createForm(this),
                queryParam: {
                    startTime: "",
                    endTime: "",
                    conversionType:"01"
                },
                columns: [
                    {title: "校区", dataIndex: "sub_name", width: 50},
                    {title: "订单总数", dataIndex: "orderCount", width: 80},
                    {title: "小白卡订单", dataIndex: "xb_orderCount", width: 80},
                    {title: "预制卡订单", dataIndex: "yz_orderCount", width: 80},
                    {title: "订单状态", children: [
                        {title: "待识别", dataIndex: "status_1", width: 80},
                        {title: "待处理", dataIndex: "status_2", width: 80},
                        {title: "待配送", dataIndex: "status_3", width: 80},
                        {title: "待活体", dataIndex: "status_4", width: 80},
                        {title: "已完成", dataIndex: "status_5", width: 80},
                        ]
                    }
                ],
                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>