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.Pallethandling',
})
export class Pallethandling extends VuexModule {
  orderNoItemList: any = [];
  @MutationAction
  async queryOrderNo(orderNo: any) {
    const result: any = await http.get(url.lanjumes.product.getInfoByRfid, {
      //loginName: session.loginName,
      params: {
        factoryCode: session.FactoryCode,
        rfid: 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.ErrorPalletHandling, params);
    const SubmitCode = result;
    return { SubmitCode };
  }
  //目的地点下拉列表
  Destination: any = [];
  @MutationAction
  async getpalletDestination(params) {
    const result: any = await http.post(url.lanjumes.product.getDestination, params);
    const DictListoild: [] = result;
    if (DictListoild) {
      const Destination = DictListoild.map((item: any) => ({
        label: item.location,
        value: item.location,
      }));
      return { Destination };
    }
  }
  //起始位置下拉列表
  DictList: any = [];
  @MutationAction
  async getpalletLocation(params) {
    const result: any = await http.post(url.lanjumes.product.getDestination, params);
    const DictListoild: [] = result;
    if (DictListoild) {
      const DictList = DictListoild.map((item: any) => ({
        label: item.location,
        value: item.location,
      }));
      return { DictList };
    }
  }
  //缓存区下拉列表
  locList: any = [];
  @MutationAction
  async getDictList() {
    const result: any = await http.post(url.lanjumes.product.GetBufferLoc, {
      factoryCode: session.FactoryCode,
    });
    const DictListoild: [] = result;
    const locList = DictListoild.map((item: any) => ({
      label: item.location,
      value: item.bufferType,
    }));
    return { locList };
  }
  // bind绑定接口
  @MutationAction
  async bindOrderNo(orderNo: any) {
    const result: any = await http.post(url.lanjumes.product.BindOrderByRFID, {
      //loginName: session.loginName,
      factoryCode: session.FactoryCode,
      rfid: orderNo,
    });
    const SubmitCode = result;
    return { SubmitCode };
  }
}

export default getModule(Pallethandling);
