
// import Qs from 'qs'
// console.log('qs',qs)
var hostUrl = "http://zhongyao.fscuc.cn"
var hostUrl2 ='http://zy-web.fscuc.cn'

// var hostUrl = "http://zy-web.fscuc.cn"
export const service = (params = {}) => {
	// 发送请求
	
	return new Promise((resolve, reject) => {
		console.log('params.data.data', params.data.data)
		
		let datas = {}
		let query = ''
		let tokens = ''
		if (params.data.data) {
			datas = params.data.data
		}
		if (params.data.token) {
			tokens = params.data.token
		}
		if (params.data.query) {
			// query = params.url + '?' + Qs.stringify(params.data.query)
		} else {
			query = params.url
		}
		
		console.log('params.data.token', tokens)
		uni.request({
			
			url: hostUrl + query, // 接收请求的API
			header: {
				'Authorization':'Bearer '+ tokens,
				// 'Accept': 'application/json, text/plain, */*',
				
				// 'Content-Type': 'application/json',
				// 'Access-Control-Allow-Origin': '*',
			},
			
			method: params.method || 'POST', // 接收请求的方式，如果不传默认为POST
			data: params.data.data,//JSON.stringify(params.data.data), // 接收请求的data，不传默认为空
			
			
			success: res => {
				if (res.statusCode !== 200 && res.statusCode !== 201) {
					return uni.$showMsg('请求失败！请联系平台客服', 2000)
				} else {
					// console.log('api request response>>>', res.data)
					resolve(res)
				}
			},
			fail: err => {
				return uni.$showMsg('请求接口失败！', 2000)
				reject(err)
			}
		})
	})
};

// 直接通过uni.login获取微信接口提供的code
export const login = (params = {}) => {
	return new Promise((resolve, reject) => {
		console.log('request login ', hostUrl)
		uni.request({
			url: hostUrl + '/login/v2',
			method: params.method || 'POST',
			data: JSON.stringify(params), 
			
			success: res => {
				if (res.statusCode !== 200 && res.statusCode !== 201) {
					return uni.$showMsg('请求失败！请联系平台客服', 2000)
				} else {
					// console.log('api request response>>>', res.data)
					resolve(res)
				}
			},
			fail: err => {
				return uni.$showMsg('请求接口失败！', 2000)
				reject(err)
			}
		})
	})
};

// 打印成功后请求这个接口
export const sendToUser = (params = {}) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: hostUrl2 + '/userPrescription/sendToUser',
			method: 'POST',
			data: params.data, 
			headers: { Authorization: "Bearer " + params.token },
			success: res => {
				if (res.statusCode !== 200 && res.statusCode !== 201) {
					return uni.$showMsg('请求失败！请联系平台客服', 2000)
				} else {
					// console.log('api request response>>>', res.data)
					resolve(res)
				}
			},
			fail: err => {
				return uni.$showMsg('请求接口失败！', 2000)
				reject(err)
			}
		})
	})
};

export const selectOrderDetail = (params = {}) => {
	return new Promise((resolve, reject) => {
		uni.request({
			// url: 'http://zhongyao.fscuc.cn' + '/login/v2',
			url: hostUrl + `/prescription/prescriptionCore/selectOrderDetail?id=${params.data.id}&preNo=${params.data.preNo}&depolyStatus=${params.data.depolyStatus}`,
			method: params.method || 'POST',
			data: JSON.stringify(params), 
			header: {
				'Authorization':'Bearer '+ params.data.token,
			},
			success: res => {
				if (res.statusCode !== 200 && res.statusCode !== 201) {
					return uni.$showMsg('请求失败！请联系平台客服', 2000)
				} else {
					// console.log('api request response>>>', res.data)
					resolve(res)
				}
			},
			fail: err => {
				return uni.$showMsg('请求接口失败！', 2000)
				reject(err)
			}
		})
	})
};


export const releaseOrder = (params = {}) => {
	return new Promise((resolve, reject) => {
		uni.request({
			// url: 'http://zhongyao.fscuc.cn' + '/login/v2',
			url: hostUrl + `/pharmacistStatus/releaseOrder?ids=${params.data.ids}`,
			method: params.method || 'POST',
			data: JSON.stringify(params), 
			header: {
				'Authorization':'Bearer '+ params.data.token,
			},
			success: res => {
				if (res.statusCode !== 200 && res.statusCode !== 201) {
					return uni.$showMsg('请求失败！请联系平台客服', 2000)
				} else {
					// console.log('api request response>>>', res.data)
					resolve(res)
				}
			},
			fail: err => {
				return uni.$showMsg('请求接口失败！', 2000)
				reject(err)
			}
		})
	})
};


export const upload = (params = {}) => {
	console.log('upload api params', params)
	return new Promise((resolve, reject) => {
		uni.request({
			
			url: hostUrl + `/common/upload`,
			method: params.method || 'POST',
			data: params.data.file,
			header: {
				'Authorization':'Bearer ', //+ params.data.token,
				
				// 'Accept': 'application/json, text/plain, */*',
				
				'Content-Type': 'multipart/form-data',
				// 'Access-Control-Allow-Origin': '*',
			},
			success: res => {
				if (res.statusCode !== 200 && res.statusCode !== 201) {
					return uni.$showMsg('请求失败！请联系平台客服', 2000)
				} else {
					// console.log('api request response>>>', res.data)
					resolve(res)
				}
			},
			fail: err => {
				return uni.$showMsg('请求接口失败！', 2000)
				reject(err)
			}
		})
	})
};