<template>
    <el-dialog id="tableBody" title="导出数据" :visible.sync="dialogVisible" width="45%"   center :before-close="handleClose">
        <div style="margin-left:20%">
            <!-- <h3>请选择时间：</h3> -->
            <!-- <br/> -->
            <!-- <div>
                <el-row :gutter="20" style="margin-left:5%;line-height: 25px;">
                     <el-form>
                    <el-form-item label="放款时间：">
                    <el-date-picker v-model="searchInfo.date" type="daterange"  range-separator="至"
                                    start-placeholder="开始日期"
                                    end-placeholder="结束日期" :clearable="false" ></el-date-picker>
                    </el-form-item>
                     </el-form>
                </el-row>
               
            </div> -->
             <!-- <br/>
            <br/> -->
            <el-button size="mini" type="button">
            <downloadexcel
                class = "btn btn-default"
                :fetch   = "fetchData"
                :fields = "json_fields"
                name    = "filename.xls"
                type    = "xls">
                导出
            </downloadexcel>
          </el-button>
            
        </div>
    </el-dialog>
</template>

<script>
import * as moment from "moment";
import downloadexcel  from 'vue-json-excel'

    export default {
        name: "byhExportMarket",
        props: {
            dialogVisible: {
                type: Boolean
            },
            type: {
                type: Number
            },
            batchNo: {
                type: String
            },
        },
         components: {
            downloadexcel 
        },
        data () {
            return {
                client: {
                    type:'',
                    batchNo:''
                },
                searchInfo: {
                    date: [],
                },
                  json_fields: {
                        '银行账号': 'bankAccount',
                        '放款编号': 'bizNo',
                        '银行名称': 'openBankName',
                        '证件号码': 'ownerIdNo',
                        '银行账户名': 'ownerName',
                        '放款金额': 'raiseAmt',
                    },
                    json_meta: [
                            [
                                {
                                    'key': 'charset',
                                    'value': 'utf-8'
                                }
                            ]
                        ],
            }
        },
        created() {
            console.log(this)
            this.client = {
                type: this.type,
                batchNo: this.batchNo,
            }
        },
        methods: {
            async  fetchData(){
                console.log(this)
                var response =  await this.$$get('/raise/exportExecl?batchNo='+this.client.batchNo);
                this.handleClose();
                if(response.data.result != null){
                    return response.data.result;
                }else{
                    alert("暂无数据")
                }

            },
               /** 关闭处理 */
            handleClose () {
                this.visible = false
                setTimeout(() => {
                    this.$emit('update:dialogVisible', false)
                }, 100)
            },
      
           
        },
        mounted: function () {
        },
    }
</script>

<style scoped lang="stylus" >

#tableBody{
    text-align:center;
}
 .el-row {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
  }
</style>