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.PurchaseWHPO',
})
export class PurchaseWHPO extends VuexModule {
  WlList = [];
  orderNoItemList: any = [];
  orderNoItemListdes: any = [];
  @MutationAction
  async PurchaseOrderWarehousingPda(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.PurchaseWHPO.PurchaseOrderWarehousingPda, 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 };
  }
  SubmitCode: any = '';
  @MutationAction
  async PurchaseOrderRKPda(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.PurchaseWHPO.PurchaseOrderRKPda, data);
    const SubmitCode: [] = result;
    return { SubmitCode };
  }

  DictTypeList: any = [];
  @MutationAction
  async Stashlist() {
    const result: any = await http.post(url.lanjuwms.raw.PurchaseWHPO.list, {
      factoryCode: session.FactoryCode,
    });
    const DictTypeListoild: [] = result.data;
    const DictTypeList = DictTypeListoild.map((item: any) => ({
      label: item.warehouseName,
      value: item.warehouseCode,
      ...item,
    }));
    return { DictTypeList };
  }
}

export default getModule(PurchaseWHPO);
