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.WhiteManagement.WhiteInstorage',
})
// http.defaults.headers.common['poolName'] = session.PoolName;
export class WhiteInstorage extends VuexModule {
  WlList = [];
  orderNoItemList: any = {};
  Picilist: any = [];
  @MutationAction
  async queryOrderNo(orderNo: any) {
    const result: any = await http.post(url.lanjuwms.WhiteManagement.WhiteInstorage.selectWmsOdsWhiteEmbryoInhAnd, {
      orderCode: orderNo,
      siteCode: session.FactoryCode,
      // headers: {
      //   poolName: session.PoolName,
      // },
    });
    // http.defaults.headers.common['Accept-Language'] = session.PoolName;
    const orderNoItemList = result.data;
    const proOrderWorkorderBatchList = result.data.proOrderWorkorderBatchList;
    const Picilist = proOrderWorkorderBatchList.map((item) => ({
      ...item,
      label: item.batchCode,
      value: item.batchCode,
    }));
    return { orderNoItemList, Picilist };
  }
  productCodeList: any = [];
  @MutationAction
  async list(orderNo: any) {
    const result: any = await http.get(url.lanjuwms.product.OfflineStorage.list + '/' + orderNo, {});
    const productCodeList = result.data;
    return { productCodeList };
  }
  SubmitCode: any = '';
  @MutationAction
  async insertTary(params: any) {
    const result: any = await http.post(url.lanjuwms.product.OfflineStorage.insertTary, params);
    const SubmitCode = result.code;
    return { SubmitCode };
  }
  @MutationAction
  async deleteTray(item: any) {
    console.log(item);
    const result: any = await http.delete(url.lanjuwms.product.OfflineStorage.deleteTray + '/' + item.sn + '/' + item.orderNo);
    const SubmitCode = result.code;
    return { SubmitCode };
  }
  @MutationAction
  async handPut(params: any) {
    const result: any = await http.post(url.lanjuwms.WhiteManagement.WhiteInstorage.addtWmsOdsWhiteEmbryoInhAnd, 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 };
  }
}

export default getModule(WhiteInstorage);
