<template>
  <!-- 烟叶站数量弹窗 -->
  <el-dialog center ref="dialog" :title="dataTitle" :show-close="false" modal :destory-on-close="true"
    class="dialogClass" :append-to-body="true" width="871px" custom-class="custom-dialog" v-model="isShow">
    <section class="button">
      <el-button @click="exportExcels" :loading="excelLoading">导出</el-button>
      <el-button @click="closeDialog">关闭</el-button>
    </section>

    <div class="itemTrading">
      <el-table v-loading="tableloading" show-summary stripe :summary-method="getSummaries" ref="detailTable"
        height="450px" border :data="yysgdata" id="out-table">
        <el-table-column property="orgname" label="企业名称" width="250"></el-table-column>
        <el-table-column property="workstation" label="烟叶工作站数量"></el-table-column>
        <el-table-column property="acquisitionPoint" label="烟叶收购点数量"></el-table-column>
        <el-table-column property="purchaseNum" label="年收购量(万担)"></el-table-column>
        <el-table-column label="主要设备">
          <el-table-column property="packingPress" label="打包机数量"></el-table-column>
          <el-table-column property="loader" label="装卸机数量"></el-table-column>
        </el-table-column>
        <el-table-column label="动力保障设备">
          <el-table-column property="highPressure" label="高压配电柜数量"></el-table-column>
          <el-table-column property="transformer" label="变压器数量"></el-table-column>
          <el-table-column property="dynamo" label="发电机数量"></el-table-column>
        </el-table-column>

      </el-table>
    </div>
  </el-dialog>
</template>
<script setup>
import { getSummaries } from "@/utils/tools";
import { ref, defineProps, reactive, onMounted, defineEmits } from "vue";
import { getApi, postApi } from "@/api/tobAcco_api.js";
import { exportXlsx } from "@/excel/Export2Excel.js";
const props = defineProps({
  title: String,
  isShow: Boolean
});
const tableloading = ref(false)
const excelLoading = ref(false)
const emit = defineEmits(['changeVi'])
const isShow = ref(false);
const dataTitle = props.title;
const detailTable = ref();
const yysgdata = ref([]); //烟叶收购
onMounted(() => {
  isShow.value = true;
  getTobaccoData()
});

// 烟叶站数量列表
const getTobaccoData = () => {
  yysgdata.value = []
  tableloading.value = true
  getApi({}, '/mosty-jcgl/basicData/tobaccoStationListDisplay').then((res) => {
    yysgdata.value = res ? res : []
  }).finally(() => {
    tableloading.value = false
  })
}


//关闭弹窗事件
function closeDialog() {
  emit('changeVi', false)
}

const exportExcels = () => {
  excelLoading.value = true
  let title = {
    orgname: '企业名称',
    workstation: "烟叶工作站数量",
    acquisitionPoint: "烟叶收购点数量",
    purchaseNum: "年收购量(万担)",
    loader: "打包机数量",
    packingPress: "装卸机数量",
    highPressure: "高压配电柜数量",
    transformer: "变压器数量",
    dynamo: "发电机数量",
  };
  getApi({}, "/mosty-jcgl/basicData/tobaccoStationListDisplay").then((res) => {
    if (res) {
      let data = res;
      let obj = {
        orgname: '合计',
        workstation: 0,
        acquisitionPoint: 0,
        purchaseNum: 0,
        loader: 0,
        packingPress: 0,
        highPressure: 0,
        transformer: 0,
        dynamo: 0,
      }
      if (data) {
        for (let i = 0; i < data.length; i++) {
          obj.workstation += data[i].workstation;
          obj.acquisitionPoint += data[i].acquisitionPoint;
          obj.purchaseNum += data[i].purchaseNum;
          obj.packingPress += data[i].packingPress;
          obj.highPressure += data[i].highPressure;
          obj.transformer += data[i].transformer;
          obj.dynamo += data[i].dynamo;
        }
        data.push(obj)
        let tablename = "烟叶收购站台账.xlsx";
        exportXlsx(title, data, '烟叶收购站台账', tablename);
        excelLoading.value = false
      }
      excelLoading.value = false
    }
  }).catch(() => {
    excelLoading.value = false
  });
};
</script>
<style lang="scss" scoped>
@import "~@/assets/css/element-plus.scss";
</style>
