<!-- 问题履历 -->
<template>
  <div>
    <dialog-edit :appendToBody="appendToBody" :visible.sync="dialogVisible" :editModel="editModel" :form="form" :title="$t('effectDealFeedBackMain.questionResume')">
      <div class="flex-center box-column-margin-bottom box-column-margin-top">{{$t('feedbackMaterialIndex.historyTitle')}}</div>
      <data-table class="relationdatatable" :sourceData.sync="table" :columns="columns" :api="api" :loadCount="loadCount" :queryParas.sync="queryParas" v-bind="{maxHeight:400, spanMethod:e => objectSpanMethod(table,e)}" :loadPage="loadPage">
        <template slot="fileOssids" slot-scope="scope">
          <btn-batch-download :disabled="scope.data.row.fileOssids.length === 0" size="small" :title="$t('common.downLoad')" :fileID="scope.data.row.fileOssids" :downloadFileName="scope.data.row.fileOssids.length > 1 ? $t('feedbackMaterialIndex.attachmentDownload') + '.zip':null"></btn-batch-download>
        </template>
        <template slot="relationFileIds" slot-scope="scope">
          <btn-batch-download :disabled="scope.data.row.relationFileIds.length === 0" size="small" :title="$t('common.downLoad')" :fileID="scope.data.row.relationFileIds" :downloadFileName="scope.data.row.relationFileIds.length > 1 ?$t('coordManageMain.relatedAttachment') + '.zip':null"></btn-batch-download>
        </template>
        <template #feedbackQuestionContent="scope">
          <span-plus :index="scope.data.$index" :text="scope.data.row.feedbackQuestionContent"></span-plus>
        </template>
        <template #replyLawContent="scope">
          <span-plus :index="scope.data.$index" :text="scope.data.row.replyLawContent"></span-plus>
        </template>
        <template #practicableSuggestion="scope">
          <span-plus :index="scope.data.$index" :text="scope.data.row.practicableSuggestion"></span-plus>
        </template>
        <template #relationResolution="scope">
          <span-plus :index="scope.data.$index" :text="scope.data.row.relationResolution"></span-plus>
        </template>
      </data-table>
    </dialog-edit>
  </div>
</template>

<script>
import effectDealFeedBackApi from '@/api/assetoutfeedback/effectDealFeedBack/effectDealFeedBackApi'
import BasePage from '@/pages/baseEditPage'
import * as format from '@/filters/index'
import { DialogEdit, DataTable, btnBatchDownload, SpanPlus } from 'newepoch-components'
export default {
  components: { DialogEdit, DataTable, btnBatchDownload, SpanPlus },
  extends: new BasePage(),
  props: {
    form: {
      type: Object,
      default () {
        return {}
      }
    },
    editModel: {
      type: String,
      default () {
        return 'V'
      }
    },
    reKeyId: {
      type: String,
      default () {
        return ''
      }
    }
  },
  data () {
    return {
      loadPage: 'getDefaultHistory',
      queryParas: {
        pageIndex: 1,
        pageSize: 10
      },
      loadCount: 0,
      appendToBody: true,
      table: [],
      columns: [
        {
          // 问题序号
          prop: 'qusetionNumber',
          align: 'center',
          width: '60px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.problemNo
        }, {
          // 反馈次数
          prop: 'feedbackTimes',
          align: 'center',
          width: '60px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.feedbackTimes
        }, {
          // 律所意见
          prop: 'feedbackQuestionContent',
          align: 'left',
          slot: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.feedbackQuestionContent
        }, {
          // 合同回复律所意见
          prop: 'replyLawContent',
          align: 'left',
          slot: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.replyLawContent
        }, {
          // 合规附件
          prop: 'fileOssids',
          align: 'center',
          slot: true,
          width: '60px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.fileOssids
        }, {
          // 合规落实
          prop: 'practicableSuggestion',
          align: 'left',
          slot: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.practicableSuggeste
        }, {
          // 相关方
          prop: 'relationType',
          align: 'center',
          width: '60px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.relation,
          format (row) {
            return format.formatDict(row.relationType, 'AUDIT_OUT_RELATION_TYPE')
          }
        }, {
          // 相关方意见
          prop: 'relationResolution',
          align: 'left',
          solt: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.relationResolution
        }, {
          // 相关方附件
          prop: 'relationFileIds',
          align: 'center',
          slot: true,
          width: '70px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.relation + this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.annex
        }
      ]
    }
  },
  computed: {
    // 取得相关履历
    api () {
      return effectDealFeedBackApi.getDealInfo
    },
    effectForm: {
      get: function () {
        return this.form
      }
    }
  },
  mounted () {
    this.queryParas.feedbackAssetKey = this.effectForm.keyId
    this.$nextTick(() => {
      this.handleFilter()
    })
  },
  methods: {
    // 更新表数据
    handleFilter () {
      this.loadCount = this.loadCount + 1
    },
    // 行合并
    objectSpanMethod (item, { row, column, rowIndex, columnIndex }) {
      let spanCount = 1
      let spanCountOne = 1
      if (columnIndex > -1 && columnIndex < 1) {
        if (rowIndex === 0 || item[rowIndex - 1].qusetionNumber !== row.qusetionNumber) {
          item.reduce((last, current) => {
            if (last.qusetionNumber === row.qusetionNumber && last.qusetionNumber === current.qusetionNumber) {
              spanCount++
            }
            return current
          })
          return {
            rowspan: spanCount,
            colspan: 1
          }
        }
        return {
          rowspan: 0,
          colspan: 0
        }
      }
      if (columnIndex === 1) {
        if (rowIndex === 0 || item[rowIndex - 1].qusetionNumber !== row.qusetionNumber || item[rowIndex - 1].feedbackTimes !== row.feedbackTimes) {
          item.reduce((last, current) => {
            if (last.qusetionNumber === row.qusetionNumber && last.qusetionNumber === current.qusetionNumber && last.feedbackTimes === row.feedbackTimes && last.feedbackTimes === current.feedbackTimes) {
              spanCountOne++
            }
            return current
          })
          return {
            rowspan: spanCountOne,
            colspan: 1
          }
        }
        return {
          rowspan: 0,
          colspan: 0
        }
      }
    }
  }
}
</script>

<style>

</style>
