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.receivePO',
})
export class receivePO extends VuexModule {
  WlList = [];
  orderNoItemList: any = [];
  orderNoItemListdes: any = [];
  @MutationAction
  async PurchaseOrderPda(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceivePO.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.ReceivePO.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.ReceivePO.sapPurchaseOrderSync, data);
    const sapPurchasecode = result.code;
    return { sapPurchasecode };
  }
  deliverycode: any = '';
  @MutationAction
  async getDeliveryNoteDetail(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceivePO.getDeliveryNoteDetail, data);
    const deliverycode = result.code;
    return { deliverycode };
  }
  SubmitCode: any = '';
  @MutationAction
  async PurchaseOrderdeliPda(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceivePO.PurchaseOrderdeliPda, data);
    const SubmitCode: [] = result;
    return { SubmitCode };
  }

  @MutationAction
  async PurchaseOrderdetailPda(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceivePO.PurchaseOrderdetailPda, data);
    const orderNoItemListdes = result.data;
    return { orderNoItemListdes };
  }
  DictTypeList: any = [];
  @MutationAction
  async Stashlist() {
    const result: any = await http.post(url.lanjuwms.raw.ReceivePO.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.ReceivePO.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 = '';
  submitmsg: any = '';
  @MutationAction
  async OnSubmit(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceivePO.addOrderCardX, data);
    const submitcode = result.code;
    const submitmsg = result.msg;
    return {
      submitcode,
      submitmsg,
    };
  }
  Arrivalcode: any = '';
  Arrivalmsg: any = '';
  @MutationAction
  async ArrivalRegistration(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceivePO.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.ReceivePO.selectArrivalRegistration, data);
    const singcode = result.code;
    const singobj = result.data;
    return { singcode, singobj };
  }
  //最新仓库查询
  workloclist: any = {};
  @MutationAction
  async getworkloc(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceivePO.listTableCK, data);
    const workloclist = result.data;
    // let workloclist = oldworkloclist.map((item: any) => ({
    //   label: item.warehouseName,
    //   value: item.warehouseCode,
    //   ...item,
    // }));
    //let wacode = oldwacode[0].areaCode;
    return { workloclist };
  }
  ///扫描标志卡
  getidcardcode: any = '';
  byidcardobj: any = {};
  @MutationAction
  async getByidcard(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceivePO.selectOrderCard, data);
    const getidcardcode = result.code;
    const byidcardobj = result.data;
    return { getidcardcode, byidcardobj };
  }
}

export default getModule(receivePO);
