<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="false" @queryByParams="queryByParams" />
        <!-- <a-row type="flex" justify="space-between" style="border-top:1px solid #0014ff2e;">
        </a-row> -->
        <pblm-table
          ref="sdccPblmMonthlyReportTable"
          :pblmTableSetting="sdccPblmMonthlyReportTableSetting"
          @pageChange="handlePageChange"
          @sizeChange="handleSizeChange"
          @selectionChange="handleSelectionChange" />
      </a-card>
    </a-layout-content>
  </a-layout>
</template>

<script>
import { formatDateTime2 } from '../../utils/gw_date';
import { requestAllPblmsForProvince } from '../PblmRectify/Common/rectify_api';
import { formatDeadLineDate } from '../PblmRectify/Common/rectify_date';
import {
  PblmRectifyMontlyReport,
  PblmRectifyMontlyReportAll,
  PblmRectifyMontlyReportSj,
} from './Common/monthlyReport_api';
import pblmQueryTerms from './Components/pblmMonthlyReportQuery';
import pblmTable from './Components/pblmMonthlyReportTable';
export default {
  name: 'SdccPblmMonthlyReport',
  props: [],
  components: {
    pblmQueryTerms,
    pblmTable,
  },
  data() {
    return {
      loading: false,
      queryParams: {
        hasVedio: '',
        adCode: '',
        pblmStat: '',
        inspPblmCate: '',
        ifCasePblm: '',
        nm: '',
        rsName: '',
        adFullName: '',
        startTime: '',
        endTime: '',
        objType: '', // 为空才能不区分督查类别
        inspPblmName: '',
        dataStat: '2',
        persId: localStorage.getItem('userid'),
        villType: '0',
        pageSize: 20,
        pageNum: 1,
        pblmTotal: 0,
        pTypeCode: '', // 督查类别
        pYear: '', // 年度
        zgXianOrgId: null, // 接收单位
        zgWh: '', // 整改文号
        workflowStat: '', // 整改状态 important 不指定状态返回所有
        ym: Date.parse(new Date()), // 当前时间
      },
      sdccPblmMonthlyReportTableSetting: {
        data: [], // 主数据源
        pagination: {
          pageSize: 20,
          pageNum: 1,
          pblmCount: 0,
        }, // 翻页相关配置项
        height: 650,
        currentPblmId: '', // 当前选中的问题的ID
        selectedPblms: {}, // 多选模式下选中的所有问题集合
        multiSelect: true, // 是否出现行复选框
        enablePblmRectifyInfo: false, // 操作栏是否有整改信息输入按钮
        showWorkflowStat: true, // 是否显示整改状态
      },
    };
  },
  created() {
    this.getAllPblms();
  },
  computed: {
    formatDateTime() {
      return formatDateTime2;
    },
    formatDeadLineDate() {
      return formatDeadLineDate;
    },
  },
  methods: {
    // 按指定条件获取待下发问题列表数据
    queryByParams(val) {
      this.queryParams = val.queryParams;
      this.$refs.sdccPblmMonthlyReportTable.clearSelection(); // 清空原有的选中行信息
      this.getAllPblms();
    },
    // 获取待下发问题列表数据
    getAllPblms() {
      this.loading = true;
      this.queryParams.workflowStat = '20';
      this.queryParams.pageSize =
        this.sdccPblmMonthlyReportTableSetting.pagination.pageSize;
      this.queryParams.pageNum =
        this.sdccPblmMonthlyReportTableSetting.pagination.pageNum;
      PblmRectifyMontlyReport(this.queryParams).then((res) => {
        this.loading = false;
        if (res.data !== null) {
          this.sdccPblmMonthlyReportTableSetting.data = res.data.list;
          /* this.sdccPblmMonthlyReportTableSetting.data.sort(function (x, y) {
             return x.zgDate - y.zgDate;
           }); */
          this.sdccPblmMonthlyReportTableSetting.pagination.pblmCount =
            res.data.total;
        } else {
          this.sdccPblmMonthlyReportTableSetting.data = [];
          this.sdccPblmMonthlyReportTableSetting.pagination.pblmCount = 0;
        }
        // this.$refs.sdccPblmMonthlyReportTable.$refs.pblmMonthlyReportDataTable.doLayout();
      });
    },
    // 直接页数跳转
    handlePageChange(val) {
      this.sdccPblmMonthlyReportTableSetting.pagination.pageNum = val.pageNum;
      this.getAllPblms();
    },
    // 调整每页显示记录数
    handleSizeChange(val) {
      this.sdccPblmMonthlyReportTableSetting.pagination.pageSize = val.pageSize;
      this.getAllPblms();
    },
    // 选中行时获取所有已选中行
    handleSelectionChange(val) {
      this.sdccPblmMonthlyReportTableSetting.selectedPblms = val.selectedPblms;
    },
    approvedMonthlyReport(blAllPblm) {
      const data = {
        bisInspPblmZgList: [],
      };
      this.sdccPblmMonthlyReportTableSetting.selectedPblms.forEach((item) => {
        const id = {
          id: item.id,
        };
        data.bisInspPblmZgList.push(id);
      });
      if (!blAllPblm) {
        if (this.sdccPblmMonthlyReportTableSetting.selectedPblms.length > 0) {
          this.$confirm({
            title: '提示',
            content: '您将提交选中问题, 是否继续?',
            okType: 'warning',
            onOk: () => {
              PblmRectifyMontlyReportSj(data).then((res) => {
                this.$refs.ywcsPblmMonthlyReportTableSetting.$refs.pblmMonthlyReportDataTable.clearSelection(); // 清空原有的选中行信息
                this.getAllPblms();
              });
            },
          });
        } else {
          this.$message.warning('请选择需要操作的问题!');
        }
      }
    },
    submitAll() {
      this.$confirm({
        title: '提示',
        content: '您将提全部问题, 是否继续?',
        okType: 'warning',
        onOk: () => {
          PblmRectifyMontlyReportAll(this.queryParams).then((res) => {
            this.getAllPblms();
          });
        },
      });
    },
  },
};
</script>

<style lang='less' scoped>

</style>
