<script setup lang="ts">
import { ElMessage } from 'element-plus'
import { useFilterList } from '../composables/useFilterList'
import { syncExperimentExam } from '../api'

const emit = defineEmits<{
  (e: 'update'): void
}>()

const { experiments } = useFilterList()
const form = reactive({ experiment_id: '' })
// 同步
function handleSync() {
  syncExperimentExam({ experiment_id: form.experiment_id }).then(() => {
    ElMessage.success('同步成功')
    emit('update')
  })
}
</script>

<template>
  <el-dialog title="同步1+X考试成绩" :close-on-click-modal="false" width="440px">
    <el-form>
      <el-form-item label="实验名称">
        <el-select v-model="form.experiment_id" value-key="id">
          <el-option v-for="item in experiments" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
        &nbsp;&nbsp;
        <el-button type="primary" :disabled="!form.experiment_id" @click="handleSync">一键同步成绩</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
