<template>
  <div :style="{ 'height': tableHeight1 + 'px' }" class="pblmRectifyReviewSituation">
    <a-button @click="addProblem" type="primary" style="float: right;margin-bottom: 10px;position: relative;z-index: 1;" :disabled="ifView">新增整改问题</a-button>
    <a-table
      :data-source="problemList"
      :columns="columns"
      :loading="loading"
      bordered
      :pagination="false"
      ref="multipleTable"
      :style="{ height: tableHeight + 'px' }"
      :scroll="{y: tableHeight - 60}"
      style="width: 100%">
      <span slot="index" slot-scope="text, record, index">
        {{ (currentPage - 1) * pageSize + (index + 1) }}
      </span>
      <span slot="pblmTm" slot-scope="text">
        {{ formatterD(text, 'pblmTm') }}
      </span>
      <span slot="revwInfo" slot-scope="text">
        <span v-if="text.revwRectConc=='1'">未整改</span>
        <span v-if="text.revwRectConc=='2'">正在整改</span>
        <span v-if="text.revwRectConc=='3'">整改完成</span>
        <span v-if="text.revwRectConc=='4'">整改不到位</span>
        <span v-if="text.revwRectConc=='5'">上报整改情况与实际不符</span>
      </span>
      <span slot="revwInfo" slot-scope="text">
        <p v-if="text.revwState == 0"><span class="inspPblmCate" style="background: #EC808D;">未复查</span>
        </p>
        <!--<p v-if="text.revwState == 1"><span class="inspPblmCate"-->
        <!--style="background: #f59a23;">复查中</span>-->
        <p v-if="text.revwState == 2"><span class="inspPblmCate" style="background: #f59a23;">已复查</span>
          <!--0:未填报;1:填报中;2:已填报-->
        </p>
      </span>
      <span slot="realPlanDt" slot-scope="text, recode">
        {{ formatterD(text, recode) }}
      </span>
      <span slot="action" slot-scope="text">
        <a-button icon="edit" type="link" @click="showDetails(text.id)"></a-button>
        <a-button icon="delete" type="link" v-if="ownPriv('manage')" title="删除问题" @click="removeSuperviseOne(text)">
        </a-button>
      </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="pageIndexChange"
      style="margin-top: 50px;"
      class="paginationCenter" />
    <!-- 详情组件-->
    <supervision-details
      ref="xianqing"
      :problemId="currentProblemId"
      v-if="supervisionDetailsVisible"
      @cancelHandler="cancelHandler"
      :ifView="ifView"></supervision-details>

    <!-- 添加问题组件 -->
    <problem-dialog
      v-if="showAddProblemDialog"
      :objId="currentObjectId"
      :regId="currentObjectRgstrId"
      :objName="currentObjectName"
      :currentProblemId="currentProblemId"
      :currentResCode="currentResCode"
      :currentRsvrNm="currentRsvrNm"
      :currentAdCode="currentAdCode"
      :problemId="currentProblemId"
      @closeDialog="closePlDialog"
      :objType="92"
      :currentObjectRgstrId="currentObjectRgstrId">
    </problem-dialog>
  </div>
</template>

