<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"
          :ywcs="'1'"
          :showRectifyStatus="false"
          @queryByParams="queryByParams"
          @showUpdateDate="showUpdateDate"
          :isDuty="ywcsPblmMonthlyReportTableSetting.isDuty" />
        <a-row  type="flex" justify="space-between" style="border-top:1px solid #0014ff2e;margin-top: 1%;">
        </a-row>
        <pblm-table
          style="margin-top: 1%;"
          ref="ywcsPblmMonthlyReportTable"
          :pblmTableSetting="ywcsPblmMonthlyReportTableSetting"
          @pageChange="handlePageChange"
          @sizeChange="handleSizeChange"
          @refreshTable="refreshTable"
          @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,
  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()), // 当前时间
        ywsc: '1',
      },
      ywcsPblmMonthlyReportTableSetting: {
        isDuty: true,
        data: [], // 主数据源
        pagination: {
          pageSize: 20,
          pageNum: 1,
          pblmCount: 0,
        }, // 翻页相关配置项
        height: 700,
        currentPblmId: '', // 当前选中的问题的ID
        selectedPblms: {}, // 多选模式下选中的所有问题集合
        multiSelect: true, // 是否出现行复选框
        enablePblmRectifyInfo: false, // 操作栏是否有整改信息输入按钮
        showWorkflowStat: true, // 是否显示整改状态
      },
    };
  },
  created() {
    this.getAllPblms();
  },
  computed: {
    formatDateTime() {
      return formatDateTime2;
    },
    formatDeadLineDate() {
      return formatDeadLineDate;
    },
  },
  methods: {
    refreshTable() {
      this.getAllPblms();
    },
    showUpdateDate() {
      this.$refs.ywcsPblmMonthlyReportTable.showBatchUpdate();
    },
    // 按指定条件获取待下发问题列表数据
    queryByParams(val) {
      this.queryParams = val.queryParams;
      this.$refs.ywcsPblmMonthlyReportTable.clearSelection(); // 清空原有的选中行信息
      this.getAllPblms();
    },
    // 获取待下发问题列表数据
    getAllPblms() {
      this.loading = true;
      this.queryParams.workflowStat = '20';
      this.queryParams.pageSize =
        this.ywcsPblmMonthlyReportTableSetting.pagination.pageSize;
      this.queryParams.pageNum =
        this.ywcsPblmMonthlyReportTableSetting.pagination.pageNum;
      PblmRectifyMontlyReport(this.queryParams).then((res) => {
        this.loading = false;
        if (res.data !== null) {
          this.ywcsPblmMonthlyReportTableSetting.data = res.data.list;
          /* this.ywcsPblmMonthlyReportTableSetting.data.sort(function (x, y) {
             return x.zgDate - y.zgDate;
           }); */
          this.ywcsPblmMonthlyReportTableSetting.pagination.pblmCount =
            res.data.total;
        } else {
          this.ywcsPblmMonthlyReportTableSetting.data = [];
          this.ywcsPblmMonthlyReportTableSetting.pagination.pblmCount = 0;
        }
        // this.$refs.ywcsPblmMonthlyReportTable.doLayout()
      });
    },
    // 直接页数跳转
    handlePageChange(val) {
      this.ywcsPblmMonthlyReportTableSetting.pagination.pageNum = val.pageNum;
      this.getAllPblms();
    },
    // 调整每页显示记录数
    handleSizeChange(val) {
      this.ywcsPblmMonthlyReportTableSetting.pagination.pageSize = val.pageSize;
      this.getAllPblms();
    },
    // 选中行时获取所有已选中行
    handleSelectionChange(val) {
      this.ywcsPblmMonthlyReportTableSetting.selectedPblms = val.selectedPblms;
    },
    /*   approvedMonthlyReport(blAllPblm){
         if (!blAllPblm){
           if (this.ywcsPblmMonthlyReportTableSetting.selectedPblms.length > 0){

           } else{
             this.$message.warning("请选择需要操作的问题!");
           }
         }
       } */
    approvedMonthlyReport(blAllPblm) {
      const data = {
        bisInspPblmZgList: [],
      };
      this.ywcsPblmMonthlyReportTableSetting.selectedPblms.forEach((item) => {
        const id = {
          id: item.id,
        };
        data.bisInspPblmZgList.push(id);
      });
      if (!blAllPblm) {
        if (this.ywcsPblmMonthlyReportTableSetting.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('请选择需要操作的问题!');
        }
      }
    },
  },
};
</script>

<style lang='less' scoped>

</style>
