<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter"
      :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <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-card>
      </div>
    </transition>
    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus" @click="handleAdd"
              v-hasPermi="['design:drawingreview:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()"
              v-hasPermi="['design:drawingreview:edit']">修改</el-button>
          </el-col>
          <!-- <el-col :span="1.5">
            <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()"
              v-hasPermi="['design:drawingreview:remove']">删除</el-button>
          </el-col> -->
          <!-- <el-col :span="1.5">
            <el-button type="warning" plain icon="Download" @click="handleExport"
              v-hasPermi="['design:drawingreview:export']">导出</el-button>
          </el-col> -->
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" :data="drawingreviewList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="项目ID" align="center" prop="id" v-if="true" />
        <el-table-column label="文件名称" align="center" prop="fileName" />
        <el-table-column label="审核类型" align="center" prop="auditType" />
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <!-- <el-tooltip content="修改" placement="top">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
                v-hasPermi="['design:drawingreview:edit']"></el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
                v-hasPermi="['design:drawingreview:remove']"></el-button>
            </el-tooltip> -->
            <el-tooltip content="修改" placement="top">
              <el-button link type="primary" icon="Edit" @click="handleExamine(scope.row)"></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-card>
    <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
      <el-form ref="drawingreviewFormRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目ID" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入项目ID" />
        </el-form-item>
        <el-form-item label="审核类型" prop="auditType">
          <el-upload ref="uploadRef" class="upload-demo" :http-request="importExcel">
            <template #trigger>
              <el-button type="primary">上传excel</el-button>
            </template>
          </el-upload>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog title="审核" v-model="examineDialog" width="500px" append-to-body>
      <el-form ref="formRef" :model="examineForm" :rules="rules1" label-width="120px" class="info-form">
        <!-- 基本信息区域 -->
        <el-form-item label="编号" prop="num">
          <el-input v-model="examineForm.num" placeholder="请输入编号" />
        </el-form-item>

        <el-form-item label="专业" prop="professional">
          <el-input v-model="examineForm.professional" placeholder="请输入专业" />
        </el-form-item>

        <el-form-item label="设计阶段" prop="stage">
          <el-input v-model="examineForm.stage" placeholder="请输入设计阶段" />
        </el-form-item>

        <el-form-item label="卷册" prop="volume">
          <el-input v-model="examineForm.volume" placeholder="请输入卷册" />
        </el-form-item>

        <!-- 项目信息区域 -->
        <el-form-item label="项目ID" prop="projectId">
          <el-input v-model="examineForm.projectId" placeholder="请输入项目ID" />
        </el-form-item>

        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="examineForm.projectName" placeholder="请输入项目名称" />
        </el-form-item>

        <el-form-item label="子项目ID" prop="subprojectId">
          <el-input v-model="examineForm.subprojectId" placeholder="请输入子项目ID" />
        </el-form-item>

        <el-form-item label="子项目名称" prop="subprojectName">
          <el-input v-model="examineForm.subprojectName" placeholder="请输入子项目名称" />
        </el-form-item>

        <!-- 人员信息区域 -->
        <el-form-item label="设计人" prop="designer">
          <el-input v-model="examineForm.designer" placeholder="请输入设计人" />
        </el-form-item>

        <el-form-item label="校审人员" prop="proofreading">
          <el-input v-model="examineForm.proofreading" placeholder="请输入校审人员" />
        </el-form-item>

        <el-form-item label="校审人员ID" prop="proofreadingId">
          <el-input v-model="examineForm.proofreadingId" placeholder="请输入校审人员ID" />
        </el-form-item>

        <el-form-item label="校审时间" prop="proofreadingDate">
          <el-date-picker v-model="examineForm.proofreadingDate" type="datetime" placeholder="选择校审时间"
            value-format="YYYY-MM-DD HH:mm:ss" />
        </el-form-item>

        <el-form-item label="审核人员" prop="audit">
          <el-input v-model="examineForm.audit" placeholder="请输入审核人员" />
        </el-form-item>

        <el-form-item label="审核人员ID" prop="auditId">
          <el-input v-model="examineForm.auditId" placeholder="请输入审核人员ID" />
        </el-form-item>

        <el-form-item label="审核时间" prop="auditDate">
          <el-date-picker v-model="examineForm.auditDate" type="datetime" placeholder="选择审核时间"
            value-format="YYYY-MM-DD HH:mm:ss" />
        </el-form-item>

        <el-form-item label="执行人员" prop="executor">
          <el-input v-model="examineForm.executor" placeholder="请输入执行人员" />
        </el-form-item>

        <el-form-item label="执行人员ID" prop="executorId">
          <el-input v-model="examineForm.executorId" placeholder="请输入执行人员ID" />
        </el-form-item>

        <el-form-item label="执行时间" prop="executorDate">
          <el-date-picker v-model="examineForm.executorDate" type="datetime" placeholder="选择执行时间"
            value-format="YYYY-MM-DD HH:mm:ss" />
        </el-form-item>

        <!-- 意见和内容区域 -->
        <el-form-item label="验证内容" prop="verificationContent">
          <el-input v-model="examineForm.verificationContent" type="textarea" placeholder="请输入验证内容" />
        </el-form-item>

        <el-form-item label="验证意见" prop="verificationOpinion">
          <el-input v-model="examineForm.verificationOpinion" type="textarea" placeholder="请输入验证意见" />
        </el-form-item>

        <el-form-item label="执行意见" prop="executionOpinion">
          <el-input v-model="examineForm.executionOpinion" type="textarea" placeholder="请输入执行意见" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitexamineForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Drawingreview">
