<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="topbuttonHandle"
      @inlineDialog="inlineDialog"
      @sortChange="sortChange"
      @alertoldSkipCount="alertoldSkipCount"
      @alterResultCount="alterResultCount"
      @handleSelectionChange="handleSelectionChange"
      :currentPageProps="oldSkipCount"
      :quicklySearchOption="quicklySearchOption"
      @quicklySearchClick="quicklySearchClick"
      @quicklySearchClear="quicklySearchClear"
      :primarySearchOption="primarySearchOption"
      @overallSearchFormClick="overallSearchFormClick"
      :httpOverallSearchData="httpOverallSearchData"
      :setUTableHeight="140"
    >
    </tablePagination>
    <!-- 新导入 disabledMethod 导入方式禁用 disabledIsAllowPartImport 是否局部导入禁用-->
    <!-- methodValue 导入方式默认选项  是否局部导入 默认选项  -->
    <importFile
      :loading="Loading.importLoading"
      :show="displayDialog.importDialog"
      :URL="URL"
      :disabledMethod = {method1:false,method2:false,method3:false}
      :disabledIsAllowPartImport = {isAllowPartImport1:false,isAllowPartImport2:false}
      isAllowPartImportValue="1"
      @importClick="postImportMergeClick(arguments)"
      @postImportDown="importDown"
    ></importFile>
    <!--抽屉-->
    <curren-Drawer
      :title="tableColumns"
      :DrawerLoading="Loading.DrawerLoading"
      :drawer="displayDialog.detailsDialog"
      :propsData="propsData"
      :tabsDesTions="tabsDesTions"
      :Butttondata="DrawerButtonData"
      @drawerbutton="drawerbutton"
      @drawerShut="(val) => (displayDialog.detailsDialog = val)"
      @handleCommand="drawerHandle"
      @close-value="closeValue"
      :tableColumns="detailsTableColumns"
      :totalCount="totalCountDetails"
      :MaxResultCount="MaxResultCountDetails"
      @alterResultCountDetails="alterResultCountDetails"
      @alertoldSkipCountDetails="alertoldSkipCountDetails"
    ></curren-Drawer>
    <!-- 新增与编辑 -->
    <newAndEdiDialog
      :loading="Loading.newAndEdiLoading"
      :active="active"
      :pageStatus="pageStatus"
      :formReveal="formReveal"
      :formTitle="formTitle"
      :displayDialog="editDialog"
      :FormData="formReveal ? CreateFormData : editFormData"
      :Form="formReveal ? CreateForm : editForm"
      :Options="editOptions"
      :Handle="editHandle"
      :Rules="formReveal ? editRules.cerateRule : editRules.editRule"
      @FormSubmit="FormSubmitHandle"
      @close="FormCloseHandle"
      @goBack="goBack"
    >
      <template>
        <curren-descriptions
          v-if="this.displayDialog.newDialog"
          :border="true"
          :column="3"
          :direction="'horizontal'"
          :colon="false"
          :tabsDesTions="detailsTableColumns"
          :propsData="propsData.details[0]"
          class="drawerDescriptionsFirst"
          style="width:100%;padding-top:20px"
        >
        </curren-descriptions>
      </template>
    </newAndEdiDialog>
    <!-- 搜索按钮——窗体组件 -->
    <searchPage
      ref="searchTable"
      :tableLoading="Loading.autoTableLoading"
      :advancedFilter="advancedFilter()"
      :filterPageListParams="filterPageListParams"
      :formTitle="searchTitle"
      :displayDialog="displayDialog.AddNewDialog"
      :searchTableData="searchData"
      :searchTableColumns="searchColumns"
      :searchTotalCount="searchTotalCount"
      :supplierItemPage="searchPageListParams"
      @handleSelectionChange="prepareFormData"
      @SizeChange="searchAlterResultCount($event, searchPageListParams)"
      @CurrentChange="searchAlertoldSkipCount($event, searchPageListParams)"
      @tableButtonClick="searchSubmit(arguments)"
    ></searchPage>
  </div>
