<template>
    <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="390" >
                    <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 prop="paybackTime" label="还款日期" show-overflow-tooltip ></el-table-column>
                    <el-table-column prop="remark" label="备注说明" show-overflow-tooltip ></el-table-column>
                    <el-table-column prop="uploaderName" label="上传者" show-overflow-tooltip ></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="260">
                        <template slot-scope="scope">
                            <div class="flex-row align-items-center">
                                <el-button size="mini" @click="handleCaseShow(scope)">查看凭证</el-button>
                                <el-button size="mini" v-if="scope.row.status.code == 1" @click="EffectDialog = scope.row">效验</el-button>
                                <el-button size="mini" v-if="scope.row.status.code == 1" @click="handEffectCancel(scope.row)">取消</el-button>
                            </div>
                        </template>
                    </el-table-column>
                    
                </el-table>
            </div>
        </div>
        <!-- 文件预览 -->
        <showFile v-if="fileDialog" :fileDialog.sync="fileDialog" />
        <!-- 效验 -->
        <RepaymentEffectDialog v-if="EffectDialog" :EffectDialog.sync="EffectDialog" />
    </div>
</template>
<script>
import api from "@/services/caseManagement";
    export default {
        components: {
            showFile: () => import('../../../components/showFile.vue'),//
            RepaymentEffectDialog: () => import('./RepaymentEffectDialog.vue'),//效验
        },
        props: {
            eventTraDialog: {
                type: Object,
                default: () => {
                    return {}
                },
            },
        },
        data() {
            return {
                EffectDialog:null,
                fileDialog:null,
                queryParam:{},
                tableData:[],
                total:0,

            };
        },
        mounted () {
            this.getProofList()
        },
        methods: {
            getProofList(){
                api.gettraceProof_list({caseId:this.eventTraDialog.caseId}).then(res => {
                     if(!res.code){
                        this.tableData = res
                     }
                })
            },
            // 取消效验
            handEffectCancel(proofitem){
                this.$confirm("请确定是否取消效验这些数据?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }).then(() => {
                    if(!this.$clickThrottle()) { return }//防止重复点击
                    let data = {
                        id:proofitem.id
                    }
                    api.gettraceProof_cancel(data).then((res) => {
                        this.$message.success("取消成功");
                        this.getProofList()
                    });
                }).catch(() => {});
            },
            async handleCaseShow(scope){
                let previewUrl = await this.getProofFile(scope.row.proofUrl)
                this.fileDialog = {showfile:{fullUrl:previewUrl,url:scope.row.proofUrl},filelist:[]}
            },
            async getProofFile(url){
                let previewUrl = await this.$fetchApi.viewFullFile({path: url})
                return previewUrl
            },
            handleClose() {
                this.$emit('update:eventTraDialog', null)
            },
        }
    };
</script>
<style scoped lang="scss">
.dialog-trace{
    padding: 16px 20px;
    max-height:500px
}

</style>