<script>
import request from '../../../utils/gw_ajax_request';
import problemDialog from './addProblemDialog.vue';
import supervisionDetails from './problemDetail.vue';
export default {
  props: [
    'currentObjectId',
    'currentObjectName',
    'currentObjectRgstrId',
    'activeLabel',
    'ifReadyOnly',
    'currentResCode',
    'currentAdCode',
    'currentRsvrNm',
    'ifView',
  ],
  data() {
    return {
      tableHeight: window.innerHeight * 0.45,
      tableHeight1: window.innerHeight * 0.65,
      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',
          width: 80,
          align: 'center',
          ellipsis: true,
        },
        {
          title: '对象名称',
          dataIndex: 'nm',
          width: 180,
          align: 'center',
          ellipsis: true,
        },
        {
          title: '问题描述',
          dataIndex: 'pblmNote',
          width: 300,
          align: 'center',
          ellipsis: true,
        },
        {
          title: '问题来源',
          dataIndex: 'pblmSour',
          width: 230,
          align: 'center',
          ellipsis: true,
        },
        {
          title: '问题下发时间',
          dataIndex: 'pblmTm',
          width: 100,
          align: 'center',
        },
        {
          title: '当前问题状态',
          dataIndex: 'pblmState',
          width: 100,
          align: 'center',
          ellipsis: true,
        },
        {
          title: '整改情况',
          dataIndex: 'revwInfo',
          width: 100,
          align: 'center',
        },
        {
          title: '实际/计划整改完成时间',
          dataIndex: 'realPlanDt',
          width: 180,
          align: 'center',
        },
      ],
    };
  },
  components: {
    // 详情页
    supervisionDetails,
    problemDialog,
  },
  computed: {
    persId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096';
    },
  },
  created() {
    if (!this.ifView) {
      this.columns.push({
        title: '操作',
        dataIndex: 'action',
        // width: 100,
        align: 'center',
      });
    }
  },
  mounted() {
    this.getProblemList();
  },
  methods: {
    formatterD(row, column) {
      console.log(row, column);
      if (row[column] == null || row[column] == '') {
        return '';
      }
      const date = new Date(row[column]);
      const Y = date.getFullYear() + '-';
      const M =
        (date.getMonth() + 1 < 10
          ? '0' + (date.getMonth() + 1)
          : date.getMonth() + 1) + '-';
      const D =
        date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate();
      return Y + M + D;
    },
    removeSuperviseOne(row) {
      this.$confirm({
        title: '提示',
        content: '确定要删除该问题吗？',
        okType: 'warning',
        onOk: () => {
          request.post(`/bis/insp/prjchk/pblm/delete/` + row.id).then((res) => {
            if (res.success) {
              this.getProblemList();
              this.$message.success('删除成功');
            } else {
              this.$message.error(res.message);
            }
          });
        },
      });
    },
    // 通知List
    getProblemList() {
      const obj = {
        pageSize: this.pageSize,
        pageNum: this.currentPage,
        nm: this.currentObjectName,
        adCode: this.currentAdCode,
      };
      this.loading = true;
      request
        .post(`/bis/insp/prjchk/pblm/listOfPage`, obj, {
          headers: { orgId: this.persId },
        })
        .then((res) => {
          if (res.success) {
            this.problemList = res.data.list;
            this.total = res.data.total;
            this.loading = false;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    showDetails(pblmId) {
      console.log('xxxxxx', pblmId);
      this.currentProblemId = pblmId;
      this.supervisionDetailsVisible = true;
      // this.showAddProblemDialog = true
      this.getProblemList();
    },
    deleteSuccess() {
      this.problemDeleteVisible = false;
      this.getProblemList();
    },
    pageIndexChange(val) {
      this.currentPage = val;
      this.getProblemList();
    },
    handleSizeChange(size, val) {
      this.pageSize = val;
      this.getProblemList();
    },
    timestampToTime(row, column) {
      var date = new Date(row);
      var Y = date.getFullYear() + '-';
      var M =
        (date.getMonth() + 1 < 10
          ? '0' + (date.getMonth() + 1)
          : date.getMonth() + 1) + '-';
      var D =
        (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
      var h =
        (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
      var m =
        date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
      return Y + M + D + h + m;
    },
    closeEditDialog() {
      this.getProblemList();
      this.changeSupervisionVisible = false;
    },
    addProblem(item) {
      // let rest = this.rsvrRules;
      // this.probId = rest[0].id;
      this.showAddProblemDialog = true;
    },
    closePlDialog() {
      this.getProblemList();
      this.showAddProblemDialog = false;
    },
    cancelHandler(val) {
      if (val) this.getProblemList();
      this.supervisionDetailsVisible = false;
    },
  },
  watch: {
    activeLabel(val) {
      if (val == '问题清单') {
        this.getProblemList();
      }
    },
  },
  filters: {
    checkPointBz(val) {
      if (val == '1') {
        return '质量安全';
      } else if (val == '2') {
        return '合同';
      } else if (val == '3') {
        return '资金';
      } else {
        return '';
      }
    },
  },
};
</script>

<style lang='less' scoped>
.pblmRectifyReviewSituation {
  .inspPblmCate {
    padding: 2px 10px;
    color: #fff;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
  }
}
</style>
