<template>
  <div>
    <el-dialog :title="'上报历史' + props.params.year + '年'" width="90%" v-model="visible" @close="closed">
      <div class="treeBox2 ww100">
        <el-table ref="multipleTableRef" v-loading="loading" :row-key="keyid" :data="pageData.tableData" border
          style="width: 100%">
          <el-table-column v-for="(item, index) in pageData.tableColumn" :key="index" :prop="item.prop"
            :label="item.label">
            <template #default="{ row }" v-if="item.prop == 'total'">
              <span>{{ Number(row.gcmyjzNum || 0) + Number(row.lhgfNum || 0) + Number(row.xzNum || 0) + Number(row.czNum
                || 0)
                }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作" width="170" fixed="right">
            <template #default="{ row }">
              <el-link type="primary" @click="handleClickDetail(row)">查看</el-link>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
    <ChooseTable :title="'上报历史'" v-if="isShowSubLevel" @close="isShowSubLevel = false" :currCode="props.currCode"
      :orgId="props.orgId" :isAuth="props.isAuth" :rootId="props.rootId" :ywId="props.ywId" :params="props.params"
      :isShowDec="false" :isReport="isReport" />
  </div>
</template>
<script setup>
// 引入
import { ref, reactive, onMounted, computed, getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();
const { D_BZ_SF } = proxy.$dict("D_BZ_SF");
import ChooseTable from './ChooseTable.vue'
import { postApi } from "@/api/tobAcco_api.js";
import { ElMessage } from "element-plus";
const pageData = reactive({
  tableData: [],
  tableColumn: [
    { label: '企业名称', prop: 'orgName' },
    { label: '上报次数', prop: 'sbcs' },
    { label: '建筑总数', prop: 'total' },
    { label: '高层民用建筑总数', prop: 'gcmyjzNum' },
    { label: '联合工坊总数', prop: 'lhgfNum' },
    { label: '闲置场所总数', prop: 'xzNum' },
    { label: '出租场所总数', prop: 'czNum' },
    { label: '上报时间', prop: 'updateTime' },
  ],
  orgCodes: [],
  params: {},
  currItem: {}
});
const loading = ref(false);
const isShowSubLevel = ref(false)
const multipleTableRef = ref(null);
const active = ref('-1')
const orgCode = ref(false)
const visible = ref(true)
const currOrgCode = ref(null)
const currTotal = ref(0)
const props = defineProps({
  chooseUserVisible: {
    type: Boolean,
    default: true,
  },
  orgId: {
    type: String,
    default: ''
  },
  currCode: {
    type: String,
    default: ''
  },
  rootId: {
    type: String,
    default: ''
  },
  isAuth: {
    type: Boolean,
  },
  params: {
    type: Object,
    default: () => { }
  },
  isReport: {
    type: Boolean,
  },
  currTotal: Number,
  ywId: String
});


// 详情
const handleClickDetail = (row) => {
  pageData.currItem = row
  currTotal.value = row.sbzs
  currOrgCode.value = row.orgcode
  isShowSubLevel.value = true
}
const emits = defineEmits(["close"]);
const closed = () => {
  emits("close");
};
onMounted(() => {
  orgCode.value = props.currCode
  getListData()
})

//获取列表
const getListData = (params = {}) => {
  params = Object.assign(params, props.params)
  params.sbcs = props.currTotal
  params.orgCode = orgCode.value
  loading.value = true
  postApi(params, '/mosty-jcgl/data/BuildSafeStat/queryReportingHistoryStat').then(res => {
    if (res) {
      pageData.tableData = res
      loading.value = false
    }
  }).finally(() => {
    loading.value = false
  })
}
</script>

<style lang="scss" scoped>
@import "@/assets/css/layout.scss";
@import "@/assets/css/element-plus.scss";

::v-deep .el-form--inline {
  padding-left: 0 !important;
}

::v-deep .el-radio__label {
  display: none !important;
}

.table-box-radio .el-table1__header-wrapper .el-checkbox {
  display: none !important;
}

:v-deep .el-tree-node {
  .is-leaf+el-checkbox .el-checkbox__inner {
    display: inline-block;
  }
}

::v-deep .el-overlay-dialog {
  overflow: hidden !important;
}

:v-deep .el-checkbox .el-checkbox__inner {
  display: none;
}

:v-deep .wrap .el-checkbox__input.is-disabled {
  display: none;
}

.el-form {
  margin-top: 10px;
  display: flex;
  //   flex-wrap: wrap;
  justify-content: space-between;
}

.search {
  width: 300px;
  display: flex;
  position: absolute;
  right: 20px;
  top: 20px;
}

.el-form-item {
  text-align: center;
  width: 400px;
}

.flx {
  display: flex;
  width: 100%;

  .el-button {
    margin-left: 10px;
  }
}

.box {
  width: 100%;
  height: 516px;
  overflow-y: hidden;
  border: 1px solid var(--el-color-primary);
  display: flex;
  justify-content: space-between;
}

.treeBox2 {
  overflow: auto;
}

.cskbox {
  width: 40px;
  padding: 107px 0;
  margin-right: 20px;

  .el-icon {
    width: 4em !important;
    height: 6em !important;
  }

  .el-icon svg {
    width: 3em !important;
    height: 3em !important;
  }
}

.listbox {
  border: 1px solid var(--el-color-primary);
  width: 45%;
  overflow-y: scroll;

  ul>li {
    padding: 4px 10px;
    box-sizing: border-box;
  }

  .activ {
    background-color: var(--el-color-primary);
  }
}

.bot_font {
  width: 100%;
  text-align: center;
  font-size: 16px;
  color: #ffff;
  margin-top: 10px;
}

.fenye {
  margin-top: 10px;
}

::v-deep .el-dialog__body {
  overflow: auto !important;
  height: 600px !important;
}
</style>
