<template>
	<view class="zt">
		<div class="container" :style="{'width':width,'height':height}">
			<div class="leftInnerMatrix">
				<div v-for="(item,index) in weatherProphetData_8_15" :key="index">
					<weatherCalendarCard8_15 ref="weatherCalendarCard8_15"></weatherCalendarCard8_15>
				</div>
			</div>
		</div>
	</view>
</template>

<script>
	import weatherCalendarCard8_15 from '../../weathercomponents/weatherCalendarCardList8_15/weatherCalendarCard8_15/weatherCalendarCard8_15.vue'
	export default {
		components: {
			"weatherCalendarCard8_15": weatherCalendarCard8_15
		},
		data: function() {
			return {
				width: "",
				height: "",
				weatherProphetData_8_15: [],
				// innerMatrixWidth: "",
				// innerMatrixHeight: "",
				weatherIconsDay: [],
				weatherIconsNight: [],
				classNameDay: "",
				classNameNight: "",
				classNameWeatherIconBackgroundColor: []

			}
		},
		created: function() {

		},
		methods: {
			getWeatherData: function(width, height, weatherProphetData_8_15) {			
				this.width = width + "%";
				this.height = height + "px";
				this.weatherProphetData_8_15 = weatherProphetData_8_15;
				this.weatherIconsDay = [];
				this.weatherIconsNight = [];
				for (let i = 0; i < weatherProphetData_8_15.length; i++) {
					this.weatherIconsDay.push(weatherProphetData_8_15[i].weather1);
					this.weatherIconsNight.push(weatherProphetData_8_15[i].weather2);
				}
				this.commitData();
			},
			commitData: async function() {
				let _this = this;
				await uni.request({
					url: "http://49.4.78.143:8081/WeatherfdController/weatherInformationChangePictureName?model=weatherTemperatureWindSpeedCardList_8_15,weatherTemperatureWindSpeedCard_8_15,white30&weatherInformation=" +
						this.weatherIconsDay, //仅为示例，并非真实接口地址。
					data: {

					},
					method: 'GET',
					success: function(res) {
						//_this.classNameDay = "";
						_this.classNameDay = res.data;
					},
					fail: (e) => {
						console.log(e);
					}
				});
				await uni.request({
					url: "http://49.4.78.143:8081/WeatherfdController/weatherInformationChangePictureName?model=weatherTemperatureWindSpeedCardList_8_15,weatherTemperatureWindSpeedCard_8_15,white30&weatherInformation=" +
						this.weatherIconsNight, //仅为示例，并非真实接口地址。
					data: {

					},
					method: 'GET',
					success: function(res) {
						//_this.classNameNight = "";
						_this.classNameNight = res.data;
						_this.setWeatherIcon();
					},
					fail: (e) => {
						console.log(e);
					}
				});
				
			},
			setWeatherIcon: function() {
				this.classNameWeatherIconBackgroundColor = [];
				for (let i = 0; i < this.classNameDay.length; i++) {
					if (this.classNameDay[i].toLowerCase().search("taiyang") != -1) {
						this.classNameWeatherIconBackgroundColor.push("firstGradeBlue");
					} else if (this.classNameDay[i].toLowerCase().search("xue") != -1) {
						this.classNameWeatherIconBackgroundColor.push("fourGradeBlue");
					} else if (this.classNameDay[i].toLowerCase().search("shui") != -1 || this.classNameDay[i].toLowerCase().search(
							"sanhenggang") != -1) {
						this.classNameWeatherIconBackgroundColor.push("threeGradeBlue");
					} else {
						this.classNameWeatherIconBackgroundColor.push("twoGradeBlue");
					}
				}
				this.pushWeatherData();
			},
			pushWeatherData: function() {
				
				for (let i = 0; i < this.weatherProphetData_8_15.length; i++) {
					this.$nextTick(function(){
						this.$refs.weatherCalendarCard8_15[i].getWeatherData(this.width, this.height,
							this.classNameWeatherIconBackgroundColor[i], this.classNameDay[i], this.classNameNight[i], this.weatherProphetData_8_15[
								i]);
					})
					
				}
			}
		}
	}
</script>

<style scoped="scoped">
</style>
