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.ProductionREQ',
})
export class ProductionREQ extends VuexModule {
  orderNoItemList: any = [];
  @MutationAction
  async ProductionMaterialRequisition(orderNo: any) {
    const result: any = await http.post(url.lanjuwms.raw.ProductionREQ.ProductionMaterialRequisitionSC, {
      // headers: {
      //   poolName: session.PoolName,
      // },
      userDefined4: orderNo,
      factoryCode: session.FactoryCode,
    });
    // http.defaults.headers.common['Accept-Language'] = session.PoolName;
    const orderNoItemList = result.data.map((element: any) => ({
      label: element.materialDesc,
      value: element.materialCode,
      ...element,
    }));
    return { orderNoItemList };
  }
  information: any = [];
  @MutationAction
  async queryinformation(item: any) {
    const result: any = await http.post(url.lanjuwms.raw.ProductionREQ.ProductionMaterialRequisition, {
      ...item,
      factoryCode: session.FactoryCode,
    });
    const information = result.data.map((element: any) => ({
      label: element.userDefined1,
      value: element.userDefined1,
      ...element,
    }));
    return { information };
  }
  TraysList: any = {};
  @MutationAction
  async showTrays(item: any) {
    const result: any = await http.post(url.lanjuwms.raw.ProductionREQ.ProductionMaterialRequisition, {
      ...item,
      factoryCode: session.FactoryCode,
    });
    const TraysList = result.data[0];
    return { TraysList };
  }
  SubmitCode: any = '';
  selloutconntraydata: any = {};
  @MutationAction
  async selloutconntray(params: any) {
    const result: any = await http.post(url.lanjuwms.raw.ProductionREQ.ProductionMaterialRequisitionsn, {
      sn: params,
      factoryCode: session.FactoryCode,
    });
    const SubmitCode = result.code;
    const selloutconntraydata = result.data;
    return { SubmitCode, selloutconntraydata };
  }
  @MutationAction
  async deleteTray(item: any) {
    console.log(item);
    const result: any = await http.delete(url.lanjuwms.product.SaleOutWH.deleteTray + '/' + item.barcode);
    const SubmitCode = result.code;
    return { SubmitCode };
  }
  Submitmsg: any = '';
  @MutationAction
  async out(params: any) {
    const result: any = await http.post(url.lanjuwms.raw.ProductionREQ.NewConMaterialOutSCNew, params);
    const SubmitCode = result.code;
    const Submitmsg = result.msg;
    return { SubmitCode, Submitmsg };
  }
  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.warehouseName,
      value: element.warehouseCode,
      ...element,
    }));
    return { warehouselist };
  }

  ///扫描标志卡
  getidcardcode: any = '';
  byidcardobj: any = {};
  byidcarmsg: any = '';
  @MutationAction
  async getByidcard(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReceivePO.SweepMaterialCardSC, data);
    const getidcardcode = result.code;
    const byidcardobj = result.data;
    const byidcarmsg = result.msg;
    return { getidcardcode, byidcardobj, byidcarmsg };
  }
}

export default getModule(ProductionREQ);


export function submitReverseMaterialList(data: any): Promise<any> {
  return http.post(url.lanjuwms.raw.ProductionREQ.submitReverseMaterialList, data);
}

export function submitTransferMaterialList(data: any): Promise<any> {
  return http.post(url.lanjuwms.raw.ProductionREQ2.submitTransferMaterialList, data);
}



