<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>
    <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"
      @drawerShut="(val) => (displayDialog.detailsDialog = val)"
      @drawerbutton="drawerbutton"
      @close-value="closeValue"
      :currenButtonData="currenButtonData"
      :tableColumns="detailsTableColumns"
      :totalCount="totalCountDetails"
      :MaxResultCount="MaxResultCountDetails"
      @alterResultCountDetails="alterResultCountDetails"
      @alertoldSkipCountDetails="alertoldSkipCountDetails"
    ></curren-Drawer>
  </div>
</template>
  <script>
import { getDetailed, getPageList} 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 { requestData } from "@/utils/processButtonData"
export default {
  name: "customerDismantle",
  mixins: [
    tableMixins,
    LoadingMixins,
    drawerMixins,
    TableHeaderMixins,
    mixins,
  ],
  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.requestStatus == key) {
            data = false
          }
        })
        return data
      }
    },
  },
  data() {
    return {
      URL: "wms/store/product-recycle-request",
      //常用按钮数据
      currenButtonData: [
        this.defaultImportBtn(),//导入
        this.defaultFieldSettingBtn(),//字段设置
        this.defaultFreshBtn(),//刷新
        this.defaultFilterBtn(),//筛选
      ],
      DrawerButtonData: [
        ...requestData(this)
      ],
    };
  },
  mounted() {
    this.paging();
  },
  methods: {
    //渲染数据
    paging() {
      this.Loading.tableLoading = true;
      this.PageListParams.SkipCount = (this.oldSkipCount - 1) * this.PageListParams.MaxResultCount,
      getPageList(this.PageListParams, this.URL,true)
        .then(res => {
          this.tableData = res.items
          this.totalCount = res.totalCount
          this.tableData.forEach(item=>{
            item.itemCode = item.details[0].itemCode
            item.qty = item.details[0].qty
            item.rawLocationCode = item.details[0].rawLocationCode
            item.preStartTime = item.details[0].preStartTime
            item.workHour = item.details[0].workHour
          })
          this.pagingCallback()
        })
        .catch(err => {
          this.Loading.tableLoading = false
        })
    },
    //点击Table行内名称
    inlineDialog(val) {
      //打开抽屉
      this.Loading.DrawerLoading = true
      this.displayDialog.detailsDialog = true;
      getDetailed(val.id, this.URL).then(res => {
        if (res.details) {
          // 前端分页处理
          this.tableDataDetails = JSON.parse(JSON.stringify(res))
          let linshiTableDataDetails = JSON.parse(JSON.stringify(this.tableDataDetails))
          this.totalCountDetails = res.details.length
          // 删除除当前页面最大数以外数据
          linshiTableDataDetails.details.splice(this.MaxResultCountDetails,this.totalCountDetails); 
          this.propsData = linshiTableDataDetails
        } else {
          this.propsData = res
        }
        this.propsData.itemCode = this.propsData.details[0].itemCode
        this.propsData.qty = this.propsData.details[0].qty
        this.propsData.rawLocationCode = this.propsData.details[0].rawLocationCode
        this.propsData.preStartTime = this.propsData.details[0].preStartTime
        this.propsData.workHour = this.propsData.details[0].workHour
        this.inlineDialogCallback()
      }).catch(err => {
        this.Loading.DrawerLoading = false
      })
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../../../styles/basicData.scss";
</style>