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";
import vm from '@/main';
// import { order } from '@/pages/raw/handover/kan-dan/model';
class OrderInInfo {
  stoAmount?: 0;
  stoNo?: string; //STO采购单号
  orderAmount?: string; //单据总数
  Allocated?: string; //已分配
  Unallocated?: string; //未分配
}
@Module({
  namespaced: true,
  dynamic: true,
  store,
  name: "product.inbound.finishProductOffline",
})
export class PickingModule extends VuexModule {
  /**
   * 库位列表
   */
  returningTypeList: any[] = [];
  firstLocation: any = {};
  /**
   * 物料列表
   */
  materielList: any = [];
  /**
   * 条码查询结果
   */
  orderInInfo: OrderInInfo = new OrderInInfo();
  //确认按钮的code码
  code = "";
  //data
  data: any = {};
  /**
   * 查询库位列表
   */
  @MutationAction
  async queryReturningTypeList() {
    const data: any = await http.get(url.inbound.finishProductOffline.kuwei, {
      params: {
        factoryCode: session.factoryCode,
        loginName: session.loginName,
        warehouseCode: session.warehouseCode, //仓库编码
      },
    });
    console.log("data", data.data);
    const returningTypeList = data.data.map((item: any) => ({
      label: item.locationCode,
      value: item.locationCode + '(' + item.sendSpot + ')',
    }));
    const firstLocation = returningTypeList[0];
    // const firstLocation = data.data[0];
    // firstLocation.label = firstLocation.locationCode;
    // firstLocation.value = firstLocation.locationCode + '(' + firstLocation.sendSpot + ')';
    return { returningTypeList, firstLocation };
  }
  /**
   * 查询条码号
   * @param orderNo
   */
  @MutationAction
  async queryOrderInInfo(form: any) {
    console.log("loc", form);
    const { data, code, msg }: any = await http.post(
      url.inbound.finishProductOffline.barcode,
      {
        barcode: form.barCode,
        locCode: form.aimWl.label,
        loginName: session.loginName,
      }
    );
    if (code == "1") {
      uni.showToast({ icon: "success", title: msg });
    } else {
      //uni.showToast({ icon: "none", title: msg });
      vm.customToast(msg);
    }
    const materielList2 = [];
    materielList2.push(data);
    const materielList = materielList2;
    return { materielList };
  }
  /**
   * 确认按钮
   * @param orderNo
   */
  @MutationAction
  async confirm(list: any[]) {
    const { code, data, msg } = await http.post(
      url.inbound.finishProductOffline.confirm,
      list
    );
    console.log("res数据", code, data, msg);
    if (code == "1") {
      uni.showToast({ icon: "success", title: msg });
    } else {
      //uni.showToast({ icon: "none", title: msg });
      vm.customToast(msg);
    }
    return { code, data };
  }
}

export default getModule(PickingModule);
