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.mes.PalletChange',
})
export class PalletChange extends VuexModule {
  orderNoItemList: any = [];
  //rfid查询数据
  @MutationAction
  async requestDestinationStation(orderNo: any) {
    const result: any = await http.post(url.lanjumes.product.requestDestinationStation, {
      //loginName: session.loginName,
      factory: session.FactoryCode,
      rfidNo: orderNo,
    });
    const orderNoItemList = result.data;
    return { orderNoItemList };
  }
  @MutationAction
  async empty() {
    const orderNoItemList = [];
    return { orderNoItemList };
  }
  SubmitCode: any = '';
  //提交接口
  @MutationAction
  async palletInforUpdate(params: any) {
    const result: any = await http.post(url.lanjumes.product.saveRfidWithEquip, params);
    const SubmitCode = result.code;
    return { SubmitCode };
  }
  //工厂查询设备类型列表
  DictTypeList: any = [];
  @MutationAction
  async getAllEquipmentsType() {
    const result: any = await http.get(url.lanjumes.product.getDictList, {
      params: {
        equipmentTypeCode: 'equ_type',
      },
    });
    const DictTypeListoild: [] = result.data;
    const DictTypeList = DictTypeListoild.map((item: any) => ({
      label: item.itemName,
      value: item.itemCode,
      ...item,
    }));
    return { DictTypeList };
  }
  //工厂查询设备列表
  DictList: any = [];
  @MutationAction
  async getAllEquipments() {
    const result: any = await http.post(url.lanjumes.product.getAllEquipments, {
      factoryCode: session.FactoryCode,
    });
    const DictListoild: [] = result.data;
    const DictList = DictListoild.map((item: any) => ({
      label: item.equipmentName,
      value: item.equipmentCode,
      ...item,
    }));
    return { DictList };
  }
  //工厂根据设备类型查询设备列表
  seleDictList: any = [];
  @MutationAction
  async getAllEquipmentsle(params: any) {
    const result: any = await http.post(url.lanjumes.product.getAllEquipments, params);
    const DictListoild: [] = result.data;
    const seleDictList = DictListoild.map((item: any) => ({
      label: item.equipmentName,
      value: item.equipmentCode,
      ...item,
    }));
    return { seleDictList };
  }
}

export default getModule(PalletChange);
