import useStorage from '@/utils/useStroage'

// const baseURL = 'http://192.168.2.128:9000/cashierService'
// const baseURL = 'http://192.168.2.41:9888/cashierService'
const baseURL = 'https://wxcashiertest.sxczgkj.cn/cashierService'
// const baseURL = 'https://cashier.sxczgkj.cn/cashierService'

export default function(api = '', data = {}, method = 'GET') {
	return new Promise((resolve, reject) => {
		uni.request({
			url: `${baseURL}${api}`,
			method: method,
			data: data,
			header: {
				'environment': 'wx',
				'type': 'ios',
				'version': '1.0.0',
				'token': useStorage.get('token'),
				'Content-Type': 'application/json'
			},
			success: res => {
				if (res.data.code == 0) {
					resolve(res.data)
				} else {
					uni.showToast({
						icon: 'none',
						"title": res.data.msg
					})
					reject(res.data.msg)
				}
			},
			fail: err => {
				uni.showToast({
					icon: 'none',
					"title": err.errMsg
				})
				reject(err)
			}
		})
	})
}