<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="small" 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
            },
            clientNo: {
                type: String
            },
            raiseNo: {
                type: String
            },
            clientName: {
                type: String
            },
            result: {
                type: String
            },
            bizType: {
                type: String
            },
            raiseDateStart: {
                type: Date
            },
            raiseDateEnd: {
                type: Date
            },
        },
         components: {
            downloadexcel 
        },
        data () {
            return {
                client: {
                    type:'',
                    clientNo: '',
                    raiseNo: '',
                    clientName: '',
                    result: '',
                    bizType: '',
                    raiseDateStart: '',
                    raiseDateEnd: '',
                },
                searchInfo: {
                    date: [],
                },
                  json_fields: {
                        '放款编号': 'raiseNo',
                        '客户编号': 'clientNo',
                        '流水号(支付公司)': 'raiseNo',
                        '放款金额': 'raiseAmt',
                        '放款时间': {
                            field: 'raiseDate',
                            callback: (value) => {
                                return moment(value).format("YYYY-MM-DD");
                            }
                        },
                        '放款状态': 'resultStr',
                        '客户名称': 'cardOwnerName',

                    },
                    json_meta: [
                            [
                                {
                                    'key': 'charset',
                                    'value': 'utf-8'
                                }
                            ]
                        ],
            }
        },
        created() {
            this.client = {
                type: this.type,
                clientNo:this.clientNo,
                raiseNo:this.raiseNo,
                clientName:this.clientName,
                result:this.result,
                bizType:this.bizType,
                raiseDateStart:this.raiseDateStart,
                raiseDateEnd:this.raiseDateEnd,
            }
        },
        methods: {
            async  fetchData(){

                console.log(this.client.raiseDateEnd,99999)
                

                if(this.isValidDate(this.client.raiseDateEnd)){
                     var  end = new Date(this.client.raiseDateEnd)
                    var start= new Date(this.client.raiseDateStart)

                    end=end.setDate(end.getDate()+1);
                    end=new Date(end);
                    var raiseDateStart = (Date.parse(start))
                    var raiseDateEnd = Date.parse(end)

                }else{
                    var raiseDateStart = ''
                    var raiseDateEnd = ''

                }
               
                if(this.client.bizType == undefined){
                    this.client.bizType = ''
                }

                if(this.client.result == undefined){
                    this.client.result = ''
                }

                if(this.client.raiseNo == undefined){
                    this.client.raiseNo = ''
                }

            
                var response =  await this.$$get('/raise/exportAllExecl?raiseDateStart='+raiseDateStart
                +"&raiseDateEnd="+raiseDateEnd
                +"&clientNo="+this.client.clientNo
                +"&bizType="+this.client.bizType
                +"&result="+this.client.result
                +"&clientName="+this.client.clientName
                +"&raiseNo="+this.client.raiseNo
                );
                this.handleClose();
                if(response.data.result != null){
                    return response.data.result;
                }else{
                    alert(response.data.message)
                }

            },
         
            isValidDate(date) {
                return date instanceof Date && !isNaN(date.getTime())
            },
               /** 关闭处理 */
            handleClose () {
                this.visible = false
                setTimeout(() => {
                    this.$emit('update:dialogVisible', false)
                }, 100)
            },

            buildParam () {
                var return_hash = {
                };
                if (this.client.clientNo != '') {
                    return_hash['clientNo'] = this.client.clientNo
                }
                if (this.client.bizNo != '') {
                    return_hash['raiseNo'] = this.client.bizNo
                }
                // 修改手机号查询为客户编号查询
                if (this.client.clientName != '') {
                    return_hash['clientName'] = this.client.clientName
                }
                if (this.client.status != '') {
                    return_hash['result'] = this.client.status
                }
                // 系统类型
                if (this.client.hangUp != '') {
                    return_hash['bizType'] = this.client.hangUp
                }
                return_hash['raiseDateStart'] = this.client.raiseDateStart;
                return_hash['raiseDateEnd'] = this.client.raiseDateEnd

                return return_hash;
            },
      
           
        },
        mounted: function () {
        },
    }
</script>

<style scoped lang="stylus" >

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