import { request } from '../../boot/axios';
import { Pagination } from '../class';
import {
  AsnDetailSearchEntity,
  AsnReceiptEntity,
  AsnRowReceivingVOListEntity,
  AsnSearchEntity
} from './model/asn';
const pathName = 'asn';
const pathNameAsnDetail = 'asnRow';
const asnReceivingBatchPath = 'asnReceivingBatch';

class AsnApi {
  getPage = (val?: Pagination<AsnSearchEntity>) => {
    return request.postForPage(`${pathName}/page`, val);
  };
  add = (val?: any) => {
    return request.post(`${pathName}/add`, val);
  };
  delete = (val: number) => {
    return request.delete(`${pathName}/del/${val}`);
  };
  update = (val: any) => {
    return request.post(`${pathName}/update`, val);
  };
  // 收货
  receiving = (val: AsnReceiptEntity) => {
    return request.put(`${pathName}/receiving`, val);
  };
  view = (val1: number, val2: number, val3: number) => {
    return request.get(`${pathName}/viewPrint/${val1}/${val2}/${val3}`);
  };
  getStock = (val?: any) => {
    return request.post(`${pathName}getStock/${val}`, {});
  };
  getStockPage = (val?: any) => {
    return request.post('stock/getStockPage/');
  };
  // 入库单 上架
  putaway = (val?: any) => {
    return request.put(`${pathName}/putaway`, val);
  };
  // 根据 asnId 查询 asnRow列表
  getListByAsnId = (val?: number) => {
    return request.get(`${pathNameAsnDetail}/listByAsnId/${val}`);
  };

  // 查询 asnRow列表
  // 必传 asnId
  // 新增 keyword 模糊搜索 （物料名称、规格型号）
  getListByKeyword = (val?: any) => {
    return request.post(`${pathNameAsnDetail}/listByKeyword`, val);
  };

  // 修改状态
  getFinishEdit = (val?: number) => {
    return request.put(`${pathName}/finishEdit/${val}`);
  };

  // 删除 入库单草稿
  removeById = (val: number) => {
    return request.delete(`${pathName}/removeById/${val}`);
  };

  // 完成收货 修改状态
  overReceiving = (val: number) => {
    return request.put(`${pathName}/overReceiving/${val}`);
  };

  // 根据采购订单 查询
  getSapMarketOrder = (val: any) => {
    return request.post(`${pathName}/getSapMarketOrder`, val);
  };

  // 查询可打印的物料集合
  getAsnPrintList = (val?: Pagination<AsnSearchEntity>) => {
    return request.postForPage(`${pathName}/getAsnPrintList`, val);
  };

  // 入库单 查询 交货单/销售 列表
  getDelivery = (val: any) => {
    return request.post(`${pathName}/getDelivery`, val);
  };
}

const asnApi = new AsnApi();

class AsnRowApi {
  getPage = (val?: Pagination<AsnDetailSearchEntity>) => {
    return request.postForPage(`${pathNameAsnDetail}/page`, val);
  };
  getListByAsnId = (val?: number) => {
    return request.get(`${pathNameAsnDetail}/listByAsnId/${val}`);
  };
}

const asnRowApi = new AsnRowApi();

class AsnReceivingBatchApi {
  getPage = (val?: Pagination<AsnDetailSearchEntity>) => {
    return request.postForPage(`${asnReceivingBatchPath}/page`, val);
  };
}

const asnReceivingBatchApi = new AsnReceivingBatchApi();

export { asnApi, asnRowApi, asnReceivingBatchApi };
