<!-- 落实反馈 -->
<template>
  <div class="feedbackImplementation">
    <!-- 律所反馈意见 -->
      <el-form-item label-width="98px" :label="$t('effectDealFeedBackMain.lawFirmFeedback')">
        <el-input v-if="effectForm.notImplementAssetInfoDto.questionList[effectForm.index]" disabled v-model="effectForm.notImplementAssetInfoDto.questionList[effectForm.index].feedbackQuestionContent"></el-input>
        <el-input v-else disabled value=""></el-input>
      </el-form-item>
      <!-- 历史往来意见 -->
      <externalTransition v-if="effectForm.notImplementAssetInfoDto.questionList[effectForm.index] && effectForm.notImplementAssetInfoDto.questionList[effectForm.index].historyDealingsSuggestionDtoList && effectForm.notImplementAssetInfoDto.questionList[effectForm.index].feedbackTimes > 1 && effectForm.notImplementAssetInfoDto.questionList[effectForm.index].historyDealingsSuggestionDtoList.length > 0" :isCollapse="true" :title="$t('effectDealFeedBackMain.historical')">
        <template slot="transition">
            <data-table class="box-column-margin-bottom" :showPage="showPage" :sourceData.sync="effectForm.notImplementAssetInfoDto.questionList[effectForm.index].historyDealingsSuggestionDtoList" :columns="columns_1" maxHeight="400px">
              <el-table-column :label="$t('effectDealFeedBackMain.fileOssids')" align="center" width="120px" fixed="right">
                <template slot-scope="scope">
                  <btn-batch-download :disabled="scope.row.fileList.length === 0" :fileID="scope.row.fileList.length > 0 ? scope.row.fileList.map(item=>{return item.fileId}) : scope.row.fileList" :classType="false" :downloadFileName="scope.row.fileList.length > 1 ? $t('effectDealFeedBackMain.fileOssids') + '.zip':null"></btn-batch-download>
                </template>
                </el-table-column>
                <!-- 律所意见 -->
                <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>
            </data-table>
        </template>
      </externalTransition>
      <!-- 统筹人打回意见 -->
      <externalTransition v-if="effectForm.notImplementAssetInfoDto.questionList[effectForm.index] && effectForm.notImplementAssetInfoDto.questionList[effectForm.index].repulseSuggestionDtoList && effectForm.notImplementAssetInfoDto.questionList[effectForm.index].repulseSuggestionDtoList.length > 0" :isCollapse="true" :title="$t('effectDealFeedBackMain.repulseSuggestion')">
        <template slot="transition">
            <data-table class="box-column-margin-bottom" :showPage="showPage" :sourceData.sync="effectForm.notImplementAssetInfoDto.questionList[effectForm.index].repulseSuggestionDtoList" :columns="columns_2" v-bind="{maxHeight:400}">
                <!-- 律所反馈问题 -->
                <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 slot="fileList" slot-scope="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 v-if="effectForm.notImplementAssetInfoDto.questionList[effectForm.index] && effectForm.notImplementAssetInfoDto.questionList[effectForm.index].relationHandlingDtoList && effectForm.notImplementAssetInfoDto.questionList[effectForm.index].relationHandlingDtoList.length > 0" :isCollapse="true" :title="$t('effectDealFeedBackMain.taskHandledParties')">
        <template slot="transition">
          <data-table class="box-column-margin-bottom" :showPage="showPage" :sourceData.sync="effectForm.notImplementAssetInfoDto.questionList[effectForm.index].relationHandlingDtoList" :columns="columns_3" v-bind="{maxHeight:400, spanMethod:e => objectSpanMethod(effectForm.notImplementAssetInfoDto.questionList[effectForm.index].relationHandlingDtoList,e)}">
            <template slot="fileList" slot-scope="scope">
              <div v-if="scope.data.row.canCheckFlag === '1'">
                <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>
              </div>
            </template>
            <!-- 律所反馈问题 -->
            <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 slot="relationFeedbackQustionNoFlag" slot-scope="scope">
              <el-checkbox :index="scope.data.$index"  v-model="scope.data.row.relationFeedbackQustionNoFlag" true-label="1" false-label="0"></el-checkbox>
            </template>
            <template slot="relationFeedbackQustionNoFlaghead" slot-scope="scope">
              <el-checkbox :index="scope.data.$index"  v-model="scope.data.column.prop"  @change="allReviewFlag(scope.data.column.prop)" true-label="1" false-label="0"></el-checkbox>
              <span style="margin-left: 10px">{{scope.data.column.label}}</span>
            </template>
            <el-table-column :label="$t('common.operate')" align="center" width="100px">
              <template slot-scope="scope">
                <auth-button v-if="scope.row.canCheckFlag === '1' && scope.row.status === $t('effectDealFeedBackMain.noApproved')" size="small" class="iconCircle marginLeft"
                            :title="$t('common.audit')" icon="iconfont iconreview" @click="examine(scope.row, scope.$index)"></auth-button>
                <auth-button v-if="scope.row.canCheckFlag === '1' && scope.row.status === $t('effectDealFeedBackMain.yesApproved')" size="small" class="iconCircle marginLeft"
                            :title="$t('effectDealFeedBackMain.auditAgain')" icon="iconfont iconzhongxinshenhe" @click="examine(scope.row, scope.$index)"></auth-button>
              </template>
            </el-table-column>
          </data-table>
        </template>
      </externalTransition>
      <audit-relation-pop v-if="auditRelationVisible" :visible.sync="auditRelationVisible" :form.sync="effectForm" :editModel="'SLS'" :index="index" @determin="determin" :changeForm="changeForm"></audit-relation-pop>
      <pre-view ref="preView" :oosUrl="config.VUE_APP_OSS_URL" :fileUrl="config.VUE_APP_BASE_URL" :dialogAttrs="dialogAttrs"></pre-view>
  </div>
