<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="租户ID" prop="comId">
        <el-input
          v-model="queryParams.comId"
          placeholder="请输入租户ID"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目id" prop="projectId">
        <el-input
          v-model="queryParams.projectId"
          placeholder="请输入项目id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="留痕图片" prop="marksPicture">
        <el-input
          v-model="queryParams.marksPicture"
          placeholder="请输入留痕图片"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="留痕视频" prop="marksVideo">
        <el-input
          v-model="queryParams.marksVideo"
          placeholder="请输入留痕视频"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="拍摄位置" prop="problemArea">
        <el-input
          v-model="queryParams.problemArea"
          placeholder="请输入拍摄位置"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="施工部位" prop="workParts">
        <el-input
          v-model="queryParams.workParts"
          placeholder="请输入施工部位"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="整改要求" prop="changeInfo">
        <el-input
          v-model="queryParams.changeInfo"
          placeholder="请输入整改要求"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主送人姓名" prop="lordSent">
        <el-input
          v-model="queryParams.lordSent"
          placeholder="请输入主送人姓名"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主送人手机号" prop="lordSentUser">
        <el-input
          v-model="queryParams.lordSentUser"
          placeholder="请输入主送人手机号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抄送人姓名" prop="copySend">
        <el-input
          v-model="queryParams.copySend"
          placeholder="请输入抄送人姓名"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抄送人手机号" prop="copySendUser">
        <el-input
          v-model="queryParams.copySendUser"
          placeholder="请输入抄送人手机号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流程状态" prop="checkState">
        <el-input
          v-model="queryParams.checkState"
          placeholder="请输入流程状态"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="整改定位" prop="nickedArea">
        <el-input
          v-model="queryParams.nickedArea"
          placeholder="请输入整改定位"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="整改截至时间" prop="nickedTime">
        <el-date-picker clearable
          v-model="queryParams.nickedTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择整改截至时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="工序名称" prop="processName">
        <el-input
          v-model="queryParams.processName"
          placeholder="请输入工序名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工程名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入工程名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="留痕说明" prop="nickedInfo">
        <el-input
          v-model="queryParams.nickedInfo"
          placeholder="请输入留痕说明"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人" prop="checkUser">
        <el-input
          v-model="queryParams.checkUser"
          placeholder="请输入审核人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人手机号" prop="checkUserPhone">
        <el-input
          v-model="queryParams.checkUserPhone"
          placeholder="请输入审核人手机号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除状态" prop="isDel">
        <el-input
          v-model="queryParams.isDel"
          placeholder="请输入删除状态"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="createUser">
        <el-input
          v-model="queryParams.createUser"
          placeholder="请输入创建人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="修改人" prop="updateUser">
        <el-input
          v-model="queryParams.updateUser"
          placeholder="请输入修改人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改时间" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择修改时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="复检人" prop="recheckSend">
        <el-input
          v-model="queryParams.recheckSend"
          placeholder="请输入复检人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="复检人手机号" prop="recheckSendUser">
        <el-input
          v-model="queryParams.recheckSendUser"
          placeholder="请输入复检人手机号"
          clearable
          @keyup.enter="handleQuery"
        />
      </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="['trouble:problemmodifyDraft:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['trouble:problemmodifyDraft:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['trouble:problemmodifyDraft:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['trouble:problemmodifyDraft:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="problemmodifyDraftList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="id" />
      <el-table-column label="租户ID" align="center" prop="comId" />
      <el-table-column label="项目id" align="center" prop="projectId" />
      <el-table-column label="信息类型" align="center" prop="infoType" />
      <el-table-column label="留痕图片" align="center" prop="marksPicture" />
      <el-table-column label="留痕视频" align="center" prop="marksVideo" />
      <el-table-column label="拍摄位置" align="center" prop="problemArea" />
      <el-table-column label="施工部位" align="center" prop="workParts" />
      <el-table-column label="整改要求" align="center" prop="changeInfo" />
      <el-table-column label="主送人姓名" align="center" prop="lordSent" />
      <el-table-column label="主送人手机号" align="center" prop="lordSentUser" />
      <el-table-column label="抄送人姓名" align="center" prop="copySend" />
      <el-table-column label="抄送人手机号" align="center" prop="copySendUser" />
      <el-table-column label="流程状态" align="center" prop="checkState" />
      <el-table-column label="整改定位" align="center" prop="nickedArea" />
      <el-table-column label="整改截至时间" align="center" prop="nickedTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.nickedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="工程类型" align="center" prop="projectType" />
      <el-table-column label="工序名称" align="center" prop="processName" />
      <el-table-column label="工程名称" align="center" prop="projectName" />
      <el-table-column label="留痕说明" align="center" prop="nickedInfo" />
      <el-table-column label="审核人" align="center" prop="checkUser" />
      <el-table-column label="审核人手机号" align="center" prop="checkUserPhone" />
      <el-table-column label="智能公司展示的图片url" align="center" prop="smarkUrl" />
      <el-table-column label="删除状态" align="center" prop="isDel" />
      <el-table-column label="创建人" align="center" prop="createUser" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="updateUser" />
      <el-table-column label="修改时间" align="center" prop="updateTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="隐患类型" align="center" prop="dangerType" />
      <el-table-column label="复检人" align="center" prop="recheckSend" />
      <el-table-column label="复检人手机号" align="center" prop="recheckSendUser" />
      <el-table-column label="角色类型" align="center" prop="roleType" />
      <el-table-column label="问题类型" align="center" prop="problemType" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['trouble:problemmodifyDraft:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['trouble:problemmodifyDraft:remove']">删除</el-button>
        </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="500px" append-to-body>
      <el-form ref="problemmodifyDraftRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="租户ID" prop="comId">
          <el-input v-model="form.comId" placeholder="请输入租户ID" />
        </el-form-item>
        <el-form-item label="项目id" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入项目id" />
        </el-form-item>
        <el-form-item label="留痕图片" prop="marksPicture">
          <el-input v-model="form.marksPicture" placeholder="请输入留痕图片" />
        </el-form-item>
        <el-form-item label="留痕视频" prop="marksVideo">
          <el-input v-model="form.marksVideo" placeholder="请输入留痕视频" />
        </el-form-item>
        <el-form-item label="拍摄位置" prop="problemArea">
          <el-input v-model="form.problemArea" placeholder="请输入拍摄位置" />
        </el-form-item>
        <el-form-item label="施工部位" prop="workParts">
          <el-input v-model="form.workParts" placeholder="请输入施工部位" />
        </el-form-item>
        <el-form-item label="整改要求" prop="changeInfo">
          <el-input v-model="form.changeInfo" placeholder="请输入整改要求" />
        </el-form-item>
        <el-form-item label="主送人姓名" prop="lordSent">
          <el-input v-model="form.lordSent" placeholder="请输入主送人姓名" />
        </el-form-item>
        <el-form-item label="主送人手机号" prop="lordSentUser">
          <el-input v-model="form.lordSentUser" placeholder="请输入主送人手机号" />
        </el-form-item>
        <el-form-item label="抄送人姓名" prop="copySend">
          <el-input v-model="form.copySend" placeholder="请输入抄送人姓名" />
        </el-form-item>
        <el-form-item label="抄送人手机号" prop="copySendUser">
          <el-input v-model="form.copySendUser" placeholder="请输入抄送人手机号" />
        </el-form-item>
        <el-form-item label="流程状态" prop="checkState">
          <el-input v-model="form.checkState" placeholder="请输入流程状态" />
        </el-form-item>
        <el-form-item label="整改定位" prop="nickedArea">
          <el-input v-model="form.nickedArea" placeholder="请输入整改定位" />
        </el-form-item>
        <el-form-item label="整改截至时间" prop="nickedTime">
          <el-date-picker clearable
            v-model="form.nickedTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择整改截至时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="工序名称" prop="processName">
          <el-input v-model="form.processName" placeholder="请输入工序名称" />
        </el-form-item>
        <el-form-item label="工程名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入工程名称" />
        </el-form-item>
        <el-form-item label="留痕说明" prop="nickedInfo">
          <el-input v-model="form.nickedInfo" placeholder="请输入留痕说明" />
        </el-form-item>
        <el-form-item label="审核人" prop="checkUser">
          <el-input v-model="form.checkUser" placeholder="请输入审核人" />
        </el-form-item>
        <el-form-item label="审核人手机号" prop="checkUserPhone">
          <el-input v-model="form.checkUserPhone" placeholder="请输入审核人手机号" />
        </el-form-item>
        <el-form-item label="智能公司展示的图片url" prop="smarkUrl">
          <el-input v-model="form.smarkUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="删除状态" prop="isDel">
          <el-input v-model="form.isDel" placeholder="请输入删除状态" />
        </el-form-item>
        <el-form-item label="创建人" prop="createUser">
          <el-input v-model="form.createUser" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="修改人" prop="updateUser">
          <el-input v-model="form.updateUser" placeholder="请输入修改人" />
        </el-form-item>
        <el-form-item label="复检人" prop="recheckSend">
          <el-input v-model="form.recheckSend" placeholder="请输入复检人" />
        </el-form-item>
        <el-form-item label="复检人手机号" prop="recheckSendUser">
          <el-input v-model="form.recheckSendUser" 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="ProblemmodifyDraft">
import { listProblemmodifyDraft, getProblemmodifyDraft, delProblemmodifyDraft, addProblemmodifyDraft, updateProblemmodifyDraft } from "@/api/trouble/problemmodifyDraft";

const { proxy } = getCurrentInstance();

const problemmodifyDraftList = 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 data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    comId: null,
    projectId: null,
    infoType: null,
    marksPicture: null,
    marksVideo: null,
    problemArea: null,
    workParts: null,
    changeInfo: null,
    lordSent: null,
    lordSentUser: null,
    copySend: null,
    copySendUser: null,
    checkState: null,
    nickedArea: null,
    nickedTime: null,
    projectType: null,
    processName: null,
    projectName: null,
    nickedInfo: null,
    checkUser: null,
    checkUserPhone: null,
    smarkUrl: null,
    isDel: null,
    createUser: null,
    createTime: null,
    updateUser: null,
    updateTime: null,
    dangerType: null,
    recheckSend: null,
    recheckSendUser: null,
    roleType: null,
    problemType: null
  },
  rules: {
    comId: [
      { required: true, message: "租户ID不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询安全问题草稿列表 */
function getList() {
  loading.value = true;
  listProblemmodifyDraft(queryParams.value).then(response => {
    problemmodifyDraftList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    comId: null,
    projectId: null,
    infoType: null,
    marksPicture: null,
    marksVideo: null,
    problemArea: null,
    workParts: null,
    changeInfo: null,
    lordSent: null,
    lordSentUser: null,
    copySend: null,
    copySendUser: null,
    checkState: null,
    nickedArea: null,
    nickedTime: null,
    projectType: null,
    processName: null,
    projectName: null,
    nickedInfo: null,
    checkUser: null,
    checkUserPhone: null,
    smarkUrl: null,
    isDel: null,
    createUser: null,
    createTime: null,
    updateUser: null,
    updateTime: null,
    dangerType: null,
    recheckSend: null,
    recheckSendUser: null,
    roleType: null,
    problemType: null
  };
  proxy.resetForm("problemmodifyDraftRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加安全问题草稿";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getProblemmodifyDraft(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改安全问题草稿";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["problemmodifyDraftRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateProblemmodifyDraft(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addProblemmodifyDraft(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除安全问题草稿编号为"' + _ids + '"的数据项？').then(function() {
    return delProblemmodifyDraft(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('trouble/problemmodifyDraft/export', {
    ...queryParams.value
  }, `problemmodifyDraft_${new Date().getTime()}.xlsx`)
}

getList();
</script>
