import Http from "../utils/net/Http";
import Urls from "./Urls";
const tagInfo = "[/src/api/Company.ts]:";
/**
 * 企业模型
 */
let Company = {
	/**
	 * 添加企业
	 * @returns
	 */
	async add(param: object = {}): Promise<any> {
		let url = Urls.company.addEnterPrise;
		let res = await Http.post(url, param);
		return res;
	},
	async edit(param: object = {}): Promise<any> {
		let url = Urls.company.editEnterPrise;
		let res = await Http.post(url, param);
		return res;
	},
	/**
	 * 获取企业列表
	 * @returns
	 */
	async getEnterpriseList(keyword: string = "", page: number = 1, pageSize: number = 10): Promise<any> {
		let url = Urls.company.getEnterprise;
		let param = {
			keyword,
			page,
			pageSize
		};
		let res = await Http.get(url, param);
		return res;
	},
	/**
	 * 获取企业详情
	 * @param id 企业id
	 * @returns
	 */
	async getEnterpriseDetail(id: number | string): Promise<any> {
		let url = Urls.company.getEnterpriseDetail;
		let param = {
			enterprise_id: id
		};
		let res = await Http.get(url, param);
		if (res.code != 0) {
			return res;
		}
		let photoList: Array<any> = [];
		if (res.data.enterprise.photo) {
			//如果有相册
			let photoListOrg = res.data.enterprise.photo.split(",");
			//console.log(tagInfo, "photoListOrg", photoListOrg);
			photoListOrg.forEach((item: string) => {
				let obj = {
					url: item
				};
				photoList.push(obj);
			});
		}
		res.data.enterprise.photo_list = photoList;
		//console.log(tagInfo, "getEnterpriseDetail res.data.enterprise.photo_list", res.data.enterprise, res.data.enterprise.photo_list);
		return res;
	},
	/**
	 * 删除企业
	 * @param ids  	删除的企业id集合以逗号隔开
	 * @returns
	 */
	async delEnterPrise(ids: Array<number | string>): Promise<any> {
		let url = Urls.company.delEnterPrise;
		let param = {
			ids
		};
		let res = await Http.get(url, param);
		return res;
	}
};
export default Company;
