<template>
    <div class="hc-layout-box">
        <HcCard>
            <template #header>
                <el-button type="primary" hc-btn @click="toBackClick">
                    <HcIcon name="arrow-go-back"/>
                    <span>返回上一级</span>
                </el-button>
            </template>
            <el-table :data="tableData" lazy :load="loadData" v-loading="isLoading" border height="100%" row-key="primaryKeyId">
                <el-table-column prop="title" label="节点名称"></el-table-column>
                <el-table-column label="施工台账" align="center">
                    <el-table-column prop="standingBookNotAmount" label="未开始" align="center" width="80"></el-table-column>
                    <el-table-column prop="standingBookEndAmount" label="已完成" align="center" width="80"></el-table-column>
                </el-table-column>
                <el-table-column label="开工报告" align="center">
                    <el-table-column prop="workStartNotSubmitAmount" label="未开始" align="center" width="80"></el-table-column>
                    <el-table-column prop="workStartNotTaskAmount" label="未上报" align="center" width="80"></el-table-column>
                    <el-table-column prop="workStartAwaitAmount" label="待审批" align="center" width="80"></el-table-column>
                    <el-table-column prop="workStartApprovalAmount" label="已审批" align="center" width="80"></el-table-column>
                </el-table-column>
                <el-table-column label="工序资料" align="center">
                    <el-table-column prop="processNotSubmitAmount" label="未开始" align="center" width="80"></el-table-column>
                    <el-table-column prop="processNotTaskAmount" label="未上报" align="center" width="80"></el-table-column>
                    <el-table-column prop="processAwaitAmount" label="待审批" align="center" width="80"></el-table-column>
                    <el-table-column prop="processApprovalAmount" label="已审批" align="center" width="80"></el-table-column>
                </el-table-column>
                <el-table-column label="质量评定" align="center">
                    <el-table-column prop="evaluationNotSubmitAmount" label="未开始" align="center" width="80"></el-table-column>
                    <el-table-column prop="evaluationNotTaskAmount" label="未上报" align="center" width="80"></el-table-column>
                    <el-table-column prop="evaluationAwaitAmount" label="待审批" align="center" width="80"></el-table-column>
                    <el-table-column prop="evaluationApprovalAmount" label="已审批" align="center" width="80"></el-table-column>
                </el-table-column>
                <el-table-column label="中间交工" align="center">
                    <el-table-column prop="completionNotSubmitAmount" label="未开始" align="center" width="80"></el-table-column>
                    <el-table-column prop="completionNotTaskAmount" label="未上报" align="center" width="80"></el-table-column>
                    <el-table-column prop="completionAwaitAmount" label="待审批" align="center" width="80"></el-table-column>
                    <el-table-column prop="completionApprovalAmount" label="已审批" align="center" width="80"></el-table-column>
                </el-table-column>
            </el-table>
        </HcCard>
    </div>
</template>

<script setup>
import {ref, onMounted} from "vue";
import {useRouter} from 'vue-router'
import {useAppStore} from "~src/store";
import DataApi from "~api/schedule/data"
import {getArrValue} from "vue-utils-plus"

//变量
const router = useRouter()
const useAppState = useAppStore()
const projectId = ref(useAppState.getProjectId);
const contractId = ref(useAppState.getContractId);

//渲染完成
onMounted(() => {
    if (contractId.value) {
        getTableData()
    }
})

//初始数据获取
const isLoading = ref(false)
const tableData = ref([])
const getTableData = async () => {
    isLoading.value = true
    const { error, code, data } = await DataApi.queryContractTreeMaterialProgress({
        projectId: projectId.value,
        contractId: contractId.value,
        parentId: ''
    });
    isLoading.value = false
    if (!error && code === 200) {
        tableData.value = getArrValue(data['treeMaterialProgressList']);
    } else {
        tableData.value = [];
    }
}

//懒加载数据
const loadData = async (row, treeNode, resolve) => {
    const { error, code, data } = await DataApi.queryContractTreeMaterialProgress({
        projectId: projectId.value,
        contractId: row.contractId || contractId.value,
        parentId: row.id
    });
    if (!error && code === 200) {
        resolve(getArrValue(data['treeMaterialProgressList']))
    } else {
        resolve([])
    }
}

//返回上级
const toBackClick = () => {
    router.push({
        path: '/schedule/data'
    })
}
</script>

<style lang="scss" scoped>
@import '../../styles/schedule/hc-table.scss';
</style>
