<template>
	<div class="ev-list-container" style="width: 98%; margin: 0 auto"  >
		<!-- 筛选部分 -->
		<Loading :top="200" v-show="dataLoading" hideMask type="1"></Loading>
		<div class="filter-wrap">
			<div class="filter-item" v-show="!isShowSchoolBank">
				<span class="filter-title">{{$t('evaluation.filter.origin')}}:</span>
				<RadioGroup v-model="filterOrigin" type="button" @on-change="filterOriginChange">
					<Radio :label="schoolCode" v-if="isShowSchoolBank">{{$t('evaluation.filter.schoolBank')}}</Radio>
					<Radio :label="userId">{{$t('evaluation.filter.privateBank')}}</Radio>
					<Radio :label="schoolCode" v-if="!isShowSchoolBank && hasSchool">{{$t('evaluation.filter.schoolBank')}}</Radio>
				</RadioGroup>
			</div>
			<div class="filter-item" v-show="isShowSchoolBank || (filterOrigin === schoolCode)">
				<span class="filter-title">{{$t('evaluation.filter.period')}}:</span>
				<RadioGroup v-model="filterPeriod" type="button" @on-change="filterPeriodChange">
					<Radio v-for="(item, index) in periodList" :key="index" :label="index">{{ item.name }}<span class="filter-count">（{{ periodCountArr.length ? periodCountArr[index] : 0 }}）</span></Radio>
				</RadioGroup>
			</div>
			<div class="filter-item" v-show="isShowSchoolBank || (filterOrigin === schoolCode)">
				<span class="filter-title">{{$t('evaluation.filter.grade')}}:</span>
				<CheckboxGroup v-model="filterGrade" border @on-change="filterGradeChange">
					<Checkbox lable="all">{{$t('evaluation.filter.all')}}</Checkbox>
					<Checkbox v-for="(item, index) in gradeList" :key="index" :label="index">{{ item }} <span class="filter-count">（{{ gradeCountArr.length ? gradeCountArr[index] : 0 }}）</span></Checkbox>
				</CheckboxGroup>
			</div>
			<div class="filter-item" v-show="isShowSchoolBank || (filterOrigin === schoolCode)">
				<span class="filter-title">{{$t('evaluation.filter.subject')}}:</span>
				<CheckboxGroup v-model="filterSubject" border @on-change="filterSubjectChange">
					<Checkbox lable="all">{{$t('evaluation.filter.all')}}</Checkbox>
					<Checkbox v-for="(item, index) in subjectList" :key="index" :label="item.id">{{ item.name }}<span class="filter-count">（{{ subjectCountArr.length ? subjectCountArr[index] : 0 }}）</span></Checkbox>
				</CheckboxGroup>
			</div>
			<div class="filter-item">
				<span class="filter-title">{{$t('evaluation.filter.type')}}:</span>
				<CheckboxGroup v-model="filterType" border @on-change="filterTypeChange">
					<Checkbox label="all">{{$t('evaluation.filter.all')}}</Checkbox>
					<Checkbox label="single">{{$t('evaluation.single')}}</Checkbox>
					<Checkbox label="multiple">{{$t('evaluation.multiple')}}</Checkbox>
					<Checkbox label="judge">{{$t('evaluation.judge')}}</Checkbox>
					<Checkbox label="complete">{{$t('evaluation.complete')}}</Checkbox>
					<Checkbox label="subjective">{{$t('evaluation.subjective')}}</Checkbox>
					<Checkbox label="connector">{{$t('evaluation.connector')}}</Checkbox>
					<Checkbox label="correct">{{$t('evaluation.correct')}}</Checkbox>
					<Checkbox label="compose">{{$t('evaluation.compose')}}</Checkbox>
				</CheckboxGroup>
			</div>
			<div class="filter-item">
				<span class="filter-title">{{$t('evaluation.filter.diff')}}:</span>
				<CheckboxGroup v-model="filterDiff" border @on-change="filterDiffChange">
					<Checkbox label="all">{{$t('evaluation.filter.all')}}</Checkbox>
					<Checkbox v-for="(item, index) in exersicesDiff" :key="index" :label="index + 1">{{ item }}</Checkbox>
				</CheckboxGroup>
			</div>
			<div class="filter-item">
				<span class="filter-title">{{$t('evaluation.filter.level')}}:</span>
				<CheckboxGroup v-model="filterField" border @on-change="filterFieldChange">
					<Checkbox label="all">{{$t('evaluation.filter.all')}}</Checkbox>
					<Checkbox :label="1">{{$t('evaluation.level1')}}</Checkbox>
					<Checkbox :label="2">{{$t('evaluation.level2')}}</Checkbox>
					<Checkbox :label="3">{{$t('evaluation.level3')}}</Checkbox>
					<Checkbox :label="4">{{$t('evaluation.level4')}}</Checkbox>
					<Checkbox :label="5">{{$t('evaluation.level5')}}</Checkbox>
					<Checkbox :label="6">{{$t('evaluation.level6')}}</Checkbox>
				</CheckboxGroup>
			</div>
			<div class="filter-item">
				<span class="filter-title">{{$t('evaluation.filter.sort')}}:</span>
				<RadioGroup v-model="filterSort" type="button" @on-change="filterSortChange">
					<Radio label="createTime">{{$t('evaluation.filter.createTime')}}
						<Icon type="md-arrow-round-down" />
					</Radio>
					<Radio label="useCount">{{$t('evaluation.filter.useCount')}}
						<Icon type="md-arrow-round-down" />
					</Radio>
				</RadioGroup>
			</div>
		</div>
		<!-- 筛选部分结束 -->
		<!-- 题目列表部分 -->
		<div v-if="exerciseList.length === 0" class="no-data-text">
			<img src="@/assets/icon/no_data_evaluation.png" width="120" />
			<span style="margin-top: 15px; color: #808080">{{$t('evaluation.noData')}}</span>
		</div>
		<div class="content-wrap" ref="mathJaxContainer" v-else>
			<!-- <Loading :top="100" v-show="dataLoading" hideMask></Loading> -->
			<div class="exercise-item" v-for="(item, index) of exerciseList" :key="index" @click="onQuestionToggle(index, item.id, $event)">
				<!-- 题干部分 -->
				<div class="item-question">
					<div>
						<div class="item-question-order">
							{{ pageSize * (pageNum - 1) + index + 1 }} :
						</div>
						<div class="item-question-text" v-html="item.question"></div>
					</div>
					<span class="item-btn-toggle" style="justify-content: flex-end;">
						<Icon :type="
                collapseList.indexOf(index) > -1
                  ? 'ios-arrow-dropup'
                  : 'ios-arrow-dropdown'
              " />
					</span>
				</div>
				
				<div class="exercise-item-children" v-if="item.children.length">
					<BaseChild :children="item.children"></BaseChild>
				</div>
				
				<!-- 选项部分 -->
				<div v-for="(option, optionIndex) in item.option" :key="optionIndex" class="item-options">
					<div class="item-option-content">
						<div class="item-option-order">
							{{ String.fromCharCode(64 + parseInt(optionIndex + 1)) }} :
						</div>
						<div class="item-option-text" v-html="option.value"></div>
					</div>
				</div>
				<transition name="slide"  v-if="item.type !== 'compose'">
					<div v-show="collapseList.indexOf(exerciseList.indexOf(item)) > -1" class="toggle-area">
						<div>
							<!-- 答案展示部分 -->
							<div class="item-explain">
								<span class="explain-title">【{{$t('evaluation.answer')}}】</span>
								<div class="item-explain-details">
									<!-- 问答题答案 -->
									<div v-if="item.type === 'subjective' || item.type === 'complete' || item.type === 'connector' || item.type === 'correct' ">
										<span v-for="(answer, index) in item.answer" :key="index" v-html="item.answer.length ? answer : $t('evaluation.noAnswer')"></span>
									</div>
									<!-- 判断题答案 -->
									<div v-else-if="item.type === 'judge'">
										<span>{{ item.answer.length ? (item.answer[0] === 'A' ? $t('evaluation.isTrue') : $t('evaluation.isFalse')) : $t('evaluation.noAnswer') }}</span>
									</div>
									<!-- 其余题型答案 -->
									<div v-else>
										<span :class="[ item.type === 'complete' ? 'item-answer-item' : '']" v-for="(answer, index) in item.answer"
										 :key="index">{{ answer }}</span>
									</div>
								</div>
							</div>
							<!-- 解析部分 -->
							<div class="item-explain">
								<span class="explain-title">【{{$t('evaluation.explain')}}】</span>
								<div class="item-explain-details">
									<span v-html="item.explain ||$t('evaluation.noExplain')"></span>
								</div>
							</div>
							<!-- 知识点部分 -->
							<div class="item-explain">
								<span class="explain-title">【{{$t('evaluation.knowledgePoints')}}】</span>
								<div class="item-explain-details">
									<span v-if="!item.knowledge || !item.knowledge.length">{{$t('evaluation.noPoints')}}</span>
									<div v-else>
										<span v-for="(point, index) in item.knowledge" class="item-point-tag" :key="index">
											{{ point }}
										</span>
									</div>
								</div>
							</div>
						</div>
						<!-- 如果是综合题 则加载子题渲染组件 -->
						<!-- <div v-else>
							<BaseChild :children="item.children"></BaseChild>
						</div> -->
					</div>
				</transition>
				<!-- 底部题目操作栏 -->
				<div class="item-tools">
					<span class="item-tools-info">{{$t('evaluation.filter.type')}}：{{ exersicesType[item.type] }}</span>
					<span class="item-tools-info">{{$t('evaluation.filter.diff')}}：{{ exersicesDiff[item.level - 1] }}</span>
					<span class="item-tools-info">{{$t('evaluation.filter.level')}}：{{ exersicesField[item.field - 1] }}</span>
					<span class="item-tools-info">{{$t('evaluation.filter.useCount')}}：{{ item.usageCount || 0 }} {{ $t('unit.text4') }}</span>
					<span class="item-tools-info">{{$t('evaluation.updateTime')}}：{{ $tools.formatTime(item.createTime)  || 0 }} </span>

					<!--<span class="item-tools-info" style="border:0">更新时间：{{ formatDateTime(new Date(item.createTime * 1000)) }}</span>-->
					<!--<Button type="info" :style="{backgroundColor:basketList.all.indexOf(item) > -1 ? '#bbbbbb' : ''}" @click="handleChoose(item)">{{basketList.all.indexOf(item) > -1 ? '已选入' : '选题'}} </Button>-->
					<Button type="text" @click.stop="handleDelete(item)" v-if="($access.can('admin.*||exercise-upd') ||  (filterOrigin !== schoolCode))"
					 icon="md-trash">{{$t('evaluation.deleteItem')}}</Button>
					<Button type="text" @click.stop="handleEdit(item)" v-if="($access.can('admin.*||exercise-upd') ||  (filterOrigin !== schoolCode))"
					 icon="md-create">{{$t('evaluation.editItem')}}</Button>
					
				</div>
			</div>
		</div>

		<Modal v-model="editExerciseModal" class-name="edit-exercise-modal" width="1200px" footer-hide @on-visible-change="editModalChange"
		 :title="$t('evaluation.editItem')">
			<template v-if="!hasSchool || periodList.length">
				<BaseEditExercise :exerciseItem="currentExercise" @onEditSuccess="onEditSuccess" refId="listEdit" ref="editRef"></BaseEditExercise>
			</template>
			<div slot="footer">
				<Button type="success">{{$t('evaluation.editItem')}}</Button>
			</div>
		</Modal>

		<!-- 底部分页区域 -->
		<Page :total="totalNum" show-sizer show-total :page-size="pageSize" :current="pageNum" @on-page-size-change="pageSizeChange"
		 @on-change="pageChange" :page-size-opts="[5, 10, 15, 20]" />
	</div>
