Browse Source

课程全选,更改获取课程接口

SanHQin 1 year ago
parent
commit
065460b5c7

+ 1 - 1
src/components/pages/test/add/components/course/courseDilog.vue

@@ -37,7 +37,7 @@ export default {
             immediate: true,
             deep: true,
             handler(newValue, oldValue) {
-                this.courseArray = newValue;
+                this.courseArray = JSON.parse(JSON.stringify(this.courses));
                 this.$forceUpdate()
             }
         }

+ 33 - 1
src/components/pages/test/add/components/course/courseIndex.vue

@@ -127,6 +127,9 @@
                 </div>
               </div>
             </div> -->
+						<div class="chooseAll">
+							<el-checkbox v-model="checkedAll" style="display: flex;">全选</el-checkbox>
+						</div>
           </div>
         </div>
       </div>
@@ -400,6 +403,28 @@
         btnDisplay: false,
       };
     },
+		computed:{
+			checkedAll:{
+				get(){
+					return this.course.every(i=>this.courseArray.includes(i.courseId));
+				},
+				set(newValue){
+					if(newValue){//获取当前页的所有
+						this.course.forEach(i=>{
+							if(!this.courseArray.includes(i.courseId)){
+								this.$emit('updateCourseArray',i.courseId)
+							}
+						})
+					}else{//删除当前页的所有
+						this.course.forEach(i=>{
+							if(this.courseArray.includes(i.courseId)){
+								this.$emit('updateCourseArray',i.courseId)
+							}
+						})
+					}
+				}
+			}
+		},
     methods: {
       change(val) {
         console.log(val);
@@ -1973,5 +1998,12 @@
   
   .buttonBox>div:hover {
     background: #f6f8ff;
-  }</style>
+  }
+
+	.checkedAll >>> .el-checkbox{
+		display: flex !important;
+		align-items: center !important;
+
+	}
+	</style>
   

+ 8 - 14
src/components/pages/test/add/components/course/index.vue

@@ -16,7 +16,7 @@
                 <div @click="openCourse" class="setting">设置课程选择范围</div>
 								<!-- {{courses}} -->
                 <div class="set_title_list">
-                    <div v-for="(item,index) in courses" class="set_title_list_item">
+                    <div v-for="(item,index) in courses" class="set_title_list_item" v-if="coursesList.find(i=>i.courseId==item)">
 											<!-- {{ `课程名称:${item.title}     创建人:${item.username}`}} -->
 											<div class="set_title_list_itemBtn el-icon-remove-outline" @click.stop="delCourse(item)"></div>
 											<div class="set_title_list_itemLabel">
@@ -79,20 +79,14 @@ export default {
             },
             deep: true
         },
-				courses(newValue){
+				async courses(newValue){
 					let result = [];
-					newValue.forEach(async (item,index)=>{
-						let params = {
-							cid: item
-						}
-
-						let data = await this.ajax.get(this.$store.state.api + 'getCourseInfoTest',params);
-						console.log(data)
-						result.push(data.data[0][0]);
-						if(result.length-1==index){
-							this.coursesList = result;
-						}
-					})
+					let params = {
+						cid: this.courses.join(',')
+					}
+					let data = await this.ajax.get(this.$store.state.api + 'getCourseInfoTestAll',params);
+					result = data.data[0]
+					this.coursesList = result;
 				}
     },
     methods: {

+ 14 - 6
src/components/pages/test/check/index.vue

@@ -616,12 +616,20 @@ export default {
               let _answer = topic.courses
               topic.array = _answer
               topic.courseArray = [];
-              topic.array.forEach(async i => {
-                let data = await this.getCourse(i)
-								console.log(data.update_at)
-                data.update_at = new Date(data.update_at).toLocaleString('zh-CN', {year: 'numeric',month: '2-digit',day: '2-digit',hour: '2-digit',minute: '2-digit',second: '2-digit',hour12: false}).replace(/\//g,'-')
-                topic.courseArray.push(data)
-              })
+							let params = {
+								cid:topic.array.join(",")
+							}
+
+							let data = await this.ajax.get(this.$store.state.api + 'getCourseInfoTestAll',params);
+							let result = data.data[0]
+							result.forEach(i=>i.update_at=new Date(i.update_at).toLocaleString('zh-CN', {year: 'numeric',month: '2-digit',day: '2-digit',hour: '2-digit',minute: '2-digit',second: '2-digit',hour12: false}).replace(/\//g,'-'))
+							topic.courseArray = result;
+              // topic.array.forEach(async i => {
+              //   let data = await this.getCourse(i)
+							// 	console.log(data.update_at)
+              //   data.update_at = new Date(data.update_at).toLocaleString('zh-CN', {year: 'numeric',month: '2-digit',day: '2-digit',hour: '2-digit',minute: '2-digit',second: '2-digit',hour12: false}).replace(/\//g,'-')
+              //   topic.courseArray.push(data)
+              // })
             } else if (topic.type == 7) {
               for (var t = parseInt(topic.small); t <= parseInt(topic.big); t++) {
                 topic.array.push({