2023-12-05 16:45:28 +08:00
|
|
|
|
<template>
|
2023-12-08 15:26:16 +08:00
|
|
|
|
<!-- 听力 -->
|
2023-12-05 16:45:28 +08:00
|
|
|
|
<view>
|
|
|
|
|
<!-- 外层循环 -->
|
|
|
|
|
<view v-for="(item,index) in listHearing" :key="item.id">
|
|
|
|
|
<!-- 听力标题渲染 -->
|
|
|
|
|
<view class="view_bages">
|
|
|
|
|
<view>{{item.title}}</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="substance">
|
|
|
|
|
<!-- 渲染Text -->
|
2023-12-09 18:15:29 +08:00
|
|
|
|
<text :class="{ 'active': itemActive[item.id] === TextIndex }"
|
|
|
|
|
v-for="(TextItem,TextIndex) in item.tests" :key="TextIndex"
|
|
|
|
|
@click="Bages_addActive(TextIndex,item.id) ">
|
2023-12-05 16:45:28 +08:00
|
|
|
|
{{TextItem.name}}
|
|
|
|
|
</text>
|
|
|
|
|
</view>
|
|
|
|
|
<!-- 渲染part -->
|
|
|
|
|
<view v-for="(TextItem,TextIndex) in item.tests" :key="TextIndex">
|
2023-12-09 18:15:29 +08:00
|
|
|
|
<view v-for="(partitem,partindex) in TextItem.parts" :key="partindex"
|
|
|
|
|
v-if="itemActive[item.id] === TextIndex">
|
2023-12-05 16:45:28 +08:00
|
|
|
|
<view>
|
|
|
|
|
<view class="Part1">
|
|
|
|
|
<view class="imaflex" @click="icon(partitem.id)">
|
|
|
|
|
<!-- part前面的图表 -->
|
|
|
|
|
<view class="image">
|
2023-12-09 18:15:29 +08:00
|
|
|
|
<image src="http://tmp/IFVuR12hLLNO034931f24322ab271b1f57fdf626bcbf.png" mode=""
|
|
|
|
|
v-if="image"></image>
|
|
|
|
|
<image src="http://tmp/8OOgvfEpdnT2e4e421b97006c70b30a9df99e51a6df1.png" mode=""
|
|
|
|
|
v-else></image>
|
2023-12-05 16:45:28 +08:00
|
|
|
|
</view>
|
|
|
|
|
<view>{{partitem.name}}</view>
|
|
|
|
|
</view>
|
|
|
|
|
<!-- part的多选框 -->
|
|
|
|
|
<view>
|
2023-12-09 18:15:29 +08:00
|
|
|
|
<u-checkbox @change="checkboxChange(partitem,$event)" v-model="partitem.checked"
|
|
|
|
|
shape="circle"></u-checkbox>
|
2023-12-05 16:45:28 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2023-12-12 00:42:01 +08:00
|
|
|
|
<view class="partshow" v-if="selectedItems.includes(partitem.id)">
|
2023-12-05 16:45:28 +08:00
|
|
|
|
<view class="Part2" v-for="(quesitem,quesindex) in partitem.modules" :key="quesindex">
|
|
|
|
|
<view class="imaflex">
|
2023-12-09 18:15:29 +08:00
|
|
|
|
<view>{{quesitem.number}}{{quesitem.typeText}}</view>
|
2023-12-05 16:45:28 +08:00
|
|
|
|
</view>
|
|
|
|
|
<view>
|
2023-12-09 18:15:29 +08:00
|
|
|
|
<u-checkbox @change="handleCheckboxChange(quesitem)"
|
|
|
|
|
v-model="quesitem.subsets"></u-checkbox>
|
2023-12-05 16:45:28 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
listHearing: [],
|
|
|
|
|
checked: [],
|
|
|
|
|
subsets: [],
|
|
|
|
|
itemActive: {},
|
|
|
|
|
image: true,
|
|
|
|
|
tk: null,
|
2023-12-09 18:15:29 +08:00
|
|
|
|
selectwrite: [],
|
2023-12-12 00:42:01 +08:00
|
|
|
|
selectedItems: [],
|
2023-12-05 16:45:28 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
this.hearing()
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2023-12-09 18:15:29 +08:00
|
|
|
|
updatawrite(data){
|
|
|
|
|
this.selectwrite=data
|
|
|
|
|
|
|
|
|
|
},
|
2023-12-08 15:26:16 +08:00
|
|
|
|
// 听力调取接口渲染
|
2023-12-05 16:45:28 +08:00
|
|
|
|
hearing() {
|
|
|
|
|
this.$u.get('https://api.admin-v2.langsi.online/admin-api/ielts/paper/list', {
|
|
|
|
|
classify: 2
|
|
|
|
|
}).then(res => {
|
|
|
|
|
this.listHearing = res.data
|
2023-12-08 15:26:16 +08:00
|
|
|
|
let activeindex = {}
|
|
|
|
|
let arr = res.data
|
|
|
|
|
for (let parper of arr) {
|
|
|
|
|
let test = parper.tests[0]
|
|
|
|
|
activeindex[parper.id] = 0
|
|
|
|
|
}
|
|
|
|
|
this.itemActive = activeindex
|
2023-12-09 18:15:29 +08:00
|
|
|
|
this.updateSubsetsInListHearing()
|
2023-12-12 00:42:01 +08:00
|
|
|
|
const uniquePartIds = new Set();
|
|
|
|
|
|
|
|
|
|
// Loop through listHearing and collect unique part IDs
|
|
|
|
|
this.listHearing.forEach((paper) => {
|
|
|
|
|
paper.tests.forEach((test) => {
|
|
|
|
|
test.parts.forEach((part) => {
|
|
|
|
|
const hasSelectedQuesitem = part.modules.some((quesitem) => quesitem.subsets);
|
|
|
|
|
|
|
|
|
|
if (hasSelectedQuesitem) {
|
|
|
|
|
uniquePartIds.add(part.id);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Convert the Set to an array and update selectedItems
|
|
|
|
|
this.selectedItems = Array.from(uniquePartIds);
|
|
|
|
|
console.log( this.selectedItems ,' this.selectedItems ');
|
2023-12-05 16:45:28 +08:00
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
// 听力test点击事件
|
2023-12-08 15:26:16 +08:00
|
|
|
|
Bages_addActive(TextIndex, id) {
|
|
|
|
|
this.itemActive[id] = TextIndex
|
2023-12-05 16:45:28 +08:00
|
|
|
|
this.$forceUpdate()
|
|
|
|
|
},
|
|
|
|
|
// 点击变化图表
|
2023-12-12 00:42:01 +08:00
|
|
|
|
icon(id) {
|
|
|
|
|
this.image = !this.image;
|
|
|
|
|
if (this.image) {
|
|
|
|
|
this.selectedItems = this.selectedItems.filter(item => item !== id);
|
|
|
|
|
} else {
|
|
|
|
|
this.selectedItems.push(id);
|
|
|
|
|
}
|
|
|
|
|
console.log(this.selectedItems,'this.selectedItemsthis.selectedItems');
|
|
|
|
|
},
|
2023-12-09 18:15:29 +08:00
|
|
|
|
checkboxChange(partitem, e) {
|
2023-12-05 16:45:28 +08:00
|
|
|
|
if (e.value) {
|
2023-12-09 18:15:29 +08:00
|
|
|
|
this.listHearing.forEach((paper) => {
|
|
|
|
|
paper.tests.forEach((test, testIndex) => {
|
|
|
|
|
test.parts.forEach((part) => {
|
|
|
|
|
if (part.id === partitem.id) {
|
|
|
|
|
part.modules.forEach((quesitem, quesIndex) => {
|
|
|
|
|
this.addToSelectWrite(
|
|
|
|
|
quesitem,
|
|
|
|
|
partitem.id,
|
|
|
|
|
testIndex + 1,
|
|
|
|
|
paper.title
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-12-05 16:45:28 +08:00
|
|
|
|
} else {
|
2023-12-09 18:15:29 +08:00
|
|
|
|
partitem.modules.forEach((quesitem) => {
|
|
|
|
|
this.removeFromSelectWrite(quesitem.id);
|
|
|
|
|
});
|
2023-12-05 16:45:28 +08:00
|
|
|
|
}
|
2023-12-09 18:15:29 +08:00
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
|
2023-12-05 16:45:28 +08:00
|
|
|
|
|
2023-12-09 18:15:29 +08:00
|
|
|
|
// 在这里执行额外的操作,遍历 selectwrite 中的每一项,更新 listHearing 中的 subsets
|
|
|
|
|
this.updateSubsetsInListHearing();
|
|
|
|
|
this.$parent.updataread(this.selectwrite)
|
2023-12-05 16:45:28 +08:00
|
|
|
|
},
|
2023-12-09 18:15:29 +08:00
|
|
|
|
handleCheckboxChange(quesitems) {
|
|
|
|
|
const existingIndex = this.selectwrite.findIndex(item => item.id === quesitems.id);
|
|
|
|
|
|
|
|
|
|
if (existingIndex !== -1) {
|
|
|
|
|
// 如果已存在,将 subsets 设为 false,并清除该项
|
|
|
|
|
this.selectwrite.splice(existingIndex, 1);
|
|
|
|
|
quesitems.subsets = false;
|
2023-12-05 16:45:28 +08:00
|
|
|
|
} else {
|
2023-12-09 18:15:29 +08:00
|
|
|
|
// 如果不存在,添加该项,并将 subsets 设为 true
|
|
|
|
|
this.listHearing.forEach((paper) => {
|
|
|
|
|
paper.tests.forEach((test, testIndex) => {
|
|
|
|
|
test.parts.forEach((part) => {
|
|
|
|
|
part.modules.forEach((quesitem, quesIndex) => {
|
|
|
|
|
if (quesitem.id == quesitems.id) {
|
|
|
|
|
this.addToSelectWrite(
|
|
|
|
|
quesitems,
|
|
|
|
|
quesitems.id, // 使用 quesitem 的 id
|
|
|
|
|
testIndex + 1, // 使用内层循环的 testIndex
|
|
|
|
|
paper.title // 使用 quesitem 的 paperTitle
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
quesitems.subsets = true;
|
2023-12-05 16:45:28 +08:00
|
|
|
|
}
|
2023-12-09 18:15:29 +08:00
|
|
|
|
|
|
|
|
|
console.log(this.selectwrite, 'selectwriteselectwrite');
|
|
|
|
|
this.updateSubsetsInListHearing()
|
|
|
|
|
this.$parent.updataread(this.selectwrite)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 在这里添加一个新的方法,用于更新 listHearing 中的 subsets
|
|
|
|
|
updateSubsetsInListHearing() {
|
|
|
|
|
this.listHearing.forEach((paper) => {
|
|
|
|
|
paper.tests.forEach((test) => {
|
|
|
|
|
test.parts.forEach((part) => {
|
|
|
|
|
part.modules.forEach((quesitem) => {
|
|
|
|
|
const selected = this.selectwrite.find((item) => {
|
|
|
|
|
return item.id === quesitem.id;
|
|
|
|
|
});
|
|
|
|
|
if (selected) {
|
|
|
|
|
quesitem.subsets = true;
|
|
|
|
|
} else {
|
|
|
|
|
quesitem.subsets = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 额外的逻辑,遍历 listHearing 中的每一个 part,判断是否全部 modules 的 subsets 都为 true
|
|
|
|
|
this.listHearing.forEach((paper) => {
|
|
|
|
|
paper.tests.forEach((test) => {
|
|
|
|
|
test.parts.forEach((part) => {
|
|
|
|
|
part.checked = part.modules.every((quesitem) => quesitem.subsets);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-12-12 00:42:01 +08:00
|
|
|
|
console.log(this.selectwrite,'selectwriteselectwrite');
|
|
|
|
|
|
2023-12-09 18:15:29 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 添加信息到selectwrite数组
|
|
|
|
|
addToSelectWrite(quesitem, partId, testIndex, paperTitle) {
|
|
|
|
|
// Split the guideText into words
|
|
|
|
|
|
|
|
|
|
const item = {
|
|
|
|
|
id: quesitem.id,
|
|
|
|
|
paperId: quesitem.paperId,
|
|
|
|
|
papername: paperTitle,
|
|
|
|
|
partId: partId,
|
|
|
|
|
testId: quesitem.testId,
|
|
|
|
|
testname: `Test ${testIndex}`,
|
|
|
|
|
typeName: quesitem.typeText,
|
|
|
|
|
questionname: quesitem.number,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.selectwrite.push(item);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
removeFromSelectWrite(itemId) {
|
|
|
|
|
const index = this.selectwrite.findIndex((item) => item.id === itemId);
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
this.selectwrite.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-12-05 16:45:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.view_bages {
|
|
|
|
|
font-size: 40rpx;
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
color: #2E4975;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.substance {
|
|
|
|
|
margin: 20rpx 0;
|
|
|
|
|
|
|
|
|
|
text {
|
|
|
|
|
padding: 10rpx 30rpx;
|
|
|
|
|
margin-right: 20rpx;
|
|
|
|
|
background: #FFFFFF;
|
|
|
|
|
border-radius: 12rpx 12rpx 12rpx 12rpx;
|
|
|
|
|
}
|
2023-12-08 15:26:16 +08:00
|
|
|
|
|
2023-12-05 16:45:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-08 15:26:16 +08:00
|
|
|
|
|
2023-12-05 16:45:28 +08:00
|
|
|
|
.Part1 {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
padding: 24rpx;
|
|
|
|
|
background: #FFFFFF;
|
|
|
|
|
border-radius: 20rpx 20rpx 20rpx 20rpx;
|
|
|
|
|
margin-top: 30rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.Part2 {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
padding: 24rpx 0;
|
|
|
|
|
border-bottom: 2rpx solid #F2F2F2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.partshow {
|
|
|
|
|
background: #FFFFFF;
|
|
|
|
|
border-radius: 20rpx 20rpx 20rpx 20rpx;
|
|
|
|
|
margin-top: 15rpx;
|
|
|
|
|
padding: 15rpx 30rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.substance .active {
|
|
|
|
|
background: #2D7CE6;
|
|
|
|
|
color: #fff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.imaflex {
|
|
|
|
|
display: flex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.image {
|
|
|
|
|
width: 20rpx;
|
|
|
|
|
height: 20rpx;
|
|
|
|
|
margin-right: 10rpx;
|
|
|
|
|
}
|
2023-12-09 18:15:29 +08:00
|
|
|
|
</style>
|