<!-- 审核相关方资料 -->
<template>
  <div class="auditRelationPop">
    <dialog-edit :appendToBody="appendToBody" :visible.sync="dialogVisible"
    :editModel="editModel" :form="form" :title="$t('common.audit')" :saveFlag="false" :autoClose="true" @close="close">
      <externalTransition v-if="table.relationNewestHandleResultDtoList && table.relationNewestHandleResultDtoList.length > 0" :isCollapse="true" :collapseTitleMargin="'margin: 0 0 0 0'" :title="$t('effectDealFeedBackMain.handleLatestResults')">
        <template slot="transition">
          <!-- 相关方处理最新结果 -->
          <data-table :showPage="showPage" :sourceData.sync="table.relationNewestHandleResultDtoList" :columns="relateColumns">
            <!-- 律所反馈意见 -->
            <template #feedbackQuestionContent="scope">
              <span-plus :index="scope.data.$index" :text="scope.data.row.feedbackQuestionContent"></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>
            <template #fileIds="scope">
              <btn-batch-download :disabled="scope.data.row.fileList.length === 0" :fileID="scope.data.row.fileList.length > 0 ? scope.data.row.fileList.map(item=>{return item.fileId}) : scope.data.row.fileList" :classType="false" :downloadFileName="scope.data.row.fileList.length > 1 ? $t('effectDealFeedBackMain.xgfFileList') + '.zip':null"></btn-batch-download>
              <el-popover
                class="box-column-margin-left"
                placement="right"
                width="200"
                trigger="hover">
                <div v-for="(item,index) in scope.data.row.fileList" :key="index">
                  <el-link type="primary" @click="preView(getFile(item.fileName),item.fileId)">{{item.fileName}}</el-link>
                </div>
                <auth-button :disabled="scope.data.row.fileList.length === 0" slot="reference" size="small" class="iconCircle" :title="$t('common.preview')" icon="iconfont iconview"></auth-button>
              </el-popover>
            </template>
          </data-table>
        </template>
      </externalTransition>
      <!-- 历史往来意见 -->
      <externalTransition v-if="table.historyDealingsSuggestionDtoList && table.historyDealingsSuggestionDtoList.length > 0" :isCollapse="true" :collapseTitleMargin="'margin: 10px 0 0 0'" :title="$t('effectDealFeedBackMain.historical')">
        <template slot="transition">
          <data-table :showPage="showPage" :sourceData.sync="table.historyDealingsSuggestionDtoList" :columns="historyColumns">
            <!-- 律所反馈意见 -->
            <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 #fileOssids="scope">
              <btn-batch-download :disabled="scope.data.row.fileList.length === 0" :fileID="scope.data.row.fileList.length > 0 ? scope.data.row.fileList.map(item=>{return item.fileId}) : scope.data.row.fileList" :classType="false" :downloadFileName="scope.data.row.fileList.length > 1 ? $t('effectDealFeedBackMain.xgfFileList') + '.zip' : null"></btn-batch-download>
            </template>
          </data-table>
        </template>
      </externalTransition>
      <externalTransition v-if="table.repulseSuggestionDtoList && table.repulseSuggestionDtoList.length > 0" :isCollapse="true" :collapseTitleMargin="'margin: 10px 0 0 0'" :title="$t('effectDealFeedBackMain.repulseSuggestion')">
        <template slot="transition">
          <data-table :showPage="showPage" :sourceData.sync="table.repulseSuggestionDtoList" :columns="planColumns">
            <!-- 律所反馈意见 -->
            <template #feedbackQuestionContent="scope">
              <span-plus :index="scope.data.$index" :text="scope.data.row.feedbackQuestionContent"></span-plus>
            </template>
            <!-- 合规落实结果-->
            <template #result="scope">
              <span-plus :index="scope.data.$index" :text="scope.data.row.result"></span-plus>
            </template>
            <!-- 合规意见-->
            <template #suggestion="scope">
              <span-plus :index="scope.data.$index" :text="scope.data.row.suggestion"></span-plus>
            </template>
            <!-- 统筹人意见意见-->
            <template #repulseSuggestion="scope">
              <span-plus :index="scope.data.$index" :text="scope.data.row.repulseSuggestion"></span-plus>
            </template>
            <template #fileIds="scope">
              <btn-batch-download :disabled="scope.data.row.fileList.length === 0" :fileID="scope.data.row.fileList.length > 0 ? scope.data.row.fileList.map(item=>{return item.fileId}) : scope.data.row.fileList" :classType="false" :downloadFileName="scope.data.row.fileList.length > 1 ? $t('effectDealFeedBackMain.fileOssids') + '.zip':null"></btn-batch-download>
              <el-popover
                class="box-column-margin-left"
                placement="right"
                width="200"
                trigger="hover">
                <div v-for="(item,index) in scope.data.row.fileList" :key="index">
                  <el-link type="primary" @click="preView(getFile(item.fileName),item.fileId)">{{item.fileName}}</el-link>
                </div>
                <auth-button :disabled="scope.data.row.fileList.length === 0" slot="reference" size="small" class="iconCircle" :title="$t('common.preview')" icon="iconfont iconview"></auth-button>
              </el-popover>
            </template>
          </data-table>
        </template>
      </externalTransition>
      <externalTransition :isCollapse="true" :title="$t('common.audit')">
        <template slot="transition">
          <effectFeedBackContentLawSub ref="effectFeedBack" :form.sync="effectForm" :effApi="proApi" v-on="$listeners" :code="code" :lawEditModel="editModel"></effectFeedBackContentLawSub>
        </template>
      </externalTransition>
      <template slot="footer">
          <!--确定-->
          <auth-button :label="$t('projectCompany.btnDone')"
                        type="primary"
                        size="medium"
                        @click="determine"></auth-button>
      </template>
    </dialog-edit>
    <pre-view ref="preView" :oosUrl="config.VUE_APP_OSS_URL" :fileUrl="config.VUE_APP_BASE_URL" :dialogAttrs="dialogAttrs"></pre-view>
  </div>
