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 { order } from '@/pages/raw/handover/kan-dan/model';
class OrderInInfo {
  stoAmount?: 0;
  stoNo?: string; //STO采购单号
  orderAmount?: string; //单据总数
  productDescEn?: string; //物料描述
  primaryUom?: string; //单位
}
@Module({
  namespaced: true,
  dynamic: true,
  store,
  name: 'SemiProduct.outbound',
})
export class PickingModule extends VuexModule {
  /**
   * 库位列表
   */
  returningTypeList: any[] = [];
  /**
   * 物料列表
   */
  materielList: any = [];
  /**
   * 条码查询结果
   */
  orderInInfo: OrderInInfo = new OrderInInfo();
  //确认按钮的code码
  code = '';
  //data
  data: any = {};
  /**
   * 查询库位列表
   */
  @MutationAction
  async queryReturningTypeList() {
    const data: any = await http.get(url.inbound.semiFinishProductOfflineRefrigerator.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,
    }));
    return { returningTypeList };
  }
  /**
   * 查询条码号
   * @param orderNo
   */
  @MutationAction
  async queryOrderInInfo(barcode: string) {
    const productCode = barcode;
    const { data, code, msg }: any = await http.post(
      url.inbound.semiFinishProductOfflineRefrigerator.materialCode,
      {
        productCode,
        loginName: session.loginName,
      },
    );
    if (code == '1') {
      uni.showToast({ icon: 'success', title: msg });
    } else {
      uni.showToast({ icon: 'none', title: msg });
    }
    const materielList2 = [];
    materielList2.push(data);
    const materielList = materielList2;
    const orderInInfo = data || {};
    return { materielList, orderInInfo };
  }
  /**
   * 确认按钮
   * @param orderNo
   */
  @MutationAction
  async confirm(list: any[]) {
    const { code, data, msg }: any = await http.post(
      url.inbound.semiFinishProductOfflineRefrigerator.confirm3,
      list,
    );
    if (code == '1') {
      uni.showToast({ icon: 'success', title: msg });
    } else {
      uni.showToast({ icon: 'none', title: msg });
    }
    return { code, data };
  }
}

export default getModule(PickingModule);
