<template>
  <el-dialog
    :modal="true"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    destroy-on-close
    title="查看详情"
    :model-value="dialogVisible"
    :before-close="handleClose"
  >
    <my-table
      :each-tr-height="40"
      :table-data="tableData"
      border
      :headers="myHeader"

    ></my-table>
    <ele-pagination  ref="refEl"
                     @sizeOrPageChange="handleSizeChange"
                     class="page"
                     :default-page-size="pageSize"
                     :total-count="totalCount">

      <template #default>
        <div class="m-s">
          显示第 {{pageSize * (pageIndex -1) + 1 }} 到第 {{pageSize * pageIndex}} 条记录，总共 {{totalCount}} 条记录 共显示

        </div>
      </template>
    </ele-pagination>
  </el-dialog>
</template>

<script>
import MyTable from "@/components/common/MyTable.vue";
import {computed, onBeforeMount, ref} from "vue";
import {staTabReflectArr} from "@/data/all-reflect";
import {useRoute} from "vue-router";
import ElePagination from "@/components/common/ElePagination.vue";
import {usePagination} from "@/unit/use-method/usePagination";
import {useRootStore} from "@/stores/useStore";
import {
  shareUseHomeTableKjHeader1,
  shareUseHomeTableKjHeader2,
  shareUseHomeTableKjHeader3,
  shareUseHomeTableKjHeader4,
  shareUseHomeTableKjHeader5,
  shareUseHomeTableKjHeader6, shareUseHomeTableZWHeader1,
  shareUseHomeTableZwHeader2,
  shareUseHomeTableZwHeader3, shareUseHomeTableZwHeader4, shareUseHomeTableZwHeader5,
  shareUseHomeTableZwHeader6
} from "@/data/all-table-header";

