<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>
      <!-- 新导入 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> -->
      <!-- 表格导入-前端 -->
      <UploadExcelByFe 
        ref="UploadExcelByFe_Ref"
        :before-upload="beforeUpload"
        :show="displayDialog.importDialog"
        @postImportDown="importDown()"
        @submitForm="uploadSubmitForm"
      />
      <!--抽屉-->
      <curren-Drawer
        :title="tableColumns"
        :DrawerLoading="Loading.DrawerLoading"
        :drawer="displayDialog.detailsDialog"
        :propsData="propsData"
        :tabsDesTions="tabsDesTions"
        :Butttondata="DrawerButtonData"
        @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 { 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 UploadExcelByFe from '@/components/UploadExcelByFe/index.vue'
  import { kittingRequestExcel } from "@/filters/excelOrReportsOption";
  import { getNowToT } from '@/utils/formatTime'
  import { createImportExcelByFE } from '@/api/wms-api'
  import store  from '@/store'
  export default {
    name: "KittingIssueRequest",
    mixins: [
      tableMixins,
      LoadingMixins,
      drawerMixins,
      TableHeaderMixins,
      mixins,
    ],
    components: { UploadExcelByFe },
    computed: {
      hideButton: function () {
        return function (val) {
          let data = true
          val.forEach(key => {
            if (this.propsData.requestStatus == key) {
              data = false
            }
          })
          return data
        }
      },
    },
    data() {
      return {
        URL: "wms/store/kitting-issue-request",
        //常用按钮数据
        currenButtonData: [
          this.defaultImportBtn(),//导入
          this.defaultFieldSettingBtn(),//字段设置
          this.defaultFreshBtn(),//刷新
          this.defaultFilterBtn(),//筛选
        ],
        DrawerButtonData: [
          {
            type: 'warning',
            label: '执行',
            hide: false,
            name: "handleGetIds",
            hide: () => { return this.hideButton([1,5,9]) },
            size: 'mini',
            handleGetJobsUrl:'wms/store/kitting-issue-job',
            // handleRequestUrl:'wms/store/kitting-issue-request',
          },
          {
            type: 'danger',
            label: '取消',
            hide: false,
            name: "cancelRequest",
            hide: () => { return this.hideButton([1,5,9]) },
            size: 'mini'
          },
          {
            type: 'success',
            label: '完成',
            hide: false,
            name: "completeRequest",
            hide: () => { return this.hideButton([1,5,9]) },
            size: 'mini'
          },
        ],
      };
    },
    mounted() {
      this.paging();
    },
    methods:{
      uploadSubmitForm(index,data){
        // 确定
        if(index == '1'){
          let _result = data.results;
          let _data = []
          for(let i in _result){
            let _item = {
              worker: store.getters.name.userName,
              remark: "",
              extraProperties: {},
              activeDate: getNowToT(),
              autoSubmit: true,
              autoAgree: false,
              autoHandle: false,
              autoCompleteJob: false,
              directCreateNote: true,
              issueRequestType: 5,
              useOnTheWayLocation: false,
              details: [{
                remark: "",
                qty: _result[i][kittingRequestExcel.qty],
                itemCode: _result[i][kittingRequestExcel.itemCode],
                toLocationCode: _result[i][kittingRequestExcel.toLocationCode],
                itemName:"",
                uom:""
              }]
            }
            _data.push(_item)
          }
          this.$refs.UploadExcelByFe_Ref.loading = true
          createImportExcelByFE(this.URL,_data)
          .then(res=>{
            this.$refs.UploadExcelByFe_Ref.loading = false
            this.displayDialog.importDialog = false;
            this.displayDialog.detailsDialog = false
            this.$successMsg("导入成功")
            this.paging()
          })
          .catch(err=>{
            this.$refs.UploadExcelByFe_Ref.loading = false
          })
        }
        // 取消
        else{
          this.displayDialog.importDialog = false;
        }
      },
      beforeUpload(file) {
        return true
      }
    }
  };
  </script>
  <style lang="scss" scoped>
  @import "@/styles/mainbasicData.scss";
  </style>