</template>

<script>
import effectFeedBackContentLawSub from '@/pages/assetoutfeedback/effectDealFeedBack/effectFeedBackContentLawSub'
import effectDealFeedBackApi from '@/api/assetoutfeedback/effectDealFeedBack/effectDealFeedBackApi'
import externalTransition from '@/components/element/assetoutfeedback/externalTransition'
import { DialogEdit, DataTable, authButton, btnBatchDownload, preView, SpanPlus } from 'newepoch-components'
import BasePage from '@/pages/baseEditPage'
export default {
  extends: new BasePage(),
  components: { DialogEdit, DataTable, authButton, externalTransition, SpanPlus, preView, btnBatchDownload, effectFeedBackContentLawSub },
  props: {
    form: {
      type: Object,
      default () {
        return {}
      }
    },
    changeForm: {
      type: Object,
      default () {
        return {}
      }
    },
    editModel: {
      type: String,
      default () {
        return 'E'
      }
    },
    index: {
      type: Number,
      default () {
        return 0
      }
    },
    effApi: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  computed: {
    effectForm: {
      get: function () {
        return this.form
      },
      set: function (value) {
        this.$emit('update:form', value)
      }
    },
    reapi () {
      return effectDealFeedBackApi.getRelateInfo
    },
    proApi () {
      return this.effApi
    }
  },
  data () {
    return {
      config: process.env,
      code: '',
      middleChange: {},
      appendToBody: true,
      showPage: false,
      table: {
        historyDealingsSuggestionDtoList: [],
        relationNewestHandleResultDto: {},
        repulseSuggestionDTO: {}
      },
      relateTable: [],
      relateColumns: [
        {
          // 律所反馈意见
          prop: 'feedbackQuestionContent',
          align: 'left',
          slot: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].factoringBusinessInfo.law_feedback_opinion
        }, {
          // 合规对相关方回复
          prop: 'practicableSuggestion',
          align: 'left',
          slot: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.replyForRelated
        }, {
          // 相关方
          prop: 'relation',
          align: 'center',
          width: '60px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.relation
        }, {
          // 相关方最新一次回复给合规
          prop: 'relationResolution',
          align: 'left',
          slot: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.relationresolutions
        }, {
          // 相关提供附件下载
          prop: 'fileIds',
          align: 'center',
          slot: true,
          width: '70px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.fileIdsDown
        }
      ],
      historyTable: [],
      historyColumns: [
        {
          // 反馈次数
          prop: 'feedbackTimes',
          align: 'center',
          width: '60px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.feedbackTimes
        }, {
          // 律所意见
          prop: 'feedbackQuestionContent',
          slot: true,
          align: 'left',
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.replyLawContent
        }, {
          // 合规回复律所意见
          prop: 'replyLawContent',
          slot: true,
          align: 'left',
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.feedbackQuestionContent
        }, {
          // 合规附件
          prop: 'fileOssids',
          align: 'center',
          slot: true,
          width: '60px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.fileIdsDown
        }
      ],
      planTable: [],
      planColumns: [
        {
          // 律所反馈意见
          prop: 'feedbackQuestionContent',
          align: 'left',
          slot: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.law_feedback_opinion
        }, {
          // 合规落实结果
          prop: 'result',
          align: 'left',
          slot: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.result
        }, {
          // 合规意见
          prop: 'suggestion',
          align: 'left',
          slot: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.practicableSuggestic
        }, {
          // 合规附件
          prop: 'fileIds',
          align: 'center',
          slot: true,
          width: '60px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.fileOssids
        }, {
          // 统筹人打回意见
          prop: 'repulseSuggestion',
          align: 'left',
          slot: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.repulseSuggestion
        }
      ],
      dialogAttrs: {
        'append-to-body': true,
        'center': true,
        'title': this.$t('common.preview')
      }
    }
  },
  mounted () {
    this.codeFind()
    let param = {}
    if (this.editModel === 'SLS') {
      param = {
        relationHandleKeyId: this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList[this.index].relationKeyId,
        qstDetailKeyId: this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList[this.index].questionKeyId
      }
    } else if (this.editModel === 'A') {
      param = {
        relationHandleKeyId: this.effectForm.notHandleQuestionDtoList[this.effectForm.index].handleInfoKeyId,
        qstDetailKeyId: this.effectForm.notHandleQuestionDtoList[this.effectForm.index].qstDetailKeyId
      }
    } else {
      param = {
        relationHandleKeyId: this.effectForm.notHandleQuestionDtoList[this.effectForm.cindex].handleInfoKeyId,
        qstDetailKeyId: this.effectForm.notHandleQuestionDtoList[this.effectForm.cindex].qstDetailKeyId
      }
    }
    this.reapi.getDefaultInfo(param).then(res => {
      if (res.code === '0' && res.data) {
        this.table = res.data
      }
    })
  },
  methods: {
    // 确定
    determine () {
      this.$refs.effectFeedBack.checkData('2', res => {
        if (res) {
          this.$emit('determin', true)
          this.dialogVisible = false
        }
      })
    },
    codeFind () {
      if (this.editModel === 'A') {
        this.code = 'LS'
      } else if (this.editModel === 'SLS') {
        this.code = 'SLS'
      } else {
        this.code = 'SH'
      }
    },
    // 结果还原
    checkClear () {
      if (this.editModel === 'A') {
        this.effectForm.checked = ['1']
      } else {
        this.effectForm.checkedAudit = ['1']
      }
    },
    // 关闭画面
    close () {
      if (this.editModel === 'A') {
        this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index] = this.changeForm
      } else if (this.editModel === 'SLS') {
        this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList[this.effectForm.aindex] = this.changeForm
      } else if (this.editModel === 'IS') {
        this.effectForm.notHandleQuestionDtoList[this.effectForm.cindex].checkButtonPostDtoList[0] = this.changeForm
      }
      this.checkClear()
      this.dialogVisible = false
    },
    // 预览
    preView (type, id) {
      this.$refs.preView.show(type, id)
    },
    // 获取文件类型
    getFile (e) {
      let name = ''
      let test = e.indexOf('.')
      if (test !== -1) {
        e.slice(test + 1)
      }
      return name
    }
  }
}
</script>

<style>

</style>
