import axios from 'axios';
// var baseURL='https://www.scxjc.club'
var baseURL = ''
axios.interceptors.request.use(
	config => {
		const token = localStorage.getItem('token');
		// if (config.url.indexOf('downloadzip') >= 0) {
			if (token) { // 判断是否存在token，如果存在的话，则每个http header都加上token                      
				config.headers.Authorization = `${token}`;   
			} else {
				//未登录
				window.location.hash = "/login";
			}
		// } 
		return config;
	},
	err => {
		return Promise.reject(err);
	});
axios.interceptors.response.use(function (response) {
	// console.log(response.headers)
	// IE 8-9 
	if (response.data == null && response.config.responseType === 'json' && response.request.responseText != null) {
		try {
			// eslint-disable-next-line no-param-reassign
			response.data = JSON.parse(response.request.responseText);
		} catch (e) {
			// ignored
		}
	}
	// 对响应数据做点什么
	if (response.data.code == 401) {
		window.location.hash = "/login";
	}
	if (response.data.code == 305) {
		window.location.hash = "/";
	}
	return response;
}, function (error) {
	// 对响应错误做点什么
	if (error.request.status == 403) {
		window.location.hash = "/login";
	}
	// console.log(Object.getOwnPropertyNames(error))
	// console.log(error.request,error.message)
	return Promise.reject(error);
});
export default {
	//登录
	login: params => {
		return axios.post(`${baseURL}/api/account/login`, params);
	},
	logout: params => {
		return axios.post(`${baseURL}/api/account/logout`, params);
	},
	getInfo: params => {
		return axios.get(`${baseURL}/api/admin/user`)
	},
	uploadFile: params => {
		return axios.post(`${baseURL}/api/admin/uploadfile`, params);
	},
	getdefault: params => {
		return axios.get(`${baseURL}/api/admin/getdefault`)
	},
	//获取验证码
	getCode: params => {
		return axios.get(`${baseURL}/api/account/imgcode`)
	},
	//政府管理
	getGovermentList: params => {
		return axios.get(`${baseURL}/api/admin/goverment/list`,{params:params})
	},
	downloadMon: params => {
		return axios.get(`${baseURL}/api/admin/monitjob/download`, {
			params: params,
			responseType:'blob'
		})
	},
	getGoverment: params => {
		return axios.get(`${baseURL}/api/admin/goverment`,{params:params})
	},
	saveGoverment: params => {
		return axios.post(`${baseURL}/api/admin/goverment`, params);
	},
	putGoverment: params => {
		return axios.put(`${baseURL}/api/admin/goverment`, params);
	},
	deleteGoverment: params => {
		return axios.delete(`${baseURL}/api/admin/goverment`, {params:params});
	},
	getGovermentList: params => {
		return axios.get(`${baseURL}/api/admin/goverment/list`,{params:params})
	},
	//企业
	getEnterpriseList: params => {
		return axios.get(`${baseURL}/api/admin/enterprise/list`,{params:params})
	},
	getEnterpriseAll: params => {
		return axios.get(`${baseURL}/api/admin/enterprise/all`,{params:params})
	},
	getEnterprise: params => {
		return axios.get(`${baseURL}/api/admin/enterprise`,{params:params})
	},
	deleteEnterprise: params => {
		return axios.delete(`${baseURL}/api/admin/enterprise`, {params:params});
	},
	saveSubent: params => {
		return axios.post(`${baseURL}/api/admin/goverment/subent`, params);
	},
	deleteSubent: params => {
		return axios.delete(`${baseURL}/api/admin/goverment/subent`, {params:params});
	},
	saveEnterprise: params => {
		return axios.post(`${baseURL}/api/admin/enterprise`, params);
	},
	updateEnterprise: params => {
		return axios.put(`${baseURL}/api/admin/enterprise`, params);
	},
	//部门
	getDepartmentList: params => {
		return axios.get(`${baseURL}/api/admin/department/list`,{params:params})
	},
	saveDepartment: params => {
		return axios.post(`${baseURL}/api/admin/department`, params);
	},
	updateDepartment: params => {
		return axios.put(`${baseURL}/api/admin/department`, params);
	},
	deleteDepartment: params => {
		return axios.delete(`${baseURL}/api/admin/department`, {params:params});
	},
	//员工
	getStaffuserList: params => {
		return axios.get(`${baseURL}/api/admin/staffuser/list`,{params:params})
	},
	saveStaffuser: params => {
		return axios.post(`${baseURL}/api/admin/staffuser`, params);
	},
	updateStaffuser: params => {
		return axios.put(`${baseURL}/api/admin/staffuser`, params);
	},
	deleteStaffuser: params => {
		return axios.delete(`${baseURL}/api/admin/staffuser`, {params:params});
	},
	//风险点
	getRiskpointList: params => {
		return axios.get(`${baseURL}/api/admin/riskpoint/list`,{params:params})
	},
	getRiskpoint: params => {
		return axios.get(`${baseURL}/api/admin/riskpoint`,{params:params})
	},
	saveRiskpoint: params => {
		return axios.post(`${baseURL}/api/admin/riskpoint`, params);
	},
	updateRiskpoint: params => {
		return axios.put(`${baseURL}/api/admin/riskpoint`, params);
	},
	deleteRiskpoint: params => {
		return axios.delete(`${baseURL}/api/admin/riskpoint`, {params:params});
	},
	//任务
	getMonittaskList: params => {
		return axios.get(`${baseURL}/api/admin/monittask/list`,{params:params})
	},
	saveMonittask: params => {
		return axios.post(`${baseURL}/api/admin/monittask`, params);
	},
	updateMonittask: params => {
		return axios.put(`${baseURL}/api/admin/monittask`, params);
	},
	deleteMonittask: params => {
		return axios.delete(`${baseURL}/api/admin/monittask`, {params:params});
	},
	uploadMonittask: params => {
		return axios.post(`${baseURL}/api/admin/monittask/upload`, params);
	},
	//巡检
	getMonitjobList: params => {
		return axios.get(`${baseURL}/api/admin/monitjob/list`,{params:params})
	},
	
	//消息
	getMessagesList: params => {
		return axios.get(`${baseURL}/api/admin/messages/list`,{params:params})
	},
	deleteMessages: params => {
		return axios.delete(`${baseURL}/api/admin/messages`, {params:params});
	},
	sendMessage: params => {
		return axios.post(`${baseURL}/api/admin/messages`, params);
	},
	//资料
	getDocumentionList: params => {
		return axios.get(`${baseURL}/api/admin/documention/list`,{params:params})
	},
	saveDoc: params => {
		return axios.post(`${baseURL}/api/admin/documention`, params);
	},
	deleteDoc: params => {
		return axios.delete(`${baseURL}/api/admin/documention`, {params:params});
	},
	//清单
	getBillList: params => {
		return axios.get(`${baseURL}/api/admin/bill/list`,{params:params})
	},
	saveBill: params => {
		return axios.post(`${baseURL}/api/admin/bill`, params);
	},
	deleteBill: params => {
		return axios.delete(`${baseURL}/api/admin/bill`, {params:params});
	},
	//友情链接
	saveFriendlink: params => {
		return axios.post(`${baseURL}/api/admin/friendlink`, params);
	},
	updateFriendlink: params => {
		return axios.put(`${baseURL}/api/admin/friendlink`, params);
	},
	deleteFriendlink: params => {
		return axios.delete(`${baseURL}/api/admin/friendlink`, {params:params});
	},
	getFriendlinkList: params => {
		return axios.get(`${baseURL}/api/admin/friendlink/list`,{params:params})
	},
	//首页可视化
	getChartData: params => {
		return axios.get(`${baseURL}/api/admin/dashboard/index`,{params:params})
	},
}