<template>
  <custom-modal v-model="visible" :width="1280" title="Mini Radionuclide Laboratory Reports" :destroyOnClose="true" @cancel="handleCancel">
    <a-spin :spinning="isLoading">
      <div class="rlr">
        <div class="rlr-tabs">
          <div
            class="rlr-tabs-item"
            :class="activeKey == index ? 'active' : ''"
            v-for="(tab, index) in tabs"
            :key="index"
            @click="handleChangeView(index)"
          >
            {{ tab }}
          </div>
        </div>
        <div class="rlr-content">
          <h4>{{ tabs[activeKey] }}</h4>
          <div class="rlr-content-detail">
            <template v-if="activeKey == 0">
              <c-header :allData="allInfo" />
            </template>
            <template v-if="activeKey == 1">
              <Objective :allData="allInfo" />
            </template>
            <template v-if="activeKey == 2">
              <collection :allData="allInfo" />
            </template>
            <template v-if="activeKey == 3">
              <sample-receipt :allData="allInfo" />
            </template>
            <template v-if="activeKey == 4">
              <test :allData="allInfo" />
            </template>
            <template v-if="activeKey == 5">
              <peaks-method :allData="allInfo" />
            </template>
            <template v-if="activeKey == 6">
              <peak-fit :tableData="allInfo.peakFit" />
            </template>
            <template v-if="activeKey == 7">
              <g-analysis-methods :allData="allInfo" />
            </template>
            <template v-if="activeKey == 8">
              <peak-association :allData="allInfo" />
            </template>
            <template v-if="activeKey == 9">
              <references :allData="allInfo" />
            </template>
            <template v-if="activeKey == 10">
              <results :allData="allInfo" />
            </template>
            <template v-if="activeKey == 11">
              <nuclide-ratios :allData="allInfo" />
            </template>
            <template v-if="activeKey == 12">
              <g-coincidence-correction />
            </template>
            <template v-if="activeKey == 13">
              <mda />
            </template>
            <template v-if="activeKey == 14">
              <conclusions :allData="allInfo" />
            </template>
            <template v-if="activeKey == 15">
              <comment :allData="allInfo" />
            </template>
          </div>
        </div>
      </div>
    </a-spin>
    <div slot="custom-footer" style="text-align: center;">
      <a-space :size="20">
        <a-button type="primary" @click="handleSave">Save</a-button>
        <a-button @click="handleCancel">Cancel</a-button>
      </a-space>
    </div>
  </custom-modal>
</template>

<script>
import ModalMixin from '@/mixins/ModalMixin'
import CHeader from './components/Header.vue'
import Objective from './components/Objective.vue'
import Collection from './components/Collection.vue'
import SampleReceipt from './components/SampleReceipt.vue'
import Test from './components/Test.vue'
import PeaksMethod from './components/PeaksMethod.vue'
import PeakFit from './components/PeakFit.vue'
import GAnalysisMethods from './components/g_AnalysisMethods.vue'
import PeakAssociation from './components/PeakAssociation.vue'
import References from './components/References.vue'
import Results from './components/Results.vue'
import NuclideRatios from './components/NuclideRatios.vue'
import GCoincidenceCorrection from './components/g_CoincidenceCorrection.vue'
import Mda from './components/MDA.vue'
import Conclusions from './components/Conclusions.vue'
import Comment from './components/Comment.vue'
import { getAction } from '@/api/manage'
import Custom from '@/views/account/settings/Custom.vue'
import SampleDataMixin from '@/views/spectrumAnalysis/SampleDataMixin'

const tabs = [
  'Header',
  'Objective',
  'Collection',
  'SampleReceipt',
  'Test',
  'PeaksMethod',
  'PeakFit',
  'g_AnalysisMethods',
  'PeakAssociation',
  'References',
  'Results',
  'NuclideRatios',
  'g_CoincidenceCorrection',
  'MDA',
  'Conclusions',
  'Comment'
]

export default {
  mixins: [ModalMixin, SampleDataMixin],
  components: {
    CHeader,
    Objective,
    Collection,
    SampleReceipt,
    Test,
    PeaksMethod,
    PeakFit,
    GAnalysisMethods,
    PeakAssociation,
    References,
    Results,
    NuclideRatios,
    GCoincidenceCorrection,
    Mda,
    Conclusions,
    Comment,
    Custom
  },
  data() {
    this.tabs = tabs
    return {
      isLoading: false,
      activeKey: 0,
      allInfo: {}
    }
  },
  mounted () {
    sessionStorage.removeItem("isCellEmpty")
  },
  methods: {
    handleSave() {
      let val = sessionStorage.getItem("isCellEmpty")
      if (val=="false") {
        this.visible = false
      } else {
        this.$message.warning("Please finishi ti edit new inserted row first.")
      }
    },
    handleCancel() {
      this.visible = false
      sessionStorage.removeItem("isCellEmpty")
    },
    handleChangeView(index) {
      let val = sessionStorage.getItem("isCellEmpty")
      if (val=="false"||!val) {
        this.activeKey = index
      } else {
        this.$message.warning("Please finishi ti edit new inserted row first.")
      }
    },
    beforeModalOpen() {
      this.activeKey = 0
      this.getGammaViewRLR();
    },
    getGammaViewRLR() {
      this.isLoading = true
      const { sampleId, inputFileName: fileName } = this.sampleData
      let params = {
        sampleId,
        fileName
      }
      getAction("/gamma/viewRLR", params).then(res => {
        this.isLoading = false
        if (res.success) {
          this.allInfo = res.result
        } else {
          this.$message.warning("This operation fails. Contact your system administrator")
        }
      })
    },
  }
}
</script>

<style lang="less" scoped>
.rlr {
  display: flex;

  &-tabs {
    width: 170px;
    background-color: #275466;
    padding: 3px 0;

    &-item {
      cursor: pointer;
      user-select: none;
      padding: 0 5px;
      height: 32px;
      line-height: 32px;

      &.active {
        background-color: #296d81;
      }
    }
  }

  &-content {
    margin-left: 20px;
    flex: 1;

    h4 {
      color: #fff;
    }

    &-detail {
      height: 600px;
      padding: 20px;
      overflow: auto;
      background-color: #082f3e;
    }
  }
}
/deep/.ant-modal-title{
  letter-spacing: 1px;
}
</style>
