import store from '../common/store.js'

class Dataprocessing {
	constructor() {
		this.initial();
	}

	initial() {
		let organlist=[];
		let ip = store.state.wholeSituationBackStageIp;
		let port = store.state.wholeSituationBackStagePort;
		uni.request({
			url: 'http://' + ip + ':' + port + '/GyeeorganController/gyeeOrganAll',
			data: {},
			method: 'GET',
			success: function(res) {


				for (let j = 0; j < res.data.data.length; j++) {

					var obj = {};
					obj.name = res.data.data[j].describes;
					obj.id = res.data.data[j].name;
					organlist.push(obj);
				}
				
				uni.setStorageSync('organlist', organlist);
			}
		})
	}
	//
	putWindPowerStationName(windPowerStationName) {
		uni.setStorageSync('windpowerstationName', windPowerStationName);
	}

	putWindPowerStationId(windPowerStationId) {
		uni.setStorageSync('windPowerStationId', windPowerStationId);
	}

	getWindPowerStationName() {
		return uni.getStorageSync('windpowerstationName');
	}

	getWindPowerStationId() {
		return uni.getStorageSync('windPowerStationId');
	}

	getWindPowerStationNameById(name) {

		let organlist=uni.getStorageSync('organlist');
		for (let j = 0; j < organlist.length; j++) {

			var obj = organlist[j];
			if (obj.name == name) {
				return obj.id;
			}
		}


	}

	getWindPowerStationNameByWeatherId(name) {
		let organlist=uni.getStorageSync('organlist');
		for (let j = 0; j <  organlist.length; j++) {

			var obj =  organlist[j];
			if (obj.name == name) {
				if (obj.id == "0") {
					return store.state.default_weather_wpid;
				} else {
					return obj.id;
				}

			}
		}

	}

	getWindPowerStationNameByNames(name) {
		let organlist=uni.getStorageSync('organlist');
		let windStations = [];
		for (let j = 0; j <  organlist.length; j++) {

			var obj =  organlist[j];
			if (obj.name != name) {
				windStations.push(obj.name);
			}
		}
		return windStations;
	}

	viewUserid() {
		let userid = uni.getStorageSync('userid');
		let ip = store.state.wholeSituationBackStageIp;
		let port = store.state.wholeSituationBackStagePort;
		uni.request({
			url: 'http://' + ip + ':' + port + '/GyeeorganController/GyeeOrganList?userid=' + userid,
			data: {},
			method: 'GET',
			success: function(res) {

				let plusDrawerList = [];
				let plusDrawerList_weather = [];
				for (let j = 0; j < res.data.data.length; j++) {

					var obj = {};
					obj.name = res.data.data[j].describes;
					obj.windId = res.data.data[j].name;

					plusDrawerList.push(obj);
				}
				uni.setStorageSync('windpowerstationName', plusDrawerList[0].name);
				uni.setStorageSync('windPowerStationId', plusDrawerList[0].windId);


				for (let j = 0; j < res.data.data.length; j++) {

					var obj = {};
					obj.name = res.data.data[j].describes;

					if (res.data.data[j].name == '0') {
						obj.windId = store.state.default_weather_wpid;
					} else {
						obj.windId = res.data.data[j].name;
					}
					plusDrawerList_weather.push(obj);
				}

				uni.setStorageSync('plusList', plusDrawerList);
				uni.setStorageSync('plusList_we', plusDrawerList_weather);
			}
		})
	}


	monitoringAuthority() {
		let userid = uni.getStorageSync('userid');
		let ip = store.state.wholeSituationBackStageIp;
		let port = store.state.wholeSituationBackStagePort;
		uni.request({
			url: 'http://' + ip + ':' + port + '/GyeepermissionController/GyeePermissionList?userid=' + userid,
			data: {},
			method: 'GET',
			success: function(res) {

				let leftlist1 = [];
				let leftlist2 = [];
				let leftlist3 = [];
				let leftlist4 = [];
				let leftlist5 = [];

				for (let j = 0; j < res.data.data.length; j++) {

					let gyeePermissionList = res.data.data[j].gyeePermissionList;

					if (j == 0) {
						for (let k = 0; k < gyeePermissionList.length; k++) {
							var obj = {};
							obj.name = gyeePermissionList[k].permisssionname;
							obj.remark1 = gyeePermissionList[k].remark1;
							leftlist1.push(obj);
						}
					} else if (j == 1) {

						for (let k = 0; k < gyeePermissionList.length; k++) {
							var obj = {};
							obj.name = gyeePermissionList[k].permisssionname;
							obj.remark1 = gyeePermissionList[k].remark1;
							leftlist2.push(obj);
						}
					} else if (j == 2) {

						for (let k = 0; k < gyeePermissionList.length; k++) {
							var obj = {};
							obj.name = gyeePermissionList[k].permisssionname;
							obj.remark1 = gyeePermissionList[k].remark1;
							leftlist3.push(obj);
						}
					} else if (j == 3) {

						for (let k = 0; k < gyeePermissionList.length; k++) {
							var obj = {};
							obj.name = gyeePermissionList[k].permisssionname;
							obj.remark1 = gyeePermissionList[k].remark1;
							leftlist4.push(obj);
						}
					} else if (j == 4) {

						for (let k = 0; k < gyeePermissionList.length; k++) {
							var obj = {};
							obj.id = gyeePermissionList[k].id;
							obj.name = gyeePermissionList[k].permisssionname;
							obj.remark1 = gyeePermissionList[k].remark1;
							leftlist5.push(obj);
						}
					}

				}
				uni.setStorageSync('leftlist1', leftlist1);
				uni.setStorageSync('leftlist2', leftlist2);
				uni.setStorageSync('leftlist3', leftlist3);
				uni.setStorageSync('leftlist4', leftlist4);
				uni.setStorageSync('leftlist5', leftlist5);
			}

		})
	}
}


let dataprocessing = new Dataprocessing();
export default  dataprocessing;
