<template>
  <el-dialog title="上报历史" width="1400px" 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"> </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="1400px" v-model="detailVisible">
    <el-table
      border
      ref="multipleTableRef"
      id="mergeTable"
      :data="detailTable"
      style="width: 100%"
      highlight-current-row
      :header-cell-style="{ background: '#F6F6F6' }"
      v-loading="detailLoading"
      height="550px"
    >
      <el-table-column :prop="item.prop" :label="item.label" v-for="(item, i) in detailColumn" :key="i">
        <template v-if="item.prop == 'safetyMemberFlag'" #default="{ row }">
          <span>{{ row.safetyMemberFlag === "1" ? "是" : "否" }}</span>
        </template>
        <template v-if="item.prop == 'seFlag'" #default="{ row }">
          <span>{{ row.seFlag === "1" ? "是" : "否" }}</span>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
</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"

const { proxy } = getCurrentInstance()
const props = defineProps({
  params: Object
})
const dialogVisible = ref(false)
const dataTable = ref([])
const tableColumn = ref([
  { label: "企业名称", prop: "orgName",},
  { label: "上报次数", prop: "sbcs" },
  { label: "上报时间", prop: "updateTime" },
  { label: "专职安全管理人员数量（人）", prop: "zzaqryzs" },
  { label: "注安师人员数量（人）", prop: "zasrs" },
  { label: "注消师人员数量（人）", prop: "zxsrs" },
  { label: "安技委成员人数（人）", prop: "ajwrs" },
  { label: "评聘为安全工程师人数（人）", prop: "aqgcsrs" }
  // { label: "上报时间", prop: "gxTime" }
])
const detailColumn = reactive([
  { label: "企业名称", prop: "baOrgName" },
  { label: "姓名", prop: "employeeName" },
  { label: "性别", prop: "sexName" },
  { label: "政治面貌", prop: "politicalAffiliation" },
  { label: "出生年月", prop: "birthDate" },
  { label: "岗位名称", prop: "postName" },
  { label: "职务", prop: "dutiesName" },
  { label: "擅长领域", prop: "areasExpertiseName" },
  { label: "累计从事专职安全管理年限", prop: "safetyManageYear" },
  { label: "注册安全工程师级别", prop: "cseLevelName" },
  { label: "注册消防工程师级别", prop: "fireEngineerLevelName" },
  { label: "是否为安技委成员", prop: "safetyMemberFlag" },
  { label: "是否评聘为安全工程师", prop: "seFlag" }
])
const tableLoading = ref(false)
const detailVisible = ref(false)
const detailTable = ref([])
const detailLoading = ref(false)
defineExpose({ dialogVisible })

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

  postApi(props.params, "/mosty-jcgl/data/safeManageTeamStat/queryReportingHistoryStat").then(res => {
    if (res) {
      dataTable.value = res
      tableLoading.value = false
    }
  })
}
const getDetailList = e => {
  detailTable.value = []
  detailLoading.value = true
  props.params.orgCode = e.orgCode
  props.params.sbcs = e.sbcs
  postApi(props.params, "/mosty-jcgl/data/safeManageTeamStat/queryReportingHistoryStatLogDetails").then(res => {
    if (res) {
      detailTable.value = res
      detailLoading.value = false
    }
  })
}
const onDetail = e => {
  detailVisible.value = true
  getDetailList(e)
}

watch(
  () => dialogVisible.value,
  (n, o) => {
    if (n) {
      getDataList()
    }
  },
  { deep: true }
  // { immediate: true, deep: true }
)
</script>

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