<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, watch, toRef } from 'vue';
import flow from '@/api/flow/flow';
import { ElMessage } from 'element-plus';
export default {
    props: {
        delModal: {
            type: Boolean,
            required: true
        },//父组件返回模态框状态
        modelIds: {
            type: String,
            required: true
        },//模型id
        delFcda: {
            type: String,
            required: true
        },//需要删除的fcdaid
        copyReload: {
            type: Function,
            required: true
        },//刷新父组件显示列表
    },
    setup(props, { emit }) {
        let dialogVisible = ref(false)//模态框开关
        let module = ref('')//本组件模型id
        let needDel = ref("")//本组件需要删除的fcdaid
        watch(() => props.modelIds, (newVal) => {
            module.value = newVal
        })
        watch(() => props.delFcda, (newVal) => {
            needDel.value = newVal
        })
        // 初始化函数
        function reload() {
            module.value = props.modelIds
            needDel.value = props.delFcda
            dialogVisible.value = props.delModal
        }
        function closeModal() {
            dialogVisible.value = false
            emit('delBack', dialogVisible.value)
        }
        function sureModal() {
            flow.delModelOn({
                model_id: module.value - 0,
                fcda_id: needDel.value - 0,
            }).then(res => {
                if (res.code == 0) {
                    ElMessage({
                        type: "success",
                        message: "删除成功！"
                    })
                    props.copyReload()
                    dialogVisible.value = false
                    emit('delBack', dialogVisible.value)
                } else {
                    ElMessage({
                        message: res.msg,
                        type: "error"
                    })
                }
            })
        }
        onMounted(() => {
            reload()
        })
        return {
            reload,//初始化函数
            dialogVisible,//模态框开关
            closes: closeModal,//关闭模态框
            cancels: closeModal,//关闭模态框
            sureAdd: sureModal,//确认关闭模态框
            module,//本组件模型id
            needDel,//本组件需要删除的fcdaid
        }
    }
}
</script>

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