export default {
  name: "StaTabContentDetailDialog",
  components: {ElePagination, MyTable},
  props:{
    dialogVisible:{

    },
    dialogHeaders:{

    },
    currentDialogObj:{

    },
    type:{

    }
  },
  setup(props,{emit}){
    const myHeader = ref({...props.dialogHeaders})
    const route = useRoute()
    function getTableListData(){
      let params = {}
      console.log('route.params.name',route.name,route)
      if (route.name === 'share-exchange-sta'){

        if (currentObj.value.tabName === 'kj'){
          params = {
            pageIndex:pageIndex.value,
            pageSize:pageSize.value,
            start_time:props.currentDialogObj.start_time  || '',
            end_time:props.currentDialogObj.end_time  || '',
            a_type:props.currentDialogObj.prop.name,
            a_code:props.currentDialogObj.CODE,
            appkey:useRootStore().userInfo.ptjk_userkeycode
          }
        }else {
          params = {
            pageIndex:pageIndex.value,
            pageSize:pageSize.value,
            start_time:props.currentDialogObj.start_time || '',
            end_time:props.currentDialogObj.end_time || '',
            a_type:props.currentDialogObj.prop.name,
            a_code:props.currentDialogObj.CODE,
            appkey:useRootStore().userInfo.ptjk_userkeycode
          }
        }
      }
      else if (route.name === 'share-use-sta'){


        if (currentObj.value.tabName === 'kj'){

          // a_type没拿到，明天看
          params = {
            pageIndex:pageIndex.value,
            pageSize:pageSize.value,
            a_start_time:props.currentDialogObj.start_time  || '',
            a_end_time:props.currentDialogObj.end_time  || '',
            a_type:props.currentDialogObj.prop.name,
            a_unitcode:props.currentDialogObj.CODE,
            appkey:useRootStore().userInfo.ptjk_userkeycode
          }
        }else {

          params = {
            pageIndex:pageIndex.value,
            pageSize:pageSize.value,
            a_start_time:props.currentDialogObj.start_time  || '',
            a_end_time:props.currentDialogObj.end_time  || '',
            a_type:props.currentDialogObj.prop.name,
            a_unitcode:props.currentDialogObj.UNIT_CODE,
            appkey:useRootStore().userInfo.ptjk_userkeycode
          }
        }
      }
      else if (route.name === 'service-use-sta'){


        if (currentObj.value.tabName === 'kj'){

          // a_type没拿到，明天看
          params = {
            pageIndex:pageIndex.value,
            pageSize:pageSize.value,
            a_start_time:props.currentDialogObj.start_time  || '',
            a_end_time:props.currentDialogObj.end_time  || '',
            a_type:props.currentDialogObj.prop.name,
            a_unitname:props.currentDialogObj.NAME,
            a_unitcode:props.currentDialogObj.CODE,
            appkey:useRootStore().userInfo.ptjk_userkeycode
          }
        }else {

          params = {
            pageIndex:pageIndex.value,
            pageSize:pageSize.value,
            a_start_time:props.currentDialogObj.start_time  || '',
            a_end_time:props.currentDialogObj.end_time  || '',
            a_type:props.currentDialogObj.prop.name,
            a_unit:props.currentDialogObj.UNIT_CODE,
            appkey:useRootStore().userInfo.ptjk_userkeycode
          }
        }
      }
      else if (route.name === 'tool-use-sta'){


        if (currentObj.value.tabName === 'kj'){

          // a_type没拿到，明天看
          params = {
            pageIndex:pageIndex.value,
            pageSize:pageSize.value,
            START_DATE:props.currentDialogObj.start_time  || '',
            END_DATE:props.currentDialogObj.end_time  || '',
            RESOURCE_TYPE:'1',

            UNIT_CODE:props.currentDialogObj.CODE,
            appkey:useRootStore().userInfo.ptjk_userkeycode
          }
        }else {

          params = {
            pageIndex:pageIndex.value,
            pageSize:pageSize.value,
            START_DATE:props.currentDialogObj.start_time  || '',
            END_DATE:props.currentDialogObj.end_time  || '',
            RESOURCE_TYPE:'3',

            UNIT_CODE:props.currentDialogObj.CODE,
            appkey:useRootStore().userInfo.ptjk_userkeycode
          }
        }
      }
      currentObj.value.dialogUrl(params).then(res => {
        tableData.value = res.msg[0].Rows||[]
        totalCount.value = res.msg[0].TotalRowCount

      })
    }
    const {pageSize,pageIndex,totalCount,handleSizeChange,initSearch,refEl,tableData} = usePagination(getTableListData)
    onBeforeMount(() => {
      if (route.name === 'share-use-sta'){
        console.log(props.currentDialogObj.prop.prop)

        if (currentObj.value.tabName !== 'kj'){

          if (props.currentDialogObj.prop.name === '1'){
            myHeader.value = [...shareUseHomeTableKjHeader1]
          }else  if (props.currentDialogObj.prop.name === '2'){
            myHeader.value = [...shareUseHomeTableKjHeader2]
          }else  if (props.currentDialogObj.prop.name === '3'){
            myHeader.value = [...shareUseHomeTableKjHeader3]
          }else  if (props.currentDialogObj.prop.name === '4'){
            myHeader.value = [...shareUseHomeTableKjHeader4]
          }else  if (props.currentDialogObj.prop.name === '5'){
            myHeader.value = [...shareUseHomeTableKjHeader5]
          }else  if (props.currentDialogObj.prop.name === '6'){
            myHeader.value = [...shareUseHomeTableKjHeader6]
          }
        }else {

          if (props.currentDialogObj.prop.name === '1'){
            myHeader.value = [...shareUseHomeTableZWHeader1]
          }else  if (props.currentDialogObj.prop.name === '2'){
            myHeader.value = [...shareUseHomeTableZwHeader2]
          }else  if (props.currentDialogObj.prop.name === '3'){
            myHeader.value = [...shareUseHomeTableZwHeader3]
          }else  if (props.currentDialogObj.prop.name === '4'){
            myHeader.value = [...shareUseHomeTableZwHeader4]
          }else  if (props.currentDialogObj.prop.name === '5'){
            myHeader.value = [...shareUseHomeTableZwHeader5]
          }else  if (props.currentDialogObj.prop.name === '6'){
            myHeader.value = [...shareUseHomeTableZwHeader6]
          }
        }

      }

    })
    function handleClose(){
      emit('update:dialogVisible',false)
    }
    const currentObj = computed(() =>{
      return staTabReflectArr.find(i=>i.id===route.name).tabArr.find(i=>i.tabName === props.type)
    })
    return {
      handleClose,
      currentObj,
      pageSize,pageIndex,totalCount,handleSizeChange,initSearch,refEl,tableData,
      myHeader
    }
  }
}
</script>

<style scoped lang="scss">

</style>
