<template>
  <custom-modal v-model="visible" :width="1000" :title="type == 1 || type == 3 ? 'ARR' : 'RRR'">
    <a-spin :spinning="isLoading">
      <pre>{{ content }}</pre>
    </a-spin>
    <div slot="custom-footer" style="text-align: center;">
      <a-space :size="20">
        <a-button type="primary">Export</a-button>
        <a-button @click="visible = false">Cancel</a-button>
      </a-space>
    </div>
  </custom-modal>
</template>

<script>
import ModalMixin from '@/mixins/ModalMixin'
import { getAction } from '../../../../api/manage'
export default {
  mixins: [ModalMixin],
  props: {
    type: {
      type: Number
    },
    sampleId: {
      type: Number
    }
  },
  data() {
    return {
      content: '',
      isLoading: true
    }
  },
  methods: {
    async getContent() {
      let url = ''
      switch (this.type) {
        case 3:
          url = '/spectrumAnalysis/viewARR'
          break
        case 4:
          url = '/spectrumAnalysis/viewRRR'
      }
      try {
        this.content = ''
        this.isLoading = true
        const res = await getAction(url, { sampleId: this.sampleId })
        this.content = res
      } catch (error) {
        console.error(error)
      } finally {
        this.isLoading = false
      }
    },

    beforeModalOpen() {
      if (this.sampleId) {
        this.getContent()
      }
    }
  }
}
</script>

<style lang="less" scoped>
pre {
  height: 450px;
  padding: 5px;
  overflow: auto;
  background-color: #285367;
}
</style>
