<template>
  <div class="pull-record">
    <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 { pullRecord } from '@/api/omsOrder'
@Component({ components: {} })
export default class OrderPay extends Vue {
  config: any = {
    attr: {
      calculateH: true
    },
    search: {
      attr: {
        size: 'small'
      },
      columns: [
        [{
          label: '订单来源',
          span: 8,
          prop: 'sourceName',
          component: 'by-input'
        }]
      ]
    },
    tool: {
      tools: {
        search: true,
        refresh: true
      }
    },
    table: {
      attr: {
        size: 'mini',
        seq: true,
        // align:'center',
      },
      columns: [{
        title: '订单来源',
        field: 'sourceName'
      }, {
        title: '内部订单号(聚水潭)',
        field: 'biz'
      }, {
        title: '成功拉取数量',
        field: 'successQty',
        width: 130
      }, {
        title: '已同步到OMS的订单数量',
        field: 'syncQty',
        width: 160
      }, {
        title: '更新的OMS数量',
        field: 'updateQty',
        width: 130
      }, {
        title: '新增的OMS订单数量',
        field: 'insertQty',
        width: 150
      }, {
        title: '时间',
        field: 'createTime',
        width: 150
      }]
    }
  }
  load = false
  isSearch = false
  timeNum = 0;
  mounted() {
    this.$nextTick(() => {
      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();
    this.requestList(data);
  }
  //列表请求（包含分页和搜素条件）
  queryList() {
    this.isSearch = true;
    let data = (this.$refs.view as any).getQuery();
    this.requestList(data);
  }
  requestList(data: any) {
    this.load = true;
    pullRecord(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>
.pull-record {
  height: 100%;
  width: 100%;
  overflow-y: hidden;
}
</style>