<template>
    <TableHeader area ref="TableHeaderRef">
        <template #select>
            <el-form-item label="干扰源类型">
                <el-select v-model="tableStore.table.params.loadType" clearable placeholder="请选择干扰源类型">
                    <el-option
                        v-for="item in interferenceType"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="干扰源用户名称">
                <el-input
                    v-model="tableStore.table.params.userName"
                    clearable
                    placeholder="请选择干扰源用户名称"
                ></el-input>
            </el-form-item>

            <el-form-item label="是否上传报告:">
                <el-select v-model="tableStore.table.params.fileUploadflag" clearable placeholder="请选择是否上传报告">
                    <el-option label="否" value="0" />
                    <el-option label="是" value="1" />
                </el-select>
            </el-form-item>
        </template>
        <template #operation>
            <el-button icon="el-icon-Plus" type="primary" @click="addList">新增</el-button>

            <el-button icon="el-icon-Download" type="primary">导出</el-button>
        </template>
    </TableHeader>
    <Table ref="tableRef" />
    <!-- 新增 -->
    <Add ref="addRef" @onSubmit="tableStore.index()" />
    <!-- 上传 -->
    <Audit ref="AuditRef" @onSubmit="tableStore.index()" />
</template>
<script setup lang="ts">
import { ref, onMounted, provide, nextTick } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import { mainHeight } from '@/utils/layout'
import Add from './add.vue'
import Audit from './audit.vue'
import { useDictData } from '@/stores/dictData'
const dictData = useDictData()

const TableHeaderRef = ref()
const interferenceType = dictData.getBasicData('Interference_Source')

const istatusList = dictData.getBasicData('On-network_Status')

const addRef = ref()
const AuditRef = ref()
const ruleFormRef = ref()
const fileList = ref([])
const tableStore = new TableStore({
    url: '/process-boot/loadTypeUserManage/getLoadTypeUserList',
    publicHeight: 65,
    method: 'POST',
    column: [
        // { width: '60', type: 'checkbox' },
        { field: 'orgName', title: '所属单位' },
        {
            field: 'loadType',
            title: '干扰源类型',
            formatter: row => {
                return interferenceType.filter(item => item.id == row.cellValue)[0]?.name
            }
        },
        { field: 'userName', title: '干扰源用户名称' },
        { field: 'recordTime', title: '建档时间' },
        {
            field: 'iisFileUpload',
            title: '是否上传报告',
            render: 'tag',
            custom: {
                0: 'warning',
                1: 'success'
            },
            replaceValue: {
                0: '否',
                1: '是'
            }
        },
        {
            field: 'istatus',
            title: '入网评估报告状态',
            formatter: row => {
                return istatusList.filter(item => item.id == row.cellValue)[0]?.name
            }
        },

        {
            title: '操作',
            width: '180',
            render: 'buttons',
            buttons: [
                {
                    name: 'edit',
                    title: '上传',
                    type: 'primary',
                    disabled: row => {
                        return !(
                            row.istatus == null ||
                            istatusList.filter(item => item.code == 'Newly')[0]?.id == row.istatus ||
                            istatusList.filter(item => item.code == 'Failed')[0]?.id == row.istatus
                        )
                        // ||
                        // istatusList.filter(item => item.code == 'Failed')[0]?.id == row.istatus
                    },
                    icon: 'el-icon-Plus',
                    render: 'basicButton',
                    click: row => {
                        AuditRef.value.open('未建档干扰源用户入网报告结论上传', row)
                    }
                },

                {
                    name: 'edit',
                    text: '查看',
                    type: 'primary',
                    disabled: row => {
                        return row.istatus == null
                    },
                    icon: 'el-icon-Delete',
                    render: 'basicButton',
                    click: row => {
                        AuditRef.value.open('未建档干扰源用户详情', row)
                    }
                }
            ]
        }
    ],

    beforeSearchFun: () => {
        tableStore.table.params.orgNo = tableStore.table.params.deptIndex
        tableStore.table.params.relationUserName = tableStore.table.params.userName
    }
})

tableStore.table.params.loadType = ''
tableStore.table.params.userName = ''
tableStore.table.params.fileUploadflag = ''

provide('tableStore', tableStore)
// 新增
const addList = () => {
    addRef.value.open()
}
// 提交
const submit = () => {
    console.log(123, fileList.value)
}
// 保存
const preservation = () => {}

onMounted(() => {
    tableStore.index()
})
</script>

<style scoped lang="scss">
:deep(.el-upload-list__item) {
    width: 400px;
}
</style>
