<template>
  <div class="print-log">
    <module-view :propConfig="config" ref="view" v-loading="load" @pagination="pagination" @onRefresh="getList" @resert="queryList" @search="queryList"/>
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import { query} from '@/api/printLog'
import SuccessTag from "./components/successTag.vue";
@Component({components:{}})
export default class PrintLog extends Vue {
  load=false;
  isSearch=false
  timeNum = 0;
  config:any={
    attr:{
      calculateH:true
    },
    search:{
      attr:{
        size:'small',
        labelWidth:'130px'
      },
      columns:[
        [{
          span:8,
          label:'模板名称',
          prop:'templateName',
          component:'by-input',
          compConfig:{
            attr:{
              clearable:true
            }
          }
        },{
          span:8,
          label:'外部用户标识',
          prop:'userName',
          component:'user-modal'
        }]
      ]
    },
    tool:{
      tools:{
        search:true,
        refresh:true
      }
    },
    table:{
      attr:{
        size:'mini',
        seq:true,
        // checkbox:true
      },
      columns:[{
        title:'外部用户标识',
        field:'userId',
        width:130
      },{
        title:'模板名称',
        field:'templateName'
      },{
        title:'打印时间',
        field:'printTime',
        width:150
      },{
        title:'输出类型',
        field:'outType',
        width:120
      },{
        title:'输出是否成功',
        field:'success',
        width:120,
        component:SuccessTag
      }]
    }
  }
  mounted(){
    this.getList();
  }
  //分页
  pagination(){
    if(this.isSearch){
      this.queryList();
    }else{
      this.getList()
    }
  }
  //列表请求（只有分页，不包含搜素条件）
  getList(){
    if(!this.$refs.view){
      if(this.timeNum > 5){
        return
      }
      setTimeout(()=>{
        this.getList()
      },500) 
      this.timeNum ++;
      return
    }
    this.isSearch = false;
    let data = (this.$refs.view as any).getPage();
    delete data.total;
    this.requestList(data);
  }
  //列表请求（包含分页和搜素条件）
  queryList(){
    this.isSearch = true;
    let data = (this.$refs.view as any).getQuery();
    delete data.total;
    this.requestList(data);
  }
  requestList(data:any){
    this.load = true;
    query(data).then((res:any) => {
      this.load = false;
      (this.$refs.view as any).setTableValue(res.data.records);
      let page = {
        pageNo: res.data.current, //当前页
        pageSize: res.data.size, //每页条数
        total: res.data.total //总条数
      };
      (this.$refs.view as any).setPage(page)

    }).catch(()=>{
      this.load = false;
    })
  }
}
</script>
<style lang="scss" scoped>
.print-log{
  height: 100%;
  width: 100%;
  overflow-y: hidden;
}
</style>