<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"
      :tableSelection="true"
      :MaxResultCount="PageListParams.MaxResultCount"
      :isShowIndex="true"
      @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"
      :tabsDesTions="tabsDesTions"
      :Butttondata="[]"
      @drawerShut="(val) => (displayDialog.detailsDialog = val)"
      @close-value="closeValue"
      :tableColumns="detailsTableColumns"
      :summaryTableColumns="summaryTableColumns"
      :totalCount="totalCountDetails"
      :MaxResultCount="MaxResultCountDetails"
      @alterResultCountDetails="alterResultCountDetails"
      @alertoldSkipCountDetails="alertoldSkipCountDetails"
    ></curren-Drawer>
  </div>
</template>
<script>
import { getPageListWip, convertOk } 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 store from '@/store'
export default {
  name: "unqualifiedToQualified",
  mixins: [
    tableMixins,
    LoadingMixins,
    drawerMixins,
    TableHeaderMixins,
    mixins,
  ],
  data () {
    return {
      //form数据显示操控
      formReveal: true,
      URL: 'wms/store/inspect-note',
      selectionData:[],
      //常用按钮数据
      currenButtonData: [
        this.defaultExportBtn(),//导出
        {
          type: "primary",
          icon: "el-icon-d-arrow-right",
          label: "批量转合格",
          name: "custom",
          size: "mini",
          customHandle: this.convertList()
        },
        this.defaultFieldSettingBtn(),//字段设置
        this.defaultFreshBtn(),//刷新
        this.defaultFilterBtn(),//筛选
      ],
    };
  },
  mounted () {
    this.paging();
  },
  methods: {
    //渲染数据
    paging() {
      this.Loading.tableLoading = true;
      this.PageListParams.SkipCount = (this.oldSkipCount - 1) * this.PageListParams.MaxResultCount,
      getPageListWip(this.PageListParams, 'wms/inventory/inventory-balance/by-hold-location-code-and-no-ok')
        .then(res => {
          this.tableData = res.items
          this.totalCount = res.totalCount
          this.getSupplierByCodesHandle_table()
        }).catch(err => {
          this.Loading.tableLoading = false
        })
    },
    handleSelectionChange(val) {
      this.selectionData = val
    },
    // 批量转合格
    convertList() {
      if (this.selectionData != undefined ) {
        if (this.selectionData.length > 0) {
          this.Loading.appMainLoading = true
          // 20230407
          let params = {
            tenantId: null,
            remark: null,
            extraProperties: null,
            worker: store.getters.name.userName,
            activeDate: new Date(),
            autoSubmit: false,
            autoAgree: false,
            autoHandle: false,
            autoCompleteJob: false,
            directCreateNote: false,
            number: null,
            details: []
            // warehouseCode: null,
            // requestStatus: 0,
            // company: localStorage.getItem('company'),
          }
          // company "DongYang"
          // concurrencyStamp "187ecf6d642e48f68a86f05ceddcbaea"
          // creationTime "2022-10-31T09:07:29.4765498"
          // creatorId null
          // extraProperties null
          // id "5b951169-7e82-f544-4a16-3a073dc120ac"
          // isActive true
          // lastCountLabel null
          // lastCountPlanNumber null
          // lastCountTime "0001-01-01T00:00:00"
          // lastModificationTime null
          // lastModifierId null
          // lastTransNumber null
          // lastTransType 13
          // manageType 1
          // putInTime "2022-10-31T09:07:29.0686103"
          // serialNumber null
          // status 3
          // tenantId null
          this.selectionData.forEach(item => {
            //  20230407
            item.stdPackQty = 0
            item.fromPackingCode = item.packingCode
            item.toPackingCode = item.packingCode
            item.fromLot = item.lot
            item.toLot = item.lot
            item.fromLocationCode = item.locationCode
            item.toLocationCode = item.locationCode
            item.fromLocationGroup = item.locationGroup
            item.toLocationGroup = item.locationGroup
            item.fromLocationArea = item.locationArea
            item.toLocationArea = item.locationArea
            item.fromLocationErpCode = item.locationErpCode
            item.toLocationErpCode = item.locationErpCode
            item.fromWarehouseCode = item.warehouseCode
            item.toWarehouseCode = item.warehouseCode
            item.fromStatus = 3
            item.toStatus = 2
            item.arriveNoticeNumber = null
            item.asnNumber = null
            item.rpNumber = null
            item.poNumber = null
            item.supplierCode = null
            params.details.push(item)
            // item.fromContainerCode = item.containerCode
            // item.toContainerCode = item.containerCode
            // item.stdPackUom = null
          })
          convertOk(params).then(res => {
            this.$message.success('已成功转为合格')
            this.paging()
            this.Loading.appMainLoading = false
          }).catch(err => {
            this.Loading.appMainLoading = false
            console.log(err)
          })
        } else {
          this.$message.warning('请至少选择一条数据！')
        }
      }
      return this.convertList
    }
  }
};
</script>
<style lang="scss" scoped>
@import "../../../styles/mainbasicData.scss";
</style>