<template>
    <div class="relative h-full flex">
        <div :id="`hc_tree_card_${uuid}`">
            <hc-new-card scrollbar>
                <template #header>
                    <el-button hc-btn type="primary">归集工区清单</el-button>
                </template>
                <hc-lazy-tree :h-props="treeProps" is-load-menu @load="treeLoadNode" @loadMenu="treeLoadMenu" @menuTap="treeMenuTap" />
            </hc-new-card>
        </div>
        <div :id="`hc_table_card_${uuid}`" class="flex-1">
            <hc-new-card scrollbar title="合同工程清单明细">
                <div class="relative">
                    <infoTable />
                    <HcTitle title="下级节点列表" />
                    <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" is-new :index-style="{ width: 60 }" />
                </div>
            </hc-new-card>
        </div>
    </div>
</template>

<script setup>
import { nextTick, onMounted, ref } from 'vue'
import { getRandom } from 'js-fast-way'
import infoTable from './components/check-list/info-table.vue'

defineOptions({
    name: 'ProjectPeriodsBaseList1',
})

const uuid = getRandom(4)

//渲染完成
onMounted(() => {
    setSplitRef()
})

//初始化设置拖动分割线
const setSplitRef = () => {
    //配置参考： https://split.js.org/#/?direction=vertical&snapOffset=0
    nextTick(() => {
        window.$split(['#hc_tree_card_' + uuid, '#hc_table_card_' + uuid], {
            sizes: [20, 80],
            snapOffset: 0,
            minSize: [50, 500],
        })
    })
}

//搜索表单
const searchForm = ref({})

//数据格式
const treeProps = {
    label: 'name',
    children: 'children',
    isLeaf: 'leaf',
}

//懒加载的数据
const treeLoadNode = ({ level }, resolve) => {
    if (level === 0) {
        return resolve([{ name: 'region' }])
    }
    if (level > 3) {
        return resolve([])
    }
    setTimeout(() => {
        resolve([
            { name: 'leaf', leaf: true },
            { name: 'zone' },
        ])
    }, 500)
}

//菜单
const treeLoadMenu = ({ item, level }, resolve) => {
    if (level === 1) {
        return resolve([
            { icon: 'arrow-up-down-line', label: '排序', key: 'sort' },
        ])
    } else {
        return resolve([
            { icon: 'arrow-up-down-line', label: '排序', key: 'sort' },
        ])
    }
}

const treeMenuTap = ({ key, node, data }) => {

}

//表格数据
const tableLoading = ref(false)
const tableColumn = ref([
    { key: 'key1', name: '清单编号' },
    { key: 'key2', name: '清单名称' },
    { key: 'key3', name: '单位' },
    { key: 'key4', name: '现行单价' },
    { key: 'key5', name: '合同数量' },
    { key: 'key6', name: '合同金额' },
    { key: 'key7', name: '变更后单价' },
    { key: 'key8', name: '变更后数量' },
    { key: 'key9', name: '变更后金额' },
    { key: 'key10', name: '是否增补' },
])
const tableData = ref([
    { key1: '1111' },
])
</script>
