<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, confirm, getDetailed } 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"
export default {
  name: "lineSideWarehouseAllocationConfirm",
  mixins: [
    tableMixins,
    LoadingMixins,
    drawerMixins,
    TableHeaderMixins,
    mixins,
  ],
  computed: {
    hideButton: function () {
      return function (val) {
        // 2023-01-03 增加确认人，在导入模板增加一列“确认人”，系统判断，只有该账户能确认调拨数据
        // 获取当前用户名称 判断是否与后端给的确认人一致，如果一致显示按钮
        // console.log(this.$store.getters.name.name)
        let data = true
        val.forEach(key => {
          if (this.propsData.confirmed == key) {
            data = false
          }
        })
        return data
      }
    },
  },
  data () {
    return {
      URL: 'wms/store/transfer-note',
      //常用按钮数据
      currenButtonData: [
        this.defaultFieldSettingBtn(),//字段设置
        this.defaultFreshBtn(),//刷新
        this.defaultFilterBtn(),//筛选
      ],
      DrawerButtonData: [
        {
          type: 'primary',
          icon: 'el-icon-circle-check',
          label: '确认',
          name: "handle",
          hide: () => { return this.hideButton([false]) },
          size: 'mini'
        },
        // {
        //   type: 'danger',
        //   icon: 'el-icon-delete-solid',
        //   label: '作废',
        //   name: "invalid",
        //   hide: () => { return this.hideButton([1]) },
        //   size: 'mini'
        // }
      ],
    };
  },
  mounted () {
    this.paging();
  },
  methods: {
    //抽屉常用按钮
    drawerbutton (val) {
      if (val == 'handle') {
        this.Loading.appMainLoading = true
        let data = {
          id: this.propsData.id
        }
        confirm(this.propsData.id, this.URL).then(res => {
          this.$successMsg('已确认')
          getDetailed(this.propsData.id, this.URL).then(res => {
            this.propsData = res
          })
          this.paging()
          this.Loading.appMainLoading = false
        }).catch(err => {
          console.log(err)
          this.Loading.appMainLoading = false
        })
      }
      //  else if(val == 'invalid'){
      //   let data = {
      //     id: this.propsData.id
      //   }
      //   this.Loading.appMainLoading = true
      //   transferRequestCancel(this.URL, data).then(res=>{
      //      this.displayDialog.detailsDialog = false
      //      this.$successMsg('已作废！')
      //      this.paging()
      //      this.Loading.appMainLoading = false
      //   }).catch(err=>{
      //      console.log(err)
      //      this.Loading.appMainLoading = false
      //   })
      // }
    },
    //渲染数据
    paging() {
      this.Loading.tableLoading = true;
      this.PageListParams.SkipCount = (this.oldSkipCount - 1) * this.PageListParams.MaxResultCount,
      getPageListWip(this.PageListParams, 'wms/store/transfer-note/get-wip-list').then(res => {
          this.tableData = res.items
          this.totalCount = res.totalCount
          this.pagingCallback()
        }).catch(err => {
          this.Loading.tableLoading = false
        })
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../../../styles/basicData.scss";
</style>