<!--进线管理界面-->
<template>
    <div class='default-main'>
        <TableHeader>
            <template v-slot:operation>
                <el-button type='primary' @click='add' class='ml10' :icon='Plus'>新增</el-button>
            </template>
        </TableHeader>
        <!--表格-->
        <Table ref='tableRef'></Table>
        <!--弹框-->
        <incoming-line-popup ref='incomingLinePopup' />
    </div>
</template>
<script setup lang='ts'>
import { provide, ref } from 'vue'
import { Plus } from '@element-plus/icons-vue'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import IncomingLinePopup from './incomingLinePopup.vue'
import TableStore from '@/utils/tableStore'
import { ElMessage } from 'element-plus'
import { deleteSgIncomingLine } from '@/api/advance-boot/sgGroven/incomingLine'

//进线信息弹出框
const incomingLinePopup = ref()


const userId = ref()

const tableStore = new TableStore({
    url: '',
    method: 'GET',
    publicHeight: 350,
    showPage: false,
    column: [
    { title: '序号',  width: 80,formatter: (row: any) => {
        return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
      } },
        { title: '进线名称', field: 'name' },
        { title: '监测点名称', field: 'lineName' },
        {
             title: '操作',fixed: 'right',
            align: 'center',
            width: '150',
            render: 'buttons',
            buttons: [
                {
                    name: 'update',
                    title: '编辑',
                    type: 'primary',
                    icon: 'el-icon-EditPen',
                    render: 'basicButton',
                    click: row => {
                        incomingLinePopup.value.open('修改进线', row)
                    }
                },
                {
                    name: 'update',
                    title: '删除',
                    type: 'danger',
                    icon: 'el-icon-Delete',
                    render: 'confirmButton',
                    popconfirm: {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        confirmButtonType: 'danger',
                        title: '确定删除吗？'
                    },
                    click: row => {
                        deleteSgIncomingLine(row.id).then(res => {
                            ElMessage.success('删除成功')
                            tableStore.index()
                        })
                    }
                }
            ]
        }
    ]
})

const getTableData = (tempId: string) => {
    userId.value = tempId
    tableStore.url = '/advance-boot/sgIncomingLine/list?userId=' + userId.value
    tableStore.index()
}


/**********新增、编辑进线************/
//新增进线信息
const add = () => {
    incomingLinePopup.value.open('新增进线', { userId: userId.value })
}


provide('tableStore', tableStore)
defineExpose({ getTableData })

</script>