<script>
import Card from "@/components/common/card.vue";
import CoreData from "@/components/common/coreData.vue";
import Query from "@/components/common/query.vue";

import CarbonPvEmissionChart from "@/components/doubleCarbon/PV/charts/carbonPvEmissionChart.vue";
import CarbonPvQuotaChart from "@/components/doubleCarbon/PV/charts/carbonPvQuotaChart.vue";
import apiCarbonPv from "@/api/carbon/apiCarbonPv";

export default {
    components: {
        Card,
        CoreData,
        Query,
        CarbonPvEmissionChart,
        CarbonPvQuotaChart,
    },
    data() {
        return {
            queryData: {
                companyId: "0",
                timeRange: this.$util.dateUtil.getNearlyMonthRange(),
            },
            companyOptions: [
                {
                    label: '全部',
                    value: '0'
                }
            ],
            coreData: [
                {
                    title: "光伏累计减排(tCO₂e)",
                    num: 0,
                    historyDesc: "同比",
                    historyNum: 0,
                },
                {
                    title: "光伏发电量(kWh/天)",
                    num: 0,
                    historyDesc: "同比",
                    historyNum: 0,
                },
                {
                    title: "光伏节约金额(元/天)",
                    num: 0,
                    historyDesc: "同比",
                    historyNum: 0,
                },
                {
                    title: "光伏补贴金额(元/天)",
                    num: 0,
                    historyDesc: "同比",
                    historyNum: 0,
                },
                {
                    type: 1,
                    title: "值得关注",
                    showStar: true,
                    content: "建议扩大光伏 发电面积",
                },
            ],
            newsData: [
                {
                    title: "xxxxxxxxxx",
                    tag: "双碳小知识",
                    author: "张峰",
                    time: "2022-02-02 15:00:00",
                },
            ],
        };
    },
    mounted() {
        this.init();
    },
    methods: {
        init() {
            this.$store.loadingStore().loadingWithApi(this.getCoreData(), 2000);
        },
        reset() {
        },
        search(data) {
            this.$util.asyncPromise(
                this.getCoreData(),
                this.$refs.CarbonPvEmissionChart.getData(),
                this.$refs.CarbonPvEmissionChart.getData()
            );
        },
        getCoreData() {
            return apiCarbonPv.getCoreData(this.queryData).then((res) => {
                this.coreData[0].num = res.list[0].value;
                this.coreData[0].historyNum = res.list[0].compare;
                this.coreData[1].num = res.list[1].value;
                this.coreData[1].historyNum = res.list[1].compare;
                this.coreData[2].num = res.list[2].value;
                this.coreData[2].historyNum = res.list[2].compare;
                this.coreData[3].num = res.list[3].value;
                this.coreData[3].historyNum = res.list[3].compare;
                this.coreData[4].content = res.worthAttention;
            });
        },
        callBackCompanyOption(options) {
            this.companyOptions = [
                {
                    label: '全部',
                    value: '0'
                }
            ]
            if (options) {
                options.forEach(item => {
                    this.companyOptions.push(item);
                })
            }
            this.$forceUpdate()
        },
    },
};
</script>

<template>
    <div class="doubleCarbon-pv">
        <div class="page-query-core">
            <Query
                    :show="['company', 'time']"
                    :query-data.sync="queryData"
                    :reset="reset"
                    :search="search"
                    :company-options="companyOptions"
            ></Query>
        </div>
        <div class="page-query-core">
            <Card title="核心指标">
                <CoreData :data-list="coreData"></CoreData>
            </Card>
        </div>

        <div style="margin-top: 12px">
            <a-row :gutter="[12, 12]">
                <a-col :span="18">
                    <div class="ioc-card-content">
                        <Card title="光伏减排分析">
                            <div class="doubleCarbon-pv-analyse">
                                <CarbonPvEmissionChart
                                        ref="CarbonPvEmissionChart"
                                        :query-data="queryData"
                                        :callBackCompanyOption="callBackCompanyOption"
                                        :height="450"
                                />
                            </div>
                        </Card>
                    </div>
                </a-col>
                <a-col :span="6">
                    <div class="ioc-card-content">
                        <Card title="光伏减排排名">
                            <div class="doubleCarbon-pv-quota">
                                <CarbonPvQuotaChart
                                        ref="CarbonPvQuotaChart"
                                        :query-data="queryData"
                                        :height="450"
                                />
                            </div>
                        </Card>
                    </div>
                </a-col>
            </a-row>
        </div>
    </div>
</template>

<style lang="less" scoped>
.doubleCarbon-pv {
  width: 100%;
  height: auto;
  padding-bottom: 15px;
  vertical-align: top;

  .doubleCarbon-pv-analyse {
    padding: 12px;
  }

  .doubleCarbon-pv-quota {
    padding: 12px;
  }

  .doubleCarbon-pv-news {
    padding: 0 12px;
    height: 300px;
  }

  .doubleCarbon-pv-percent {
    padding: 0 12px;
    height: 300px;
  }
}
</style>
