<template>
    <view class="basic">
        <!-- <view class="grid-card">
            <view class="grid-card-title">模块</view>
            <view class="grid-card-content-4">
                <view class="item item-title">名称</view>
                <view class="item item-title">实际输出电流（A）</view>
                <view class="item item-title">总谐波电流（A）</view>
                <view class="item item-title">总谐波电压（V）</view>
                <view class="item">模块1</view>
                <view class="item">300</view>
                <view class="item">200</view>
                <view class="item">110</view>
                <view class="item">模块2</view>
                <view class="item">300</view>
                <view class="item">200</view>
                <view class="item">110</view>
                <view class="item">模块3</view>
                <view class="item">300</view>
                <view class="item">200</view>
                <view class="item">110</view>
                <view class="item">模块4</view>
                <view class="item">300</view>
                <view class="item">200</view>
                <view class="item">110</view>
             
            </view>
        </view> -->
        <view class="grid-card">
            <view class="grid-card-title">电网电流</view>
            <view class="grid-card-content-3">
                <view class="item item-title">名称</view>
                <view class="item item-title">有效值(A)</view>
                <view class="item item-title">THDI(%)</view>
                <template v-for="(item, index) in renderData.电网侧">
                    <view class="item">{{ item.phase }}</view>
                    <view class="item">{{ item['A(A)'] }}</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-4">
                <view class="item item-title">名称</view>
                <view class="item item-title">电压(V)</view>
                <view class="item item-title">频率(Hz)</view>
                <view class="item item-title">THDU(%)</view>
                <template v-for="(item, index) in renderData.电网侧">
                    <view class="item">{{ item.phase }}</view>
                    <view class="item">{{ item['PhV(V)'] }}</view>
                    <view class="item">{{ item['Hz(Hz)'] }}</view>
                    <view class="item">{{ item['ThdPhV(%)'] }}</view>
                </template>
            </view>
        </view>
        <view class="grid-card">
            <view class="grid-card-title">负载电流</view>
            <view class="grid-card-content-3">
                <view class="item item-title">名称</view>
                <view class="item item-title">有效值(A)</view>
                <view class="item item-title">THDI(%)</view>
                <template v-for="(item, index) in renderData.负载侧">
                    <view class="item">{{ item.phase }}</view>
                    <view class="item">{{ item['A(A)'] }}</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-3">
                <view class="item item-title">名称</view>
                <view class="item item-title">有效值(A)</view>
                <view class="item item-title">负载率(%)</view>
                <template v-for="(item, index) in renderData.输出侧">
                    <view class="item">{{ item.phase }}</view>
                    <view class="item">{{ item['A(A)'] }}</view>
                    <view class="item"></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',
                    },
                ]
                console.log(this.deviceInfo)
                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>
