zhouwx
2025-06-10 c8c99bf1f753e27c4d99a0ff6058ce16f973f9c4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<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>