<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;margin-top: 1%;">
          <a-col style="margin-top: 0.5%;" :span="24" class="el-row-operation">
            <a-button
              @click="approvedMonthlyReport(false)"
              :disabled="loading"
              size="small"
              type="primary"
              style="color:rgba(255,255,255,1);float:left;margin-right:10px;">选中问题送省水利厅</a-button>
            <a-button
              @click="submitAll"
              :disabled="loading"
              size="small"
              type="primary"
              style="color:rgba(255,255,255,1);float:left;margin-right:10px;">所有问题送省水利厅</a-button>
          </a-col>
        </a-row>
        <pblm-table
          style="margin-top: 0.5%;"
          ref="sjdwPblmMonthlyReportTable"
          :pblmTableSetting="sjdwPblmMonthlyReportTableSetting"
          @pageChange="handlePageChange"
          @sizeChange="handleSizeChange"
          @selectionChange="handleSelectionChange" />
        <monthly-report-comment
          v-if="showMonthlyReportCommentDialog"
          :isAg="this.isAg"
          :activityName="this.actName"
          @saveMonthlyReportComment="saveMonthlyReportComment"
          @closeMonthlyReportCommentDialog="closeMonthlyReportCommentDialog" />
      </a-card>
    </a-layout-content>
  </a-layout>
</template>

<script>
import { formatDateTime2 } from '../../utils/gw_date';
import { exportModel } from '../../utils/gw_exportModel';
import { requestAllPblmsForProvince } from '../PblmRectify/Common/rectify_api';
import { formatDeadLineDate } from '../PblmRectify/Common/rectify_date';
import MonthlyReportComment from '../PblmRectifyMonthlyReport/Components/MonthlyReportComment.vue';
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,
    MonthlyReportComment,
  },
  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()), // 当前时间
      },
      sjdwPblmMonthlyReportTableSetting: {
        data: [], // 主数据源
        pagination: {
          pageSize: 20,
          pageNum: 1,
          pblmCount: 0,
        }, // 翻页相关配置项
        height: 650,
        currentPblmId: '', // 当前选中的问题的ID
        selectedPblms: [], // 多选模式下选中的所有问题集合
        multiSelect: true, // 是否出现行复选框
        enablePblmRectifyInfo: false, // 操作栏是否有整改信息输入按钮
        showWorkflowStat: true, // 是否显示整改状态
      },
      isAg: 1, // 流程流转方向 0-正常向后 1=正常向前 2=列入调度清单
      actName: '', // 流程流转方向名称
      showMonthlyReportCommentDialog: false,
    };
  },
  created() {
    this.getAllPblms();
  },
  computed: {
    formatDateTime() {
      return formatDateTime2;
    },
    formatDeadLineDate() {
      return formatDeadLineDate;
    },
  },
  methods: {
    async downloadMonthlyReportExcelTemplate() {
      const datas = JSON.stringify(this.queryParams);
      const url = '/pdcApi/dc/insp/pblm/page/rever/exportxian';
      const type = 'post';
      const exportName = '整改进度月报模板.xls';
      const result = await exportModel(type, url, exportName, datas);
    },
    // 上报整改进度月报
    SubmitMonthlyReportForSelectedPblm(
      isAg,
      activityComment,
      fileExt,
      filePath,
    ) {
      const data = {
        fileName: filePath,
        persId: localStorage.getItem('userid'),
        persName: localStorage.getItem('account1'),
      };
      request.post('/dc/insp/pblm/insertXls', data).then((res) => {
        if (res.data.type) {
          this.$message.error('当前文件不存在！');
        } else {
          this.$message.success(
            '成功:' + res.data.success + '条,失败:' + res.data.false + '条',
          );
        }
      });
    },
    saveMonthlyReportComment(val) {
      this.closeMonthlyReportCommentDialog();
      this.SubmitMonthlyReportForSelectedPblm(
        val.isAg,
        val.Comment,
        val.fileExt,
        val.filePath,
      );
    },
    closeMonthlyReportCommentDialog() {
      this.showMonthlyReportCommentDialog = false;
    },
    openMonthlyReportDialog(isAg, e) {
      this.isAg = isAg;
      this.actName = e.currentTarget.innerText;
      this.showMonthlyReportCommentDialog = true;
    },
    // 按指定条件获取待下发问题列表数据
    queryByParams(val) {
      this.queryParams = val.queryParams;
      this.$refs.sjdwPblmMonthlyReportTable.clearSelection(); // 清空原有的选中行信息
      this.getAllPblms();
    },
    // 获取待下发问题列表数据
    getAllPblms() {
      this.loading = true;
      this.queryParams.workflowStat = '10';
      this.queryParams.pageSize =
        this.sjdwPblmMonthlyReportTableSetting.pagination.pageSize;
      this.queryParams.pageNum =
        this.sjdwPblmMonthlyReportTableSetting.pagination.pageNum;
      PblmRectifyMontlyReport(this.queryParams).then((res) => {
        this.loading = false;
        if (res.data !== null) {
          this.sjdwPblmMonthlyReportTableSetting.data = res.data.list;
          /* this.sjdwPblmMonthlyReportTableSetting.data.sort(function (x, y) {
             return x.zgDate - y.zgDate;
           }); */
          this.sjdwPblmMonthlyReportTableSetting.pagination.pblmCount =
            res.data.total;
        } else {
          this.sjdwPblmMonthlyReportTableSetting.data = [];
          this.sjdwPblmMonthlyReportTableSetting.pagination.pblmCount = 0;
        }
        // this.$refs.sjdwPblmMonthlyReportTable.$refs.pblmMonthlyReportDataTable.doLayout();
      });
    },
    // 直接页数跳转
    handlePageChange(val) {
      this.sjdwPblmMonthlyReportTableSetting.pagination.pageNum = val.pageNum;
      this.getAllPblms();
    },
    // 调整每页显示记录数
    handleSizeChange(val) {
      this.sjdwPblmMonthlyReportTableSetting.pagination.pageSize = val.pageSize;
      this.getAllPblms();
    },
    // 选中行时获取所有已选中行
    handleSelectionChange(val) {
      this.sjdwPblmMonthlyReportTableSetting.selectedPblms = [];
      this.sjdwPblmMonthlyReportTableSetting.selectedPblms = val.selectedPblms;
    },
    approvedMonthlyReport(blAllPblm) {
      const data = {
        bisInspPblmZgList: [],
      };
      this.sjdwPblmMonthlyReportTableSetting.selectedPblms.forEach((item) => {
        const id = {
          id: item.id,
        };
        data.bisInspPblmZgList.push(id);
      });
      if (!blAllPblm) {
        if (this.sjdwPblmMonthlyReportTableSetting.selectedPblms.length > 0) {
          this.$confirm({
            title: '提示',
            content: '您将提交选中问题, 是否继续?',
            okType: 'warning',
            onOk: () => {
              PblmRectifyMontlyReportSj(data).then((res) => {
                this.$refs.ywcsPblmMonthlyReportTableSetting.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>
