<template>
  <el-dialog title="上报历史" width="80%" v-model="dialogVisible">
    <el-table border :data="dataTable" style="width: 100%; margin-bottom: 10px" v-loading="tableLoading"
      :header-cell-style="{ background: '#F6F6F6' }" height="70vh">
      <el-table-column :prop="item.prop" :label="item.label" v-for="(item, i) in tableColumn" :key="i">
        <template #default="{ row }" v-if="item.prop === 'total'">
          {{ row.constructionTotal * 1 + row.completeTotal * 1 }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="170" fixed="right">
        <template #default="{ row }">
          <el-link type="primary" @click="onDetail(row)">详情</el-link>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>

  <el-dialog title="上报历史" width="90%" v-model="detailVisible">
    <el-table border :data="detailTable" style="width: 100%; margin-bottom: 10px" v-loading="detailLoading"
      :header-cell-style="{ background: '#F6F6F6' }" height="70vh">
      <el-table-column :prop="item.prop" :label="item.label" v-for="(item, i) in detailColumn" :key="i">
        <template #default="{ row }" v-if="item.prop == 'ecProjBuildStatusName'">
          <dict-tag :options="D_BZ_XMSGZT" v-model="row.ecProjBuildStatusName" :tag="false" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="170" fixed="right">
        <template #default="{ row }">
          <el-link type="primary" @click="handleDetail(row)">详情</el-link>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
  <Detailcc @close="detailCCVisible = false" :title="dialogTitle" :detail="detail" v-if="detailCCVisible"
    type="report" />
</template>

<script setup>
import { onMounted, ref, reactive, getCurrentInstance, nextTick, watch } from "vue"
import { getApi, postApi } from "@/api/tobAcco_api.js"
import * as MOSTY from "@/components/MyComponents/index"
import { getItem } from "@/utils/storage"
import { ElMessage } from "element-plus"
import Detailcc from "./Detailcc.vue"
const { proxy } = getCurrentInstance()
const { D_BZ_XMSGZT } = proxy.$dict("D_BZ_XMSGZT")
const props = defineProps({
  params: Object
})
const dialogVisible = ref(false)
const dataTable = ref([])
const tableColumn = ref([
  { label: "企业名称", prop: "orgName" },
  { label: "上报次数", prop: "sbcs" },
  { label: "项目总数(个)", prop: "total" },
  { label: "在建项目数(个)", prop: "constructionTotal" },
  { label: "已竣工验收项目数(个)", prop: "completeTotal" },
  { label: "上报时间", prop: "updateTime" }
])
const tableLoading = ref(false)
const detailVisible = ref(false)
const detailCCVisible = ref(false)
const dialogTitle = ref("")
const detail = ref(null)
const detailTable = ref([])
const detailColumn = ref([
  { label: "企业名称", prop: "orgName" },
  { label: "所属单位/部门", prop: "orgName" },
  { label: "项目名称", prop: "uimsProName" },
  { label: "施工状态", prop: "ecProjBuildStatusName" },
  { label: "占地面积", prop: "totalLandArea" },
  { label: "建筑面积", prop: "totalBuildingArea" },
  { label: "总投资（万元）", prop: "proActualInvestmentAmount" },
])
const detailLoading = ref(false)
defineExpose({ dialogVisible })

const getDataList = () => {
  dataTable.value = []
  tableLoading.value = true

  postApi(props.params, "/mosty-jcgl/data/StsFileEscalationStat/queryReportingHistoryStat").then(res => {
    if (res) {
      dataTable.value = res
      tableLoading.value = false
    }
  })
}
const getDetailList = data => {
  detailTable.value = []
  detailLoading.value = true
  let _data = props.params
  _data.sbcs = data.sbcs
  _data.orgCode = data.orgCode
  postApi(_data, "/mosty-jcgl/data/StsFileEscalationStat/queryReportingHistoryStatLogDetails").then(res => {
    if (res) {
      detailTable.value = res
      detailLoading.value = false
    }
  })
}
const onDetail = e => {
  detailVisible.value = true
  getDetailList(e)
}
const handleDetail = row => {
  detail.value = row
  dialogTitle.value = `三同时管理详情`
  detailCCVisible.value = true
}
watch(
  () => dialogVisible.value,
  (n, o) => {
    if (n) {
      getDataList()
    }
  },
  { deep: true }
  // { immediate: true, deep: true }
)
</script>

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