import { computed, getCurrentInstance,toRefs } from 'vue';
import { listDrawingreview, getDrawingreview, addDrawingreview, updateDrawingreview,fillOutTheDesignVerificationForm } from '@/api/design/drawingreview';
import { useUserStoreHook } from '@/store/modules/user';
import { fromFile } from 'geotiff';
const { proxy } = getCurrentInstance();
const userStore = useUserStoreHook();
const loading = ref(true);
const buttonLoading = ref(false);
const total = ref(0);
const drawingreviewList = ref([]);
const fromData = new FormData()
const currentProject = computed(() => userStore.selectedProject);
const dialog = reactive({
  visible: false,
  title: ''
});
const initexamineForm = {
  id: undefined,
  projectId: currentProject.value?.id,
  auditType: undefined,
  remark: undefined,
}
const drawingreviewFormRef = ref();
const data = reactive({
  form: { ...initexamineForm },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    projectId: currentProject.value?.id,
    auditType: undefined,
    params: {
    }
  },
  rules: {
    id: [
      { required: true, message: "项目ID不能为空", trigger: "blur" }
    ],
  }
});
const { queryParams, form, rules } = toRefs(data);
const examineForm = reactive({
  audit: '',
  auditDate: '',
  auditId: '',
  designer: '',
  executionOpinion: '',
  executor: '',
  executorDate: '',
  executorId: '',
  id: '1',
  num: '',
  professional: '',
  projectId: '',
  projectName: '',
  proofreading: '',
  proofreadingDate: '',
  proofreadingId: '',
  stage: '',
  subprojectId: '',
  subprojectName: '',
  verificationContent: '',
  verificationOpinion: '',
  volume: ''
});
/** 查询设计-图纸评审列表 */
const getList = async () => {
  loading.value = true;
  const res = await listDrawingreview(queryParams.value);
  drawingreviewList.value = res.rows;
  total.value = res.total;
  loading.value = false;
}
/** 新增按钮操作 */
const handleAdd = () => {
  reset();
  dialog.visible = true;
  dialog.title = "添加设计-图纸评审";
}
/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
}
/** 表单重置 */
const reset = () => {
  form.value = { ...initexamineForm };
  drawingreviewFormRef.value?.resetFields();
}
function handleQuery(){}
function handleExamine(){}
/** 提交按钮 */
const submitForm = () => {
  drawingreviewFormRef.value?.validate(async (valid) => {
    if (valid) {
      buttonLoading.value = true;
      if (form.value.id) {
        await updateDrawingreview(form.value).finally(() => buttonLoading.value = false);
      } else {
        await addDrawingreview(form.value, fromData).finally(() => buttonLoading.value = false);
      }
      proxy?.$modal.msgSuccess("操作成功");
      dialog.visible = false;
      await getList();
    }
  });
}
// 上传excel
function importExcel(options) {
  fromData.append("file", options.file)
}
onMounted(() => {
  getList();
});
</script>
