<template>
    <div class="index-time">
        <div class="content">
            <div class="left-box">
                <!-- 左侧树菜单 -->
                <div class="card-toggle">
                    <div :class="gasType == 'gasDayNight' ? 'card-item1' : 'card-item'"
                        @click="handlerToggle('gasDayNight')">夜班</div>
                    <div :class="gasType == 'gasDayEarly' ? 'card-item1' : 'card-item'"
                        @click="handlerToggle('gasDayEarly')">早班</div>
                    <div :class="gasType == 'gasDayNoon' ? 'card-item1' : 'card-item'"
                        @click="handlerToggle('gasDayNoon')">中班</div>
                </div>
                <div v-if="listArr.length != 0" class="card-file">
                    <fileSystem :selected="selected" :list="listArr" :draggable="true" @on-click="onClick">
                        <template #icon="{ item }">
                            <template v-if="item.isFolder">
                                <SvgIcon v-if="item.isexpanded" size="18" name="file-open" />
                                <SvgIcon v-else size="18" name="file-close" />
                            </template>
                            <treeIcon class="iconfont" :title="item.title" v-else />
                        </template>
                    </fileSystem>
                </div>
            </div>
            <div class="right-box">
                <a-table :columns="columns" size="small" :data-source="tableData" :scroll="{ y: 754 }" class="tableW"
                    :pagination="false"></a-table>
            </div>
        </div>
    </div>1
</template>

<script setup lang="ts">
import { ref, nextTick, reactive, onMounted } from 'vue';
import fileSystem from './comment/common/cameraTree.vue';
import { SvgIcon } from '/@/components/Icon';
import treeIcon from './comment/common/Icon/treeIcon.vue';
import { columnsType, columnBlt, columnBd, columnSgt, columnCctr, columnYjl, columnCct, columnWlml } from './gasReportInspect.data';
import { queryReportData, queryReportList } from './gasReportInspect.api';
import { useGlobSetting } from '/@/hooks/setting';

let glob = useGlobSetting();
let gasType = ref('gasDayNight')
//左侧菜单列表
let listArr = reactive<any[]>([]);
//lxh 当前选中树节点
let selected = reactive<any>({
    id: null,
    pid: null,
    title: '',
    isFolder: false,
});
let columns = glob.sysOrgCode == 'sdmtjtbltmk' ? columnBlt : glob.sysOrgCode == 'sdmtjtbdmk' ? columnBd : glob.sysOrgCode == 'sdmtjtsgtmk' ? columnSgt : glob.sysOrgCode == 'sdmtjtcctrk' ? columnCctr : glob.sysOrgCode == 'sdmtjtyjlmk' ? columnYjl : glob.sysOrgCode == 'sdmtjtcctmk' ? columnCct : glob.sysOrgCode == 'sdmtjtwlmlmk' ? columnWlml :  glob.sysOrgCode == 'sdmtjtjjmk' ? columnWlml :  glob.sysOrgCode == 'sdmtjthlgmk' ? columnWlml  : columnsType
let tableData = ref<any[]>([])
let tableList = ref<any[]>([])
let handlerToggle = (param) => {
    gasType.value = param
    getTreeList({ type: gasType.value })
}
//获取左侧菜单树
async function getTreeList(param) {
    // const res = await queryReportData({ type: param })
    listArr.length = 0
    const res = await queryReportList({ pageNo: 1, pageSize: 100, ...param })
    tableList.value = res.records || []
    selected.id = tableList.value[0].id;
    selected.pid = tableList.value[0].pid;
    selected.title = tableList.value[0].title;
    selected.isFolder = tableList.value[0].isFolder;
    selected.ppid = tableList.value[0].ppid
    if (tableList.value && tableList.value.length != 0) {
        tableList.value.forEach(el => {
            listArr.push({
                id: el.id,
                pid: null,
                title: el.fileName,
                isFolder: true,
            })
        })
    }
    tableData.value = JSON.parse(tableList.value[0].content)
}
//点击目录
function onClick(node) {
    selected.id = node.id;
    selected.pid = node.pid;
    selected.title = node.title;
    selected.isFolder = node.isFolder;
    selected.ppid = node.ppid
    tableData.value = JSON.parse(tableList.value.filter(v => v.id == selected.id)[0].content)
};

onMounted(() => {
    getTreeList({ type: gasType.value })
})
</script>

<style lang="less" scoped>
.index-time {
    width: 100%;
    height: 100%;
    position: relative;

    .content {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
        position: relative;

        // z-index: 999;
        .left-box {
            width: 15%;
            height: 100%;
            padding: 20px;
            border: 1px solid #99e8ff66;
            background: #27546e1a;
            box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
            -moz-box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
            -webkit-box-shadow: 0px 0px 50px 1px rgb(149 235 255 / 5%) inset;
            overflow-y: auto;

            .card-toggle {
                height: 30px;
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin-bottom: 10px;
                color: #fff;

                .card-item {
                    width: calc(33.3% - 5px);
                    height: 100%;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    background: #1a5b7f;
                    border-radius: 5px;
                    cursor: pointer;
                }

                .card-item1 {
                    width: calc(33.3% - 5px);
                    height: 100%;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    background: #5dd8f7;
                    border-radius: 5px;
                    cursor: pointer;
                }
            }

            .card-file {
                height: calc(100% - 40px);
                overflow-y: auto;
            }

            // lxh
            .iconfont {
                color: #fff;
                font-size: 12px;
                margin-left: 5px;
            }
        }

        .right-box {
            width: 85%;
            height: 100%;
            padding: 0px 0px 0px 15px;
            box-sizing: border-box;
        }
    }
}

::v-deep .zxm-table-thead>tr>th:last-child,
.zxm-table-thead .zxm-table-column-title:last-child {
    border-right: 1px solid #91e9fe !important;
}
</style>