<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="培训类型" prop="eutrType"><el-select v-model="queryParams.eutrType" placeholder="请选择培训类型" clearable style="width: 200px"><el-option v-for="dict in eutr_rec_stat" :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="['eutr:offlrec:add']">新增</el-button></el-col>
      <el-col :span="1.5"><el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate" v-hasPermi="['eutr:offlrec:edit']">修改</el-button></el-col>
      <el-col :span="1.5"><el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete" v-hasPermi="['eutr:offlrec:remove']">删除</el-button></el-col>
      <el-col :span="1.5"><el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['eutr:offlrec:export']">导出</el-button></el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns" storageKey="eutr-offlrec-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="开始日期" align="center" prop="eutrStartDate" v-if="columns.eutrStartDate.visible" width="180" />
      <el-table-column label="结束日期" align="center" prop="eutrEndDate" v-if="columns.eutrEndDate.visible" width="180" />
      <el-table-column label="地点" align="center" prop="eutrLoc" v-if="columns.eutrLoc.visible" :show-overflow-tooltip="true" />
      <el-table-column label="培训内容" align="center" prop="eutrCont" v-if="columns.eutrCont.visible" :show-overflow-tooltip="true" />
      <el-table-column label="培训类型" align="center" prop="eutrType" v-if="columns.eutrType.visible"><template #default="scope"><dict-tag :options="eutr_rec_stat" :value="scope.row.eutrType" /></template></el-table-column>
      <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="['eutr:offlrec:edit']"></el-button></el-tooltip><el-tooltip content="删除" placement="top"><el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['eutr:offlrec: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="650px" append-to-body>
      <el-form ref="formRef" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="开始日期" prop="eutrStartDate"><el-date-picker v-model="form.eutrStartDate" type="datetime" value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择" /></el-form-item>
        <el-form-item label="结束日期" prop="eutrEndDate"><el-date-picker v-model="form.eutrEndDate" type="datetime" value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择" /></el-form-item>
        <el-form-item label="地点" prop="eutrLoc"><el-input v-model="form.eutrLoc" placeholder="请输入地点" /></el-form-item>
        <el-form-item label="培训内容" prop="eutrCont"><el-input v-model="form.eutrCont" type="textarea" placeholder="请输入培训内容" /></el-form-item>
        <el-form-item label="培训主题" prop="eutrThem"><el-input v-model="form.eutrThem" placeholder="请输入培训主题" /></el-form-item>
        <el-form-item label="参训人数" prop="eutrNum"><el-input v-model="form.eutrNum" placeholder="请输入参训人数" /></el-form-item>
        <el-form-item label="学时" prop="eutrHuor"><el-input v-model="form.eutrHuor" placeholder="请输入学时" /></el-form-item>
        <el-form-item label="组织单位" prop="orgGuid"><el-input v-model="form.orgGuid" placeholder="请输入机构guid" /></el-form-item>
        <el-form-item label="培训类型" prop="eutrType"><el-select v-model="form.eutrType" placeholder="请选择"><el-option v-for="dict in eutr_rec_stat" :key="dict.value" :label="dict.label" :value="dict.value" /></el-select></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="EutrOfflRec">
import { listOfflRec, getOfflRec, addOfflRec, updateOfflRec, delOfflRec } from "@/api/slaj/eutr";
import { getCurrentInstance, reactive, ref, toRefs } from "vue";

const { proxy } = getCurrentInstance();
const { eutr_rec_stat } = proxy.useDict("eutr_rec_stat");

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({ eutrStartDate: { visible: true }, eutrEndDate: { visible: true }, eutrLoc: { visible: true }, eutrCont: { visible: true }, eutrType: { visible: true } });

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

function getList() { loading.value = true; listOfflRec(queryParams.value).then(response => { dataList.value = response.rows; total.value = response.total; loading.value = false; }); }
function handleQuery() { queryParams.value.pageNum = 1; getList(); }
function resetQuery() { proxy.resetForm("queryRef"); handleQuery(); }
function handleSelectionChange(selection) { ids.value = selection.map(item => item.guid); single.value = selection.length !== 1; multiple.value = !selection.length; }
function handleAdd() { reset(); open.value = true; title.value = "添加线下培训记录"; }
function handleUpdate(row) { reset(); getOfflRec(row.guid || ids.value[0]).then(response => { form.value = response.data; open.value = true; title.value = "修改线下培训记录"; }); }
function submitForm() { proxy.$refs["formRef"].validate(valid => { if (valid) { if (form.value.guid != null) { updateOfflRec(form.value).then(() => { proxy.$modal.msgSuccess("修改成功"); open.value = false; getList(); }); } else { addOfflRec(form.value).then(() => { proxy.$modal.msgSuccess("新增成功"); open.value = false; getList(); }); } } }); }
function handleDelete(row) { proxy.$modal.confirm('是否确认删除？').then(function() { return delOfflRec(row.guid || ids.value.join(",")); }).then(() => { getList(); proxy.$modal.msgSuccess("删除成功"); }); }
function handleExport() { proxy.download('/eutr/offlrec/export', { ...queryParams.value }, `线下培训记录_${new Date().getTime()}.xlsx`); }
function cancel() { open.value = false; reset(); }
function reset() { form.value = { guid: null, eutrStartDate: null, eutrEndDate: null, eutrLoc: null, eutrCont: null, eutrThem: null, eutrNum: null, eutrHuor: null, orgGuid: null, eutrType: null, note: null }; proxy.resetForm("formRef"); }
getList();
</script>
