<template>
  <div class="page-box" v-loading="Loading.appMainLoading">
    <tablePagination
      :currenButtonData="currenButtonData"
      :tableData="tableData"
      :tableLoading="Loading.tableLoading"
      :tableColumns="tableColumns"
      @rowDrop="rowDrop"
      :totalCount="totalCount"
      :multipleSelection="multipleSelection"
      :MaxResultCount="PageListParams.MaxResultCount"
      @topbutton="topbutton"
      @inlineDialog="inlineDialog"
      @sortChange="sortChange"
      @alertoldSkipCount="alertoldSkipCount"
      @alterResultCount="alterResultCount"
      @handleSelectionChange="handleSelectionChange"
      :currentPageProps="oldSkipCount"
      :quicklySearchOption="quicklySearchOption"
      @quicklySearchClick="quicklySearchClick"
      @quicklySearchClear="quicklySearchClear"
      :primarySearchOption="primarySearchOption"
      @overallSearchFormClick="overallSearchFormClick"
      :httpOverallSearchData="httpOverallSearchData"
    >
    </tablePagination>
    <!-- 抽屉 -->
    <curren-Drawer
      :title="tableColumns"
      :DrawerLoading="Loading.DrawerLoading"
      :drawer="displayDialog.detailsDialog"
      :propsData="propsData"
      :Butttondata="DrawerButtonData"
      :tabsDesTions="tabsDesTions"
      @drawerShut="(val) => (displayDialog.detailsDialog = val)"
      @drawerbutton="drawerbutton"
      @handleCommand="drawerHandle"
      @close-value="closeValue"
      :tableColumns="detailsTableColumns"
      :totalCount="totalCountDetails"
      :MaxResultCount="MaxResultCountDetails"
      @alterResultCountDetails="alterResultCountDetails"
      @alertoldSkipCountDetails="alertoldSkipCountDetails"
    ></curren-Drawer>
  </div>
</template>
<script>
import { getPageListWip } from "@/api/wms-api"
import { tableMixins } from "@/mixins/TableMixins"
import { LoadingMixins } from "@/mixins/LoadingMixins"
import { drawerMixins } from "@/mixins/drawerMixins"
import { TableHeaderMixins } from "@/mixins/TableHeaderMixins"
import { mixins } from "@/mixins/mixins"
import { initPrintAllData } from '@/mixins/printMixin'
import { getInventoryLabelByCodes} from "@/api/wms-core"
export default {
  name: "PutawayNote",
  mixins: [
    tableMixins,
    LoadingMixins,
    drawerMixins,
    TableHeaderMixins,
    mixins,
  ],
  data () {
    return {
      URL: 'wms/store/putaway-note',
      //常用按钮数据
      currenButtonData: [
        this.defaultExportBtn(),//导出
        this.defaultFieldSettingBtn(),//字段设置
        this.defaultFreshBtn(),//刷新
        this.defaultFilterBtn(),//筛选
      ],
      DrawerButtonData: [
        {
          type: 'info',
          icon: 'el-icon-printer',
          label: '打印',
          hide: false,
          name: "print",
          size: 'mini'
        },
      ],
    };
  },
  mounted () {
    this.paging();
  },
  methods: {
    //渲染数据
    paging() {
      this.Loading.tableLoading = true;
      this.PageListParams.SkipCount = (this.oldSkipCount - 1) * this.PageListParams.MaxResultCount,
      getPageListWip(this.PageListParams, 'wms/store/putaway-note/get-list-by-purchase').then(res => {
          this.tableData = res.items
          this.totalCount = res.totalCount
          this.pagingCallback()
        }).catch(err => {
          this.Loading.tableLoading = false
        })
    },
    //抽屉常用按钮
    drawerbutton (val) {
      // 打印
      if(val == 'print'){
        let _ids = []
        this.propsData.details.forEach(item => {
          _ids.push(item.handledPackingCode)
        });
        getInventoryLabelByCodes(_ids).then(res => {
          this.Loading.appMainLoading = false;
          let _printData = JSON.parse(JSON.stringify(this.propsData))
          if(res && res.length > 0){
            _printData.supplierCode = res[0].supplierCode;
            _printData.supplierSimpleName = res[0].supplierSimpleName;
            res.forEach((item)=>{
              _printData.details.forEach((item2)=>{
                if(item.itemCode == item2.itemCode){
                  item2.supplierItemCode = item.supplierItemCode
                }
              })
            })
          }
          let data = initPrintAllData(_printData,'ysd.rdlx');
          this.Print(data)
        }).catch(err => {
          this.Loading.appMainLoading = false;
        })
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../../../styles/basicData.scss";
</style>