<template>
    <div class="default-main">
        <TableHeader ref="tableHeaderRef" :showReset="false" showExport>
            <template #select>
                <el-form-item label="关键字筛选">
                    <el-input v-model="tableStore.table.params.keywords" clearable placeholder="请输入关键字" />
                </el-form-item>
                <el-form-item label="通讯状态">
                    <el-select
                        v-model.trim="tableStore.table.params.devType"
                        filterable
                        placeholder="请选择通讯状态"
                        clearable
                    >
                        <el-option
                            v-for="item in DevTypeOptions"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="装置型号">
                    <el-select
                        v-model.trim="tableStore.table.params.devType"
                        filterable
                        placeholder="请选择装置型号"
                        clearable
                    >
                        <el-option
                            v-for="item in DevTypeOptions"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="装置系列">
                    <el-select
                        v-model.trim="tableStore.table.params.devType"
                        filterable
                        placeholder="请选择装置系列"
                        clearable
                    >
                        <el-option
                            v-for="item in DevTypeOptions"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="升级装置筛选">
                    <el-select
                        v-model.trim="tableStore.table.params.devType"
                        filterable
                        placeholder="请选择升级装置筛选"
                        clearable
                    >
                        <el-option
                            v-for="item in DevTypeOptions"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>
            </template>
            <template #operation>
                <el-button :icon="EditPen" type="primary" class="ml10" @click="maintenance">终端版本维护</el-button>
                <el-button :icon="Share" type="primary" class="ml10">批量升级</el-button>
            </template>
        </TableHeader>
        <Table ref="tableRef" />
    </div>
</template>
<script setup lang="ts">
import { ref, onMounted, provide } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import { ElMessage } from 'element-plus'
import { queryByCode, queryByid } from '@/api/system-boot/dictTree'
import { useDictData } from '@/stores/dictData'
import { Share, EditPen } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'
defineOptions({
    name: 'govern/manage/programVersion'
})
const dictData = useDictData()
const DevTypeOptions = ref()
const tableHeaderRef = ref()
const { push, options, currentRoute } = useRouter()
const tableStore = new TableStore({
    url: '/cs-device-boot/edData/queryEdDataPage',
    method: 'POST',
    column: [
        { type: 'checkbox', width: '60' },
        {
            field: 'index',
            title: '序号',
            width: '80',
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        { title: '装置名称', field: 'devTypeName', minWidth: '100' },
        { title: '版本号', field: 'versionNo', minWidth: '100' },
        { title: '协议版本', field: 'versionAgreement', minWidth: '100' },
        { title: '版本日期', field: 'versionDate', minWidth: '100' },
        { title: '装置系列', field: 'versionDate', minWidth: '100' },
        { title: '装置型号', field: 'versionDate', minWidth: '100' },
        { title: '供电公司', field: 'versionDate', minWidth: '100' },
        { title: '变电站', field: 'versionDate', minWidth: '100' },
        {
            title: '状态',
            field: 'status',
            render: 'tag',
            minWidth: '80',
            custom: {
                0: 'error',
                1: 'success'
            },
            replaceValue: {
                0: '禁用',
                1: '启用'
            }
        },
        { title: '更新时间', field: 'versionDate', minWidth: '100' },
        { title: '修改人员', field: 'versionDate', minWidth: '100' },

        {
            title: '操作',
            fixed: 'right',
            align: 'center',
            width: '120',
            render: 'buttons',
            buttons: [
                {
                    name: 'productSetting',
                    title: '升级',
                    type: 'primary',
                    icon: 'el-icon-EditPen',
                    render: 'basicButton'
                },
                {
                    name: 'productSetting',
                    title: '升级日志',
                    type: 'primary',
                    icon: 'el-icon-EditPen',
                    render: 'basicButton'
                }
            ]
        }
    ],
    loadCallback: () => {}
})
queryByCode('Device_Type').then(res => {
    const id = res.data.id
    queryByid(id).then(res1 => {
        res1.data.map((item: any, index: any) => {
            if (item.pid == id) {
                res1.data.splice(index, 1)
            }
        })

        DevTypeOptions.value = res1.data
    })
})
// 版本维护
const maintenance = () => {
    push({
        path: '/versionMaintenance'
    })
}

tableStore.table.params.devType = ''
provide('tableStore', tableStore)
onMounted(() => {
    tableHeaderRef.value.onComSearch()
})
</script>
