<template>
    <div>
        <div>
            <el-dialog v-model="dialogVisible" title="删除信息" width="30%" @close="closes">
                <h2><el-icon style="color: red;">
                        <WarningFilled />
                    </el-icon>确定删除该信息？</h2>
                <template #footer>
                    <span class="dialog-footer">
                        <el-button @click="cancels">取消</el-button>
                        <el-button type="primary" @click="sureClick">
                            确定
                        </el-button>
                    </span>
                </template>
            </el-dialog>
        </div>
    </div>
</template>

<script>
import { ref, onMounted, toRefs, watch } from 'vue';
import { ElMessage } from 'element-plus';
import litLine from '@/api/litLine';
export default {
    props: {
        delModal: {
            type: Boolean,
            required: true
        },
        needList: {
            type: Object,
            required: true
        },
        search: {
            type: Function,
            required: true
        }
    },
    setup(props, { emit }) {
        let dialogVisible = ref(false)
        let result = props.delModal
        let lastList = props.needList
        let delId = ref('')
        let { cancels, sureClick } = toRefs(props)
        function lineList() {
            delId.value = lastList.id
            dialogVisible.value = result
        }
        function canBack() {
            dialogVisible.value = false
            emit("delBack", dialogVisible.value)
        }
        function sureGet() {
            litLine.delLine({ id: delId.value - 0 }).then(res => {
                if (res.code == 0) {
                    ElMessage({
                        type: "success",
                        message: "删除成功",
                        duration: 1500
                    })
                    props.search()
                    dialogVisible.value = false
                    emit("delBack", dialogVisible.value)
                }
            })

        }
        onMounted(() => {
            lineList()
        })
        return {
            dialogVisible,
            cancels: canBack,
            sureClick: sureGet,
            closes: canBack,
        }
    }
}
</script>

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