<template>
    <HcCard ui="hc-count-card-ui" body-ui="hc-count-card">
        <div id="hc-count-tree" class="hc-count-tree">
            <el-scrollbar>
                <HcTreeData :is-menu="false" @nodeTap="treeNodeTap" />
            </el-scrollbar>
        </div>
        <div id="hc-count-body" class="hc-count-body">
            <el-scrollbar>
                <div class="hc-count-echarts-1">
                    <el-row :gutter="14">
                        <el-col :span="10">
                            <HcCardItem title="面积进度柱状图统计" style="height: 440px">
                                <BarLabelEcharts :lables="planLables" :color="planColors" :datas="planDatas" />
                            </HcCardItem>
                        </el-col>
                        <el-col :span="14">
                            <HcCardItem title="面积进度" style="height: 160px">
                                <el-row :gutter="20" class="h-full">
                                    <el-col :span="6">
                                        <div class="hc-count-area-progress">
                                            <div class="num">
                                                {{ progress[0] || 0 }}
                                            </div>
                                            <div class="text">
                                                已签协议面积(亩)
                                            </div>
                                        </div>
                                    </el-col>
                                    <el-col :span="6">
                                        <div class="hc-count-area-progress">
                                            <div class="num">
                                                {{ progress[1] || 0 }}
                                            </div>
                                            <div class="text">
                                                已签协议比例
                                            </div>
                                        </div>
                                    </el-col>
                                    <el-col :span="6">
                                        <div class="hc-count-area-progress">
                                            <div class="num">
                                                {{ progress[2] || 0 }}
                                            </div>
                                            <div class="text">
                                                已结算面积(亩)
                                            </div>
                                        </div>
                                    </el-col>
                                    <el-col :span="6">
                                        <div class="hc-count-area-progress">
                                            <div class="num">
                                                {{ progress[3] || 0 }}
                                            </div>
                                            <div class="text">
                                                已结算比例
                                            </div>
                                        </div>
                                    </el-col>
                                </el-row>
                            </HcCardItem>
                            <HcCardItem title="金额进度" style="height: 266px; margin-top: 14px">
                                <BarLabelEcharts :lables="planLables1" :color="planColors1" :datas="planDatas1" />
                            </HcCardItem>
                        </el-col>
                    </el-row>
                </div>
                <HcCardItem title="结算统计图（单位：元）" style="height: 440px; margin-top: 14px">
                    <stackEcharts />
                </HcCardItem>
            </el-scrollbar>
        </div>
    </HcCard>
</template>

<script setup>
import { onMounted, onUnmounted, ref } from 'vue'
import BarLabelEcharts from '~com/echarts/BarLabel.vue'
import stackEcharts from '~com/echarts/stackEcharts.vue'
import split from 'split.js'
import countApi from '~api/count/index.js'
import { getArrValue } from 'js-fast-way'
import { useAppStore } from '~src/store'
const useAppState = useAppStore()
const projectId = ref(useAppState.getProjectId)



//树节点被点击
const treeNodeTap = ({ node, data }) => {
    areaId.value = data.id
    getAreProgress()
    getPlanDatas()
    getPlanDatas1()
}

//渲染完成
onMounted(() => {
    setSplitDom()
})
//获取面积进度
const areaId = ref('')
const progress = ref([])
const getAreProgress = async () => {
    const { error, code, data } = await countApi.getStatArea({
        projectId: projectId.value,
        areaId:areaId.value,
    })
    if (!error && code === 200) {
        progress.value = getArrValue(data)
      
    } else {
        progress.value = []
     
    }
}
// 初始化设置拖动分割线
const splitvar = ref(null)
const setSplitDom = () => {
    try {
        //配置参考： https://split.js.org/#/?direction=vertical&snapOffset=0
        splitvar.value = split([
            '#hc-count-tree',
            '#hc-count-body',
        ], {
            sizes: [20, 80],
            minSize: [200, 900],
        })
    } catch (e) {
        setTimeout(() => {
            setSplitDom()
        }, 500)
    }
}

//面积进度柱状图统计
const planColors = ['#D97558', '#E4C476']
const planLables = ref(['农用地', '建设用地', '未利用地'])
const planDatas = ref([
    // {
    //     name: '已签面积',
    //     value: [1200, 132, 501],
    // },
    // {
    //     name: '设计面积',
    //     value: [120, 432, 1001],
    // },
])
//获取面积柱状图统计
const getPlanDatas = async () => {
    const { error, code, data } = await countApi.getstatAreaPicture({
        projectId: projectId.value,
        areaId:areaId.value,
    })
    if (!error && code === 200) {
        planDatas.value = getArrValue(data) 
    } else {
        planDatas.value = []
     
    }
}

//金额进度
const planColors1 = ['#7F83F6', '#81B336', '#E99D43']
const planLables1 = ref(['征地补偿', '专项设施', '青苗', '坟地补偿', '地上附着物'])
const planDatas1 = ref([
    // {
    //     name: '实际补助总金额',
    //     value: [1200, 132, 501, 323, 654],
    // },
    // {
    //     name: '设计补助总金额',
    //     value: [120, 432, 1001, 111, 987],
    // },
    // {
    //     name: '已结算总金额',
    //     value: [120, 432, 1001, 323, 654],
    // },
])
//获取金额进度
const getPlanDatas1 = async () => {
    const { error, code, data } = await countApi.getStatMoney({
        projectId: projectId.value,
        areaId:areaId.value,
    })
    if (!error && code === 200) {
        planDatas1.value = getArrValue(data)
      
    } else {
        planDatas1.value = []
     
    }
}
//销毁
onUnmounted(() => {
    if (splitvar.value) {
        splitvar.value.destroy()
    }
})
</script>

<style lang="scss" scoped>
.hc-count-body .hc-count-echarts-1 {
    position: relative;
    overflow: hidden;
}
</style>

<style lang="scss">
.hc-count-card-ui {
    background: white;
    .el-card__body {
        padding: 10px;
    }
}
.hc-count-card {
    display: flex;
    .hc-count-tree {
        position: relative;
        margin-right: 5px;
        height: 100%;
    }
    .hc-count-body {
        position: relative;
        margin-left: 5px;
        height: 100%;
        .hc-card-item-box {
            background: #f5f5f5;
            .hc-card-item-header {
                color: #101010;
            }
        }
    }
    .hc-count-area-progress {
        position: relative;
        height: 100%;
        background: #ffffff;
        border-radius: 5px;
        display: flex;
        align-items: center;
        justify-content: center;
        .num {
            margin-bottom: 18px;
            font-size: 20px;
        }
        .text {
            position: absolute;
            bottom: 10px;
            font-size: 14px;
        }
    }
}
</style>
