import request from '@/utils/request';


/**
 * 品类库管理/品类库审批列表
 */

export interface libraryData {
  applyDeptId: number;
  approveType: string;
  area: string;
  categoryIds: CategoryId[];
  coscoCategoryLibrarAttachments?: CoscoCategoryLibrarAttachments;
  name: string;
  termOfValidity: string;
  [property: string]: any;
}

export interface CategoryId {
  id?: string;
  lockType?: number;
  [property: string]: any;
}

export interface CoscoCategoryLibrarAttachments {
  attachmentsType: string;
  fileName: string;
  filePath: string;
  fileSize: string;
  fileType: string;
  fileUrl: string;
  [property: string]: any;
}
 export const library = (data: libraryData) => request.post('/cosco/library', { data });
 

/**
 * 品类库管理/品类库审批列表
 */

export interface getPageData {
  basePageRequest: BasePageRequest;
  [property: string]: any;
}

export interface BasePageRequest {
  pageNo: number;
  pageSize: number;
  [property: string]: any;
}
 export const getPage = (data: getPageData) => request.post('/cosco/library/getPage', { data });
 /**
 * 品类库详情
 */
 interface detailData {
  id: string;
}
export const detail = (params: detailData) => request.get(`/cosco/library/detail`, { params });
 /**
 * 查询上级部门锁定品类
 */
export const superiorLockList = () => request.get(`/cosco/library/superiorLockList`);

 /**
 * 查询上级部门锁定品类
 */
 interface treeListData {
  categoryLibraryId: string;
}
 export const treeList = (params: treeListData) => request.get(`/cosco/contain/treeList`, { params });

/**
 *修改品类库锁定状态
 */
//  export interface lockData {
//   categoryLibraryId?: string;
//   lockType?: string;
// }
interface lockData {
  categoryId: string;
  lockType: string;
  categoryLibraryId: string;
}
 export const lock = (data: lockData[]) => request.put('/cosco/contain/lock', { data });

/**
 *添加供应商
 */

export interface applyData {
   categoryLibraryId: string;
   supplierIds: string[];
  [property: string]: any;
}
 export const apply = (data: applyData) => request.post('/cosco/apply', { data });
 

/**
 * 查询添加供应商
 */

 export const getSupplierPage = (data: getPageData) => request.post(`/coscoSupplierBase/getSupplierPage`, { data });
  /**
 * 树形列表接口
 */
export const categoryTree = () => request.get('/cosco/category/categoryTree');


/**
 * 上传文件
 * @param file 上传的文件对象
 * @returns 上传结果
 */
export const uploadFile = async (file: File) => {
  const formData = new FormData();
  formData.append('file', file);

  return request('/fileConfig/files/upload', {
      method: 'POST',
      data: formData,

  });
};

