// export const BASE_URL = 'https://mz.tshe.cn/collection';
// #ifdef H5
export const BASE_URL = '/prod-api';
// #endif
// #ifndef H5
// export const BASE_URL = 'http://10.16.4.5:8080';//孙坤阳
// export const BASE_URL = 'http://10.16.4.9:8080';//陈航
export const BASE_URL = 'https://mz.tshe.cn/prod-api';//陈航
// export const BASE_URL = 'http://121.36.73.159:8055';//线上
// #endif

export const myRequest = (url, data, method, header) => {
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title: '加载中'
		});
		uni.request({
			url: BASE_URL + url,
			method: method || 'POST',
			header: {
				
				// 'Authorization': "app-829f4a08-d148-4d0f-a4ad-e22695f44426",
				'Authorization': uni.getStorageSync('token'),
				'content-type': 'application/x-www-form-urlencoded',
				 // 'content-type': 'application/json',
				...header
			},
			data: data || {},
			// data:{
			// 	loginName:'chenhang',
			// 	password:'sigezuishuai'
			// },
			success: (response) => {
				console.log(response, 'response');
				let code = response.data.code;
				let msg = response.data.msg;
				if (code == 200) {
					resolve(response.data)
				} else if (code == 401) {
					uni.setStorageSync("token","");
					uni.setStorageSync("user","");
					uni.setStorageSync("paper","");
					uni.navigateTo({
						url: '/pages/index/index'
					});
					// uni.showToast({
					// 	title: msg,
					// 	icon: 'none',
					// 	duration: 5000
					// })
					uni.showModal({
						title: '提示',
						content: msg,
						showCancel:false,
						success: function (res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				} else if(code == 500){
					console.log(code,'code');
					console.log(msg,'msg');
					// uni.showToast({
					// 	title: msg,
					// 	icon: 'none',
					// 	duration: 5000
					// })
					
					uni.showModal({
						title: '提示',
						content: msg,
						showCancel:false,
						success: function (res) {
							if (res.confirm) {
								console.log('用户点击确定');
								if(url=='/auth/app/phoneLogin')
								{
									uni.setStorageSync("token", "");
									uni.setStorageSync("user", "");
									// #ifdef H5
									location.reload();
									//	#endif
								}
								else if(url.indexOf("/education/app/exam/startExam/") != -1){
									// #ifdef H5
									location.reload();
									//	#endif
								}
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				} 
				else{
					if (msg && msg != ' ') {
						// uni.showToast({
						// 	title: msg,
						// 	icon: 'none',
						// 	duration: 5000
						// })
					uni.showModal({
						title: '提示',
						content: msg,
						showCancel:false,
						success: function (res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					}
					// resolve(response.data)
				}
			},
			fail: (err) => {
				return uni.showToast({
					title: '请求接口失败' + err
				})
				reject(err)
			},
			complete: () => {
				uni.hideLoading();
			}
		})

	})

}
