<template>
 <div class="h100">
   <common-layout
     :form-attrs="{
     spanAttrs: {
       span:4
     }
     }"
     :filter-form="personWatchHomeFilterForm"
     :table-header="personWatchHomeTableHeader"
     :get-table-list="getTableList"
     ref="layoutRef"
   >
     <template #STATE="{data}">
       {{getState(data.STATE)}}
     </template>
     <template #TIMELONG="{data}">
        {{getTimeLength(data)}}
     </template>
  <template #MODELDescription="{data}">
    {{getDescription(data)}}
  </template>

   </common-layout>
 </div>
</template>

<script>
import CommonLayout from "@/components/CommonLayout.vue";
import {ref} from "vue";
import {personWatchHomeTableHeader} from "@/data/all-table-header";
import {personWatchHomeFilterForm} from "@/data/all-forms";
import {getPersonWatchHomeTableData} from "@/service/data-service-watch/person-watch";
import {isEmptyCheck} from "@/unit/validate";

export default {
  name: "PersonWatch",
  components: {CommonLayout},
  setup() {
    const layoutRef = ref(null)
    function getState(value) {
      if(isEmptyCheck(value)){
        return "";
      }
      if(value =="true"){
        return "调用成功";
      }
      return "调用失败";
    }

    function getTimeLength(row) {
      if(isEmptyCheck(row["IN_TIME"]) || isEmptyCheck(row["OUT_TIME"])){
        return "";
      }
      return (new Date(row["OUT_TIME"]).getTime()  - new Date(row["IN_TIME"]).getTime()) / 1000;

    }
    function getDescription(row){
      switch (row["MODEL"]) {
        case "OperateSHGasBusinessInfo":
          return "一户多人口";
        case "acceptApply":
          return "受理反馈";
        case "getToken":
          return "获取共享交换token";
        case "QuerySHGasCustomer":
          return "户号查询";
        case "processApply":
          return "办理";
        case "getTokenHttp":
          return "获取大数据中心token";
        default:
          return ''
      }
    }
    function getTableList() {
      getPersonWatchHomeTableData({
        pageIndex:layoutRef.value.pageIndex,
        pageSize:layoutRef.value.pageSize,
        MODEL:layoutRef.value.form.MODEL,
        IN_TIME_START:layoutRef.value.form.IN_TIME_START,
        IN_TIME_END:layoutRef.value.form.IN_TIME_END,
      }).then(res => {
        layoutRef.value.getResData(res.msg[0].Rows||[],res.msg[0].TotalRowCount)
      })

    }
    return {
      layoutRef,
      getTableList,
      personWatchHomeTableHeader,
      personWatchHomeFilterForm,
      getDescription,
      getTimeLength,
      getState
    }
  }
}
</script>

<style scoped lang="scss">

</style>
