//import service from '../service/config.js'
 let u='http://10.88.252.231:8001'
function get(path, callback) {
 	let token
 	uni.getStorage({
 		key: 'token',
 		success: (res) => {
 			token = res.data
 		},
 		fail: () => {
 			uni.showModal({
 				title: '获取token失败',
 			})
 		}
 	})
 	if (!token) {
		uni.navigateTo({
			url: '../../login/login/login'
		});
		return;
 	}
 	return new Promise((resolve, reject) => {
 		uni.request({
 			url: service.url + path,
 			method: 'GET',
 			header: {
			    'Authorization':'Bearer' + token ,
				'content-type':'application/x-www-form-urlencoded'
 			},
 			success: (res) => {
 				var truobj = eval("(" + res.data + ")");
 				resolve(truobj)
 			},
 			fail: (res) => {
 				reject(res)
 				console.log(res)
 			}
 		});
 	});
 }

 function post(path,data,json) {
	 let token ,username,matNo
	// return new Promise((resolve, reject) => {
 	// let token=uni.getStorage("token")
 	//console.log(service.url + path)
	   
	   //从本地缓存中异步获取指定 key 对应的内容。
	  matNo=data.matNo
	  token = json.token,
	  username = json.username
	  // if (token == "" || token == null ||token == undefined || username == "" || username == null || username == undefined) {
	  // 		  uni.showModal({
	  // 		      title: '获取token失败',
	  // 		   }),
			//    //跳转页面
	  // 		uni.navigateTo({
	  // 			//路径
	  // 			url:"../login/login"
	  // 		});
	  // 		return;
	  // }
	  uni.request({
	  	// url :u+path,
		url:"http://192.168.0.103:8899/zlsc/TanShang/findMatMessage.action?matNo=P219724099200",
	  	method: 'POST',
	  	header: {
	  	    'Authorization':  token,
	  		'X-Username': username
	  		// 'content-type': 'application/x-www-form-urlencoded'
	  	},
	  	//data: data,
	  	success: (res) => {
			console.log(res)
	  		console.log("成功")
	  		//var truobj = eval("(" + res.data + ")");
	  		//resolve(res)
	  	},
	  	fail: (res) => {
	  		//reject(res);
	  		console.log("失败");
	  	}
		})
		}
	  

 function getToken(json) {
	 //Promise返回最终操作成功或失败的返回结果,参数对应成功和失败
 	//return new Promise((resolve, reject) => {
 		uni.request({
			
 			url:  "http://maomaochong.top:8899/login",
 			method: 'POST',
 			header: {
 				"Content-Type": "application/json"
 			},
 			data: json,
 			success:(res)=> {
				var r = res.data.data
				console.log(r)
				if(r !="" &&r != null && r !=undefined){
					uni.setStorageSync("token",r)
				}else{
					uni.showModal({
						title: '用户名或密码错误！'
					})
				}
 				
 			},
 			fail: () => {
 				console.log("失败");
 			}
 		});
 	//})
 }


 module.exports = {
 	get: get,
 	post: post,
 	getToken: getToken
 }
