import Pagination from '@/components/pagination'
import SaveForm from '@/components/save-form'
import { lessonType } from '@/views/knowledge-manage/knowledgeTypeData'
import {
DataTableColumn,
NButton,
NCascader,
NDataTable,
NFormItem,
NInput,
NSelect,
NSpace
} from 'naive-ui'
import { computed, defineComponent, onMounted, reactive, ref } from 'vue'
import {
examinationKnowledgePointCategoryPage,
examinationQuestionPage,
examinationQuestionPageAndAnswer
} from '../../api'
import styles from '../index.module.less'
import { difficultyCoefficients, questionTypeCode } from '../question-bank'
export default defineComponent({
name: 'add-question-list',
emits: ['select'],
props: {
selectList: {
type: Array,
default: () => []
}
},
setup(props, { emit }) {
const saveForm = ref()
const checkList = computed(() => {
const list = props.selectList?.map((n: any) => n.id) || []
return list
})
const data = reactive({
pagination: {
page: 1,
rows: 10,
total: 0
},
loading: false,
list: [] as any,
categorys: [] as any,
selectList: [] as any
})
const searchForm = reactive({
score: null, //分值
difficultyCoefficient: null, //难度
questionTypeCode: null, //题目类型,可用值:RADIO,CHECKBOX,PLAY,SORT,LINK
keyword: null, // 题目名称、编号
categoryId: null, // 考点编号
courseTypeCode: null //
})
const columns = (): DataTableColumn[] => {
return [
{
type: 'selection',
disabled: (row: any) => {
return checkList.value.includes(row.id)
}
},
{
title: '题目名称',
key: 'name',
width: 230,
render(row: any) {
return (
)
}
},
{
title: '题目类型',
key: 'questionTypeCode',
render(row: any) {
return questionTypeCode[row.questionTypeCode]
}
},
{
title: '考点',
key: 'examinationKnowledgePointCategoryName'
},
{
title: '难度',
key: 'difficultyCoefficient',
render(row: any) {
const rowName =
difficultyCoefficients.find(
(n: any) => n.value?.toLocaleUpperCase() === row.difficultyCoefficient
)?.label || row.difficultyCoefficient
row.difficultyCoefficientName = rowName
return rowName
}
},
{
title: '分值',
key: 'totalScore'
}
]
}
// 获取数据
const getList = async () => {
data.loading = true
try {
const res: any = await examinationQuestionPageAndAnswer({
page: data.pagination.page,
rows: data.pagination.rows,
...searchForm
})
if (Array.isArray(res?.data?.rows)) {
data.list = res.data.rows
data.pagination.total = res.data.total
}
} catch (error) {}
data.loading = false
}
// 获取考点类型
const getType = async () => {
try {
const res: any = await examinationKnowledgePointCategoryPage({
page: 1,
rows: 1000
})
if (Array.isArray(res?.data?.rows)) {
data.categorys = formatList(res.data.rows)
}
} catch (error) {}
}
const formatList = (item: any) => {
item.forEach((child: any) => {
if (child.children && child.children.length) {
formatList(child.children)
} else {
child.children = null
}
})
return item
}
const onSubmit = () => {
data.pagination.page = 1
getList()
}
onMounted(() => {
getType()
getList()
})
return () => (
Object.assign(searchForm, val)}
saveKey="add-question-list-key"
>
{
if (e.code === 'Enter') {
onSubmit()
}
}}
clearable
/>
{
if (e.code === 'Enter') {
onSubmit()
}
}}
clearable
/>
({
label: questionTypeCode[key],
value: key
}))}
clearable
/>
{/*
*/}
saveForm.value?.submit()}>
搜索
saveForm.value?.reset()}>
重置
row.id}
defaultCheckedRowKeys={checkList.value}
v-model:checkedRowKeys={data.selectList}
>
emit('select')}>取消
{
const list = data.list
.map((n: any) => (data.selectList.includes(n.id) ? n : null))
.filter(Boolean)
console.log("🚀 ~ list", list)
emit('select', list)
}}
>
确定
)
}
})