import { request } from '../../boot/axios';
import { Pagination } from '../class';
import {
  MaterialAddOrEditForm,
  MaterialSearchEntity,
  MaterialClassAddOrEditForm
} from './model/material';

class MaterialApi {
  getPage = (val: Pagination<MaterialSearchEntity>) => {
    return request.postForPage('materials/page', val);
  };

  add = (val: MaterialAddOrEditForm) => {
    return request.post('materials/add', val);
  };

  edit = (val: MaterialAddOrEditForm) => {
    return request.put('materials/edit', val);
  };

  remove = (val: string) => {
    return request.delete('materials/remove/' + val);
  };

  // pathName + 'updateRemark/' + row.id + '/' + row.remark
  saveRemark = (val?: any) => {
    return request.post(`materials/updateRemark/${val.id}/${val.remark}`);
  };
  // 获取状态字典
  getDnStatus = () => {
    return request.get('/dict/type/dn_status');
  };
  //  获取包装单位
  gePackUnitMap = () => {
    return request.get('materialsunit/getUnitList/1/');
  };
  // 获取记账单位
  getRecordUnitMap = () => {
    return request.get('materialsunit/getUnitList/2/');
  };
  // 获取客户列表
  getCustomerList = () => {
    return request.get('customer/customer-list');
  };
  getStock = (val?: any) => {
    return request.post(`materials/getStock/${val}`, {});
  };
  getStockPage = (val?: any) => {
    return request.post('stock/getStockPage/', val);
  };
  // 获取物料列表 下拉选项
  getMaterialsClassOptionsData = () => {
    return request.get('materials-class/options');
  };
  // 获取物料列表 下拉选项
  getMaterialsClassOptions = (val?: any) => {
    return request.get(`materials-class/options/${val}`);
  };

  materialclassAdd = (val: MaterialClassAddOrEditForm) => {
    return request.post('materials-class/add', val);
  };

  materialClassEdit = (val: MaterialClassAddOrEditForm) => {
    return request.put('materials-class/edit', val);
  };
  materialClassPage = (val: Pagination<MaterialClassAddOrEditForm>) => {
    return request.postForPage('materials-class/page', val);
  };
}
const materialApi = new MaterialApi();
export { materialApi };
