var util = require('../util/index.js');
var config = require('../../../config/index.js');
const baseUrl = config.default.baseUrl.api;
// let token = util.getAccessToken();
let token = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI1IiwianRpIjoiY2RhNjY2NGEzMzc2MjZjZjE4NDk3M2Y2MjZkMDlmZDVmMzU5NDg2ODkwZGRjNTVlZTUzNDA0ZmQwMjJhNzQxNTY5N2I1ODc5OWQzNDM4MGQiLCJpYXQiOjE2NjQyNDY4MzksIm5iZiI6MTY2NDI0NjgzOSwiZXhwIjoxNjcyMDIyODM5LCJzdWIiOiIzMSIsInNjb3BlcyI6WyIqIl19.kN0BJybVdNGX3n5NXLHEmh032SjNSdMOlfOJQ6yCinCYaPncYk1soqg8Ugkp723OGypusOUYj8lpm2htvSZq184UJ8W634izl0nUCBUzI9cWAKqSF40qg_FlNtXBdaRh2IJyBS0DbLH9v3-BFF2cDlCmE4lTfM7Xbr-5PUGqxBCyqTfxnHYr7RbjOo7l7s6H_8YEL_Gm2cjp4MjP7m2dQFcNTYvWHN1mUuSpoCm64GFsKddUxSea1BwbWJL58mPZ_mvGi3EIUXO0DY3_VKTLsD1cQBs3Mf3afEn8JRWoM4BPbYFCTH-2jaUkUpNHPS6npTCH-TQ1SDJiAuYBZFw_I1rBDJSHlq7vLOkAHFmzFpC-_WjC5oEo5XOhSrRj0TO15RDLEJjBtXJCbCourkZ_yN22WUM4c53gr82zh4vwnGJpE-MHjFfHDgmGT0fk3UAtbUVKxnbIp1hESMJ2e0oWBq5RkmEGYQREhyg1iPNwZzHoPOrgRBIVrFeHcyswNgOcm4fJUJdbvhCBKA7v8kSmArN2v1Pd28BJ8LOTaWdTOS9HJu-FoOtXRuqsPJ63U8Myo6tc-mCjMGsnzpwcRw_7DMoUo4cIuM9uxozJoi_957CX1tioVii_t8CBWky7WqjBC6mjCCqJCXBSXGFCYvNjnvl0SRjEDtF18TjqPwOiXw4'

// 接口请求
function getData(name, data, method) {
	var methodnew = method;
	if(methodnew != 'post'){
		methodnew = 'get';
	}
	uni.showLoading({
		title: '玩命加载中'
	})
	return new Promise((resolve) => {
		uni.request({
			url: baseUrl + name,
			header: {
				"Authorization": token,
				// "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI1IiwianRpIjoiZDg4Y2QxYTI3ZDAwZjIwNzU5ZWNjMjQwZDhkZjg3YzhkODU5YmQ3OTFhMjFiYmUyMzQzNjQ0MDVjNWUzOTIxYzMwMjdiNzQ0Zjc1Y2UzMTciLCJpYXQiOjE2NTY5ODQzNzgsIm5iZiI6MTY1Njk4NDM3OCwiZXhwIjoxNjY0NzYwMzc4LCJzdWIiOiIzMSIsInNjb3BlcyI6WyIqIl19.PsAa4on8UU8DcGJ3McxyXSVAkKHe_tg0Uk2WhwkO_wJiWzOvfGfG7wWqOs67sOZNbyhVpwGk5NNUd194JIOjnppwGiymzLrMSvfRpsYdgFCQ-CCJ62ZZl6Ywva7ihRW4wxmLS2_chdLURwcoSuHHaJeODagkSHfw-nIpVDFsE8YoA5y5q_y7yVQrNPSPO_tuoX_ugtm_1gSOPh4TWVepsolMVz1CAjOpM2qi8UkCagvcpqLKpMMvgSakIW-2KQworuPlKgZQ-WCUrlCB62NPvSQMrXbi1--F69UvUL1gqKyH6jYKOqKa1H0t-M4MfubmeEik8Z9h1qz_UL5_RNGNxtwcdFTzjin2qLs55rmp77fgMf1Y89Cf9GVUJ_0UtRmFrzJh4OHNjHtQojc0np6Yg-LU4qUnm1BH-x-MKdGK209nYEKuTCTDkHt4NwMA5NM5VcFQ430Ovlp0dy8JA6lbq8xSoXVDZq8uVKeo7LQ9yoBrhJNB-HEB5bXWv6bs4gETKq-vgpy8CLDY9aXiOVVnTt5qxrA2iuMkysmv0xnV4PxVbcfT_N6CzItwuPFPWx_bpSK49ahY5K0GCESRaLimS62agGCvms3S4G2hpvvSwAvuNh6YTcLPRLH2OIZdy0i7atkR3oCpVjff52fCgInmvu42YKqovutL79noLi7z0hU"
			},
			method: methodnew,
			data,
			success: res => {
				console.log(res);
				uni.hideLoading();
				var {
					data,
					msg,
					status
				} = res.data;
				if(status == 200){
					resolve(data);
				}else if(status == 401){
					uni.showToast({
						title: msg,
						icon: 'none'
					})
				}else{
					uni.showToast({
						title: msg,
						icon: 'none'
					})
				}
			},
			fail(rep) {
				uni.hideLoading();
			}
		})
	})
}

module.exports = {
	getData
}
