<template>
    <div class="relative h-full flex">
        <div :id="`hc_tree_card_${uuid}`">
            <hc-new-card scrollbar>
                <template #header>
                    <el-select v-model="searchForm.key1" filterable block placeholder="选择工区">
                        <el-option label="一工区" value="1" />
                        <el-option label="二工区" value="2" />
                    </el-select>
                </template>
                <hc-lazy-tree :h-props="treeProps" @load="treeLoadNode" />
            </hc-new-card>
        </div>
        <div :id="`hc_table_card_${uuid}`" class="flex-1">
            <hc-new-card>
                <template #header>
                    <div class="font-400 text-orange">本期计量总金额：0元</div>
                </template>
                <template #extra>
                    <el-button hc-btn type="primary">
                        <HcIcon name="24-hours" />
                        <span>自动生成结算单</span>
                    </el-button>
                    <el-button hc-btn type="warning" @click="reportClick">
                        <HcIcon name="send-plane-2" />
                        <span>按期上报</span>
                    </el-button>
                    <el-button hc-btn type="danger">
                        <HcIcon name="delete-bin" />
                        <span>按部位删除</span>
                    </el-button>
                    <el-button hc-btn color="#626aef">
                        <HcIcon name="sort-desc" :line="false" />
                        <span>按部位排序</span>
                    </el-button>
                    <el-button hc-btn color="#626aef">
                        <HcIcon name="sort-desc" :line="false" />
                        <span>按录入时间排序</span>
                    </el-button>
                    <el-button hc-btn type="success" @click="detailsModalClick">
                        <HcIcon name="file-list" />
                        <span>清单明细</span>
                    </el-button>
                    <el-button hc-btn type="success">
                        <HcIcon name="file-chart" />
                        <span>查看报表</span>
                    </el-button>
                </template>
                <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" is-new :index-style="{ width: 60 }">
                    <template #action="{ row }">
                        <el-link type="success">修改</el-link>
                        <el-link type="danger">删除</el-link>
                    </template>
                </hc-table>
                <template #action>
                    <hc-pages :pages="searchForm" @change="pageChange" />
                </template>
            </hc-new-card>
        </div>
        <!-- 上报弹窗 -->
        <hc-report-dialog v-model="isReport" />
        <!-- 清单明细 -->
        <HcDetailsModal v-model="detailsModalShow" />
    </div>
</template>

<script setup>
import { nextTick, onMounted, ref } from 'vue'
import HcDetailsModal from './components/pay/detailsModal.vue'
import { getRandom } from 'js-fast-way'

defineOptions({
    name: 'PeriodsProjectPay',
})

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({
    key1: null, current: 1, size: 10, total: 0,
})

//数据格式
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 pageChange = ({ current, size }) => {
    searchForm.value.current = current
    searchForm.value.size = size
}

//表格数据
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: 'action', name: '操作', width: 100 },
])
const tableData = ref([
    { key1: '1111' },
])

//是否上报
const isReport = ref(false)
const reportClick = () => {
    isReport.value = true
}

//收方清单明细
const detailsModalShow = ref(false)
const detailsModalClick = () => {
    detailsModalShow.value = true
}
</script>

<style scoped lang="scss">

</style>
