zhouwx
2024-07-04 00c6c38846f94687cfc4ce6d3c0506f8349a26e5
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
<template>
  <div class="app-container">
    <div style="margin-bottom: 10px">
      <el-button type="success" plain @click="openDialog('addFirst',{courseId: data.courseId})">章添加</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>
        </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">节添加</el-button>
          <el-button type="primary" plain @click="openDialog('edit',scope.row)">编辑</el-button>
          <el-button type="danger" plain @click="handleDelete(scope.row)">删除</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} from 'vue-router'
import {delClassification, getClassification} from "@/api/onlineEducation/courseClass";
import {delChapter, delPeriod, getChapters} from "@/api/onlineEducation/chapters";
const { proxy } = getCurrentInstance();
const route = useRoute()
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);
 
//页面加载
onMounted(() => {
 
  data.courseId = route.query.courseId
  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
  }else{
    ElMessage.warning(res.message)
  }
  loading.value = false;
  console.log('dataList.value',dataList.value)
}
 
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)
          }
        }
 
      })
}
 
 
</script>