<template>
  <div class="app-container problemmodify-draft">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="检查类型" prop="problemType">
          <el-select v-model="form.problemType" placeholder="请选择检查类型" clearable>
            <el-option v-for="dict in ssp_proble_type" :key="dict.value" :label="dict.label" :value="dict.value">
            </el-option>
          </el-select>
        </el-form-item>
      <el-form-item label="整改人" prop="lordSent">
        <el-input v-model="queryParams.lordSent" style="width: 200px;" 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  size="mini" @click="handleAdd"
          v-hasPermi="['trouble:smzSspProblemmodifyDraft:add']">
          <el-icon><Plus /></el-icon>新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain size="mini" @click="dataSynchronization" :disabled="single"
          v-hasPermi="['trouble:smzSspProblemmodifyDraft:add']">
          <el-icon><CopyDocument /></el-icon>
          数据同步</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-tooltip content="批量提交选择的数据！" placement="bottom">
          <el-button type="success" plain size="mini" @click="batchSubmitForm"
            :disabled="multiple" v-hasPermi="['trouble:smzSspProblemmodifyDraft:add']">
            <el-icon><Check /></el-icon>批量提交</el-button>
        </el-tooltip>
      </el-col>
      
    </el-row>
    <el-alert title="操作说明" class="tips" effect="dark" type="warning" :closable="false">
      <template #title>
        <div><strong>数据同步:</strong>将选中行的数据同步到（当前项目或项目为空）的其它行！</div>
        <div><strong>批量提交:</strong>将选中行的数据，数据验证通过后一次全部提交！</div>
      </template>
    </el-alert>

    <el-table :data="problemmodifyDraftList">
      <el-table-column type="index" width="50" align="center" label="序号">
      </el-table-column>
    
      <el-table-column  align="center" width="240" class-name="td-up-img" label="问题图片">
        <template #default="scope">
            <image-upload v-model="scope.row.smarkUrl" previewAll :limit="5" :isShowTip="false" />
          </template>
      </el-table-column>
      <el-table-column  align="center" width="240" class-name="td-proble-type" label="隐患类型">
        <template #default="scope">
          <el-select v-model="scope.row.problemType" placeholder="请选择检查类型" clearable>
            <el-option v-for="dict in ssp_proble_type" :key="dict.value" :label="dict.label" :value="dict.value">
            </el-option>
          </el-select>
          <el-select v-model="scope.row.dangerType" placeholder="请选择隐患类型" clearable style="margin-top:80px;">
            <el-option v-for="dict in ssp_proble_sub_type" :key="dict.value" :label="dict.label" :value="dict.value">
            </el-option>
          </el-select>
          </template>
      </el-table-column>
      <el-table-column label="施工部位" align="center" prop="workParts" width="180">
          <template #default="scope">
            <el-input v-model="scope.row.workParts" placeholder="请输入施工部位" type="textarea" :rows="3" />
          </template>
        </el-table-column>
        <el-table-column label="整改要求" align="center" prop="changeInfo" width="180">
          <template #default="scope">
            <el-input v-model="scope.row.changeInfo" placeholder="请输入整改要求" type="textarea" :rows="3" />
          </template>
        </el-table-column>
      <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="删除状态" 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>
  </div>
</template>

<script setup name="ProblemmodifyDraft">
import {
  listProblemmodifyDraft,
  getProblemmodifyDraft,
  delProblemmodifyDraft,
  addProblemmodifyDraft,
  updateProblemmodifyDraft,
} from "@/api/trouble/problemmodifyDraft";

const { proxy } = getCurrentInstance();
const { ssp_proble_type,ssp_proble_sub_type } = proxy.useDict('ssp_proble_type','ssp_proble_sub_type');
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 uploadFileUrl = ref(import.meta.env.VITE_APP_BASE_API + "/file/upload"); // 上传文件服务器地址

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();
problemmodifyDraftList.value.push({});
</script>
<style lang="scss">
.problemmodify-draft{
  .td-up-img{
    .component-upload-image{
      height: 150px;
      overflow: hidden;
      .el-upload-list__item{
        position: absolute;
      }
    }
  }
}
</style>