<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="请选择检查类型" clearable 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" @tab-click="tabClick">
      <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">
      <el-table-column prop="id" width="55" label="序号" align="center">
        <template #default="scope">{{ scope.$index + 1 + (queryParams.pageNum - 1) * queryParams.pageSize }}</template>
      </el-table-column>
      <el-table-column label="问题图片" align="center" prop="smarkUrl">
        <template #default="scope">
          <el-image :src="scope.row.smarkUrlPic" style="height:80px;" :preview-teleported="true"
            :preview-src-list="scope.row.smarkUrlPics"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="检查类型" align="center" prop="problemType">
        <template #default="scope">
          <dict-tag :options="ssp_proble_type" :value="scope.row.problemType" />
        </template>
      </el-table-column>
      <el-table-column label="隐患类型" align="center" prop="dangerType">
        <template #default="scope">
          <dict-tag :options="ssp_proble_sub_type" :value="scope.row.dangerType" />
        </template>
      </el-table-column>
      <el-table-column label="施工部位" align="center" prop="workParts" />
      <el-table-column label="整改要求" align="center" prop="changeInfo" />
      <el-table-column label="整改截至时间" align="center" prop="nickedTime" width="120" />
      <el-table-column label="整改人" align="center" prop="lordSent" width="200" />
      <el-table-column label="复检人" align="center" prop="recheckSend" width="200" />
      <el-table-column label="抄送人" align="center" prop="copySendUser" width="200" />
      <el-table-column label="流程状态" align="center" prop="checkState">
        <template #default="scope">
          <dict-tag :options="data.checkStates" :value="scope.row.checkState" />
        </template>
      </el-table-column>
      <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" class-name="small-padding fixed-width" width="120" fixed="right">
        <template #default="scope">

          <el-button v-if="getIsModify(scope.row)" link type="primary" size="small" :icon="Check"
            @click="handleModify(scope.row)" v-hasPermi="['trouble:problemmodify:edit']">处理</el-button>
          <el-button size="small" :icon="Document" link type="primary" @click="handleDetail(scope.row)"
            v-hasPermi="['trouble:problemmodify:query']">详情</el-button>
          <el-button v-if="getIsVdel(scope.row)" size="small" 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" />
    <detailDrawer ref="detailDrawerRef"></detailDrawer>
  </div>
</template>

<script setup name="Problemmodify">
import detailDrawer from "./detailDrawer.vue";
import { Check, Document, Delete } from '@element-plus/icons-vue'
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 detailDrawerRef = 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: {},
  checkStates: [{ value: "0", label: '待整改' }, { value: "1", label: '待复检' },
  { value: "2", label: '复检驳回' },
  { value: "3", label: '复检通过' }]
});

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 || []).map(it => {
      it.smarkUrlPic = it.smarkUrl.split(",")[0];
      it.smarkUrlPics = it.smarkUrl.split(",")
      return it;
    });
    total.value = response.total;
    loading.value = false;
  });
}

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

function tabClick() {
  setTimeout(handleQuery, 800);
}

function handleModify(row) {

}
function handleDetail(row) {
  detailDrawerRef.value.showDrawer(row);
}
function getIsVdel(row) {
  return true;
}
function getIsModify(row) {
  return true;
}
/** 重置按钮操作 */
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 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})`
    });
  });
}

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