<template>
  <div class="widget-groupPageModules" v-if="showGroupPage">
    <!--左侧模块-->
    <ContractInfo :dataInfo="dataInfo" />
    <!--中部模块-->
    <IndexStatistic :dataInfo="dataInfo" />
    <!--右侧模块-->
    <ProjectInfo :dataInfo="dataInfo" />
    <!--底部模块-->
    <ProjectStatistic />
  </div>
</template>

<script>
//信息模块
import ContractInfo from '@/views/groupPage/groupPageModules/ContractInfo.vue'
import ProjectStatistic from '@/views/groupPage/groupPageModules/ProjectStatistic.vue'
import ProjectInfo from '@/views/groupPage/groupPageModules/ProjectInfo.vue'
import IndexStatistic from '@/views/groupPage/groupPageModules/IndexStatistic.vue'
import { getParentCompanyData, getCompanyData } from '../apis'
export default {
  name: 'groupPageModules', //集团分公司页面模块
  components: {
    ContractInfo,
    ProjectStatistic,
    ProjectInfo,
    IndexStatistic
  },
  data() {
    return {
      dataInfo: null
    }
  },
  computed: {
    showGroupPage() {
      return this.$store.state.bigScreen.isShowGroupPage
    },
    code() {
      return this.$store.state.bigScreen.groupCodeValue
    }
  },
  watch: {
    code: {
      handler(n, o) {
        !n ? this.getPageData() : this.getBranchPageData()
      },
      immediate: true
    }
  },
  methods: {
    async getPageData() {
      const res = await getParentCompanyData({})
      Object.keys(res.result).forEach((val) => (res.result[val] = res.result[val] || 0))
      this.dataInfo = res.result
    },
    async getBranchPageData() {
      const res = await getCompanyData({ name: this.code })
      Object.keys(res.result).forEach((val) => (res.result[val] = res.result[val] || 0))
      this.dataInfo = res.result
    }
  }
}
</script>

<style lang='scss' scoped>
</style>