<template>
    <el-dialog draggable width="800px" v-model="dialogVisible" :title="title">
        <el-scrollbar>
            <el-form :inline="false" :model="form" label-width="auto" class="form-two">
                <el-form-item v-for="(item, index) in child" :key="index" :label="item.title">
                    <el-input v-model="form[item.field]" placeholder="请输入菜单名称" />
                </el-form-item>
            </el-form>
        </el-scrollbar>

        <template #footer>
            <span class="dialog-footer">
                <el-button @click="dialogVisible = false">取消</el-button>
                <el-button type="primary" @click="submit">确认</el-button>
            </span>
        </template>
    </el-dialog>
</template>
<script lang="ts" setup>
import { ref, inject } from 'vue'
import { reactive } from 'vue'

const emits = defineEmits<{
    (e: 'init'): void
}>()
const child: any = ref([])
const form: any = reactive({})

const dialogVisible = ref(false)
const title = ref('新增菜单')
const open = (row: any) => {

    title.value = row.title + `_${row.item.name}`
    child.value = row.item.child
    if (row.title == '新增') {
        row.item.child.forEach((item: any) => {
            form[item.field] = ''
        })
    } else {
        row.item.child.forEach((item: any) => {
            form[item.field] = row.row[item.field]
        })
    }

    dialogVisible.value = true
}
const submit = async () => {
    emits('init')
    dialogVisible.value = false
}

defineExpose({ open })
</script>
