<template>
  <div class="app-container trouble-problemodify-index">
    <el-form class="header-form" :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">

      <el-form-item label="检查类型" prop="problemType">
        <el-select v-model="queryParams.problemType" placeholder="请选择检查类型" clearable4 style="width: 160px;">
          <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="dangerType">
        <el-select v-model="queryParams.dangerType" placeholder="请选择隐患类型" clearable>
          <el-option v-for="dict in ssp_proble_sub_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" placeholder="请输入人员姓名/联系方式" clearable style="width: 180px;" />
      </el-form-item>
      <el-form-item label="提交人" prop="createUser">
        <el-input v-model="queryParams.createUser" placeholder="请输入人员姓名/联系方式" clearable style="width: 180px;" />
      </el-form-item>
      <el-form-item label="提交时间" prop="dateRange">
        <el-date-picker v-model="queryParams.dataRange" type="daterange" style="width: 300px;" range-separator="--"
          start-placeholder="开始日期" end-placeholder="结束日期" />
      </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-tabs v-model="data.activeName" class="main-tabs">
      <el-tab-pane :label="data.tabInfo['a']" name="a"></el-tab-pane>
      <el-tab-pane :label="data.tabInfo['b']" name="b"></el-tab-pane>
      <el-tab-pane :label="data.tabInfo['c']" name="c"></el-tab-pane>
      <el-tab-pane :label="data.tabInfo['d']" name="d"></el-tab-pane>
      <el-tab-pane :label="data.tabInfo['e']" name="e"></el-tab-pane>
    </el-tabs>
    <el-table v-loading="loading" :data="problemmodifyList" @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="correctionPicture" />
      <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:problemmodify:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
            v-hasPermi="['trouble:problemmodify: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" />

  </div>
</template>

<script setup name="Problemmodify">
import { listProblemmodify, getProblemmodify, delProblemmodify, addProblemmodify, updateProblemmodify, getListCount } from "@/api/trouble/problemmodify";

const { proxy } = getCurrentInstance();
const { ssp_proble_type, ssp_proble_sub_type } = proxy.useDict('ssp_proble_type', 'ssp_proble_sub_type');
const problemmodifyList = 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: {
    dateRange: [],
    pageNum: 1,
    pageSize: 10,
    comId: null,
    projectId: null,
    infoType: null,
    problemType: null,
    dangerType: null,
    lordSent: null,
    createUser: null,
  },
  rules: {
    comId: [
      { required: true, message: "租户ID不能为空", trigger: "blur" }
    ],
  },
  activeName: 'a',
  tabInfo: {}
});

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

/** 查询安全隐患整改列表 */
function getList() {
  loading.value = true;
  let postData = {
    infoType: 0,
    problemType: queryParams.value.problemType,
    dangerType: queryParams.value.dangerType,
    lordSent: queryParams.value.lordSent,
    createUser: queryParams.value.createUser,
    projectName: " abcde".indexOf(data.activeName)
  };
  if (queryParams.value.dataRange && queryParams.value.dataRange.length > 0) {
    postData.createTime = queryParams.value.dataRange[0];
    postData.updateTime = queryParams.value.dataRange[1];
  }
  listProblemmodify(postData).then(response => {
    problemmodifyList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}


// 表单重置
function reset() {
  form.value = {
    id: null,
    comId: null,
    projectId: null,
    infoType: null,
    marksPicture: null,
    marksVideo: null,
    correctionPicture: 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("problemmodifyRef");
}

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

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  queryParams.value.dataRange = [];
  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
  getProblemmodify(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改安全隐患整改";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["problemmodifyRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateProblemmodify(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addProblemmodify(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 delProblemmodify(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => { });
}

function getCount() {
  let postData = {
    infoType: 0,
    problemType: queryParams.value.problemType,
    dangerType: queryParams.value.dangerType,
    lordSent: queryParams.value.lordSent,
    createUser: queryParams.value.createUser
  };
  if (queryParams.value.dataRange && queryParams.value.dataRange.length > 0) {
    postData.createTime = queryParams.value.dataRange[0];
    postData.updateTime = queryParams.value.dataRange[1];
  }
  data.tabInfo = {
    a: '全部数据(0)',
    b: '待整改(0)',
    c: '待复检(0)',
    d: '整改完成(0)',
    e: '整改超时(0)',
  };
  getListCount(postData).then(response => {
    let obj = {
      a: '全部数据',
      b: '待整改',
      c: '待复检',
      d: '整改完成',
      e: '整改超时',
    };
    (response.data || []).forEach(it => {
      data.tabInfo[it.projectName] = obj[it.projectName] + `(${it.id || 0})`
    });
  });
  handleQuery();
}

getCount();
</script>
<style lang="scss">
.trouble-problemodify-index {
  .header-form {
    .el-form-item {
      margin-right: 10px;
    }
  }
}
</style>