import { getModule, Module, MutationAction, VuexModule } from 'vuex-module-decorators';
import store from '@/store';
import http from '@/utils/request';
import { url } from '@/utils/url';
import { session } from '@/store/modules/session';
@Module({
  namespaced: true,
  dynamic: true,
  store,
  name: 'page.product.SpecialDelivery',
})
export class SpecialDelivery extends VuexModule {
  orderNoItemList: any = [];
  @MutationAction
  async showProduceCode(orderNo: any) {
    const result: any = await http.post(url.lanjuwms.product.SpecialDelivery.selectQueryFinishedProductSales, {
      deliveryOrder: orderNo,
      factoryCode: session.FactoryCode,
    });
    const orderNoItemList = result.data;
    return { orderNoItemList };
  }

  SubmitCode: any = '';
  @MutationAction
  async selloutconntray(params: any) {
    const result: any = await http.post(url.lanjuwms.product.SaleOutWH.selloutconntray, params);
    const SubmitCode = result.code;
    return { SubmitCode };
  }
  @MutationAction
  async out(params: any) {
    const result: any = await http.post(url.lanjuwms.product.SpecialDelivery.confirmFinishedProductSales, params);
    const SubmitCode = result.code;
    return { SubmitCode };
  }
  scanCode: any = '';
  scandatalist: any = [];
  scandata: any = {};
  //整托
  @MutationAction
  async ScanCodeWholePallet(params: any) {
    const result: any = await http.post(url.lanjuwms.product.SaleOutWH.ScanCodeWholePallet, params);
    const scanCode = result.code;
    const scandatalist = result.data;
    return { scanCode, scandatalist };
  }
  //单箱
  @MutationAction
  async ScanCodeSingleBox(params: any) {
    const result: any = await http.post(url.lanjuwms.product.SaleOutWH.ScanCodeSingleBox, params);
    const scanCode = result.code;
    const scandata = result.data;
    return { scanCode, scandata };
  }
  warehouselist: any = [];
  @MutationAction
  async getwarehouselist() {
    const result = await http.post(url.lanjuwms.raw.ProductionREQ.warehouselist, {
      factoryCode: session.FactoryCode,
    });
    const warehouselist = result.data.map((element: any) => ({
      label: element.userDefined2,
      value: element.userDefined1,
      ...element,
    }));
    return { warehouselist };
  }
  tidancode: any = '';
  @MutationAction
  async selectFinishedProductSales(params) {
    const result: any = await http.post(url.lanjuwms.product.SaleOutWH.selectFinishedProductSales, params);
    const tidancode = result.code;
    return { tidancode };
  }
}

export default getModule(SpecialDelivery);
