<template>
 <div class="h100">
   <common-layout
     ref="layoutRef"
     :get-table-list="getTableList"
     :form-attrs="{
       spanAttrs: {
        span:4
       }
     }"
     :filter-form="qualityCheckRecordHomeFilterForm"
     :table-header="qualityCheckRecordHomeTableHeader"
   :table-attrs="{
     'has-operation':true
   }"
   >
     <template #INSPECTION_DATE="{data}">
       {{getTimeStart(data.INSPECTION_DATE)}}
     </template>
     <template #INSERTTIME="{data}">
       {{getNextTime(data,data.INSERTTIME)}}
     </template>
     <template #operation="{data}">
<!--       <el-button type="info" >详情</el-button>-->
       <el-button :disabled="!(+data.ERROR_NUM > 0)" type="info" @click="$emit('changeOperation','record',data)">异常记录</el-button>
     </template>
   </common-layout>
 </div>
</template>

<script>
import CommonLayout from "@/components/CommonLayout.vue";
import {qualityCheckRecordHomeTableHeader} from "@/data/all-table-header";
import {qualityCheckRecordHomeFilterForm} from "@/data/all-forms";
import {ref} from "vue";
import {getQualityCheckRecordHomeTableData} from "@/service/data-quelity-check/quality-check-record";
import {isEmptyCheck} from "@/unit/validate";
import {getDateToString, getDateToString_ymd, getDateToStrNum, GetMonday} from "@/unit/time";
import {useActiveGetTableData} from "@/unit/use-method/usePagination";

export default {
  name: "QualityCheckRecordHome",
  components: {CommonLayout},
  setup() {
    useActiveGetTableData(getTableList)
    function getTimeStart(value) {
      if (isEmptyCheck(value)) {
        return "";
      }
      return getDateToString(new Date(value));
    }
    function getNextTime(row,value) {
      if (isEmptyCheck(value)) {
        return "";
      }
      if((new Date(row["INSPECTION_DATE"])).getTime() < (new Date(value)).getTime()){
        return getDateToString(new Date((new Date(row["INSPECTION_DATE"])).getTime() + 120000));
      }
      return getDateToString(new Date(value));
    }
    function getTableList() {
      getQualityCheckRecordHomeTableData({
        pageIndex:layoutRef.value.pageIndex,
        pageSize:layoutRef.value.pageSize,
        UNITCODE:layoutRef.value.form.UNITCODE,
        CATALOG_NAME:layoutRef.value.form.CATALOG_NAME,

      }).then(res => {
        layoutRef.value.getResData(res.msg[0].Rows||[],res.msg[0].TotalRowCount)

      })

    }
    const layoutRef = ref(null)
    return{
      qualityCheckRecordHomeTableHeader,
      qualityCheckRecordHomeFilterForm,
      getTableList,
      layoutRef,
      getTimeStart,
      getNextTime
    }
  }
}
</script>

<style scoped lang="scss">

</style>
