<template>
    <div>
        <el-dialog v-model="dialogVisible" title="删除" width="30%" @close="closes" :close-on-click-modal="false">
            <div style="display: flex;justify-content:center;align-items: center;">
                <el-icon style="color: red;font-size: 40px;display: block;">
                    <WarningFilled />
                </el-icon>
                <span style="display: block;">是否确认删除该信息?</span>
            </div>
            <div style="display: flex;justify-content:center;align-items: center;margin-top: 40px;">
                <el-button style="display: block;width: 150px;height: 30px;" @click="cancels">取消</el-button>
                <el-button style="display: block;width: 150px;height: 30px;" type="primary" @click="sureAdd">确认</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { ref, onMounted, toRefs, watch } from 'vue'
import report from '@/api/report'
import { ElMessage } from 'element-plus'
export default {
    props: {
        delModal: {
            type: Boolean,
            required: true
        },
        delId: {
            type: String,
            required: true
        },
        searchReport: {
            type: Function,
            required: true
        }
    },
    setup(props, { emit }) {
        let dialogVisible = ref(false)
        let result = props.delModal
        let resultId = props.delId
        let lete = ref('')
        watch(() => props.delId, (newVal) => {
            lete.value = newVal
        })
        function reload() {
            dialogVisible.value = result
            lete.value = props.delId
        }
        function allClose() {
            dialogVisible.value = false
            emit("delrmBack", dialogVisible.value)
        }
        function allTrue() {
            report.delReport({ id: lete.value - 0 }).then(res => {
                if (res.code == 0) {
                    ElMessage({
                        type: "success",
                        message: "删除成功"
                    })
                    props.searchReport()
                    dialogVisible.value = false
                    emit("delrmBack", dialogVisible.value)
                }
            })
        }
        onMounted(() => {
            reload()
        })
        return {
            dialogVisible,
            reload,
            closes: allClose,
            cancels: allClose,
            sureAdd: allTrue,
        }
    }
}
</script>

<style lang="scss" scoped></style>