<template>
    <div>
        <div v-if="!DialogDetail">
            <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="f18 color-text-primary">筛选</div>
                </div>
                <el-collapse-transition>
                    <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-input v-model.trim="queryParam.pkgName"
                                            clearable placeholder="请输入案件包名称"
                                            @keydown.enter.native="handleSearch">
                                </el-input>
                            </div>
                        </el-col>
                        <el-col :span="5">
                            <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-input v-model.trim="queryParam.caseNo"
                                            clearable placeholder="请输入案件编号"
                                            @keydown.enter.native="handleSearch">
                                </el-input>
                            </div>
                        </el-col>
                        <el-col :span="9">
                            <div class="justify-content-start  align-items-center height-40 mb-24">
                                <span class="tabs__search-criteria-title flex-shrink-0 pr-16">操作时间</span>
                                <el-date-picker
                                        v-model="queryDate"
                                        type="daterange"
                                        clearable
                                        range-separator="至"
                                        start-placeholder="开始日期"
                                        end-placeholder="结束日期"
                                        @change="handleChangeDate">
                                </el-date-picker>
                            </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-collapse-transition>
            </div>
            <!-- table -->
            <div class="pt-8">
                <div class="height-56 flex-row align-items-center justify-content-between">
                    <div class="f18 color-text-primary">还款凭证登记列表</div>
                    <div class="flex-row">
                        
                    </div>
                </div>
                
                <div class="case-table">
                    <el-table :data="tableData" height="330" >
                        <el-table-column type="index" label="序号" width="55"></el-table-column>
                        <!-- <el-table-column type="selection" width="55" ></el-table-column> -->
                        <el-table-column prop="pkgName" label="案件包名称" show-overflow-tooltip ></el-table-column>
                        <el-table-column prop="caseNo" label="案件编号" width="200" show-overflow-tooltip ></el-table-column>
                        <el-table-column prop="respondent" label="被申请人" show-overflow-tooltip ></el-table-column>
                        <!-- <el-table-column prop="planType" label="还款计划" show-overflow-tooltip >
                            <template slot-scope="scope">
                                <span >一次性还款：{{ scope.row.createAt | formaDate("yyyy-MM-dd hh:mm:ss") }}</span>
                            </template>
                        </el-table-column> -->
                        <!-- <el-table-column prop="deadline" label="还款截止日期" show-overflow-tooltip ></el-table-column>
                        <el-table-column prop="payableAmount" label="应还金额" show-overflow-tooltip ></el-table-column> -->
                        <el-table-column prop="actualPayDate" label="实际还款日期" show-overflow-tooltip ></el-table-column>
                        <el-table-column prop="amount" label="实际还款金额" show-overflow-tooltip >
                            <template slot-scope="scope">
                                <span v-if="scope.row.amount > 0">{{ scope.row.amount }}（元）</span>
                                <span v-else>-</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="状态" show-overflow-tooltip >
                            <template slot-scope="scope">
                                <span >
                                    {{ (scope.row.status.code == 0 || scope.row.status.code == 1) ? '待效验':'' }}
                                    {{ scope.row.status.code == 2 ? '已效验':'' }}
                                    {{ (scope.row.status.code == 3 || scope.row.status.code == 4) ? '效验失败':'' }}
                                </span>
                            </template>
                        </el-table-column>

                        <el-table-column prop="createAt" label="操作时间" show-overflow-tooltip >
                            <template slot-scope="scope">
                                <span >{{ scope.row.createAt | formaDate("yyyy-MM-dd hh:mm:ss") }}</span>
                            </template>
                        </el-table-column>
                        
                        <el-table-column  label="操作" width="240">
                            <template slot-scope="scope">
                                <div class="flex-row align-items-center">
                                    <el-button size="mini" @click="handleCaseShow(scope)">查看凭证</el-button>
                                    <el-button v-if="(scope.row.status.code == 0 || scope.row.status.code == 1)" size="mini" @click="EffectDialog = scope.row">效验</el-button>
                                    <el-button v-if="(scope.row.status.code == 0 || scope.row.status.code == 1)" size="mini" @click="handEffectCancel(scope.row)">取消</el-button>
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                
                <div class="text-center pt-16">
                    <el-pagination
                        @size-change="getProofList"
                        @current-change="getProofList"
                        :current-page="queryParam.current"
                        :page-size="queryParam.size"
                        layout="total, prev, pager, next, jumper"
                        :total="total">
                    </el-pagination>
                </div>
            </div>
        </div>
        <!-- 文件预览 -->
        <showFile v-if="fileDialog" :fileDialog.sync="fileDialog" />
        <!-- 效验 -->
        <RepaymentEffectDialog v-if="EffectDialog" :EffectDialog.sync="EffectDialog" />
    </div>
    
  