</template>

<script>
import auditRelationPop from '@/pages/assetoutfeedback/effectDealFeedBack/auditRelationPop'
import externalTransition from '@/components/element/assetoutfeedback/externalTransition'
import { DataTable, authButton, SpanPlus, dymForm, btnBatchDownload, preView } from 'newepoch-components'
export default {
  components: { DataTable, authButton, SpanPlus, dymForm, externalTransition, btnBatchDownload, auditRelationPop, preView },
  props: {
    imData: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  computed: {
    effectForm: {
      get: function () {
        return this.imData
      },
      set: function (value) {
        this.$emit('update:imData', value)
      }
    }
  },
  data () {
    return {
      config: process.env,
      changeForm: {},
      obj: {
        replyOutPostDto: {
          chapterFlag: '1',
          replyLawContent: '',
          uploadFilePostDtoList: []
        },
        replyRelationPostDtoList: []
      },
      form: {},
      index: 0,
      auditRelationForm: {},
      auditRelationVisible: false,
      activeNames: '1',
      showPage: false,
      appendToBody: true,
      columns_1: [
        {
          // 反馈次数
          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.replyLawContent
        }, {
          // 合规回复律所意见
          prop: 'replyLawContent',
          align: 'left',
          slot: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.feedbackQuestionContent
        }
      ],
      columns_2: [
        {
          // 律所反馈意见
          prop: 'feedbackQuestionContent',
          align: 'left',
          slot: true,
          width: '160px',
          label: this.$i18n.messages[this.$i18n.locale].factoringBusinessInfo.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: 'fileList',
          align: 'center',
          width: '80px',
          slot: true,
          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
        }
      ],
      columns_3: [
        {
          // 律所反馈意见
          prop: 'feedbackQuestionContent',
          slot: true,
          align: 'left',
          width: '150px',
          label: this.$i18n.messages[this.$i18n.locale].factoringBusinessInfo.law_feedback_opinion
        }, {
          // 合规相关方回复
          prop: 'practicableSuggestion',
          slot: true,
          align: 'center',
          width: '150px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.replyRelated
        }, {
          // 相关方
          prop: 'relation',
          align: 'center',
          width: '80px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.relation
        }, {
          // 相关方最新一次回复给合规
          prop: 'relationResolution',
          slot: true,
          align: 'left',
          width: '120px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.relationresolutions
        }, {
          // 相关方提供附件下载
          prop: 'fileList',
          align: 'center',
          width: '100px',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.fileIdList
        }, {
          // 选为本次落实方案
          prop: 'relationFeedbackQustionNoFlag',
          align: 'center',
          width: '100px',
          slot: true,
          headslot: true,
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.selAsImplemente
        }, {
          // 状态
          prop: 'status',
          align: 'center',
          width: '60px',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingTaskManage.status
        }
      ],
      dialogAttrs: {
        'append-to-body': true,
        'center': true,
        'title': this.$t('common.preview')
      }
    }
  },
  methods: {
    // 入力数据初始化
    dataChanged (index) {
      this.effectForm.checkedAudit = ['1']
      this.obj = {
        practicableResult: '1',
        replyOutPostDto: {
          chapterFlag: '1',
          replyLawContent: '',
          uploadFilePostDtoList: []
        },
        replyRelationPostDtoList: []
      }
      if (this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList.length === 0) {
        this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList[index] = this.obj
        JSON.parse(JSON.stringify(this.changeForm = this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList[index]))
      } else {
        if (this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList[index].replyOutPostDto) {
          this.changeForm = JSON.parse(JSON.stringify(this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList[index]))
        }
        Object.assign(this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList[index], this.obj)
      }
      this.effectForm.aindex = index
    },
    // 审核状态改变
    determin (flag) {
      if (flag) {
        this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList[this.effectForm.aindex].status = '已审核'
      }
    },
    // 审核
    examine (row, index) {
      this.index = index
      this.dataChanged(index)
      this.auditRelationVisible = true
    },
    // 选为本次落实方案所有行选中
    allReviewFlag (headCheck) {
      if (this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList.length > 0) {
        this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList.forEach((res, i) => {
          this.effectForm.notImplementAssetInfoDto.questionList[this.effectForm.index].relationHandlingDtoList[i].relationFeedbackQustionNoFlag = headCheck
        })
      }
    },
    // 预览
    preView (type, id) {
      // console.log(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
    },
    // 行合并
    objectSpanMethod (item, { row, column, rowIndex, columnIndex }) {
      let spanCount = 1
      if (columnIndex > -1 && columnIndex < 1) {
        if (rowIndex === 0 || item[rowIndex - 1].feedbackQuestionContent !== row.feedbackQuestionContent) {
          item.reduce((last, current) => {
            if (last.feedbackQuestionContent === row.feedbackQuestionContent && last.feedbackQuestionContent === current.feedbackQuestionContent) {
              spanCount++
            }
            return current
          })
          return {
            rowspan: spanCount,
            colspan: 1
          }
        }
        return {
          rowspan: 0,
          colspan: 0
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/styles/assetoutfeedback/common.scss'
</style>
