<template>
  <div>
    <div
      v-if="processReportResult.processResult != undefined"
      class="form-group"
    >
      <textarea
        v-if="isTextAreaShowProcessResult"
        class="processResult-textarea"
        rows="10"
        style="width:100%"
        :value="processReportResult.processResult.result"
      />
      <div v-else>
        <h5
          class="control-label"
          style="white-space: pre-line;"
        >
          1.{{ processReportResult.processResult.result }}
        </h5>
      </div>
    </div>
    <div class="form-group">
      <div
        v-if="processReportResult.processResult != undefined && pdfOnly != true"
        class="form-group"
      >
        <a
          v-if="processReportResult.processResult.modelData&&processReportResult.processResult.modelData.data"
          target="_blank"
          role="button"
          class="btn btn-info"
        >
          Excel报表
        </a>
      </div>

      <template
        v-for="(reportResult, index) in processReportResult.reportResults"
        :key="'reportResult' + index"
      >
        <div
          v-if="processReportResult.reportResults != undefined"
          id="pr.id"
          class="form-group"
        >
          <h3 class="control-label">
            {{ index + 1 + (processReportResult.processResult == undefined ? 0 : 1) }}.{{ reportResult.reportName }}
          </h3>
          <div>
            <button
              v-if="reportResult.isSuccess && pdfOnly != true"
              class="btn btn-success"
              @click="reportDownload(reportResult.excelDownLoadUrl, reportResult.reportDefinitionType)"
            >
              Excel报表
            </button>
            <button
              v-if="reportResult.isSuccess && excelOnly != true"
              class="btn btn-success"
              @click="reportDownload(reportResult.pdfDownLoadUrl, reportResult.reportDefinitionType)"
            >
              PDF报表
            </button>
            <span
              v-else
              class="control-label label-danger"
            >生成失败</span>
          </div>
        </div>
      </template>
    </div>

    <!--<ProcessReportArchive :processReportResult="processReportResult"></ProcessReportArchive>-->
  </div>
</template>

<script>
import Common from '../../common/Common.js';
// import ProcessReportArchive from './ProcessReportArchive.vue';
import DownloadService from '../../common/DownloadService.js';

export default {
  name: 'ProcessReportResult',

  components: {
    // ProcessReportArchive,
  },

  props: {
    'processReportResult': {
      type: Object,
      default: null,
    }, 'pdfOnly': {
      type: Boolean,
      default: false,
    }, 'excelOnly': {
      type: Boolean,
      default: false,
    },
  },

  data: function () {
    return {

    };
  },

  computed: {
    // 是否文本区域显示流程结果
    isTextAreaShowProcessResult: function () {
      var result = this.processReportResult.processResult.result;
      if (result != undefined && result.length > 100) {
        return true;
      } else {
        return false;
      }
    },

  },

  mounted: function () {

  },

  methods: {
    /**
             * 下载报表
             * @param {Object} fileName
             * @author GuoZhiBo 20200410
             */
    reportDownload: function (fileName, reportDefinitionType) {
      if (reportDefinitionType == 'UReport2') {
        window.open(Common.getRootPath() + fileName);
      } else {
        DownloadService.reportDownload(fileName);
      }
    },
  },
};
</script>