<!-- 发补寄选择画面(鲜章,批量) -->
<template>
  <div>
    <dialog-edit :appendToBody="appendToBody" :visible.sync="dialogVisible" :editModel="editModel" :form="form" :title="$t('effectDealFeedBackMain.select')" :saveFlag="false">
      <data-table @selectRowChange="selectRowChange" :showSelection="showSelection" :sourceData.sync="table" :columns="editModel === 'EIS' ? elecColumns : columns" :loadCount="loadCount" :queryParas.sync="queryParas" v-bind="{maxHeight:400}" :api="editModel === 'EIS'? SupbEApi : SupbFApi">
        <template slot="relationFileIds" slot-scope="scope">
          <btn-batch-download v-if="editModel === 'EIS'" :disabled="scope.data.row.relationFileIds.length === 0" :fileID="scope.data.row.relationFileIds" :downloadFileName="scope.data.row.relationFileIds.length > 1 ? $t('retrievalContentIndex.enclosure') + '.zip':null"></btn-batch-download>
          <btn-batch-download v-else :disabled="scope.data.row.fileOssids.length === 0" :fileID="scope.data.row.fileOssids" :downloadFileName="scope.data.row.fileOssids.length > 1 ? $t('retrievalContentIndex.enclosure') + '.zip':null"></btn-batch-download>
        </template>
        <!-- 鲜章 -->
        <template #replyLawContent="scope">
          <span-plus :index="scope.data.$index" :text="scope.data.row.replyLawContent"></span-plus>
        </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>
      </data-table>
      <template slot="footer">
          <!--确定-->
          <auth-button :label="$t('projectCompany.btnDone')"
                        type="primary"
                        size="medium"
                        @click="determine"></auth-button>
      </template>
    </dialog-edit>
  </div>
</template>

<script>
import effectDealFeedBackApi from '@/api/assetoutfeedback/effectDealFeedBack/effectDealFeedBackApi'
import * as format from '@/filters/index'
import { DialogEdit, DataTable, authButton, btnBatchDownload, SpanPlus } from 'newepoch-components'
import BasePage from '@/pages/baseEditPage'
export default {
  components: { DialogEdit, DataTable, authButton, btnBatchDownload, SpanPlus },
  extends: new BasePage(),
  props: {
    form: {
      type: Object,
      default () {
        return {}
      }
    },
    editModel: {
      type: String,
      default () {
        return ''
      }
    },
    selectId: {
      type: Object,
      default () {
        return {}
      }
    },
    No: {
      type: Number,
      default () {
        return 0
      }
    }
  },
  data () {
    return {
      selectObj: [],
      showSelection: true,
      appendToBody: true,
      queryParas: {
        pageIndex: 1,
        pageSize: 10,
        flag: '2'
      },
      loadCount: 0,
      table: [],
      columns: [
        {
          // 反馈次数
          prop: 'feedbackTimes',
          align: 'center',
          width: '40px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.feedbackTimes
        }, {
          // 律所意见
          prop: 'feedbackQuestionContent',
          align: 'left',
          width: '160px',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.replyLawContent
        }, {
          // 合规回复律所意见
          prop: 'replyLawContent',
          align: 'left',
          width: '160px',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.feedbackQuestionContent
        }, {
          // 相关附件
          prop: 'relationFileIds',
          align: 'center',
          width: '40px',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.relatedAttachment
        }
      ],
      elecColumns: [
        {
          // 反馈次数
          prop: 'feedbackTimes',
          align: 'center',
          width: '60px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.feedbackTimes
        }, {
          // 律所意见
          prop: 'feedbackQuestionContent',
          align: 'left',
          width: '120px',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.replyLawContent
        }, {
          // 合规落实
          prop: 'practicableSuggestion',
          align: 'left',
          width: '120px',
          slot: true,
          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',
          slot: true,
          width: '120px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.relationResolution
        }, {
          // 相关附件
          prop: 'relationFileIds',
          align: 'center',
          slot: true,
          width: '60px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.relatedAttachment
        }
      ]
    }
  },
  computed: {
    // 电子章
    SupbEApi () {
      return effectDealFeedBackApi.getSupplementElec
    },
    // 鲜章
    SupbFApi () {
      return effectDealFeedBackApi.getSupplementFresh
    }
  },
  mounted () {
    if (this.editModel === 'EIS') {
      this.queryParas.keyId = this.selectId.keyId
      this.queryParas.relationType = this.selectId.relationType
    } else {
      this.queryParas.feedbackAssetKey = this.selectId.feedbackAssetKey
    }
    this.$nextTick(() => {
      this.handleFilter()
    })
  },
  methods: {
    // 更新表数据
    handleFilter () {
      this.loadCount = this.loadCount + 1
    },
    // 选择行数据
    selectRowChange (val) {
      val.forEach(res => {
        if (res.fileOssids && res.fileOssids.length > 0) {
          this.selectObj.push(...res.fileOssids)
          this.selectObj = Array.from(new Set(this.selectObj))
        } else if (res.relationFileIds && res.relationFileIds.length > 0) {
          this.selectObj.push(...res.relationFileIds)
          this.selectObj = Array.from(new Set(this.selectObj))
        }
      })
    },
    // 确定
    determine () {
      if (this.selectObj.length === 0) {
        this.warning('请选择数据或没有可获取文件')
      } else {
        this.success('选择成功')
        this.dialogVisible = false
        this.$emit('selectData', this.selectObj, this.No)
      }
    }
  }
}
</script>
