<template>
    <div style="padding: 20px">
        <el-button type="primary" style="margin-bottom: 20px;" @click="showFieid">新增明细</el-button>
        <el-table :data="fieidData" border style="width:50%">
            <el-table-column label="第三方标识" prop="docType" />
            <el-table-column label="金蝶标识" prop="sFormId" />
            <el-table-column label="日志名称" prop="name" />
            <el-table-column label="配置方向" prop="flag">
                <template #default="scope">
                    {{ scope.row.flag === -1 ? 'ERP->MES' : 'MES->ERP' }}
                </template>
            </el-table-column>>
            <el-table-column label="操作" width="135">
                <template #default="scope">
                    <el-link size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-link>
                    <el-link :undderline="false" type="danger" @click="handleDelete(scope.row.id)">删除
                    </el-link>
                </template>
            </el-table-column>
        </el-table>
    </div>
    <new-field ref="newFieldRef"></new-field>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus';
import { getCommonConfig } from '@/services/api/systemApi/fieldConfiguration/commonConfig'
import newField from './components/fieldConfiguration/newField.vue';

const fieidData = ref()
const newFieldRef = ref()

const handleEdit = (index: any, row: any) => { }
const handleDelete = (id: number) => {
    ElMessageBox.confirm(
        '确定删除该配置?',
        '配置',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
        }
    )
        .then(() => {
            ElMessage({
                type: 'success',
                message: '删除成功',
            })
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: '取消',
            })
        })
}


const showFieid = () => {
    newFieldRef.value.drawerVisible = true
}

// 通用配置列表数据 
const initCommonConfig = () => {
    getCommonConfig().then((res: any) => {
        if (res.code === 200) {
            fieidData.value = res.data.records
            console.log(res);
        }
    })
}
initCommonConfig()
</script>

<style scoped>
</style>