<script setup lang="ts">
import { getPaperList, getSearchList } from '../api'

const router = useRouter()
const appList = ref()
const courseListCategory: any = ref([])
const listOptions = computed(() => {
  return {
    remote: { httpRequest: getPaperList, params: { course_id: '', paper_name: '' } },
    filters: [
      {
        type: 'select',
        prop: 'course_id',
        label: '所属课程:',
        placeholder: '所属课程',
        options: courseListCategory.value,
        labelKey: 'name',
        valueKey: 'id',
        filterable: true,
        remote: true
      },
      { type: 'input', prop: 'paper_name', label: '试卷名称：', placeholder: '试卷名称' }
    ],
    columns: [
      { label: '序号', type: 'index', align: 'center', width: '100px' },
      { label: '所属课程', prop: 'course_name', align: 'center' },
      { label: '试卷用途', prop: 'paper_use_name', align: 'center' },
      {
        label: '组卷模式',
        prop: 'paper_type',
        align: 'center',
        computed(row: any) {
          if (row.row.paper_type === '1') {
            return '选题组卷'
          } else {
            return '自动组卷'
          }
        }
      },
      { label: '试卷名称', prop: 'paper_name', align: 'center', minWidth: '150' },
      { label: '总分', prop: 'paper_total_score', align: 'center' },
      { label: '及格分数', prop: 'pass_score', align: 'center' },
      { label: '操作', slots: 'table-operate', align: 'center', minWidth: '100' , fixed: 'right'}
    ]
  }
})
// 批改试卷 页面跳转
const handleCheckPaper = (row: any) => {
  router.push({
    path: '/teach/stuList',
    query: {
      course_id: row.course_id,
      paper_id: row.paper_id,
      paper_use: row.paper_use
    }
  })
}
// 获取所属课程列表
getSearchList({ type: 'course', search_id: '' }).then((res: any) => {
  courseListCategory.value = res.data
})
</script>

<template>
  <AppCard title="批改试卷">
    <AppList v-bind="listOptions" ref="appList" border stripe>
      <template #table-operate="{ row }">
        <el-space>
          <el-link type="primary" plain @click="handleCheckPaper(row)" v-permission="'v1-teaching-paper-list'"
            >批改试卷</el-link
          >
        </el-space>
      </template>
    </AppList>
  </AppCard>
</template>
