<template>
<el-dialog
  :modal="true"
  width="70%"
  :close-on-click-modal="false"
  :close-on-press-escape="false"
  destroy-on-close
  title="数据记录"
  :model-value="dialogVisible"

  :before-close="handleClose"

>
  <my-table
    border
    :is-height-equal-max-height="true"

    :headers="headers"
    :table-data="tableData"
  :page-size="10"
  >

  </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 {onBeforeMount, ref} from "vue";
import {usePagination} from "@/unit/use-method/usePagination";
import {getDtaRecordDialogTableData} from "@/service/data-quelity-check/quality-check-record";
import ElePagination from "@/components/common/ElePagination.vue";
import MyTable from "@/components/common/MyTable.vue";
import {UserInfo} from "@/unit/UserInfo";

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

    },
    currentDialogObj:{

    },
    currentOpObj:{

    }
  },
  setup(props,{emit}){
    const headers = ref([])
    function getTableData(){
      getDtaRecordDialogTableData({
        CATALOG_CODE:props.currentDialogObj.CATALOG_CODE,
        INSPECTION_DATE:props.currentDialogObj.INSPECTION_DATE,
        FIELD_NAME:props.currentDialogObj.FIELD_NAME,
        ERROR_CODE:props.currentDialogObj.ERROR_CODE,
        ERROR_NUM:props.currentOpObj.NUM,
        pageIndex:pageIndex.value,
        pageSize:pageSize.value,
        appkey:new UserInfo().GetUserKeyCode()

      }).then(res => {
        headers.value = Object.keys(res.msg[0].Rows[0]).map(i=>{
          return {
            prop:i,
            label:i
          }
        })
        headers.value.sort((pre,cur) => {
          return  ((cur.prop === 'MARK_UUID')?1:0) - (pre.prop === 'MARK_UUID'?1:0)
        })
        tableData.value = res.msg[0].Rows
        totalCount.value = res.msg[0].TotalRowCount
      })
    }
    const {pageIndex,pageSize,tableData,totalCount,initSearch,handleSizeChange,refEl}  = usePagination(getTableData)

    onBeforeMount(() => {

    })
    function handleClose(){
      emit('update:dialogVisible',false)
    }
    return {
      handleClose,
      pageIndex,pageSize,tableData,totalCount,initSearch,handleSizeChange,refEl,
      headers
    }

  }
}
</script>

<style scoped lang="scss">

</style>