</template>
<script>
	export default {
		data() {
			return {
				userId: "",
				schoolCode: "null",
				isShowSchoolBank: false,
				dataLoading: false,
				editExerciseModal: false,
				currentExercise: {},
				exerciseList: [],
				schoolInfo: {},
				isShowUploadList: false,
				exersicesType: this.$GLOBAL.EXERCISE_TYPES(),
				exersicesDiff: this.$GLOBAL.EXERCISE_DIFFS(),
				exersicesField: this.$GLOBAL.EXERCISE_LEVELS(),
				diffColors: ["#32CF74", "#E8BE15", "#F19300", "#EB5E00", "#D30000"],
				filterType: ["all"],
				filterOrigin: "",
				filterDiff: ["all"],
				filterField: ["all"],
				filterSort: "createTime",
				filterPeriod: 0,
				filterGrade: [false],
				filterSubject: [false],
				totalNum: 0,
				isShowAnswer: true,
				importLoading: false,
				pageSize: 5,
				pageNum: 1,
				currentPage: 1,
				collapseList: [],
				periodList: [],
				gradeList: [],
				subjectList: [],
				filterParams: {},
				allPointList: [],
				originData: [],
				flag:false,
				gradeCountArr:[],
				subjectCountArr:[],
				periodCountArr:[]
			};
		},
		created() {
			
			this.isShowSchoolBank = this.$route.name === "schoolBank";
			this.$EventBus.$on("showSchoolBank", (val) => {
				if (val) {
					this.isShowSchoolBank = val;
				} else {
					this.isShowSchoolBank = false;
				}
			});
			this.getSchoolInfo();
			// this.getBlobOrigin()
		},
		methods: {

			/** 获取区班校信息 */
			getSchoolInfo() {
				this.dataLoading = true;
				try {
					this.$store.dispatch("user/getSchoolProfile").then((res) => {
						let schoolBaseInfo = res.school_base;
						if (schoolBaseInfo) {
							this.schoolInfo = schoolBaseInfo;
							this.schoolCode = schoolBaseInfo.id;
							this.userId = this.$store.state.userInfo.TEAMModelId;
							this.filterOrigin = this.isShowSchoolBank ?
								this.$store.state.userInfo.schoolCode :
								this.$store.state.userInfo.TEAMModelId;
							this.periodList = schoolBaseInfo.period;
							if (schoolBaseInfo.period.length) {
								this.gradeList = schoolBaseInfo.period[0].grades;
								this.subjectList = schoolBaseInfo.period[0].subjects;
							}
						}
						this.doFilter();
					});
				} catch (e) {
					// 当前未加入学校
					this.doFilter();
				}

			},


			/** 执行筛选条件获取数据 */
			doFilter(filterKey) {
				this.dataLoading = true;
				this.collapseList = []; // 所有详情都收起来
				/** 定义查询接口的参数规格 */
				this.filterParams = {
					"@DESC": this.filterSort,
					code: (this.isShowSchoolBank || (this.filterOrigin === this.schoolCode)) ? this.$store.state.userInfo.schoolCode :
						this.$store.state.userInfo.TEAMModelId,
					periodId: (this.isShowSchoolBank || (this.filterOrigin === this.schoolCode)) && this.periodList.length && this.flag ? [this.periodList[
						this.filterPeriod].id] : [],
					"gradeIds[*]": (this.isShowSchoolBank || (this.filterOrigin === this.schoolCode)) ?
						this.deleteFalse(this.filterGrade).map(i => i + '') : [],
					subjectId: (this.isShowSchoolBank || (this.filterOrigin === this.schoolCode)) ?
						this.deleteFalse(this.filterSubject) : [],
					level: this.deleteFalse(this.filterDiff),
					type: this.deleteFalse(this.filterType),
					field: this.deleteFalse(this.filterField),
					scope: this.curScope,
					pid: null
				};
				this.getExerciseList(this.filterParams,filterKey);
			},

			/**
			 * 获取最新题库列表
			 * @param data
			 */
			async getExerciseList(data,filterKey) {
				let that = this;
				this.$api.newEvaluation.FindExerciseList(data).then(async (res) => {
					if(res.items.length){
						let list = res.items;
						if((!this.flag && this.isShowSchoolBank) || (!this.flag && !this.isShowSchoolBank && this.filterOrigin === this.schoolCode)){
							this.periodCountArr = this.getPeriodCount(res.items)
							list = res.items.filter(i => i.periodId === this.periodList[this.filterPeriod].id)
							this.flag = true
						}
						this.getItemsCount(list,filterKey)
						/* 获取试题总数 */
						this.totalNum = list.length;
						this.originData = list;
						this.pageChange(1);
					}else{
						this.originData = []
						this.exerciseList = []
						this.totalNum = 0
						this.$Message.warning(this.$t('evaluation.getEmptyItems'))
					}
					setTimeout(() => {
						that.dataLoading = false;
					}, 1000);
				});
			},
			
			/* 获取所有学段下的试题总数 */
			getPeriodCount(items){
				let periodIdArr = this.periodList.map(i => i.id)
				let periodCountArr = periodIdArr.map(i => {
					return items.filter(j => j.periodId === i).length
				})
				return periodCountArr
			},
			
			/* 获取试题的年级、科目的数量统计 */
			getItemsCount(items,filterKey){
				if(filterKey !== 'grade'){
					let gradeIdArr = this.gradeList.map((i,index) => index)
					this.gradeCountArr = gradeIdArr.map(i => {
						return items.length ? items.filter(j => j.gradeIds && j.gradeIds.includes(i+'')).length : 0
					})
				}
				if(filterKey !== 'subject'){
					let subjectIdArr = this.subjectList.map(i => i.id)
					this.subjectCountArr = subjectIdArr.map(i => {
						return items.length ? items.filter(j => j.subjectId === i).length : 0
					})
				}
			},

			/**
			 * 全部展开与全部折叠
			 * @param isAllOpen
			 */
			onHandleToggle(isAllOpen) {
				if (isAllOpen) {
					this.collapseList = [];
				} else {
					this.collapseList = [...this.exerciseList.keys()];
				}
			},

			/**
			 * 拿到当前页面所有知识点集合
			 * @param arr
			 */
			getPointIds(arr) {
				let ids = [];
				arr.forEach((i) => {
					ids = ids.concat(i.points);
				});
				return [...new Set(ids)];
			},

			editModalChange(val) {
				this.$nextTick(() => {
					console.log(this.$refs)
					this.$refs.editRef.backToTop();
				})
			},

			/**
			 * 题干展开与收缩
			 * @param index
			 * @param id
			 */
			onQuestionToggle(index, id, e) {
				let curClassName = e.target.className;
				if (
					curClassName === "item-tools" ||
					curClassName === "richText-video" ||
					curClassName === "richText-audio"
				)
					return;
				e.stopPropagation();
				let listIndex = this.collapseList.indexOf(index);
				if (listIndex > -1) {
					this.collapseList.splice(listIndex, 1);
				} else {
					this.collapseList.push(index);
					let exerciseItemDom = e.path.filter(
						(i) => i.className === "exercise-item"
					);
					if (exerciseItemDom.length) {
						this.pageScrollTo(exerciseItemDom[0].offsetTop + 240);
					}
				}

				this.$emit("toggleChange", this.collapseList);
			},

			/**
			 * 筛选学段条件
			 * @param val
			 */
			filterPeriodChange(val) {
				// this.filterPeriod = this.periodList[val].periodCode
				this.gradeList = this.schoolInfo.period[val].grades;
				this.subjectList = this.schoolInfo.period[val].subjects;
				this.filterGrade = [false];
				this.filterSubject = [false];
				this.doFilter('period');
			},

			/**
			 * 筛选年级
			 * @param val
			 */
			filterGradeChange(val) {
				if (val.length > 1 && val.indexOf(false) === 0) {
					this.filterGrade.splice(val.indexOf(false), 1);
				} else if (val.indexOf(false) > -1 || val.length === 0) {
					this.filterGrade = [false];
				}
				this.doFilter('grade');
			},

			/**
			 * 筛选科目
			 * @param val
			 */
			filterSubjectChange(val) {
				if (val.length > 1 && val.indexOf(false) === 0) {
					this.filterSubject.splice(val.indexOf(false), 1);
				} else if (val.indexOf(false) > -1 || val.length === 0) {
					this.filterSubject = [false];
				}
				this.doFilter('subject');
			},

			/**
			 * 根据题库加载题目
			 * @param val
			 */
			filterOriginChange(origin) {
				this.filterOrigin = origin;
				this.doFilter();
			},

			/**
			 * 筛选题型
			 * @param val
			 */
			filterTypeChange(val) {
				if (val.length > 1 && val.indexOf("all") === 0) {
					this.filterType.splice(val.indexOf("all"), 1);
				} else if (val.indexOf("all") > -1 || val.length === 0) {
					this.filterType = ["all"];
				}
				this.doFilter();
			},

			/**
			 * 筛选难度
			 * @param val
			 */
			filterDiffChange(val) {
				if (val.length > 1 && val.indexOf("all") === 0) {
					this.filterDiff.splice(val.indexOf("all"), 1);
				} else if (val.indexOf("all") > -1 || val.length === 0) {
					this.filterDiff = ["all"];
				}
				this.doFilter();
			},

			/**
			 * 筛选认知层次
			 * @param val
			 */
			filterFieldChange(val) {
				if (val.length > 1 && val.indexOf("all") === 0) {
					this.filterField.splice(val.indexOf("all"), 1);
				} else if (val.indexOf("all") > -1 || val.length === 0) {
					this.filterField = ["all"];
				}
				this.doFilter();
			},

			/**
			 * 排序条件更换
			 * @param val
			 */
			filterSortChange(val) {
				this.doFilter();
			},

			/**
			 * 删除筛选条件里面的False值与All值
			 * @param arr
			 */
			deleteFalse(arr) {
				console.log(arr)
				let list = JSON.parse(JSON.stringify(arr));
				list.forEach((item, index) => {
					if ((!item || item === "all") && item !== 0 ) list.splice(index, 1);
				});
				return list;
			},

			/** 前往组卷页面 */
			goCreatePaper() {
				this.$router.push({
					name: "exercisesList",
				});
			},

			/**
			 * 切换页码操作
			 * @param page
			 */
			async pageChange(page) {
				this.pageNum = page;
				let start = this.pageSize * (page - 1);
				let end = this.pageSize * page;
				// 拿到当前页码需要展示的数据
				let simpleList = this.originData.slice(start, end);
				try {
					// 执行试题换取完整JSON数据
					this.exerciseList = await this.$evTools.getFullItem(simpleList);
					this.currentPage = page;
					this.pageScrollTo(0);
				} catch (e) {
					console.log(e);
				}
			},

			/**
			 * 页面滚动事件
			 * @param scrollDistance 页面滚动距离
			 */
			pageScrollTo(scrollDistance) {
				this.$nextTick(() => {
					let parentVm = this.$parent.$parent.$parent.$parent.$parent.$parent;
					parentVm.$refs["evScroll"].scrollTo({
							y: scrollDistance,
						},
						500,
						"easeInQuad"
					);
				})
				
			},

			/**
			 * 切换每页显示数量
			 * @param val
			 */
			pageSizeChange(val) {
				this.pageSize = val;
				this.pageChange(1);
			},

			/**
			 * 更新时间日期格式化
			 * @param date
			 */
			formatDateTime(date) {
				var y = date.getFullYear();
				var m = date.getMonth() + 1;
				m = m < 10 ? "0" + m : m;
				var d = date.getDate();
				d = d < 10 ? "0" + d : d;
				var h = date.getHours();
				h = h < 10 ? "0" + h : h;
				var minute = date.getMinutes();
				minute = minute < 10 ? "0" + minute : minute;
				var second = date.getSeconds();
				second = second < 10 ? "0" + second : second;
				return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
			},

			/**
			 * 删除单个试题
			 * @param item
			 */
			handleDelete(item) {
				this.$Modal.confirm({
					title: this.$t('evaluation.newExercise.modalTip'),
					content: this.$t('evaluation.exerciseList.confirmDelete'),
					onOk: () => {
						this.dataLoading = true;
						this.$api.newEvaluation
							.DeleteExamItem({
								id: item.id,
								code: item.code,
								scope: item.scope,
							})
							.then(async (res) => {
								// 获取初始化Blob需要的数据
								this.deleteBlobPrefix(item).then(status => {
									if(status === 200){
										this.$Message.success(this.$t('evaluation.deleteSuc'));
										this.doFilter();
									}else{
										console.log(err)
										this.dataLoading = false;
									}
								})
							})
							.catch((err) => {
								console.log(err);
								this.$Message.warning(this.$t('evaluation.deleteFail'));
								this.dataLoading = false;
							});
					},
				});
			},
			
			/* 删除blob指定试题目录下所有 */
			deleteBlobPrefix(item) {
				return new Promise((resolve,reject) => {
					// 如果是综合题 则需要把主题删除的同时还要对所有子题进行删除操作
					if(item.type === 'compose' && item.children.length){
						let promiseArr = []
						let deleteIds = [item.id,...item.children.map(i => i.id)]
						deleteIds.forEach(id => {
							promiseArr.push(new Promise((r,j) => {
								this.$api.blob.deletePrefix({
									"cntr": item.scope === 'school' ? this.$store.state.userInfo.schoolCode : this.$store.state.userInfo.TEAMModelId,
									"prefix": "item/" + id
								}).then(
									(res) => {
										if (!res.error) {
											r(200)
										} else {
											r(500)
										}
									},
									(err) => {
										j(err)
									}
								)
							}))
						})
						Promise.all(promiseArr).then(result => {
							resolve(200)
						}).catch(err => {
							reject(err)
						})
					}else{
						this.$api.blob.deletePrefix({
							"cntr": item.scope === 'school' ? this.$store.state.userInfo.schoolCode : this.$store.state.userInfo.TEAMModelId,
							"prefix": "item/" + item.id
						}).then(
							(res) => {
								if (!res.error) {
									resolve(200)
								} else {
									resolve(500)
								}
							},
							(err) => {
								reject(err)
							}
						)
					}
				})
			},

			/**
			 * 编辑单个试题
			 * @param item
			 */
			handleEdit(exercise) {
				exercise.level = exercise.level || 1;
				this.currentExercise = JSON.parse(JSON.stringify(exercise));
				this.editExerciseModal = true;
			},

			/** 编辑成功 */
			onEditSuccess(item) {
				console.log("编辑好要保存的试题");
				console.log(item);
				this.$api.newEvaluation
					.SaveSingleExercise({
						itemInfo: item,
						option: "update",
					})
					.then((res) => {
						localStorage.setItem('noSave','[]')
						this.$Message.success(this.$t('evaluation.editSuc'));
						this.$refs.editRef.isLoading = false;
						this.editExerciseModal = false;
						this.doFilter();
					});
			},
		},
		computed: {
			curScope() {
				return this.filterOrigin === this.$store.state.userInfo.schoolCode ?
					"school" :
					"private";
			},
			hasSchool() {
				return this.$store.state.userInfo.hasSchool;
			},
		},
	};
</script>
<style lang="less">
	@import "../index/CommonExercise.less";
</style>

<style>
	.circle {
		border: solid 1px red;
		background-color: red;
		border-radius: 50%;
		width: 50px;
		height: 50px;
	}

	.slide-enter-active {
		transition: all 0.3s ease;
	}

	.slide-leave-active {
		transition: all 0.3s ease;
	}

	.slide-enter,
	.slide-leave-to {
		transform: translateY(10px);
		opacity: 0;
	}
</style>
