<template>
    <div class="layout-content-wrap">
        <div class="navigation-bar flex-row mb-16">
            <img src="../../assets/image/Link.png"  height="22" alt="">
            <a>/</a>
            <a>案件错误修复</a>
        </div>
        
        <div class="layout-tabs-content-box background-color-fff border-radius-4">
            <div class="pt-8 border-b-solid-lighter-1">
                <div class="height-30 flex-row align-items-center justify-content-between mb-24">
                    <div class="f22 color-text-primary">筛选</div>
                </div>
                <el-collapse-transition>
                    <div v-show="showSearch">
                        <el-row :gutter="56">
                            <el-col :span="6">
                                <div class="flex-row-center align-items-center height-40 mb-24">
                                    <span class="tabs__search-criteria-title flex-shrink-0 pr-16">案件包名称</span>
                                    <el-select v-model="queryParam.pkgId" placeholder="请选择案件包"
                                            class="width100" >
                                        <el-option
                                                v-for="item in CasepackageList"
                                                :key="item.id"
                                                :label="item.pkgName"
                                                :value="item.id">
                                        </el-option>
                                    </el-select>
                                </div>
                            </el-col>
                            <el-col :span="14">
                                <div class="flex-row align-items-center justify-content-end">
                                    &nbsp;
                                </div>
                            </el-col>
                            <el-col :span="4" >
                                <div class="flex-row align-items-center justify-content-end">
                                    <el-button @click="hanldeReset">重置</el-button>
                                    <el-button type="primary" @click="handleSearch">搜索</el-button>
                                </div>
                            </el-col>
                        </el-row>
                        
                        <el-row :gutter="56">
                            
                        </el-row>
                    </div>
                </el-collapse-transition>
            </div>
            <!-- table -->
            <div class="pt-8">
                <div class="height-56 flex-row align-items-center justify-content-between">
                    <div class="f22 color-text-primary">列表</div>
                    <div class="flex-row">
                        <el-button size="small" type="primary" @click="handleImport">增量导入案件</el-button>
                        <el-button size="small" @click="handleExport">导出错误案件</el-button>
                        <el-button size="small" @click="handleDelete">清空错误案件</el-button>
                    </div>
                </div>
                
                <div >
                    <el-table :data="tableData" :height="`${contentHeight}`"  style="width: 100%"
                    @selection-change="handleSelectionChange">
                        <el-table-column type="index" label="序号" width="55"></el-table-column>
                        <!-- <el-table-column type="selection" width="55" ></el-table-column> -->
                        <el-table-column v-for="(item,index) in Error_headers" :key="index" 
                        :prop="item.fieldKey" :label="item.name" show-overflow-tooltip min-width="180" ></el-table-column>
                        <!-- <el-table-column prop="entrustingAgencyName" label="委案机构" show-overflow-tooltip ></el-table-column>
                        <el-table-column prop="channel" label="被申请人姓名" show-overflow-tooltip ></el-table-column>
                        <el-table-column prop="channel" label="被申请人手机号码" show-overflow-tooltip ></el-table-column>
                        <el-table-column prop="months" label="身份证号码" show-overflow-tooltip ></el-table-column>
                        <el-table-column prop="caseTotal" label="金融产品名称" show-overflow-tooltip ></el-table-column>
                        <el-table-column prop="assignTotal" label="合同名称" show-overflow-tooltip ></el-table-column>
                        <el-table-column prop="assignTotal" label="委托时逾期天数" show-overflow-tooltip ></el-table-column>
                        <el-table-column prop="assignTotal" label="当前逾期金额" show-overflow-tooltip ></el-table-column> -->
                    </el-table>
                </div>
                
                <div class="text-center pt-16">
                    <el-pagination
                        @size-change="getCaseInfoList"
                        @current-change="getCaseInfoList"
                        :current-page="queryParam.current"
                        :page-size="queryParam.size"
                        layout="total, prev, pager, next, jumper"
                        :total="total">
                    </el-pagination>
                </div>

            </div>
        </div>
        <!-- 导入 -->
        <importPackageDialog v-if="importCaseDialog" :importCaseDialog.sync="importCaseDialog" />

    </div>
</template>
<script>
import cpkapi from "@/services/casePackageManagement";
    export default {
        components: {
            importPackageDialog: () => import('./components/importPackageDialog'),//导入
            
        },
        data() {
            return {
                activeName:'all',
                showSearch: true,
                queryDate: '',
                activeUsage: '',
                
                mediateStatusData:[],//所有案件状态枚举
                financialProductsTypeOptions:[],//金融产品类型
                departmentOptions:[],//区域
                queryParam: {
                    pkgId:'',
                    pkgName:'',//案件包名称
                    entrustingAgencyName: '',//委案机构
                    endTime: '',//结束时间
                    beginTime:'',//开始时间
                    willEnd:'',
                    current:1,
                    size:10,
                },
                usageOption: ['今日','昨日', '近一周', '近一月', '近半年', '近一年'],
                tableData: [],
                total:0,
                uniqueSelection:[],
                caseAllocationDialog:null,//案件分配弹框
                importCaseDialog:null,//导入
                addCaseDialog:null,//新增
                editCaseDrawer:null,//编辑
                CasepackageList:[],
                Error_headers:[],

            }
        },
        created() {
            this.getCasepkgList()
            
        },
        computed:{
            // 获取抽屉drawer的内容高度
            contentHeight(){
                let oh = document.documentElement.clientHeight;
                return oh-56-348
                    
            }  
        },
        methods: {
            jumpUrl (url) {
                this.$router.push(url);
            },
            // 案件包列表数据
            getCasepkgList(){
                cpkapi.getCasePkgQuery({current:1,size:500}).then(res => {
                    if (!res.code) {
                        this.CasepackageList = res.records;
                        if(this.CasepackageList.length > 0){
                            this.queryParam.pkgId = this.CasepackageList[0].id
                        }
                        this.getCasepkgError_headers()
                        
                    }
                })
            },
            // 错误的案件记录标头
            getCasepkgError_headers(){
                cpkapi.postcase_pkg_error_headers({id:this.queryParam.pkgId}).then(res => {
                    if (!res.code) {
                        this.Error_headers = res;
                    }
                    this.getCaseInfoList()
                })
            },

            // 列表数据
            getCaseInfoList(val){
                this.queryParam.planBegin = this.queryParam.beginTime
                this.queryParam.planEnd = this.queryParam.endTime
                this.queryParam.current = val
                cpkapi.postcase_pkg_error_page(this.queryParam).then(res => {
                    if (!res.code) {
                        this.tableData = res.records;
                        this.total = res.total;
                    }
                })
            },
            // 导入
            handleImport(){
                this.importCaseDialog={
                    title:'增量导入案件',
                }
            },
            // 导出
            handleExport(){ 
                if(!this.$clickThrottle()) { return }//防止重复点击               
                cpkapi.postcase_pkg_error_down(this.queryParam).then(res => {

                    this.$util.downloadFileByBlob(res, '错误案件列表.xlsx')
                })
            },
            handleDelete(){

            },
            // 重置
            hanldeReset() {
                for (let key in this.queryParam) {
                this.queryParam[key] = ''
                }
                this.queryParam.current = 1
                this.queryParam.size = 10
            },
            handleSearch() {
                this.queryParam.size = 10;
                this.queryParam.current = 1;
                this.getCaseInfoList(1)
            },
            handleClickUsage(item) {
                this.activeUsage = item
                this.setDateFast()
            },
        }
    }
</script>
<style scoped>
.el-badge{
    top: 3px;
}
</style>