<template>
    <div class="default-main">
        <div v-show="show && lookShow">
            <TableHeader ref="TableHeaderRef" showCustomColumn>
                <template #operation>
                    <el-button icon="el-icon-Plus" type="primary" @click="add">新增</el-button>
                </template>
            </TableHeader>
            <Table ref="tableRef" />
        </div>
        <luckysheet ref="luckysheetRef" v-if="!show" @shutDown="shutDown" />
        <!-- 查看 -->
        <look ref="lookRef" v-if="!lookShow" @shutDown="shutDown" />
        <!-- 绑定 -->
        <department ref="departmentRef" />
    </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 { delTemplate } from '@/api/harmonic-boot/luckyexcel'
import { useDictData } from '@/stores/dictData'
import { ElMessage } from 'element-plus'
import luckysheet from './luckysheet.vue'
import look from './look.vue'
import department from './department.vue'
defineOptions({
    name: 'Distributedphotovoltaic/templateConfiguration'
})
const luckysheetRef = ref()
const lookRef = ref()
const departmentRef = ref()
const show = ref(true)
const lookShow = ref(true)
const tableStore: any = new TableStore({
    url: '/cs-harmonic-boot/customReport/getTemplateList',
    method: 'POST',
    isWebPaging: true,
    column: [
        {
            title: '序号',
            width: 80,
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        { field: 'name', title: '模板名称' },
        { field: 'createBy', title: '创建用户' },
        { field: 'updateBy', title: '更新用户' },
        { field: 'createTime', title: '创建时间', sortable: true },
        { field: 'updateTime', title: '更新时间', sortable: true },
        {
            title: '操作', fixed: 'right',
            width: '220',
            render: 'buttons',
            buttons: [
                {
                    name: 'edit',
                    title: '查看 ',
                    type: 'primary',
                    icon: 'el-icon-Plus',
                    render: 'basicButton',
                    click: row => {
                        lookShow.value = false
                        setTimeout(() => {
                            lookRef.value.open(row)
                        }, 10)
                    }
                },
                {
                    name: 'edit',
                    title: '编辑',
                    type: 'primary',
                    icon: 'el-icon-Plus',
                    render: 'basicButton',
                    click: row => {
                        show.value = false
                        setTimeout(() => {
                            luckysheetRef.value.open('编辑报表模板', row)
                        }, 10)
                    }
                },
                // {
                //     name: 'edit',
                //     title: '绑定',
                //     type: 'primary',
                //     icon: 'el-icon-Plus',
                //     render: 'basicButton',
                //     click: row => {
                //         departmentRef.value.open(row)
                //     }
                // },
                {
                    name: 'del',
                    text: '删除',
                    type: 'danger',
                    icon: 'el-icon-Delete',
                    render: 'confirmButton',
                    popconfirm: {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        confirmButtonType: 'danger',
                        title: '确定删除？'
                    },
                    click: row => {
                        delTemplate({ tempId: row.id, deptId: row.deptId }).then(res => {
                            ElMessage.success('删除成功')
                            tableStore.index()
                        })
                    }
                }
            ]
        }
    ],

    loadCallback: () => {}
})
tableStore.table.params = {}
tableStore.table.params.pageSize = 20
tableStore.table.params.pageNum = 1

provide('tableStore', tableStore)
// 关闭
const shutDown = () => {
    show.value = true
    lookShow.value = true
    tableStore.index()
}
const add = () => {
    show.value = false
    setTimeout(() => {
        luckysheetRef.value.open('新增报表模板')
    }, 10)
}
onMounted(() => {
    tableStore.index()
})
</script>
