<template>
    <view class="basic">
        <view class="grid-card">
            <view class="grid-card-title">电网侧</view>
            <view class="grid-card-content-5">
                <view class="item item-title">名称</view>
                <view class="item item-title">有功功率(kw)</view>
                <view class="item item-title">无功功率(kVar)</view>
                <view class="item item-title">视在功率(kVA)</view>
                <view class="item item-title">功率因数</view>
                <template v-for="(item, index) in renderData.电网侧">
                    <view class="item">{{ item.phase }}</view>
                    <view class="item">{{ item['W(W)'] }}</view>
                    <view class="item">{{ item['VAr(var)'] }}</view>
                    <view class="item">{{ item['VA(VA)'] }}</view>
                    <view class="item">{{ item['ThdPhI(%)'] }}</view>
                </template>
            </view>
        </view>
        <view class="grid-card">
            <view class="grid-card-title">负载侧</view>
            <view class="grid-card-content-5">
                <view class="item item-title">名称</view>
                <view class="item item-title">有功功率(kw)</view>
                <view class="item item-title">无功功率(kVar)</view>
                <view class="item item-title">视在功率(kVA)</view>
                <view class="item item-title">功率因数</view>
                <template v-for="(item, index) in renderData.电网侧">
                    <view class="item">{{ item.phase }}</view>
                    <view class="item">{{ item['W(W)'] }}</view>
                    <view class="item">{{ item['VAr(var)'] }}</view>
                    <view class="item">{{ item['VA(VA)'] }}</view>
                    <view class="item">{{ item['ThdPhI(%)'] }}</view>
                </template>
            </view>
        </view>
    </view>
</template>
<script>
export default {
    data() {
        return {
            renderData: {
                电网侧: {},
                负载侧: {},
                输出侧: {},
            },
        }
    },
    props: {
        deviceInfo: {
            type: Object,
            default: () => {
                return {}
            },
        },
    },
    watch: {
        deviceInfo: {
            handler: function (newVal, oldVal) {
                let arr = [
                    {
                        name: '电网侧',
                        position: 'cb23b9ede3b652cd6da194fd7b318124',
                    },
                    {
                        name: '负载侧',
                        position: '32624d4bb3a86f2b9a01bab272e50125',
                    },
                    {
                        name: '输出侧',
                        position: '26eae70fb5ff1c090d2dc7c3a0743948',
                    },
                ]
                this.deviceInfo.appsLineTopologyDiagramPO.forEach((item1) => {
                    if (item1.value.length === 0) {
                        return
                    }
                    let index = arr.findIndex((item2) => {
                        return item2.position === item1.linePostion
                    })
                    if (index === -1) {
                        return
                    }
                    item1.value.forEach((item) => {
                        if(item.phase === 'avg'){
                            return
                        }
                        if (this.renderData[arr[index]['name']][item.phase]) {
                            this.renderData[arr[index]['name']][item.phase][item.statisticalName] = item.statisticalData
                        } else {
                            this.renderData[arr[index]['name']][item.phase] = {
                                phase: item.phase,
                                [item.statisticalName]: item.statisticalData,
                            }
                        }
                    })
                })
                console.warn(this.renderData)
            },
            deep: true,
            immediate: true,
        },
    },
    methods: {},
}
</script>
<style lang="scss">
.basic {
}
</style>
