<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="评审GUID" prop="stanReviGuid">
        <el-input v-model="queryParams.stanReviGuid" placeholder="请输入评审GUID" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="评审类型" prop="reviType">
        <el-select v-model="queryParams.reviType" placeholder="请选择评审类型" clearable>
          <el-option v-for="dict in eutr_revi_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="是否同意" prop="ifAgree">
        <el-select v-model="queryParams.ifAgree" placeholder="请选择是否同意" clearable>
          <el-option v-for="dict in eutr_revi_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="['stan:stanrevirec:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate" v-hasPermi="['stan:stanrevirec:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete" v-hasPermi="['stan:stanrevirec:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['stan:stanrevirec:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns" storageKey="stan-stanrevirec-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="评审单位编码" prop="reviWiunCode" />
      <el-table-column label="评审类型" prop="reviType" width="120">
        <template #default="scope">
          <dict-tag :options="eutr_revi_type" :value="scope.row.reviType" />
        </template>
      </el-table-column>
      <el-table-column label="是否同意" prop="ifAgree" width="120">
        <template #default="scope">
          <dict-tag :options="eutr_revi_resu" :value="scope.row.ifAgree" />
        </template>
      </el-table-column>
      <el-table-column label="确认时间" prop="confTime" width="180" />
      <el-table-column label="评审组长" prop="reviChief" />
      <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="['stan:stanrevirec:edit']"></el-button>
          </el-tooltip>
          <el-tooltip content="删除" placement="top">
            <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['stan:stanrevirec: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="700px" append-to-body>
      <el-form ref="formRef" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="评审GUID" prop="stanReviGuid">
          <el-input v-model="form.stanReviGuid" placeholder="请输入评审GUID" />
        </el-form-item>
        <el-form-item label="评审单位编码" prop="reviWiunCode">
          <el-input v-model="form.reviWiunCode" placeholder="请输入评审单位编码" />
        </el-form-item>
        <el-form-item label="评审类型" prop="reviType">
          <el-select v-model="form.reviType" placeholder="请选择评审类型">
            <el-option v-for="dict in eutr_revi_type" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="确认地点" prop="confLoc">
          <el-input v-model="form.confLoc" placeholder="请输入确认地点" />
        </el-form-item>
        <el-form-item label="参加人员" prop="partPers">
          <el-input v-model="form.partPers" placeholder="请输入参加人员" />
        </el-form-item>
        <el-form-item label="是否现场评审" prop="ifSiteRevi">
          <el-input v-model="form.ifSiteRevi" placeholder="请输入是否现场评审" />
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-date-picker v-model="form.startTime" type="datetime" placeholder="选择开始时间" clearable />
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker v-model="form.endTime" type="datetime" placeholder="选择结束时间" clearable />
        </el-form-item>
        <el-form-item label="是否同意" prop="ifAgree">
          <el-select v-model="form.ifAgree" placeholder="请选择是否同意">
            <el-option v-for="dict in eutr_revi_resu" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="推荐等级" prop="recomLevel">
          <el-input v-model="form.recomLevel" placeholder="请输入推荐等级" />
        </el-form-item>
        <el-form-item label="评审意见" prop="reviOpin">
          <el-input v-model="form.reviOpin" type="textarea" placeholder="请输入评审意见" />
        </el-form-item>
        <el-form-item label="确认时间" prop="confTime">
          <el-date-picker v-model="form.confTime" type="datetime" placeholder="选择确认时间" clearable />
        </el-form-item>
        <el-form-item label="评审组长" prop="reviChief">
          <el-input v-model="form.reviChief" placeholder="请输入评审组长" />
        </el-form-item>
        <el-form-item label="评审副组长" prop="reviViceChief">
          <el-input v-model="form.reviViceChief" placeholder="请输入评审副组长" />
        </el-form-item>
        <el-form-item label="评审组成员" prop="reviGroupMem">
          <el-input v-model="form.reviGroupMem" placeholder="请输入评审组成员" />
        </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="专家GUID" prop="persExpertGuid">
          <el-input v-model="form.persExpertGuid" placeholder="请输入专家GUID" />
        </el-form-item>
        <el-form-item label="现场评审说明" prop="siteReviNote">
          <el-input v-model="form.siteReviNote" type="textarea" placeholder="请输入现场评审说明" />
        </el-form-item>
        <el-form-item label="评审说明" prop="reviNote">
          <el-input v-model="form.reviNote" type="textarea" placeholder="请输入评审说明" />
        </el-form-item>
        <el-form-item label="评审等级" prop="reviGrade">
          <el-input v-model="form.reviGrade" placeholder="请输入评审等级" />
        </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="StanReviRec">
import { listBisStanReviRec, getBisStanReviRec, addBisStanReviRec, updateBisStanReviRec, delBisStanReviRec } from "@/api/slaj/stan";
import { getCurrentInstance, reactive, ref, toRefs } from "vue";

const { proxy } = getCurrentInstance();
const { eutr_revi_type, eutr_revi_resu } = proxy.useDict("eutr_revi_type", "eutr_revi_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({ reviWiunCode: { visible: true }, reviType: { visible: true }, ifAgree: { visible: true }, confTime: { visible: true }, reviChief: { visible: true } });

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

function getList() {
  loading.value = true;
  listBisStanReviRec(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();
  getBisStanReviRec(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) {
        updateBisStanReviRec(form.value).then(() => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addBisStanReviRec(form.value).then(() => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

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

function handleExport() {
  proxy.download('/stan/stanrevirec/export', { ...queryParams.value }, `标准化评审记录_${new Date().getTime()}.xlsx`);
}

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

function reset() {
  form.value = { guid: null, stanReviGuid: null, reviWiunCode: null, reviType: null, confLoc: null, partPers: null, ifSiteRevi: null, startTime: null, endTime: null, ifAgree: null, recomLevel: null, reviOpin: null, confTime: null, reviChief: null, reviViceChief: null, reviGroupMem: null, veriTime: null, persExpertGuid: null, siteReviNote: null, reviNote: null, reviGrade: null, note: null };
  proxy.resetForm("formRef");
}

getList();
</script>
