<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="人员三类GUID" prop="persTtsGuid">
        <el-input v-model="queryParams.persTtsGuid" placeholder="请输入人员三类GUID" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="三类类型" prop="ttsaType">
        <el-select v-model="queryParams.ttsaType" placeholder="请选择三类类型" clearable>
          <el-option v-for="dict in ttsa_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="考核结果" prop="assResu">
        <el-select v-model="queryParams.assResu" placeholder="请选择考核结果" clearable>
          <el-option v-for="dict in ttsa_ass_resu" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['ttsa:ttsascore:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate" v-hasPermi="['ttsa:ttsascore:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete" v-hasPermi="['ttsa:ttsascore:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['ttsa:ttsascore:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns" storageKey="ttsa-ttsascore-index"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="人员三类GUID" prop="persTtsGuid" />
      <el-table-column label="三类类型" prop="ttsaType" width="120">
        <template #default="scope">
          <dict-tag :options="ttsa_type" :value="scope.row.ttsaType" />
        </template>
      </el-table-column>
      <el-table-column label="三类分数" prop="ttsaScore" />
      <el-table-column label="考核结果" prop="assResu" width="120">
        <template #default="scope">
          <dict-tag :options="ttsa_ass_resu" :value="scope.row.assResu" />
        </template>
      </el-table-column>
      <el-table-column label="核实状态" prop="veriStat" />
      <el-table-column label="考试时间" prop="examTime" width="180" />
      <el-table-column label="操作" align="center" width="200">
        <template #default="scope">
          <el-tooltip content="修改" placement="top">
            <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['ttsa:ttsascore:edit']"></el-button>
          </el-tooltip>
          <el-tooltip content="删除" placement="top">
            <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['ttsa:ttsascore:remove']"></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />

    <el-dialog :title="title" v-model="open" width="750px" append-to-body>
      <el-form ref="formRef" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="人员三类GUID" prop="persTtsGuid">
          <el-input v-model="form.persTtsGuid" placeholder="请输入人员三类GUID" />
        </el-form-item>
        <el-form-item label="准考证号" prop="admiTick">
          <el-input v-model="form.admiTick" placeholder="请输入准考证号" />
        </el-form-item>
        <el-form-item label="考试申请GUID" prop="ttsaExamApplGuid">
          <el-input v-model="form.ttsaExamApplGuid" placeholder="请输入考试申请GUID" />
        </el-form-item>
        <el-form-item label="考试GUID" prop="ttsaExamGuid">
          <el-input v-model="form.ttsaExamGuid" placeholder="请输入考试GUID" />
        </el-form-item>
        <el-form-item label="三类类型" prop="ttsaType">
          <el-select v-model="form.ttsaType" placeholder="请选择三类类型">
            <el-option v-for="dict in ttsa_type" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="三类分数" prop="ttsaScore">
          <el-input v-model="form.ttsaScore" placeholder="请输入三类分数" />
        </el-form-item>
        <el-form-item label="考核结果" prop="assResu">
          <el-select v-model="form.assResu" placeholder="请选择考核结果">
            <el-option v-for="dict in ttsa_ass_resu" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="核实组织GUID" prop="veriOrgGuid">
          <el-input v-model="form.veriOrgGuid" placeholder="请输入核实组织GUID" />
        </el-form-item>
        <el-form-item label="核实时间" prop="veriTime">
          <el-date-picker v-model="form.veriTime" type="datetime" placeholder="选择核实时间" clearable />
        </el-form-item>
        <el-form-item label="核实状态" prop="veriStat">
          <el-input v-model="form.veriStat" placeholder="请输入核实状态" />
        </el-form-item>
        <el-form-item label="核实意见" prop="veriOpin">
          <el-input v-model="form.veriOpin" type="textarea" placeholder="请输入核实意见" />
        </el-form-item>
        <el-form-item label="审批组织GUID" prop="apprOrgGuid">
          <el-input v-model="form.apprOrgGuid" placeholder="请输入审批组织GUID" />
        </el-form-item>
        <el-form-item label="审批时间" prop="apprTime">
          <el-date-picker v-model="form.apprTime" type="datetime" placeholder="选择审批时间" clearable />
        </el-form-item>
        <el-form-item label="审批状态" prop="apprStat">
          <el-input v-model="form.apprStat" placeholder="请输入审批状态" />
        </el-form-item>
        <el-form-item label="审批意见" prop="apprOpin">
          <el-input v-model="form.apprOpin" type="textarea" placeholder="请输入审批意见" />
        </el-form-item>
        <el-form-item label="考试时间" prop="examTime">
          <el-date-picker v-model="form.examTime" type="datetime" placeholder="选择考试时间" clearable />
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input v-model="form.note" type="textarea" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="TtsaScore">
import { listBisTtsaScore, getBisTtsaScore, addBisTtsaScore, updateBisTtsaScore, delBisTtsaScore } from "@/api/slaj/ttsa";
import { getCurrentInstance, reactive, ref, toRefs } from "vue";

const { proxy } = getCurrentInstance();
const { ttsa_type, ttsa_ass_resu } = proxy.useDict("ttsa_type", "ttsa_ass_resu");

const dataList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const columns = ref({ persTtsGuid: { visible: true }, ttsaType: { visible: true }, ttsaScore: { visible: true }, assResu: { visible: true }, veriStat: { visible: true }, examTime: { visible: true } });

const data = reactive({
  form: {},
  queryParams: { pageNum: 1, pageSize: 10, persTtsGuid: null, ttsaType: null, assResu: null },
  rules: {}
});
const { form, queryParams, rules } = toRefs(data);

function getList() {
  loading.value = true;
  listBisTtsaScore(queryParams.value).then(r => {
    dataList.value = r.rows;
    total.value = r.total;
    loading.value = false;
  });
}

function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

function handleSelectionChange(s) {
  ids.value = s.map(i => i.guid);
  single.value = s.length !== 1;
  multiple.value = !s.length;
}

function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加考试成绩";
}

function handleUpdate(row) {
  reset();
  getBisTtsaScore(row.guid || ids.value[0]).then(r => {
    form.value = r.data;
    open.value = true;
    title.value = "修改考试成绩";
  });
}

function submitForm() {
  proxy.$refs["formRef"].validate(v => {
    if (v) {
      if (form.value.guid != null) {
        updateBisTtsaScore(form.value).then(() => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addBisTtsaScore(form.value).then(() => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

function handleDelete(row) {
  proxy.$modal.confirm('确认删除？').then(() => delBisTtsaScore(row.guid || ids.value.join(","))).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  });
}

function handleExport() {
  proxy.download('/ttsa/ttsascore/export', { ...queryParams.value }, `考试成绩_${new Date().getTime()}.xlsx`);
}

function cancel() {
  open.value = false;
  reset();
}

function reset() {
  form.value = { guid: null, persTtsGuid: null, admiTick: null, ttsaExamApplGuid: null, ttsaExamGuid: null, ttsaType: null, ttsaScore: null, assResu: null, veriOrgGuid: null, veriTime: null, veriStat: null, veriOpin: null, apprOrgGuid: null, apprTime: null, apprStat: null, apprOpin: null, examTime: null, note: null };
  proxy.resetForm("formRef");
}

getList();
</script>