</template>
<script>
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 { newAndEdiDialogMixins } from "@/mixins/newAndEdiDialogMixins"
import { filterSelectMixins } from '@/mixins/filter-Select'
import { transferLibJobHandel } from '@/api/wms-job'
import { getInventoryByPackingCode,getDetailed } from '@/api/wms-api'
import currenDescriptions from "@/components/currenDescriptions"
export default {
  name: "isPadForTransferLibJob",
  components: {
    currenDescriptions,
  },
  mixins: [
    tableMixins,
    LoadingMixins,
    drawerMixins,
    TableHeaderMixins,
    mixins,
    filterSelectMixins,
    newAndEdiDialogMixins
  ],
  computed: {
    editDialog: {
      get: function () {
        return this.displayDialog.newDialog || this.displayDialog.editDialog;
      },
    },
    //按钮显示
    hideButton: function () {
      return function (val) {
        let data = true
        val.forEach(key => {
          if (this.propsData.jobStatus == key) {
            data = false
          }
        })
        return data
      }
    }
  },
  data() {
    return {
      URL: "wms/store/transfer-lib-job",
      //常用按钮数据
      currenButtonData: [
      //   this.defaultImportBtn(),//导入
        {
          type: 'warning',
          label: '查看待执行数据',
          name: "showCanHandle",
          size: 'mini'
        },
        {
          type: 'success',
          label: '查看所有数据',
          name: "showAllData",
          size: 'mini'
        },
        this.defaultFieldSettingBtn(),//字段设置
        this.defaultFreshBtn(),//刷新
        this.defaultFilterBtn(),//筛选
      ],
      DrawerButtonData:[
        {
          type:'success',
          label: '完成库移',
          name: "handle",
          hide: () => { return this.hideButton([1,2,4]) },
          size:"mini"
        },
      ],
      CreateFormData: {
        packingCode:"",
        fromLocationCode:"",
        toLocationCode:"",
      },
      CreateForm: [
        { type: "input", label: "箱码", prop: 'packingCode', colSpan: 12,  },
        { type: "input", label: "来源库位", prop: 'fromLocationCode', colSpan: 12,  },
        { type: "input", label: "目标库位", prop: 'toLocationCode', colSpan: 12, },
      ],
      editRules: {
        cerateRule: {
          packingCode: [{ required: true, trigger: "blur", message: "不可为空" }],
          fromLocationCode: [{ required: true, trigger: "blur", message: "不可为空" }],
          toLocationCode: [{ required: true, trigger: "blur", message: "不可为空" }],
        },
      },
    };
  },
  mounted() {
    this.paging();
  },
  methods:{
    topbuttonHandle(val,item){
      if(val == 'showCanHandle'){
        this.PageListParams.condition.filters.push({
          logic:"And",
          column:"jobStatus",
          action:"In",
          value: JSON.stringify([1,2,4,30])
        })
        this.paging();
      }
      else if(val == 'showAllData'){
        this.PageListParams.condition.filters = this.PageListParams.condition.filters.filter(obj => obj.column != 'jobStatus');
        this.paging();
      }
      else{
        this.topbutton(val,item)
      }
    },
    drawerbutton(val){
      // 完成库移
      if(val == "handle"){
        this.formTitle = "完成库移";
        this.formReveal = true
        this.theEvent = "newly"
        this.displayDialog.newDialog = true;
      }
    },
    FormSubmitHandle(val){
      this.Loading.newAndEdiLoading = true
      // 先获取库存余额进行部分项赋值
      getInventoryByPackingCode(this.CreateFormData.packingCode).then(inventory => {
        // 目前定的需求为：details中只有一条明细，所以按钮写在最外层，默认赋值第一位
        let _data = this.propsData
        _data.details[0].handledFromPackingCode = this.CreateFormData.packingCode
        _data.details[0].handledToPackingCode = this.CreateFormData.packingCode
        _data.details[0].handledFromLocationCode = this.CreateFormData.fromLocationCode
        _data.details[0].handledToLocationCode = this.CreateFormData.toLocationCode
        _data.details[0].handledToLot = inventory.lot
        _data.details[0].handledFromLot = inventory.lot
        _data.details[0].handledFromSupplierBatch = inventory.supplierBatch
        _data.details[0].handledToSupplierBatch = inventory.supplierBatch
        _data.details[0].handledFromQty = inventory.qty
        _data.details[0].handledToQty = inventory.qty
        transferLibJobHandel(this.propsData.id, _data).then(res => {
          this.Loading.newAndEdiLoading = false
          this.FormResult("success")
        }).catch(err => {
          this.Loading.newAndEdiLoading = false
          this.FormResult("error")
        })
      }).catch(err => {
        this.Loading.newAndEdiLoading = false
      })
    },
    FormCloseHandle(val){
      this.FormClose(val)
      this.Loading.appMainLoading = true
      getDetailed(this.propsData.id, this.URL)
        .then(res => {
          this.propsData = res
          this.Loading.appMainLoading = false
        })
        .catch(err=>{
          this.Loading.appMainLoading = false
        })
    }
  }
};
</script>
<style lang="scss" scoped>
@import "@/styles/mainbasicData.scss";
</style>