// 民宿接口前缀
const BASE_URL = "https://www.jinganrenjiams.com/hotelReservation"

// 商城接口前缀
const BASE_URL_SHOP = "https://www.jinganrenjiams.com/cloud-mall"

export const myRequest = (options) => {
	uni.showLoading({
		title: "加载中",
		mask: true,
	});
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + options.url,
			method: options.method || "GET",
			header: options.header || {
				'userId': uni.getStorageSync('userInfo').id
			},
			data: options.data || {},
			timeout: 10000,
			success: (res) => {
				if (res.data.code === 200 || res.data.code === 205) {
					resolve(res.data)
				} else {

				}
			},
			fail: (err) => {
				uni.showToast({
					title: "请求发送失败",
					icon: "none",
					mask: true
				})
				reject(err)
			},
			complete: (res) => {
				// console.log(res);
				uni.hideLoading({
					complete: (hide) => {
						// console.log(hide);
						if (res.data.code === 200) {

						} else {
							uni.showToast({
								title: res.data.message ? res.data.message :
									'报错',
								icon: "none",
								mask: true
							})
						}
					}
				});
			}
		})
	})
}

export const myRequest_shop = (options) => {
	uni.showLoading({
		title: "加载中",
		mask: true,
	});
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL_SHOP + options.url,
			method: options.method || "GET",
			// header: options.header || {
			// 	'userId': uni.getStorageSync('userInfo').id
			// },
			data: options.data || {},
			timeout: 10000,
			success: (res) => {
				if (res.data.code === '1') {
					resolve(res.data)
				} else {

				}
			},
			fail: (err) => {
				uni.showToast({
					title: "请求发送失败",
					icon: "none",
					mask: true
				})
				reject(err)
			},
			complete: (res) => {
				// console.log(res);
				uni.hideLoading({
					complete: (hide) => {
						// console.log(hide);
						if (res.data.code === '1') {

						} else {
							uni.showToast({
								title: res.data.message ? res.data.message :
									'报错',
								icon: "none",
								mask: true
							})
						}
					}
				});
			}
		})
	})
}