<template>
  <div class="flex-grow h-2/3">
    <Module class="flex-grow h-1/3">
      <!-- :info="bsMeta && bsMeta['emplRate']" -->
      <template #title>机电日常维护</template>
      <template v-if="!loading">
        <div class="flex" style="width: 100%;">
          <div
            class="flex flex-col items-center justify-center flex-grow boxitem"
          >
            <img src="../assets/zhu1.png" alt="" />
            <span>
              <span class="money">
                {{ parseFloat(dataNum.dailyPlanAmount || 0).toFixed(2) }}
              </span>
              <span class="tip">（万元）</span>
            </span>
            <div class="name">预算金额</div>
          </div>
          <div
            class="flex flex-col items-center justify-center flex-grow boxitem"
          >
            <img src="../assets/zhu2.png" alt="" />
            <span>
              <span class="money">
                {{ parseFloat(dataNum.dailyAmount || 0).toFixed(2) }}
              </span>
              <span class="tip">（万元）</span>
            </span>
            <div class="name">合同金额</div>
          </div>
          <div
            class="flex flex-col items-center justify-center flex-grow boxitem"
          >
            <img src="../assets/zhu3.png" alt="" />
            <span>
              <span class="money">
                {{ parseFloat(dataNum.dailyJSAmount || 0).toFixed(2) }}
              </span>
              <span class="tip">（万元）</span>
            </span>
            <div class="name">计量金额</div>
          </div>
          <div
            class="flex flex-col items-center justify-center flex-grow boxitem"
          >
            <img src="../assets/zhu4.png" alt="" />
            <span>
              <span class="money">
                {{ parseFloat(dataNum.doneRate || 0).toFixed(2) }}
              </span>
              <span class="tip">（%）</span>
            </span>
            <div class="name">完成占比</div>
          </div>
        </div>
      </template>
    </Module>
    <Tollrevenue :dataNum="dataNum" :dataArr="dataArr" />
  </div>
</template>

<script lang="ts" setup>
import { computed, defineProps, reactive, watch } from 'vue'
import { useStore } from 'vuex'
import { key } from '@/store'
import { workareaNext } from '@/api/curingManage'
import { useRequest } from 'vue-request'

import Tollrevenue from './tollrevenue.vue'

import { project2 } from '@/api/ele-control-cabin'
const store = useStore(key)
const orgType = computed(() => store.state.ele?.orgType)
const orgCode = computed(() => store.state.ele?.orgCode)
const pOrg = computed(() => store.state.ele?.pOrg)
const refresh = computed(() => store.state.ele?.refresh)
const dataArr = computed(() => {
  return [
    parseFloat(dataNum.majorPlanAmount || 0).toFixed(2),
    parseFloat(dataNum.majorAmount || 0).toFixed(2),
    parseFloat(dataNum.majorJSAmount || 0).toFixed(2),
  ]
})
const currentTime = computed(() => store.state.ele?.currentTime)
const dataNum = reactive({
  dailyAmount: 0, //日常维护合同金额万元
  dailyJSAmount: '0', //日常维护结算金额万元
  majorAmount: 0, //专项工程合同金额万元
  majorJSAmount: 0, //专项工程结算金额万元
  majorNum: 0, //专项工程合同数量
  majorSSNum: 0, //专项工程实施数量
  dailyPlanAmount: 0, //日常维护预算金额万元
  doneRate: 0,
  majorPlanNum: 0,
  majorPlanAmount: 0,
})
const project = async () => {
  console.log(orgType.value)
  let params = {}
  if (orgType.value) {
    params = pOrg.value
  } else {
    params = orgCode.value
  }
  await project2({
    year: currentTime.value,
    ...params,
  }).then((res) => {
    console.log(res)
    Object.assign(dataNum, res.data)
    dataNum.doneRate =+dataNum.dailyAmount&& (
      (dataNum.dailyJSAmount / +dataNum.dailyAmount) *
      100
    ).toFixed(2)
  })
}
watch([refresh], () => {
  project()
})
</script>

<style lang="postcss" scoped>
.boxitem img {
  height: 67px;
  margin-bottom: 16px;
  width: fit-content;
}
.money {
  font-family: DIN;
  font-size: 15px;
  font-weight: bold;
  color: #fff;
  white-space: nowrap;
}
.tip {
  font-family: DIN;
  font-size: 12px;
  font-weight: bold;
  color: #fff;
  opacity: 0.4;
}
.name {
  margin-top: 2px;
  font-family: Adobe Heiti Std;
  font-size: 13px;
  font-weight: normal;
  color: #badeff;
  opacity: 0.5;
}
</style>
