<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-input  placeholder="文件名"  v-model="queryParam.fileName"></a-input>
                        </a-form-item>
                    </a-col>
                    <span class="table-page-search-submitButtons" style="float: left; overflow: hidden;">
                        <a-col :md="6" :sm="24">
                             <a-button @click="search()" type="primary">查询</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">
            <template slot="operation" slot-scope="text, record">
               <span>
          <a @click="downloadExcel(record.id)">下载</a>
          <a-divider type="vertical"/>
          <a @click="remove(record.id)">删除</a>
        </span>
            </template>
            <template slot="createTime" slot-scope="text">{{ text | dayjs}}</template>
        </s-table>
    </div>
</template>

<script>
    import STable from '@/components/table';
    import {deleteExcel,listExportExcel,uploadExcel} from "../../../api/school-center/other/exportExcel"
    import {cloneObject,exportFile} from '@/utils/util';
    import moment from "moment";
    export default {
        name: "exportExcel",
        components: {
            STable,
        },
        data(){
            return {
                emptyText: {emptyText: '暂无数据'},
                Formtable: this.$form.createForm(this),
                modifyvisible: false,
                add: true,
                queryParam: {
                    fileName  :''
                },
                modelData:{
                    id:'',
                    userName:'',
                    sign:''
                },
                columns: [
                    {dataIndex: 'fileName', title: '文件名'},
                    {dataIndex: 'createName', title: '导出人'},
                    {dataIndex: 'createTime', title: '导出时间', scopedSlots: {customRender: 'createTime'}},
                    {
                        dataIndex: 'operation',
                        title: '操作',
                        scopedSlots: {customRender: 'operation'},
                        fixed: "right"
                    }]
                ,
                rowdata: parameter => {
                    let params = {
                        pageNo: parameter.pageNo,
                        pageSize: parameter.pageSize
                    }
                    let obj = cloneObject(this.queryParam)
                    //表示
                    return listExportExcel(Object.assign(params,obj)).then(res => {
                        let data = {}
                        if (res.state !== 'success') {
                            this.$message.error("查询失败！", 5);
                            this.emptyText.emptyText = '查询失败！'
                            data = {
                                data: [],
                                pageSize: parameter.pageSize,
                                pageNo: 1,
                                totalCount: 0
                            }
                        } else {
                            data = {
                                data: res.data.records,
                                pageSize: parameter.pageSize,
                                pageNo: parameter.pageNo,
                                totalCount: res.data.total
                            }
                        }
                        return data
                    })
                }
            }
        },
        methods:{
            moment,
            search() {
                this.$refs.table.refresh({search: true})
            },
            remove(exportId) {
                deleteExcel({exportId}).then(res => {
                    if (res.state == 'success') {
                        this.$message.success(res.data, 5);
                    }else {
                        this.$message.success(res.msg, 5);
                    }
                })
            },
            downloadExcel(exportId) {
                let nowdate = moment().format("YYYY-MM-DD");
                exportFile(
                    uploadExcel({exportId}),
                    "订单清单" + nowdate + ".xls",
                );
            }
        }
    }
</script>

<style scoped>

</style>