import SaveForm from '@/components/save-form' import Pagination from '@/components/pagination' import { DataTableColumn, NButton, NCascader, NDataTable, NDatePicker, NDescriptions, NDescriptionsItem, NFormItem, NInput, NModal, NSelect, NSpace, NTag, NTooltip, useDialog, useMessage } from 'naive-ui' import { defineComponent, inject, onMounted, reactive, ref, provide } from 'vue' import { fetchCategoryList, fetchMaterialList, deleteMaterial, updateMaterailData } from '../api' import styles from '../index.module.less' import { InternalRowData } from 'naive-ui/es/data-table/src/interface' import AddMaterial from '../model/addMaterial' import { getLessonType, lessonType } from '@/views/knowledge-manage/knowledgeTypeData' import { filterTimes, getTimes } from '@/utils/dateUtil' import { useRoute } from 'vue-router' import { subjectPage } from '@views/system-manage/subject-manage/api' const classType: { [_: string]: any } = { VIDEO: '视频', IMG: '图片', SONG: '曲目' } const classTypeList = Object.keys(classType).map((key: string) => { return { label: classType[key], value: key } }) export default defineComponent({ name: 'material-list', setup(props) { const dialog = useDialog() const message = useMessage() const state = reactive({ loading: false, pagination: { page: 1, rows: 10, pageTotal: 10 }, visiableCity: false, dataList: [] as any, cityType: 'add', materail: null, isLook: false, employeeList: [] as any }) const searchForm = reactive({ keyword: null as any, time: null as any, courseTypeCode: null, materialCategoryId: null, type: null }) const route = useRoute() // 获取分类列表 const category = reactive({ list: [] as any, index: -1 }) const getCategoryList = async () => { try { const { data } = await fetchCategoryList({ page: 1 }) category.list = data?.rows || [] } catch {} } provide('categoryList', category) // 声部 const subjects = reactive({ list: [] as any }) const getSubjects = async () => { try { const { data } = await subjectPage({ page: 1, row: 1000 }) subjects.list = data?.rows || [] } catch {} } provide('subjects', subjects) onMounted(() => { console.log(route.query, 'route.query') if (route.query.id) { searchForm.keyword = route.query.id as string } getCategoryList() getSubjects() }) const columns = (): DataTableColumn[] => { return [ { title: '素材名称', key: 'name', render(row: any) { return ( {row.name} {row.id} {row.materialCategoryName} ) } }, // { // title: '编号', // key: 'id' // }, // { // title: '素材分类', // key: 'materialCategoryName' // }, 分段编号 { title: '素材信息', key: 'sn', render(row: any) { return ( {row.sn} {classType[row.type as string]} {/* {row.courseTypeName} */} ) } }, { title: '课程信息', key: 'type', render(row: any) { return ( {row.courseTypeName} {/* {row.adviseStudyTimeSecond ? row.adviseStudyTimeSecond + '秒' : ''} */} ) } }, // { // title: '课程类型', // key: 'courseTypeName', // width: 200, // ellipsis: true, // render(row: InternalRowData) { // return ( // // {{ // default: () => row.courseTypeName, // trigger: () => row.courseTypeName // }} // // ) // } // }, // { // title: '建议学习时长', // key: 'adviseStudyTimeSecond', // render(row: InternalRowData) { // return row.adviseStudyTimeSecond ? row.adviseStudyTimeSecond + '秒' : '' // } // }, { title: '操作信息', key: 'createTime', render(row: any) { return ( {row.operatorName} {row.createTime ? row.createTime : '--'} ) } }, // { // title: '上传人', // key: 'operatorName' // }, { title: '状态', key: 'delFlag', render(row: InternalRowData) { return ( <> {row.enableFlag ? '启用' : '停用'} ) } }, { title: '操作', key: 'operation', fixed: 'right', width: 160, render(row: any) { return ( {/* handleChange(row)} > {row.enableFlag ? '停用' : '启用'} */} { state.isLook = true state.materail = row state.visiableCity = true }} > 查看 { state.cityType = 'update' state.materail = row state.visiableCity = true }} > 修改 handleDelete(row)} > 删除 ) } } ] } const saveForm = ref() const onSubmit = () => { state.pagination.page = 1 getList() } const onSearch = () => { saveForm.value?.submit() } const onBtnReset = () => { saveForm.value?.reset() } const getList = async () => { try { state.loading = true const { time, ...reset } = searchForm const body = { ...reset, ...filterTimes(time, ['startTime', 'endTime']), page: state.pagination.page, rows: state.pagination.rows } const { data } = await fetchMaterialList(body) state.loading = false state.pagination.pageTotal = Number(data.total) state.dataList = data.rows || [] } catch { state.loading = false } } // 删除 const handleDelete = async (row: any) => { dialog.warning({ title: '警告', content: '是否确认删除此素材?', positiveText: '确定', negativeText: '取消', onPositiveClick: async () => { const res = await deleteMaterial(row.id) if (res.data) { onSubmit() message.success('删除成功') } } }) } // 启用,停用 const handleChange = (row: any) => { dialog.warning({ title: '提示', content: row.enableFlag ? '是否停用此素材?' : '是否启用此素材?', positiveText: '确定', negativeText: '取消', onPositiveClick: async () => { const res = await deleteMaterial(row.id) if (res.data) { await updateMaterailData({ id: row.id, enableFlag: row.enableFlag ? 0 : 1 }) message.success('修改成功') getList() } } }) } onMounted(() => { getList() }) return () => ( <> Object.assign(searchForm, val)} saveKey="material-key" > { if (e.code === 'Enter') { onSubmit() } }} placeholder={'素材名称/编号'} clearable /> 搜索 重置 { state.cityType = 'add' state.materail = null state.visiableCity = true }} > 添加素材 { state.isLook = false }} > {state.visiableCity && ( { state.visiableCity = false }} onHandleSuccess={() => { state.visiableCity = false if (!state.materail) { state.pagination.page = 1 } getList() }} /> )} ) } })