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";
		// window.location.hash = "/";
	}
	if (response.data.code == 305) {
		// window.location.hash = "/";
	}
	return response;
}, function (error) {
	// 对响应错误做点什么
	if (error.request.status == 403) {
		// window.location.hash = "/login";
		window.location.hash = "/";
	}
	// 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);
	},
	// 全局账号信息
	getAccountInfo: params => {
		return axios.get(`${baseURL}/api/account/info`)
	},
	// 验证码
	getCode: params => {
		return axios.get(`${baseURL}/api/account/imgcode`)
	},
	// 账号
	getUserList: params => {
		return axios.get(`${baseURL}/api/admin/user/list`, { params: params })
	},
	getAllSysUserList: params => {
		return axios.get(`${baseURL}/api/admin/user/all`, { params: params })
	},
	// 获取用户待选期刊列表
	getUserJournals: () => {
		return axios.get(`${baseURL}/api/admin/user/journals`)
	},
	// 获取用户待选角色列表
	getUserRoles: () => {
		return axios.get(`${baseURL}/api/admin/user/roles`)
	},
	//新增管理员
	addUser: params => {
		return axios.post(`${baseURL}/api/admin/user`, params);
	},
	// 修改管理员
	editUser: params => {
		return axios.put(`${baseURL}/api/admin/user`, params);
	},
	// 删除管理员
	delUser: params => {
		return axios.delete(`${baseURL}/api/admin/user`, { params: params });
	},
	// 获取角色权限
	getUserPermissions: () => {
		return axios.get(`${baseURL}/api/admin/user/permissions`)
	},
	// 新增表单模板
	addTemplate: params => {
		return axios.post(`${baseURL}/api/admin/message/template`, params);
	},
	// 编辑表单模板
	editTemplate: params => {
		return axios.put(`${baseURL}/api/admin/message/template`, params);
	},
	editTemplateStatus: params => {
		return axios.put(`${baseURL}/api/admin/message/template/status`, params);
	},
	// 删除表单模板
	delTemplate: params => {
		return axios.delete(`${baseURL}/api/admin/message/template`, { params: params });
	},
	// 获取模板详情
	getTemplate: params => {
		return axios.get(`${baseURL}/api/admin/message/template`, { params: params });
	},
	// 获取模板列表
	getTemplateList: params => {
		return axios.get(`${baseURL}/api/admin/message/template/list`, { params: params })
	},
	//获取所有模板列表
	getAllTemplateList: params => {
		return axios.get(`${baseURL}/api/admin/message/template/all`, { params: params })
	},
	// 新增角色
	addRole: params => {
		return axios.post(`${baseURL}/api/admin/role`, params);
	},
	// 修改角色
	editRole: params => {
		return axios.put(`${baseURL}/api/admin/role`, params);
	},
	delRole: params => {
		return axios.delete(`${baseURL}/api/admin/role`, { params: params });
	},
	// 获取角色列表
	getRoleList: params => {
		return axios.get(`${baseURL}/api/admin/role/list`, { params: params });
	},
	// 获取角色详情
	getRoleInfo: params => {
		return axios.get(`${baseURL}/api/admin/role`, { params: params });
	},
	// 消息管理
	addMessage: params => {
		return axios.post(`${baseURL}/api/admin/message`, params);
	},
	editMessage: params => {
		return axios.put(`${baseURL}/api/admin/message`, params);
	},
	editMessageStatus: params => {
		return axios.put(`${baseURL}/api/admin/message/status`, params);
	},
	getMessageList: params => {
		return axios.get(`${baseURL}/api/admin/message/list`, { params: params });
	},
	getMessageReceiverList: params => {
		return axios.get(`${baseURL}/api/admin/message/receiver/list`, { params: params });
	},
	getMessageInfo: params => {
		return axios.get(`${baseURL}/api/admin/message`, { params: params });
	},
	delMessageInfo: params => {
		return axios.delete(`${baseURL}/api/admin/message`, { params: params });
	},
	uploadFile: params => {
		return axios.post(`${baseURL}/api/admin/uploadfile`, params);
	},
	saveSurveyResult: params => {
		return axios.post(`${baseURL}/api/admin/message/survey/result`, params);
	},
	saveSurveyResultOut: params => {
		return axios.post(`${baseURL}/api/admin/message/survey/result/out`, params);
	},
	getMessageSurveyAnalyse: params => {
		return axios.get(`${baseURL}/api/admin/message/survey/analyse`, { params: params });
	},
	getMessageSurveyAnalyseOut: params => {
		return axios.get(`${baseURL}/api/admin/message/survey/analyse/out`, { params: params });
	},
	getMessageSurveyQuestionAnalyse: params => {
		return axios.get(`${baseURL}/api/admin/message/survey/question/analyse`, { params: params });
	},
	downloadSurveyResult: params => {
		return axios.get(`${baseURL}/api/admin/message/survey/result/download`, {
			params: params, responseType: "blob"
		});
	},
	downloadSurveyResultOut: params => {
		return axios.get(`${baseURL}/api/admin/message/survey/result/download/out`, {
			params: params, responseType: "blob"
		});
	},
	downloadAnalyseAll:params => {
		return axios.get(`${baseURL}/api/admin/message/survey/result/download/all`, {
			params: params, responseType: "blob"
		});
	},
	downloadAnalyseItem:params => {
		return axios.post(`${baseURL}/api/admin/message/survey/result/download/item`,params,{responseType:"blob"});
	},
	// 通知管理
	addNotice: params => {
		return axios.post(`${baseURL}/api/admin/message/notice`, params);
	},
	editNotice: params => {
		return axios.put(`${baseURL}/api/admin/message/notice`, params);
	},
	getNoticeList: params => {
		return axios.get(`${baseURL}/api/admin/message/notice/list`, { params: params });
	},
	getNoticeInfo: params => {
		return axios.get(`${baseURL}/api/admin/message/notice`, { params: params });
	},
	delNotice: params => {
		return axios.delete(`${baseURL}/api/admin/message/notice`, { params: params });
	},
	getNoticeAnalyse: params => {
		return axios.get(`${baseURL}/api/admin/message/notice/analyse`, { params: params });
	},
	downloadNoticeAnalyse: params => {
		return axios.get(`${baseURL}/api/admin/message/notice/analyse/download`, {
			params: params, responseType: "blob"
		});
	},
	// 会议相关
	getCityList: params => {
		return axios.get(`${baseURL}/api/admin/common/city`, { params: params });
	},
	getAllOrganizer: params => {
		return axios.get(`${baseURL}/api/admin/journal/organizer/all`, { params: params });
	},
}