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

<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import { skuList } from '@/api/distribution'
import CommissionModal from "./commissionModal.vue";
@Component({components:{CommissionModal}})
export default class ProductList extends Vue {
  config:any={
    attr:{
      calculateH:true
    },
    tool:{
      tools:{
        refresh:true
      }
    },
    table:{
      attr:{
        size:'mini',
        seq:true,
      },
      columns: [
        {
          // width: '200px',
          title: '标题',
          field: 'skuTitle',
        },
        {
          width: '140px',
          title: '物料编码',
          field: 'skuCode',
        },
        {
          width: '140px',
          title: '69码-商品条码',
          field: 'barCode',
        },
        {
          width: '140px',
          title: '财务编号',
          field: 'financialCode',
        },
        {
          width: '200px',
          title: '商品名称',
          field: 'extData',
        },
        {
          width: '80px',
          title: '价格',
          field: 'price',
        },
        {
          width: '80px',
          title: '重量/g',
          field: 'weight',
        },
        {
          width: 100,
          title: '操作',
          action: true,
          plugins: [{
            name: '佣金明细',
            event: {
              click: (item:any) => {
                (this.$refs.commissionModal as any).setData(item);
                (this.$refs.commissionModal as any).setShow(true);
              }
            }
          }]
        },
      ]
    }
  }
  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;
    skuList(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>
.box{
  height: 100%;
  width: 100%;
}
</style>