<template>
  <div>
    <Modal v-model="showModal" :mask-closable="false" width="900" class="zIndex-1200">
      <p slot="header">选择报告模板</p>
      <div>
        <ReportTemplate ref="reportTemplate" @on-result-change="_templateResultChange"></ReportTemplate>
      </div>
      <div slot="footer">
        <modal-footer ref="footerModal" :footer="footerList" @on-result-change="_footerResult"></modal-footer>
      </div>
    </Modal>
  </div>
</template>

<script>
import ReportTemplate from './ReportTemplate'

/**
 * 重新生成的报告选择模板
 */
export default {
  components: {
    ReportTemplate
  },
  data() {
    return {
      showModal: false,
      selectData: {},
      footerList: [
        { type: '', id: '', name: '取消' },
        { type: 'primary', id: '', name: '确定' }
      ],
      data: {}
    }
  },
  methods: {
    _open(data) {
      this.showModal = true
      this.$refs.footerModal._hideLoading()
      this.data = data
      this.$refs.reportTemplate._open(data.tempId)
    },
    _templateResultChange(selectData) {
      this.selectData = selectData
    },
    _footerResult(name) {
      switch (name) {
        case '确定':
          this.$emit('on-result-change', {
            id: this.data.id,
            tempId: this.selectData.id,
            reportBatch: this.data.reportBatch
          })
          this.showModal = false
          break
        case '取消':
          this.showModal = false
          break
      }
    }
  }
}
</script>
