<template>
    <div class="dictiontary-list-detail child-router">
        <TableHeader>
            <template #select>
                <el-form-item label="">
                    <span class="text-large font-600 mr-3" style="font-weight: 600;">{{ props.bingRow.name
                        }}_绑定测点</span>
                </el-form-item>
            </template>
            <template #operation>
                <el-button icon="el-icon-Plus" type="primary" @click="add">新增</el-button>
                <el-button icon="el-icon-Back" @click="$emit('close')">返回</el-button>
            </template>
        </TableHeader>
        <Table ref="tableRef" />
        <BindForm ref="bindFormRef" :pid="props.bingRow.id" />
    </div>
</template>
<script setup lang="ts">
import { ref, onMounted, provide } from 'vue'
import TableHeader from '@/components/table/header/index.vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import BindForm from './bindForm.vue'
import { ElMessage } from 'element-plus'
import { deleteGovernPlan } from '@/api/cs-device-boot/sensitiveLoadMange'

const props = defineProps<{
    bingRow: anyObj
}>()

defineEmits(['close'])

const bindFormRef = ref<InstanceType<typeof BindForm>>()

const tableStore = new TableStore({
    url: '/cs-harmonic-boot/pqGovernPlan/getListByPid',
    method: 'GET',
    column: [
        { title: '治理点名称', field: 'governName', width: 200 },
        {
            title: '治理类型',
            field: 'governType',
            width: 120,
            formatter: row => {
                return row.cellValue == 'harmonic' ? '稳态治理' : '暂态治理'
            }
        },
        { title: '治理方法', field: 'governMethod', width: 120 },

        { title: '治理前-监测点', field: 'ledgerBefore', minWidth: 200, formatter: row => row.cellValue || row.row?.governBefore || '/' },
        { title: '治理后-监测点', field: 'ledgerAfter', minWidth: 200, formatter: row => row.cellValue || row.row?.governAfter || '/' },
        { title: '排序', field: 'sort', width: '80' },
        {
            title: '操作',
            fixed: 'right',
            width: '180',
            render: 'buttons',
            buttons: [
                {
                    title: '编辑',
                    type: 'primary',
                    icon: 'el-icon-EditPen',
                    render: 'basicButton',
                    click: row => {
                        bindFormRef.value?.open('编辑', row)
                    }
                },
                {
                    title: '删除',
                    type: 'danger',
                    icon: 'el-icon-Delete',
                    render: 'confirmButton',
                    popconfirm: {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        confirmButtonType: 'danger',
                        title: '确定删除该方案吗？'
                    },
                    click: row => {
                        deleteGovernPlan([row.id]).then(() => {
                            ElMessage.success('删除成功')
                            tableStore.index()
                        })
                    }
                }
            ]
        }
    ]
})

const add = () => {
    bindFormRef.value?.open('新增')
}

provide('tableStore', tableStore)

onMounted(() => {
    tableStore.table.params.pid = props.bingRow.id
    tableStore.index()
})
</script>
