chenxiong 3 жил өмнө
parent
commit
6ebcdd3982
1 өөрчлөгдсөн 40 нэмэгдсэн , 51 устгасан
  1. 40 51
      pages2/plan/index.vue

+ 40 - 51
pages2/plan/index.vue

@@ -336,14 +336,11 @@ export default {
 			}
 		},
 		dealMonth(isFirst) {
-			
-			this.swiperList = []
-			let date = new Date();
-			let currentMonth = date.getMonth() + 1;
 			//初始化
 			if(isFirst) {
 				if (this.listItem != null) {
 					this.swiperList = [];
+					this.swiperIndex = 0;
 					for (let i = 0; i < this.listItem.calendarStudyVo.length; i++) {
 						let item = this.listItem.calendarStudyVo[i];
 						let firstItem = item.dayStudyList[0]
@@ -351,15 +348,6 @@ export default {
 							 //补齐1号前的日数凑满一周
 							item.dayStudyList.unshift({ date: 0 });
 						} 
-						if (item.month == currentMonth) {
-							this.swiperIndex = i;
-							if (i > 0) {
-								this.havePreviousMonth = true;
-							}
-							if (i < this.listItem.calendarStudyVo.length - 1) {
-								this.haveNextMonth = true;
-							}
-						}
 						
 							
 						for(let k = 0; k < item.dayStudyList.length; k += 7) {
@@ -373,16 +361,24 @@ export default {
 						
 					}
 					
-					if(!this.calendarStudyVo.dayStudyList) { //计划没有当前月
-						this.swiperIndex = 0;
-						// this.calendarStudyVo = this.listItem.calendarStudyVo[0];
-						
-						if(this.swiperList.length > 1) {
-							console.log('len')
-							this.haveNextMonth = true;
+					let date = new Date();
+					let currentMonth = date.getMonth() + 1;
+					
+					for(let i = 0; i < this.swiperList.length; i++) {
+						if(this.swiperList[i].month == currentMonth) {
+							this.swiperIndex = i;
+							
+							if (i > 0) {
+								this.havePreviousMonth = true;
+							}
+							if (i < this.swiperList.length - 1) {
+								this.haveNextMonth = true;
+							}
+							break;
 						}
 					}
 					
+					
 					this.dealDayList()
 				}
 			} else {  //非初始化
@@ -390,21 +386,24 @@ export default {
 					
 					this.haveNextMonth = false;
 					this.havePreviousMonth = false;
+					let currentMonth = this.listItem.calendarStudyVo.find(item => item.month == this.swiperList[this.swiperIndex].month).month;
 					this.swiperList = []
+					// this.swiperList = [];
 					if (this.listItem != null) {
 						for (let i = 0; i < this.listItem.calendarStudyVo.length; i++) {
 							let item = this.listItem.calendarStudyVo[i];
 							let firstItem = item.dayStudyList[0]
-							for (let i = 0; i < firstItem.studyDay; i++) {
+							for (let j = 0; j < firstItem.studyDay; j++) {
 								 //补齐1号前的日数凑满一周
 								item.dayStudyList.unshift({ date: 0 });
 							} 
+							console.log(currentMonth)
 							if (item.month == currentMonth) {
 								this.swiperIndex = i;
 								if (i > 0) {
 									this.havePreviousMonth = true;
 								}
-								if (i < this.swiperList.length - 1) {
+								if (i < this.listItem.calendarStudyVo.length - 1) {
 									this.haveNextMonth = true;
 								}
 							}
@@ -412,19 +411,10 @@ export default {
 							this.swiperList.push(this.listItem.calendarStudyVo[i])
 						}
 						
-						if(!this.calendarStudyVo.dayStudyList) { //计划没有当前月
-							this.monthIndex = 0;
-							// this.calendarStudyVo = this.listItem.calendarStudyVo[0];
-							
-							if(this.swiperList.length > 1) {
-								console.log('len')
-								this.haveNextMonth = true;
-							}
-						}
-						console.log(this.swiperList)
 						this.dealDayList();
 					}
 				} else { //点击收起日历
+					let currentMonth = this.listItem.calendarStudyVo.find(item => item.month == this.swiperList[this.swiperIndex].month).month;
 					this.swiperList = [];
 					for (let i = 0; i < this.listItem.calendarStudyVo.length; i++) {
 						let item = this.listItem.calendarStudyVo[i];
@@ -433,17 +423,10 @@ export default {
 							 //补齐1号前的日数凑满一周
 							item.dayStudyList.unshift({ date: 0 });
 						} 
-						if (item.month == currentMonth) {
-							this.swiperIndex = i;
-							if (i > 0) {
-								this.havePreviousMonth = true;
-							}
-							if (i < this.swiperList.length - 1) {
-								this.haveNextMonth = true;
-							}
-						}
 						
-							
+						
+						
+						//构建日历表
 						for(let k = 0; k < item.dayStudyList.length; k += 7) {
 							this.swiperList.push({
 								dayStudyList:item.dayStudyList.slice(k,k+7),
@@ -452,19 +435,25 @@ export default {
 							})
 						}
 						
-						
 					}
 					
-					if(!this.calendarStudyVo.dayStudyList) { //计划没有当前月
-						this.swiperIndex = 0;
-						// this.calendarStudyVo = this.listItem.calendarStudyVo[0];
-						
-						if(this.swiperList.length > 1) {
-							console.log('len')
-							this.haveNextMonth = true;
+					for(let i = 0; i < this.swiperList.length; i++) {
+						if(this.swiperList[i].month == currentMonth) {
+							this.swiperIndex = i;
+							
+							if (i > 0) {
+								this.havePreviousMonth = true;
+							}
+							if (i < this.swiperList.length - 1) {
+								this.haveNextMonth = true;
+							}
+							break;
 						}
 					}
 					
+					console.log(this.swiperIndex,'this.swiperIndex')
+					
+					
 					this.dealDayList()
 				}
 			}
@@ -475,7 +464,7 @@ export default {
 			this.listItem = item;
 			this.swiperIndex = 0;
 			this.isOpen = false;
-			this.dealMonth();
+			this.dealMonth(true);
 		},
 		dealDayList() {