<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>
                        <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.id" 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" :disabled="tableData.length==0 ? true: false" @click="handleExport">导出错误案件</el-button>
                        <el-button size="small" @click="handleDelete">清空错误案件</el-button>
                    </div>
                </div>
                
                <div :style="'height:'+`${contentHeight}`+'px;width: 100%;overflow: auto;'">
                    <div class="flex-column" :style="'width:'+ Error_headers.length * 170 +'px ;'">
                        <div class="error-header flex-row">
                            <span v-for="(item,index) in Error_headers" :key="index" class="f-weight500" style="color: #909399;">{{item.name}}</span>
                        </div>
                        <!-- {{tableData}} -->
                        <div class="error-cont flex-row" v-for="(item,index) in tableData" :key="index">
                            <span v-for="(item1,index) in item.fields" :key="index" style="color: #000;">
                                {{item1.fieldValue}}
                                <a v-if="item1.errorMsg" class="color-F53F3F">{{item1.errorMsg}}</a>
                            </span>
                        </div>
                        
                        <!-- tableData -->
                        <!-- <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 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> -->
                    </div>
            </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: {
                    id:'',
                    pkgName:'',//案件包名称
                    entrustingAgencyName: '',//金融机构
                    endTime: '',//结束时间
                    beginTime:'',//开始时间
                    willEnd:'',
                },
                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-288
            }  
        },
        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.id = this.CasepackageList[0].id
                        }
                        this.getCasepkgError_headers()
                    }
                })
            },
            // 错误的案件记录标头
            getCasepkgError_headers(){
                cpkapi.postcase_pkg_error_headers({id:this.queryParam.id}).then(res => {
                    if (!res.code) {
                        this.Error_headers = res;
                    }
                    this.getCaseInfoList()
                })
            },
            // 列表数据
            getCaseInfoList(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.downloadFileByUrl(res, '错误案件列表.xlsx')
                })
            },
            handleDelete(){
                this.$confirm("此操作将清空此案件包错误案件, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }).then(() => {
                    if(!this.$clickThrottle()) { return }//防止重复点击
                    cpkapi.postcase_pkg_error_clean({ id: this.queryParam.id }).then((res) => {
                        this.tableData=[]
                        this.$message.success("清空此案件包错误案件成功");
                        this.getCasepkgList()
                       
                    });
                }).catch(() => {});
            },
            // 重置
            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 lang="scss">
.error-header{
    border-bottom: 1px solid #EBEEF5;
    padding: 10px 0;
    span{min-width: 150px;margin-right: 20px;}
}
.error-cont{
    border-bottom: 1px solid #EBEEF5;
    padding: 10px 0;
    span{
        min-width: 150px;
        overflow: hidden;
        margin-right: 20px;
    }
}
.el-badge{
    top: 3px;
}
</style>