// 线上地址
const BASE_URL = "https://chtech.ncjti.edu.cn/jiaofei/jiaofei-api/tuitionpayment"
// 本地地址
// const BASE_URL = "http://192.168.161.34:9999/tuitionpayment"
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",
			data: options.data || {},
			header: {
				'card_number': localStorage.getItem("card_number")
			},
			success: (res) => {
				uni.hideLoading();
				resolve(res.data)
				if (!res.data.success) {
					if (res.data.code == 10028 || res.data.code == 10029) {
						uni.showModal({
							title: "提示",
							content: res.data.message,
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									uni.reLaunch({
										url: "/pages/home/home",
									});
								}
							},
						});
					} else {
						uni.showToast({
							title: res.data.message,
							icon: "error",
							mask: true,
						});
					}
				}
			},
			fail: (err) => {
				uni.hideLoading();
				uni.showToast({
					title: "请求数据失败",
					icon: "none",
					mask: true
				})
				reject(err)
			}
		})
	})
}
