<!--反馈履历查看页面-->
<template>
  <div>
    <dialog-edit
      :visible.sync="dialogVisible"
      :autoSave="false"
      :autoClose="false"
      :editModel="editModel"
      :form="{}"
      center
      :title="$t('common.view')">
        <template>
            <div style="margin-top:20px">
                <data-table :sourceData="tableData"
                            :span-method="objectSpanMethod"
                            :columns="columns"
                            :api="form.type==='1'?coordManageApi:reviewUpdateApi"
                            loadPage="getDefaultHistory"
                            @handleFilter="handleFilter"
                            :queryParas="queryParas"
                            :loadCount.sync="loadCount"
                            @getTableData="getTableData"
                            :showPage="true"
                            class="pagination-setting" stripe>
                            <template slot="feedbackQuestionContent" slot-scope="scope">
                              <span-plus :index="scope.data.$indx" :text="scope.data.row.feedbackQuestionContent"></span-plus>
                            </template>
                            <template slot="replyLawContent" slot-scope="scope">
                              <span-plus :index="scope.data.$indx" :text="scope.data.row.replyLawContent"></span-plus>
                            </template>
                            <template slot="practicableSuggestion" slot-scope="scope">
                              <span-plus :index="scope.data.$indx" :text="scope.data.row.practicableSuggestion"></span-plus>
                            </template>
                            <template slot="relationResolution" slot-scope="scope">
                              <span-plus :index="scope.data.$indx" :text="scope.data.row.relationResolution"></span-plus>
                            </template>
                            <template slot="fileOssids" slot-scope="scope">
                              <btn-batch-download :title="$t('common.downLoad')" :fileID="scope.data.row.fileOssids?scope.data.row.fileOssids:[]" :disabled="scope.data.row.fileOssids.length===0"></btn-batch-download>
                            </template>
                            <template slot="relationFileIds" slot-scope="scope">
                              <btn-batch-download :title="$t('common.downLoad')" :fileID="scope.data.row.relationFileIds?scope.data.row.relationFileIds:[]" :disabled="scope.data.row.relationFileIds.length===0"></btn-batch-download>
                            </template>
                </data-table >
            </div>
        </template>
    </dialog-edit>
  </div>
</template>
<script>
import { DataTable, DialogEdit, btnBatchDownload, SpanPlus } from 'newepoch-components'
import * as format from '@/filters/index'
import coordManageApi from '@/api/assetoutfeedback/coordManage/coordManageApi'
import BasePage from '@/pages/baseEditPage'
export default {
  name: 'dealAuditReviewHisPop',
  extends: new BasePage(),
  components: {
    DataTable,
    DialogEdit,
    btnBatchDownload,
    SpanPlus
  },
  props: {
    editModel: {
      type: [String],
      default () {
        return 'V'
      }
    },
    form: {
      type: [Object],
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      queryParas: {
        pageIndex: 1,
        pageSize: 10
      },
      pageAll: true,
      tableData: [],
      loadCount: 0,
      columns: [
        // 反馈次数
        {
          prop: 'feedbackTimes',
          align: 'center',
          width: '50px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.feedbackTimes,
          format: row => {
            return '第' + row.feedbackTimes + '次'
          }
        },
        // 律所意见
        {
          prop: 'feedbackQuestionContent',
          align: 'left',
          slot: true,
          width: '150px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.feedbackQuestionContent
        },
        // 合规回复律所意见
        {
          prop: 'replyLawContent',
          align: 'left',
          slot: true,
          width: '150px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.replyLawContent
        },
        // 合规附件
        {
          prop: 'fileOssids',
          align: 'center',
          slot: true,
          width: '70px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.hgFile
        },
        // 合规落实
        {
          prop: 'practicableSuggestion',
          align: 'left',
          slot: true,
          width: '150px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.hgls
        },
        // 相关方
        {
          prop: 'relationType',
          align: 'center',
          width: '80px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.relation,
          format: (row) => {
            if (row.relationChargeUserName && row.relationChargeUserName !== '') {
              return format.formatDict(row.relationType, 'AUDIT_OUT_RELATION_TYPE') + '—' + row.relationChargeUserName
            } else {
              return format.formatDict(row.relationType, 'AUDIT_OUT_RELATION_TYPE')
            }
          }
        },
        // 相关方意见
        {
          prop: 'relationResolution',
          align: 'left',
          slot: true,
          width: '150px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.relationResolution
        },
        // 相关方附件
        {
          prop: 'relationFileIds',
          align: 'center',
          slot: true,
          width: '70px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.relationFile
        }

      ],
      spanArr: []
    }
  },
  computed: {
    reviewUpdateApi () {
      return coordManageApi.reviewUpdate
    },
    coordManageApi () {
      return coordManageApi.getTrclistQust
    }
  },
  mounted () {
    if (this.form.type && this.form.type === '1') {
      Object.assign(this.queryParas, this.form)
    } else {
      this.queryParas.feedbackAssetKey = this.form.feedbackAssetKey
      this.queryParas.qusetionNumber = this.form.qusetionNumber
    }
    this.$nextTick(() => {
      this.handleFilter()
    })
  },
  methods: {
    getTableData (data) {
      this.tableData = data
      this.getOrderNumber()
    },
    // 获取相同编号的数组
    getOrderNumber () {
      let data = this.tableData
      for (var i = 0; i < data.length; i++) {
        if (i === 0) {
          this.spanArr.push(1)
          this.pos = 0
        } else {
          // 判断当前元素与上一个元素是否相同
          if (data[i].feedbackTimes === data[i - 1].feedbackTimes &&
              data[i].firmOpnion === data[i - 1].firmOpnion &&
              data[i].hgFirmOpnion === data[i - 1].hgFirmOpnion) {
            this.spanArr[this.pos] += 1
            this.spanArr.push(0)
          } else {
            this.spanArr.push(1)
            this.pos = i
          }
        }
      }
    },
    handleFilter () {
      this.loadCount = this.loadCount + 1
    },
    // 行合并
    objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex >= 0 && columnIndex <= 3) {
        const _row = this.spanArr[rowIndex]
        return {
          rowspan: _row, // 行
          colspan: 1 // 列
        }
      }
    }
  }
}
</script>