</template>
<script>
import api from "@/services/eventTracingApi";
import caseapi from "@/services/caseManagement";
    export default {
        components: {
            showFile: () => import('../../../components/showFile.vue'),//
            RepaymentEffectDialog: () => import('../../case-management/components/RepaymentEffectDialog.vue'),//效验
        },
        props: {
            eventTraDialog: {
                type: Object,
                default: () => {
                    return {}
                },
            },
        },
        data() {
            return {
                fileDialog:null,
                EffectDialog:null,
                DialogDetail:null,
                queryDate: '',
                queryParam:{
                    caseNo:'',
                    pkgName:'',
                    size:10,
                    current:1
                },
                tableData:[],
                total:0,
            };
        },
        mounted () {
            this.initializeQuery()
            this.getProofList(1)
        },
        methods: {
            initializeQuery(){
                this.queryParam.caseNo = this.eventTraDialog.caseNo
            },
            handleChangeDate() {
                this.activeUsage = ''
                if(this.queryDate === null) {
                    this.queryParam.beginTime = ''
                    this.queryParam.endTime = ''
                    this.queryDate = ''
                }else {
                    this.queryParam.beginTime = this.$util.getDayStart(this.queryDate[0])
                    this.queryParam.endTime = this.$util.getDayEnd(this.queryDate[1])
                }
            },
            // 重置
            hanldeReset() {
                for (let key in this.queryParam) {
                this.queryParam[key] = ''
                }
                this.queryParam.current = 1
                this.queryParam.size = 10
                this.activeUsage = ''
                this.queryDate = ''
                this.initializeQuery()
            },
            handleSearch() {
                this.queryParam.size = 10;
                this.queryParam.current = 1;
                this.getProofList(1)
            },
            // 列表数据
            getProofList(val){
                this.queryParam.startTime = this.queryParam.beginTime
                this.queryParam.current = val
                this.queryParam.isDebatorUpload = 1
                api.posttrace_proof(this.queryParam).then(res => {
                    if (!res.code) {
                        this.tableData = res.records;
                        this.total = res.total;
                    }
                })
            },
            
            // 取消效验
            handEffectCancel(proofitem){
                console.log(proofitem,'proofitem')
                this.$confirm("请确定是否取消效验这些数据?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }).then(() => {
                    if(!this.$clickThrottle()) { return }//防止重复点击
                    let data = {
                        id:proofitem.id
                    }
                    caseapi.gettraceProof_cancel(data).then((res) => {
                        this.$message.success("取消成功");
                        this.getProofList(1)
                    
                    });
                }).catch(() => {});
            },
            handleCaseShow(scope){
                //还款凭证相关
                this.$fetchApi.viewFullFile({path: scope.row.proofUrl}).then((res) => {
                    this.fileDialog = {showfile: {url: scope.row.proofUrl,fullUrl: res}, filelist: []}
                });
            },
        }
    };
</script>
<style scoped lang="scss">
.dialog-content{
    padding: 16px 24px;
    max-height:500px
}
.department-wrap{
    padding: 16px 24px;
    max-height: 250px;
    .department-wrap-list{
        margin-bottom:32px;
    }
    .department-wrap-list:last-child{
        margin-bottom:0;
    }
}
.min-height350{min-height: 350px;}
.department-dept ::v-deep .el-checkbox__label {color: $color-000000}
</style>