<template>
  <div id="interfaceExceptionLog">
      <ul class="topSearch">
          <li>
            <DatePicker type="datetime" v-model="beginTime" format="yyyy-MM-dd HH:mm:ss"  placeholder="开始时间" style="width: 200px"></DatePicker>
            至
            <DatePicker type="datetime" v-model="endTime" format="yyyy-MM-dd HH:mm:ss" placeholder="结束时间" style="width: 200px"></DatePicker>
          </li>
          <li>
              <Button type="primary" @click="searchBtn">搜索</Button>
          </li>
      </ul>
      <div>
            <Table border :columns="columns" :data="tableData"></Table>
      </div>
       <!--分页-->
      <div class="page">
            <Page :total="totalPage" :current.sync="page" show-total show-elevator show-sizer @on-change="changePage" @on-page-size-change="changePageSize"/>
      </div>

  </div>
</template>

<script>
import axios from '../../assets/js/axios'
import { formatDate,compareDate } from '../../tools/tools';
export default {
    name:'InterfaceExceptionLog',
    data(){
        return{
            page:1,
            pageSize:10,
            totalPage:0,
            beginTime:'',
            endTime:'',
            columns: [
                {title: '创建时间',key: 'createTime',width:130,toolTip:true},
                {title: '接口地址',key: 'apiAddress',minWidth:120,toolTip:true},
                {title: '错误消息',key: 'message',minWidth:200,toolTip:true},
                {title: '条码前缀',key: 'creatorName',minWidth:80,toolTip:true},
                {title: '条码号',key: 'barcode',minWidth:100,toolTip:true},
                {title: '检验中心',key: 'labName',minWidth:100,toolTip:true},
            ],
            tableData:[],
        }
    },
    mounted(){
        this.init()
        this.getPage()
    },
    watch:{
        beginTime(){
            if (this.beginTime && this.endTime) {
                let st = new Date(this.beginTime)
                let ed = new Date(this.endTime)
                if (st>ed) {
                    this.$Message.warning('开始时间不能大于结束时间')
                }
            }
        },
        endTime(){
           if (this.beginTime && this.endTime) {
                let st = new Date(this.beginTime)
                let ed = new Date(this.endTime)
                if (st>ed) {
                    this.$Message.warning('结束时间不能小于开始时间')
                }
            } 
        }
    },
    methods:{
        init(){
            let myDate = new Date()
            let year = myDate.getFullYear()
            let month = myDate.getMonth()
            let d = myDate.getDate()
            let sd =new Date(year,month,d,'00','00','00')
            let ld=new Date(year,month,d,'23','59','59')
            this.beginTime = sd
            this.endTime = ld
        },
        searchBtn(){
            this.page = 1
            this.getPage()
        },
        getPage(){
            axios.post('/platform-manager/report/listExceptionLogByPage',{
                beginTime:formatDate(this.beginTime,'01','03'),
                current:this.page,
                endTime:formatDate(this.endTime,'01','03'),
                size:this.pageSize
            }).then(res=>{
                if (res) {
                    let temp = res.data.data.records
                    for (let i of temp) {
                        i.createTime = formatDate(i.createTime,'01','03')
                    }
                    this.tableData = temp
                    this.totalPage = res.data.data.total
                }
            })
        },
        changePage(page){
            this.page = page
            this.getPage()
        },
        changePageSize(size){
            this.pageSize = size
            this.getPage()
        },
    }
}
</script>

<style>
#interfaceExceptionLog .topSearch{
    display: flex;
    margin: 10px 0;
}
 #interfaceExceptionLog .topSearch>li{
     margin-right: 10px;
 }
</style>