<template>
  <custom-modal v-model="visible" :width="800" title="Spectrum" :footer="null">
    <a-spin :spinning="isLoading">
      <pre>
        {{ content }}
      </pre>
    </a-spin>
  </custom-modal>
</template>

<script>
import ModalMixin from '@/mixins/ModalMixin'
import { getAction } from '@/api/manage'
import SampleDataMixin from '../../SampleDataMixin'
export default {
  mixins: [ModalMixin, SampleDataMixin],
  data() {
    return {
      content: '',
      isLoading: true
    }
  },
  methods: {
    async getContent() {
      try {
        this.isLoading = true
        const { sampleId, inputFileName: fileName } = this.sampleData
        const { success, result, message } = await getAction('/gamma/Spectrum', {
          sampleId,
          fileName
        })
        if (success) {
          this.content = result
        } else {
          this.$message.error(message)
        }
      } catch (error) {
        console.error(error)
      } finally {
        this.isLoading = false
      }
    },

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

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