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.product.SalesReturn',
})
// http.defaults.headers.common['poolName'] = session.PoolName;
export class SalesReturn extends VuexModule {
  WlList = [];
  orderNoItemList: any = [];
  @MutationAction
  async queryOrderNo(orderNo: any) {
    const result: any = await http.post(url.lanjuwms.product.SalesReturn.FinishedProductSalesReturn, {
      productOrder: orderNo,
      factoryCode: session.FactoryCode,
    });
    const orderNoItemList = result.data;
    return { orderNoItemList };
  }
  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.product.SalesReturn.FinishedProductSalesReturnConfirm, 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 };
  }
  selectdata: any = [];
  selectcode: any = '';
  @MutationAction
  async selectSnCorrelationBarcode(sn: string) {
    const result: any = await http.post(url.lanjuwms.product.OfflineStorage.selectSnCorrelationBarcode, {
      siteCode: session.FactoryCode,
      sn: sn,
    });
    const selectdata = result.data;
    const selectcode = result.code;
    return { selectdata, selectcode };
  }
  addsncode: any = '';
  @MutationAction
  async addSnCorrelationBarcode(params: any) {
    const result: any = await http.post(url.lanjuwms.product.OfflineStorage.addSnCorrelationBarcode, params);
    const addsncode = result.code;
    return { addsncode };
  }
  delsncode: any = '';
  @MutationAction
  async deletSnCorrelationBarcode(params: any) {
    const result: any = await http.post(url.lanjuwms.product.OfflineStorage.deletSnCorrelationBarcode, {
      siteCode: session.FactoryCode,
      storageId: params,
    });
    const delsncode = result.code;
    return { delsncode };
  }
  finishCode: any = '';
  @MutationAction
  async finishedProductSalesReturnTD(params: any) {
    const result:any = await http.post(url.lanjuwms.product.SalesReturn.FinishedProductSalesReturnTD, {
      factoryCode:session.FactoryCode,
      createBy:session.loginName,
      productOrder:params,
    });
    const finishCode = result.code;
    return { finishCode };
  }
}

export default getModule(SalesReturn);
