<template>
  <div id="">
    <!-- <a-button @click="addProblem" type="primary" style="float: right;margin-bottom: 10px;position: relative;z-index: 1;"
      v-if="openType">添加问题
    </a-button> -->
    <a-table
      :loading="loading"
      :columns="columns"
      bordered
      ref="multipleTable"
      :data-source="problemList"
      row-key="pblmId"
      :pagination="false"
      :style="{ height: tableHeight + 'px' }"
      style="width: 100%">
      <span slot="index" slot-scope="text, recode, index">
        {{ (currentPage - 1) * pageSize + (index + 1) }}
      </span>
      <span slot="ifCasePblm" slot-scope="text">
        <span v-if="text.ifCasePblm == '0'">否</span>
        <span v-else-if="text.ifCasePblm == '1'">是</span>
        <span v-else>{{ text.ifCasePblm }}</span>
      </span>
      <span slot="collTime" slot-scope="text">
        {{ text.collTime ? formatDateTime(text.collTime) : '' }}
      </span>
      <span slot="action" slot-scope="text">
        <a-button icon="eye" type="link" @click="showDetails(text.pblmId)" />
        <a-button icon="edit" type="link" @click="changeSup(text.pblmId)" v-if="ownPriv('manage')" />
        <a-button
          icon="delete"
          type="link"
          v-if="ownPriv('manage')"
          @click="removeSuperviseOne(text.pblmId)" />
      </span>
    </a-table>
    <a-pagination
      show-size-changer
      :pageSize.sync="pageSize"
      :total="total"
      :page-size-options="['10', '20', '50', '100']"
      :show-total="total => `共${total}条`"
      @showSizeChange="handleSizeChange"
      @change="search"
      style="margin-top: 10px;" />
    <!-- 详情组件-->
    <a-modal
      :open="supervisionDetailsVisible"
      @cancel="supervisionDetailsVisible = false"
      class="custom_dialog"
      title="问题详情"
      width="60%">
      <supervision-details ref="xianqing" :problemId="currentProblemId"></supervision-details>
      <span slot="footer">
        <a-button style="margin-top:5px;" @click="supervisionDetailsVisible = false">返回</a-button>
      </span>
    </a-modal>
    <!-- 删除组件 -->
    <a-modal
      :open="problemDeleteVisible"
      @cancel="problemDeleteVisible = false"
      class="deleteDialog"
      title="问题删除描述"
      width="60%">
      <Problem-delete ref="deleteMiaoShu" :deleteProblemId="deleteId" @deleteSuccess="deleteSuccess"></Problem-delete>
      <span slot="footer">
        <a-button @click="problemDeleteVisible = false">返回</a-button>
      </span>
    </a-modal>
    <!-- 修改组件 -->
    <problem-edit :editId="editId" @closeEditDialog="closeEditDialog" v-if="changeSupervisionVisible"></problem-edit>
    <!-- 添加问题组件 -->
    <problem-dialog
      v-if="showAddProblemDialog"
      fenlei="siluan"
      :objType="objType"
      :objId="currentObjectId"
      :objName="currentObjectName"
      @closeDialog="closePlDialog"
      :currentObjectRgstrId="currentObjectRgstrId">
    </problem-dialog>
  </div>
</template>

<script>
import request from '../../../utils/gw_ajax_request';
import { formatDateTime2 } from '../../../utils/gw_date';
import ProblemDelete from '../../duChaWenTi/problemDelete.vue';
import problemEdit from '../../duChaWenTi/siLuanProblemModify.vue';
import supervisionDetails from '../../duChaWenTi/supervisionDetails_siluan.vue';
import problemDialog from '../waterIntake/addProblemDialog.vue';

export default {
  props: [
    'currentObjectId',
    'currentObjectName',
    'currentObjectRgstrId',
    'activeLabel',
    'objType',
  ],
  data() {
    return {
      tableHeight: window.innerHeight - 250,
      problemList: [],
      loading: false,
      currentPage: 1,
      pageSize: 10,
      pageNum: 1,
      total: 0,
      supervisionDetailsVisible: false,
      currentProblemId: '',
      problemDeleteVisible: false,
      deleteId: '',
      editId: '',
      changeSupervisionVisible: false,
      showAddProblemDialog: false,
      rsvrRules: null,
      probId: '',
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          align: 'center',
          width: 40,
          ellipsis: true,
        },
        {
          title: '问题描述',
          dataIndex: 'inspPblmDesc',
          align: 'center',
          width: 140,
          ellipsis: true,
        },
        {
          title: '是否典型',
          dataIndex: 'ifCasePblm',
          align: 'center',
          width: 100,
          ellipsis: true,
        },
        {
          title: '上报时间',
          dataIndex: 'collTime',
          align: 'center',
          width: 100,
          ellipsis: true,
          sorter: (a, b) => b.collTime - a.collTime,
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 100,
        },
      ],
    };
  },
  components: {
    // 详情页
    supervisionDetails,
    // 删除描述页
    ProblemDelete,
    // 修改问题
    problemEdit,
    problemDialog,
  },
  computed: {
    persId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096';
    },
    formatDateTime() {
      return formatDateTime2;
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    this.getProblemList();
  },
  methods: {
    getProblemList() {
      const problemForm = {};
      problemForm.objId = this.currentObjectId;
      problemForm.objType = this.objType;
      problemForm.pageNum = this.currentPage;
      problemForm.pageSize = this.pageSize;
      problemForm.presId = this.persId;
      this.loading = true;
      request
        .post(`/dc/insp/pblm/list/${this.persId}`, problemForm)
        .then((res) => {
          if (res.success) {
            this.problemList = res.data.list;
            this.total = res.data.total;
            this.loading = false;
          }
        })
        .catch((err) => {
          this.$message.error(err);
          this.loading = false;
        });
    },
    showDetails(pblmId) {
      this.currentProblemId = pblmId;
      this.supervisionDetailsVisible = true;
    },
    changeSup(pblmId) {
      this.editId = pblmId;
      this.changeSupervisionVisible = true;
    },
    removeSuperviseOne(pblmId) {
      this.deleteId = pblmId;
      this.problemDeleteVisible = true;
    },
    deleteSuccess() {
      this.problemDeleteVisible = false;
      this.getProblemList();
    },
    search(val) {
      this.currentPage = val;
      this.getProblemList();
    },
    handleSizeChange() {},
    closeEditDialog() {
      this.changeSupervisionVisible = false;
      this.getProblemList();
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_BASE_PRES_EXT',
      };
      request
        .post('/bis/insp/item/ques/info/findItemByType', obj)
        .then((res) => {
          this.rsvrRules = res.data;
        });
    },
    addProblem(item) {
      const rest = this.rsvrRules;
      this.probId = rest[0].id;
      this.showAddProblemDialog = true;
    },
    closePlDialog(val) {
      this.showAddProblemDialog = false;
      this.getProblemList();
    },
    detailClose() {
      this.currentProblemId = '';
    },
    ifCasePblm(row) {
      if (row.ifCasePblm == '0') {
        return '否';
      } else if (row.ifCasePblm == '1') {
        return '是';
      } else {
        return row.ifCasePblm;
      }
    },
  },
  watch: {
    activeLabel(val) {
      if (val == '问题清单') {
        this.getProblemList();
      }
    },
  },
};
</script>

<style lang='less' scoped>
.pblmEascader .el-dialog__body {
  height: 15vh;
  overflow: auto;
}
</style>
