import { defineComponent, onMounted, reactive, watch ,ref} from 'vue'; import styles from './index.module.less'; import { NButton, NModal, NScrollbar, NSelect, NSpace, NSpin, useDialog, useMessage } from 'naive-ui'; import { usePrepareStore } from '/src/store/modules/prepareLessons'; import { useCatchStore } from '/src/store/modules/catchData'; import TrainType from '/src/views/attend-class/model/train-type'; import TheEmpty from '/src/components/TheEmpty'; import Draggable from 'vuedraggable'; import { lessonPreTrainingBatchSave, lessonPreTrainingPage, lessonPreTrainingDelete } from '../../../api'; import { evaluateDifficult } from '/src/utils/contants'; import TrainUpdate from '/src/views/attend-class/model/train-update'; import AssignHomework from './assign-homework'; import Trainguide from '@/custom-plugins/guide-page/train-guide' export default defineComponent({ name: 'courseware-modal', setup() { const catchStore = useCatchStore(); const prepareStore = usePrepareStore(); const dialog = useDialog(); const message = useMessage(); const forms = reactive({ showAttendClass: false, list: [] as any, drag: false, loadingStatus: false, trainList: [] as any, assignHomeworkStatus: false, editStatus: false, editItem: {} as any }); const showGuide = ref(false) // 完成编辑 const onOverEdit = async () => { dialog.warning({ title: '提示', content: `是否完成编辑?`, positiveText: '确定', negativeText: '取消', onPositiveClick: async () => { try { // 保存课件 await lessonPreTrainingBatchSave({ coursewareKnowledgeDetailId: prepareStore.getSelectKey, subjectId: prepareStore.getSubjectId, lessonPreTrainingDetails: forms.trainList }); forms.drag = false; message.success('编辑成功'); prepareStore.setCoursewareList(forms.trainList); } catch { // } } }); }; // 获取列表 const getList = async () => { forms.loadingStatus = true; try { // 判断是否有选择对应的课件 if (!prepareStore.getSelectKey) return; const { data } = await lessonPreTrainingPage({ coursewareKnowledgeDetailId: prepareStore.getSelectKey, subjectId: prepareStore.getSubjectId, page: 1, rows: 99 }); const tempRows = data.rows || []; const temp: any = []; tempRows.forEach((row: any) => { let tList: string[] = []; const configJson = row.trainingConfigJson; if (row.trainingType === 'EVALUATION') { tList = [ `${evaluateDifficult[configJson.evaluateDifficult]}`, '全部小节', `速度${configJson.evaluateSpeed}`, `${configJson.trainingTimes}分钟` ]; } else { tList = [ `${configJson.practiceChapterBegin}-${configJson.practiceChapterEnd}小节`, `速度${configJson.practiceSpeed}`, `${configJson.trainingTimes}分钟` ]; } temp.push({ typeList: tList || [], ...row }); }); forms.trainList = temp || []; prepareStore.setTrainList(temp || []); setTimeout(()=>{ showGuide.value = true; },500) } catch { // } forms.loadingStatus = false; }; // 监听选择的key 左侧选择了其它的课 watch( () => prepareStore.getSelectKey, () => { forms.trainList = []; getList(); } ); watch( () => prepareStore.getIsAddTrain, (val: boolean) => { if (val) { forms.trainList = []; getList(); prepareStore.setIsAddTrain(false); } } ); // 删除 const onDelete = (item: any) => { // const index = forms.trainList.findIndex((c: any) => c.id === item.id); forms.trainList.splice(index, 1); prepareStore.setCoursewareList(forms.trainList); }; // 单个删除 const onRemove = async (item: any) => { try { dialog.warning({ title: '提示', content: '该训练已下架,是否删除?', positiveText: '确定', negativeText: '取消', onPositiveClick: async () => { await lessonPreTrainingDelete({ ids: item.id }); message.success('删除成功'); getList(); } }); } catch { // } }; onMounted(async () => { // 获取教材分类列表 await catchStore.getSubjects(); const subjectList = catchStore.getSubjectList; if (subjectList.length > 0 && !prepareStore.getSubjectId) { prepareStore.setSubjectId(subjectList[0].id); } await getList(); }); return () => (