<template>
    <div v-if="visible" class="popup-model station-model comp-container">
        <div class="station-title">
            {{ title }}
        </div>
        <i class="icon el-icon-close" @click="close"></i>
        <div class="station-content">
            <el-table :data="data" v-if="title == '安全鉴定'" height="100%" stripe border size="mini" highlight-current-row>
                <el-table-column type="index" width="40">
                </el-table-column>
                <el-table-column label="水库名称" align="center" prop="rsnm" min-width='100' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="安全鉴定单位" align="center" prop="appraisalCompany" min-width='120'
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="安全鉴定时间" align="center" prop="appraisalDate" min-width='100'
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="安全鉴定级别" align="center" prop="appraisalLevel" min-width='100'
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="操作" align="center" min-width='100' show-overflow-tooltip>
                    <template slot-scope="scope">
                        <el-button size="mini" type="primary" @click="handleSafe(scope.$index, scope.row)">查看文档
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-table :data="data" v-else-if="title == '除险加固'" height="100%" stripe border size="mini"
                highlight-current-row>
                <el-table-column type="index" width="40">
                </el-table-column>
                <el-table-column label="水库名称" align="center" prop="rsnm" min-width='100' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="竣工验收时间" align="center" prop="completeDate" min-width='120'
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="投入使用时间" align="center" prop="useDate" min-width='100' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="最后一次加固开工时间" align="center" prop="lastDate" min-width='100'
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="操作" align="center" min-width='100' show-overflow-tooltip>
                    <template slot-scope="scope">
                        <el-button size="mini" type="primary" @click="handleReinforce(scope.$index, scope.row)">查看文档
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-table :data="data" v-else-if="title == '维修养护'" height="100%" stripe border size="mini"
                highlight-current-row>
                <el-table-column type="index" width="50">
                </el-table-column>
                <el-table-column label="水库名称" align="center" prop="rsnm" min-width='100' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="养护名称" align="center" prop="yhName" min-width='100' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="养护类型" align="center" prop="yhType" min-width='100' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="养护开始时间" align="center" prop="yhSDate" min-width='100' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="养护结束时间" align="center" prop="yhEDate" min-width='100' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="操作" align="center" min-width='100' show-overflow-tooltip>
                    <template slot-scope="scope">
                        <el-button size="mini" type="primary" @click="handleMaintain(scope.$index, scope.row)">查看文档
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
import digitalReservoir from '@/api/frontScreen/digitalReservoir.js'
export default {
    name: 'SafeModel',
    components: {
    },
    props: {
    },
    data() {
        return {
            visible: false,
            title: '',
            text: '',
            data: [],
            params: {
                rscd: '',
            },
            queryParam: {
                pageBean: {
                    pageSize: 10,
                    page: 1,
                },
                params: {
                    rscd: '',
                },
            },
            safeList: [],
            ReinforceList: [],
            MaintainList: [],
            path: ''
        }
    },
    created() {
        this.params.rscd = window.sessionStorage.getItem("rscdId");
        window.sessionStorage.removeItem("rscdId")
    },
    methods: {
        // 查看安全PDF
        handleSafe(index, item) {
            console.log(item);
            let PdfId = JSON.parse(item.filePaths)
            this.safeList = []
            // 获取pdf文件路径
            digitalReservoir.PdfListSaf(item.rscd, (res) => {
                if (res.state) {
                    this.safeList = res.value.安全鉴定
                    this.safeList.forEach(PdfItem => {
                        if (PdfItem.id == PdfId[0].fileId) {
                            this.path = PdfItem.filePath
                            this.$parent.openPDF(3, this.path)
                        }
                    })
                }
            })
        },
        handleReinforce(index, item) {
            let PdfId = JSON.parse(item.filePaths)
            this.ReinforceList = []
            // 获取pdf文件路径
            digitalReservoir.PdfListSaf(item.rscd, (res) => {
                if (res.state) {
                    this.ReinforceList = res.value.除险加固
                    this.ReinforceList.forEach(PdfItem => {
                        if (PdfItem.id == PdfId[0].fileId) {
                            this.path = PdfItem.filePath
                            this.$parent.openPDF(3, this.path)
                        }
                    })  
                }
            })

        },
        handleMaintain(index, item) {
            let PdfId = JSON.parse(item.filePaths)
            this.MaintainList = []
            // 获取pdf文件路径
            digitalReservoir.PdfListSaf(item.rscd, (res) => {
                if (res.state) {
                    this.MaintainList = res.value.维修养护
                    this.MaintainList.forEach(PdfItem => {
                        if (PdfItem.id == PdfId[0].fileId) {
                            this.path = PdfItem.filePath
                            this.$parent.openPDF(3, this.path)
                        }
                    })
                }
            })
        },
        open(value, id) {
            this.data = []
            this.queryParam.params.rscd = id
            if (value == 1) {
                this.title = "安全鉴定"
                this.visible = true
                digitalReservoir.ListGetSaf(this.queryParam, (res) => {
                    if (res.state) {
                        this.data = res.value.rows
                    }
                })
            } else if (value == 2) {
                this.title = "除险加固"
                this.visible = true
                digitalReservoir.ListGetRes(this.queryParam, (res) => {
                    if (res.state) {
                        this.data = res.value.rows
                    }
                })
            } else if (value == 3) {
                this.title = "维修养护"
                this.visible = true
                digitalReservoir.ListGetMain(this.queryParam, (res) => {
                    if (res.state) {
                        this.data = res.value.rows
                    }
                })
            }
        },
        close() {
            this.data = []
            this.rscd = ""
            this.title = ""
            this.visible = false
            this.$emit('close')
        },
    }

}
</script>

<style lang="scss" scoped>
@import './../css/gisComp.scss';

.popup-model {
    width: 700PX;
    height: 350PX;
    position: absolute;
    top: 50%;
    left: 55%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 99;
    border: 1px solid #d2d6dc;
    border-radius: 6px;
    color: #d3d4d7;
    padding: 20px;
    box-sizing: border-box;

    .el-icon-close {
        position: absolute;
        right: 6px;
        top: 6px;
        font-size: 20px;
        color: #f56c6c;
        cursor: pointer;
    }

    .station-title {
        display: flex;
        justify-content: center;
        /* 水平居中 */
        align-items: center;
        /* 垂直居中 */
        // text-align: center;
        font-size: 16px;
        height: 20px;
        line-height: 20px;
        font-weight: 700;
        margin-bottom: 16px;

        div {
            width: 43%;
        }
    }

    .station-content {
        height: calc(100% - 36px);
        width: 100%;
    }
}
</style>
