<template>
    <div>
        <TableHeader area datePicker ref="TableHeaderRef" showCustomColumn>
            <template #select>
                <el-form-item label="问题来源">
                    <el-select v-model="tableStore.table.params.problemSources" clearable placeholder="请选择问题来源">
                        <el-option
                            v-for="item in problemData"
                            :key="item.code"
                            :label="item.name"
                            :value="item.code"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="填报进度">
                    <el-select v-model="tableStore.table.params.reportProcess" clearable placeholder="请选择填报进度">
                        <el-option
                            v-for="item in fillingProgress"
                            :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.problemName"
                        clearable
                        placeholder="请输入问题名称"
                        style="width: 100%"
                    ></el-input>
                </el-form-item>
            </template>
        </TableHeader>
        <Table ref="tableRef" />

        <!-- 审核 -->
        <el-dialog draggable title="问题审核" v-model="dialogVisible" width="1400px" :before-close="beforeClose">
            <Filling
                ref="FillingRef"
                v-if="dialogVisible"
                :isDisabled="true"
                :audit="true"
                :flag="true"
                @beforeClose="beforeClose"
            />
        </el-dialog>

        <!-- 审核记录 -->
        <recording ref="recordingRef" />
    </div>
</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 { useDictData } from '@/stores/dictData'

import Filling from './filling.vue'
import recording from './recording.vue'
const dictData = useDictData()
const problemData = dictData.getBasicData('Problem_Sources')
const fillingProgress = dictData.getBasicData('Fill_Progress')
const TableHeaderRef = ref()
const FillingRef = ref()
const ruleFormRef = ref()

const list: any = ref({})
const recordingRef = ref(false)
const dialogVisible = ref(false)
const tableStore = new TableStore({
    url: '/process-boot/electricityQuality/getIssues',
    publicHeight: 65,
    method: 'POST',
    column: [
        {
            field: 'index',
            title: '序号',
            width: '80',
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        { field: 'orgName', title: '所属单位' },
        {
            field: 'problemSources',
            title: '问题来源'
        },
        { field: 'powerQualityProblemNo', title: '问题编号' },
        { field: 'problemName', title: '问题名称' },

        { field: 'dataDate', title: '提交时间' },
        {
            field: 'reportProcess',
            title: '填报节点',
            formatter: (row: any) => {
                return fillingProgress.filter(item => item.code == row.cellValue)[0]?.name
            }
        },
        {
             title: '操作',fixed: 'right',
            width: '150',
            render: 'buttons',
            buttons: [
                {
                    name: 'edit',
                    title: '审核',
                    type: 'primary',
                    icon: 'el-icon-Plus',
                    render: 'basicButton',
                    click: async row => {
                        dialogVisible.value = true
                        setTimeout(() => {
                            list.value = row
                            FillingRef.value.open(row)
                        }, 10)
                    }
                },
                {
                    name: 'edit',
                    title: '审核记录',
                    type: 'primary',
                    icon: 'el-icon-Plus',
                    render: 'basicButton',
                    click: async row => {
                        recordingRef.value.open(row)
                    }
                }
            ]
        }
    ],
    beforeSearchFun: () => {
        tableStore.table.params.orgNo = tableStore.table.params.deptIndex
        tableStore.table.params.dataDate = tableStore.table.params.searchBeginTime
        tableStore.table.params.dataType = TableHeaderRef.value.datePickerRef.interval
    }
})

tableStore.table.params.problemSources = ''
tableStore.table.params.reportProcess = ''
tableStore.table.params.problemName = ''
tableStore.table.params.reportProcessStatus = 'Auditt'

const beforeClose = () => {
    tableStore.index()
    dialogVisible.value = false
}
provide('tableStore', tableStore)

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