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.ReturnMaterials',
})
export class ReturnMaterials extends VuexModule {
  orderNoItemList: any = [];
  @MutationAction
  async ProductionMaterialRequisition(orderNo: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReturnMaterials.newselectOrderCardTLTWO, {
      procureCode: orderNo,
      factoryCode: session.FactoryCode,
    });
    // http.defaults.headers.common['Accept-Language'] = session.PoolName;
    const orderNoItemList = result.data;
    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 };
  }
  @MutationAction
  async out(params: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReturnMaterials.addReturnSC, params);
    const SubmitCode = result.code;
    return { SubmitCode };
  }
  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 = {};
  @MutationAction
  async getByidcard(data: any) {
    const result: any = await http.post(url.lanjuwms.raw.ReturnMaterials.selectOrderCardTL, data);
    const getidcardcode = result.code;
    const byidcardobj = result.data;
    return { getidcardcode, byidcardobj };
  }
  //最新仓库查询
  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 };
  }
}

export default getModule(ReturnMaterials);
