<template>
  <a-layout>
    <a-layout-content style="padding: 0;">
      <a-card class="box-card" style="flex: 1; overflow-y: auto; padding: 0 !important;">
        <pblm-query-terms
          ref="queryTerms"
          :showRectifyStatus="true"
          :isView="true"
          :isShowImport="true"
          :isDataScreen="isDataScreen"
          @queryByParams="queryByParams" />
        <a-row type="flex" justify="space-between" style="border-top:1px solid #0014ff2e;">
        </a-row>
        <pblm-table
          ref="sdccPblmTable"
          :pblmTableSetting="sdccPblmViewTableSetting"
          :isJdcjbr="isJdcjbr"
          @pageChange="handlePageChange"
          @sizeChange="handleSizeChange"
          @refreshTable="refreshTable"
          @selectionChange="handleSelectionChange" />
      </a-card>
    </a-layout-content>
  </a-layout>
</template>

<script>
import moment from 'moment';
import { formatDateTime2 } from '../../utils/gw_date';
import { requestAllPblmsForProvince } from './Common/rectify_api';
import { formatDeadLineDate } from './Common/rectify_date';
import pblmQueryTerms from './Components/pblmQueryTerms';
import pblmTable from './Components/pblmTable';
export default {
  name: 'SdccPblmView',
  props: ['isJdcjbr', 'isDataScreen'],
  data() {
    return {
      moment,
      loading: false,
      queryParams: {
        hasVedio: '',
        adCode: '',
        pblmStat: '',
        inspPblmCate: '',
        ifCasePblm: '',
        nm: '',
        rsName: '',
        adFullName: '',
        startTime: '',
        endTime: '',
        objType: '', // 为空才能不区分督查类别
        inspPblmName: '',
        dataStat: '2',
        persId: localStorage.getItem('persId'),
        villType: '0',
        pageSize: 10,
        pageNum: 1,
        pblmTotal: 0,
        pTypeCode: '', // 督查类别
        pYear: '', // 年度
        zgXianOrgId: null, // 接收单位
        zgWh: '', // 整改文号
        workflowStat: '', // 整改状态 important 不指定状态返回所有
        schdYear: moment(new Date().getFullYear().toString()).format('YYYY'),
      },
      sdccPblmViewTableSetting: {
        isEditVisible: true,
        data: [], // 主数据源
        pagination: {
          pageSize: 10,
          pageNum: 1,
          pblmCount: 0,
        }, // 翻页相关配置项
        height: 500,
        currentPblmId: '', // 当前选中的问题的ID
        selectedPblms: {}, // 多选模式下选中的所有问题集合
        multiSelect: false, // 是否出现行复选框
        enablePblmRectifyInfo: false, // 操作栏是否有整改信息输入按钮
        showWorkflowStat: true, // 是否显示整改状态
      },
    };
  },
  components: {
    pblmQueryTerms,
    pblmTable,
  },
  created() {},
  mounted() {
    this.$nextTick(function () {
      this.sdccPblmViewTableSetting.height =
        document.getElementsByClassName('ant-tabs')[0].offsetHeight - 260;
      this.$refs.queryTerms.queryByParams();
    });
  },
  computed: {
    formatDateTime() {
      return formatDateTime2;
    },
    formatDeadLineDate() {
      return formatDeadLineDate;
    },
  },
  methods: {
    refreshTable() {
      this.getAllPblms();
    },
    // 按指定条件获取待下发问题列表数据
    queryByParams(val) {
      this.queryParams = val.queryParams;
      this.$refs.sdccPblmTable.clearSelection(); // 清空原有的选中行信息
      this.getAllPblms();
    },
    // 获取待下发问题列表数据
    getAllPblms() {
      this.loading = true;
      this.queryParams.pageSize =
        this.sdccPblmViewTableSetting.pagination.pageSize;
      this.queryParams.pageNum =
        this.sdccPblmViewTableSetting.pagination.pageNum;
      requestAllPblmsForProvince(this.queryParams).then((res) => {
        this.loading = false;
        if (res.data !== null) {
          this.sdccPblmViewTableSetting.data = res.data.list;
          /* this.sdccPblmViewTableSetting.data.sort(function (x, y) {
             return x.zgDate - y.zgDate;
           }); */
          this.sdccPblmViewTableSetting.pagination.pblmCount = res.data.total;
        } else {
          this.sdccPblmViewTableSetting.data = [];
          this.sdccPblmViewTableSetting.pagination.pblmCount = 0;
        }
      });
    },
    // 直接页数跳转
    handlePageChange(val) {
      this.sdccPblmViewTableSetting.pagination.pageNum = val.pageNum;
      this.getAllPblms();
    },
    // 调整每页显示记录数
    handleSizeChange(val) {
      this.sdccPblmViewTableSetting.pagination.pageSize = val.pageSize;
      this.getAllPblms();
    },
    // 选中行时获取所有已选中行
    handleSelectionChange(val) {
      this.sdccPblmViewTableSetting.selectedPblms = val.selectedPblms;
    },
  },
};
</script>

<style lang='less' scoped>

</style>
