<template>
|
<div class="app-container">
|
<div style="margin-bottom: 10px;display:flex;justify-content: space-between;align-items: center">
|
<el-button type="success" plain @click="openDialog('addFirst',{courseId: data.courseId})" :disabled="disabled">章添加</el-button>
|
<el-button type="primary" plain @click="back">返回</el-button>
|
</div>
|
<!-- 表格数据 -->
|
<el-table v-loading="loading" :data="dataList" :border="true" row-key="id" :tree-props="{ children: 'chapterPeriods' }">
|
<el-table-column label="序号" type="index" align="center" width="80" />
|
<el-table-column label="章节名称" >
|
<template #default="scope">
|
<span>{{scope.row.name}}</span>
|
<span v-if="scope.row.chapterId" style="font-size: 14px;margin-left: 5px">【{{scope.row.resource.resourceType === 1 ? '视频:':scope.row.resource.resourceType === 2 ? '音频:':'文档:'}}{{scope.row.resource.name}}】| {{scope.row.timeFormat}}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="排序" prop="sort" align="center" width="80" />
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="250" >
|
<template #default="scope">
|
<el-button type="success" plain @click="openDialog('add',scope.row)" v-if="!scope.row.chapterId" :disabled="disabled">节添加</el-button>
|
<el-button type="primary" plain @click="openDialog('edit',scope.row)" :disabled="disabled">编辑</el-button>
|
<el-button type="danger" plain @click="handleDelete(scope.row)" :disabled="disabled">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
<chapters-dialog ref="areaRef" @getList="getList"></chapters-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import {getCurrentInstance, onMounted, reactive, ref, toRefs} from "vue";
|
import {ElMessage, ElMessageBox} from "element-plus";
|
import chaptersDialog from "./components/chapterDialog.vue"
|
import {delArea, getArea} from "@/api/backManage/area";
|
import {getDictList} from "@/api/backManage/evaluate";
|
import {delMonitor} from "@/api/sysUsers";
|
import {useRoute,useRouter} from 'vue-router'
|
import {delClassification, getClassification} from "@/api/onlineEducation/courseClass";
|
import {delChapter, delPeriod, getChapters} from "@/api/onlineEducation/chapters";
|
import Cookies from "js-cookie";
|
const { proxy } = getCurrentInstance();
|
const route = useRoute()
|
const router = useRouter();
|
const loading = ref(false);
|
const areaRef = ref();
|
const cityList = ref([])
|
const data = reactive({
|
queryParams: {
|
name: '',
|
},
|
total: 0,
|
dataList: [
|
],
|
courseId: ''
|
});
|
|
const { queryParams, total, dataList } = toRefs(data);
|
const backValue = ref()
|
const disabled = ref(false)
|
//页面加载
|
onMounted(() => {
|
backValue.value = JSON.parse(route.query.val)
|
const userInfo = JSON.parse(Cookies.get('userInfo'))
|
if((backValue.value.state === 2 || backValue.value.state === 1 ) && userInfo.userType == 1){
|
disabled.value = true;
|
}
|
data.courseId = backValue.value.id
|
console.log("rou",data.courseId)
|
getList();
|
});
|
const getList = async () => {
|
loading.value = true;
|
const param = {
|
courseId: data.courseId
|
}
|
const res = await getChapters(param);
|
if(res.code === 200){
|
dataList.value = res.data.map(item => {
|
return {
|
...item,
|
chapterPeriods: item.chapterPeriods.map(r => {
|
return {
|
...r,
|
timeFormat: r.resource.resourceType === 1 || r.resource.resourceType === 2 ? secondsToTime(r.resource.resourceLength) : r.resource.docPage + '页'
|
}
|
})
|
|
}
|
})
|
}else{
|
ElMessage.warning(res.message)
|
}
|
loading.value = false;
|
console.log('dataList.value',dataList.value)
|
}
|
const secondsToTime = (seconds) => {
|
const hours = Math.floor(seconds / 3600);
|
const minutes = Math.floor((seconds % 3600) / 60);
|
const secs = seconds % 60;
|
|
return [
|
hours,
|
hours > 0 ? pad(minutes) : minutes,
|
pad(secs)
|
].join(':');
|
}
|
const pad = (number) => {
|
return (number < 10 ? '0' : '') + number;
|
}
|
|
const openDialog = (type, value) => {
|
dataList.value.forEach(item => {
|
if(item.id == value.chapterId){
|
value.capterName = item.name
|
}
|
})
|
areaRef.value.openDialog(type, value);
|
}
|
|
/** 重置新增的表单以及其他数据 */
|
function reset() {
|
data.queryParams.name = '';
|
data.queryParams.pageNum = 1;
|
getList();
|
}
|
const handleDelete = (val) => {
|
ElMessageBox.confirm(
|
'确定删除此条数据?',
|
'提示',
|
{
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning',
|
})
|
.then( async() => {
|
if(!val.chapterId){
|
const res = await delChapter(val.id)
|
if(res.code == 200){
|
ElMessage.success('数据删除成功')
|
await getList()
|
}else{
|
ElMessage.warning(res.message)
|
}
|
}else {
|
const res = await delPeriod(val.id)
|
if(res.code == 200){
|
ElMessage.success('数据删除成功')
|
await getList()
|
}else{
|
ElMessage.warning(res.message)
|
}
|
}
|
|
})
|
}
|
const back = () => {
|
|
const obj = {
|
pageNum: backValue.value.pageNum,
|
pageSize: backValue.value.pageSize,
|
}
|
const v = JSON.stringify(obj)
|
router.push({ path: "/courseManage/course", query: { val: v } });
|
}
|
|
|
</script>
|