<template>
  <el-dialog title="上报历史" width="80%" v-model="dialogVisible" @close="closed">
    <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 === 'count'">
          <span>{{ Number(row.registeredNum || 0) + Number(row.dispatchNum || 0) + Number(row.outsourceNum || 0)
            }}</span>
        </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 == 'cdMotorCarAdmCode'">
          <dict-tag v-if="row.cdMotorCarAdmCode" :options="D_TB_DRIVELEVEL" :value="row.cdMotorCarAdmCode"
            :tag="false" />
          <span v-else>无</span>
        </template>
        <template #default="{ row }" v-if="item.prop == 'bbEmpSexName'">
          <dict-tag v-if="row.bbEmpSexName" :options="D_BZ_XB" :value="row.bbEmpSexName"
            :tag="false" />
          <span v-else>无</span>
        </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>
  <DetailJsy @close="detailCCVisible = false" :title="dialogTitle" :detail="detail" v-if="detailCCVisible"
    type="report" />
</template>

<script setup>
import { onMounted, ref, getCurrentInstance } from "vue"
import { postApi } from "@/api/tobAcco_api.js"
import DetailJsy from "./DetailJsy.vue"
const { proxy } = getCurrentInstance()
const { D_TB_DRIVELEVEL, D_BZ_XB } = proxy.$dict("D_TB_DRIVELEVEL", "D_BZ_XB");
const emit = defineEmits(["close"]);
const props = defineProps({
  params: Object
})
const dialogVisible = ref(true)
const dataTable = ref([])
const tableColumn = ref([
  { label: '企业名称', prop: 'orgName' },
  { label: '上报次数', prop: 'sbcs' },
  { label: '总数（个）', prop: 'count' },
  { label: '在册在岗员工数量', prop: 'registeredNum' },
  { label: '劳务派遣员工数量', prop: 'dispatchNum' },
  { label: '业务外包数量', prop: 'outsourceNum' },
  { 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: 'bbEmployeeName' },
  { label: '员工性别', prop: 'bbEmpSexName' },
  { label: '出生日期', prop: 'bbBirthDate' },
  { label: '机动车辆准驾车型名称', prop: 'cdMotorCarAdmCode' },
  { label: '人员类别名称', prop: 'bbEohPersonnelCategoryName' },
  { label: '驾驶证初次领证时间', prop: 'bbMotorCarDlTfDate' },
])
const detailLoading = ref(false)
onMounted(() => {
  getDataList()
})
const getDataList = () => {
  dataTable.value = []
  tableLoading.value = true

  postApi(props.params, "/mosty-jcgl/data/driverStat/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/driverStat/queryReportingHistoryStatLogDetails").then(res => {
    if (res) {
      detailTable.value = res
      detailLoading.value = false
    }
  })
}
const onDetail = e => {
  detailVisible.value = true
  detail.value = e
  getDetailList(e)
}
const handleDetail = row => {
  detail.value = row
  dialogTitle.value = `专职驾驶员详情`
  detailCCVisible.value = true
}
const closed = () => {
  emit("close");
};
</script>

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