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

<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import { distributionOrder } from '@/api/distribution'
@Component({components:{}})
export default class ProductList extends Vue {
  config:any={
    attr:{
      calculateH:true
    },
    tool:{
      tools:{
        refresh:true
      }
    },
    table:{
      attr:{
        size:'mini',
        seq:true,
      },
      columns: [
        {
          width: 110,
          title: '内部订单号',
          field: 'id',
        },
        {
          title: '线上订单号',
          field: 'rawSourceId',
        },
        {
          title: '订单类型',
          field: 'businessType',
          width:100,
        },
        {
          width: 100,
          title: '审核状态',
          field: 'isSubmitted',
          component:'textChange',
          compConfig:{
            attr:{
              data:[{
                label:'已审核',
                value:1
              },{
                label:'未审核',
                value:0
              }]
            }
          }
        },
        {
          width: 140,
          title: '订单状态',
          field: 'status',
          component:'textChange',
          compConfig:{
            attr:{
              data:[{
                label:'待付款',
                value:'WaitPay'
              },{
                label:'发货中',
                value:'Delivering'
              },{
                label:'被合并',
                value:'Merged'
              },{
                label:'异常',
                value:'Question'
              },{
                label:'被拆分',
                value:'Split'
              },{
                label:'等供销商|外仓发货',
                value:'WaitOuterSent'
              },{
                label:'已付款待审核',
                value:'WaitConfirm'
              },{
                label:'已客审待财审',
                value:'WaitFConfirm'
              },{
                label:'已发货',
                value:'Sent'
              },{
                label:'取消',
                value:'Cancelled'
              }]
            }
          }
        },
        {
          width: 110,
          title: '来源渠道',
          field: 'upSourceName',
        },
        {
          width: 110,
          title: '抵扣金额',
          field: 'freeAmount',
        },
        {
          width: 110,
          title: '应付',
          field: 'payAmount',
        },
        {
          width: 110,
          title: '运费',
          field: 'freight',
        },
        {
          width: 110,
          title: '实付金额',
          field: 'paidAmount',
        }
      ]
    }
  }
  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;
    data.sellType = '6';
    distributionOrder(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>

</style>