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.raw.ArrivalRegistration',
})
export class ArrivalRegistration extends VuexModule {
  WlList = [];
  orderNoItemList: any = [];
  orderNoItemListdes: any = [];
  @MutationAction
  async PurchaseOrderPda(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceiveSRM.PurchaseOrderPda, data);
    let orderNoItemList: any = [];
    if (result.data.length) {
      orderNoItemList = result.data.map((item: any) => ({
        label: item.materialDesc,
        value: item.materialCode,
        ...item,
      }));
    } else {
      orderNoItemList = [];
    }
    return { orderNoItemList };
  }
  Alreadycode: any = '';
  ProcureOrderAlreadylist: any = '';
  @MutationAction
  async selectOdsProcureOrderAlready(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceiveSRM.selectOdsProcureOrderAlready, data);
    const Alreadycode = result.code;
    const ProcureOrderAlreadylist = result.data;
    return { Alreadycode, ProcureOrderAlreadylist };
  }
  sapPurchasecode: any = '';
  @MutationAction
  async sapPurchaseOrderSync(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceiveSRM.sapPurchaseOrderSync, data);
    const sapPurchasecode = result.code;
    return { sapPurchasecode };
  }
  deliverycode: any = '';
  @MutationAction
  async getDeliveryNoteDetail(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceiveSRM.getDeliveryNoteDetail, data);
    const deliverycode = result.code;
    return { deliverycode };
  }
  SubmitCode: any = '';
  @MutationAction
  async PurchaseOrderdeliPda(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceiveSRM.PurchaseOrderdeliPda, data);
    const SubmitCode: [] = result;
    return { SubmitCode };
  }

  @MutationAction
  async PurchaseOrderdetailPda(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceiveSRM.PurchaseOrderdetailPda, data);
    const orderNoItemListdes = result.data;
    return { orderNoItemListdes };
  }
  DictTypeList: any = [];
  @MutationAction
  async Stashlist() {
    const result: any = await http.post(url.lanjuwms.raw.ReceiveSRM.list, {
      factoryCode: session.FactoryCode,
    });
    const DictTypeListoild: [] = result.data;
    const DictTypeList = DictTypeListoild.map((item: any) => ({
      label: item.warehouseName,
      value: item.warehouseCode,
      ...item,
    }));
    return { DictTypeList };
  }
  //库区查询
  wacodelist: any = [];
  @MutationAction
  async WarehouseList(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceiveSRM.WarehouseList, data);
    const oldwacode = result.data;
    let wacodelist = oldwacode.map((item: any) => ({
      label: item.areaDesc,
      value: item.areaCode,
      ...item,
    }));
    if (!wacodelist.length) {
      wacodelist = [];
    }
    return { wacodelist };
  }
  submitcode: any = '';
  @MutationAction
  async OnSubmit(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceiveSRM.PurchaseOrderdeliPdaConfirm, data);
    const submitcode = result.code;
    return {
      submitcode,
    };
  }
  Arrivalcode: any = '';
  Arrivalmsg: any = '';
  @MutationAction
  async ArrivalRegistration(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceiveSRM.ArrivalRegistration, data);
    const Arrivalcode = result.code;
    const Arrivalmsg = result.msg;
    return {
      Arrivalcode,
      Arrivalmsg,
    };
  }
  singcode: any = '';
  singobj: any = {};
  @MutationAction
  async selectArrivalRegistration(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceiveSRM.selectArrivalRegistration, data);
    const singcode = result.code;
    const singobj = result.data;
    return { singcode, singobj };
  }
  Arrivalcodesh: any = '';
  Arrivalmsgsh: any = '';
  @MutationAction
  async ArrivalRegistrationSH(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceiveSRM.ArrivalRegistrationSH, data);
    const Arrivalcodesh = result.code;
    const Arrivalmsgsh = result.msg;
    return {
      Arrivalcodesh,
      Arrivalmsgsh,
    };
  }
}

export default getModule(ArrivalRegistration);
