<template>
  <div>
    <Modal v-model="showSampleModal" v-drag width="1330"  class="zIndex-900 modal-footer-none"
           @on-visible-change="_visibleChange">
      <p slot="header"> {{name}}--管理样品</p>
      <div>
        <el-tabs v-model="activeName" @tab-click="_changeTabs">
          <el-tab-pane label="按项目录入" name="waitReceive">
            <WaitReceive ref="waitReceiveModal"></WaitReceive>
          </el-tab-pane>
          <el-tab-pane label="按样品录入" name="waitScan">
            <WaitScan ref="waitScanModal"></WaitScan>
          </el-tab-pane>
          <el-tab-pane label="查看项目报告" name="viewReport">
            <ItemReportView ref="reportModal"></ItemReportView>
          </el-tab-pane>
          <el-tab-pane label="查看原始记录" name="viewRecord">
            <OriginalRecordView ref="recordModal"></OriginalRecordView>
          </el-tab-pane>
          <el-tab-pane label="查看报告附件" name="soilAppendixRecord">
            <SoilAppendix ref="soilAppendixRecordModal"></SoilAppendix>
          </el-tab-pane>
        </el-tabs>
      </div>
    </Modal>
  </div>
</template>
<script>
import WaitReceive from './item-tabs/ItemTabs'
import WaitScan from './sample-tabs/SampleTabs'
import OriginalRecordView from './OriginalRecordView'
import SoilAppendix from './SoilAppendix'
import ItemReportView from './ItemReportView'

export default {
  components: {
    WaitReceive,
    SoilAppendix,
    WaitScan,
    OriginalRecordView,
    ItemReportView
  },
  data() {
    return {
      type: '',
      contractId: '', // 合同id
      entrustId: '',
      showSampleModal: false,
      modalTitle: '',
      selectIds: [],
      activeName: 'waitReceive',
      name: '',
      currentComponent: ''
    }
  },
  mounted() {
    // this.currentComponent = 'waitScan'
  },
  methods: {
    _open(contractId, type, name) {
      this.type = type // 类型（采样或送样）
      this.name = name
      this.showSampleModal = true
      this.entrustId = contractId // 合同id
      this.activeName = 'waitReceive'
      // this.currentComponent = 'waitScan'
      this.selectIds = []
      this._waitPage()
    },
    // 待接收
    _waitPage() {
      this.$refs.waitReceiveModal._open(this.entrustId)
    },
    // 待发放
    _waitSend() {
      this.$refs.waitScanModal._open(this.entrustId)
    },
    // 已接收
    _issuedPage() {
      this.$refs.alreadyIssuedModal._open(this.contractId, this.type)
    },
    _changeTabs(tab, event) {
      if (tab.name === 'viewRecord') {
        this.$refs.recordModal._open(this.entrustId)
      } else if (tab.name === 'soilAppendixRecord') {
        this.$refs.soilAppendixRecordModal._open(this.entrustId)
      } else if (tab.name === 'waitReceive') {
        this.$refs.waitScanModal._clearTable()
        this.$refs.waitReceiveModal._open(this.entrustId)
      } else if (tab.name === 'waitScan') {
        this.$refs.waitReceiveModal._clearTable()
        this.$refs.waitScanModal._open(this.entrustId)
      } else {
        this.$refs.reportModal._open(this.entrustId)
      }
    },
    _search() {
      this.$refs.waitReceiveModal._clearTable()
      this.$refs.waitScanModal._clearTable()
      this.$emit('on-result-change')
    },
    // 关闭弹框的时候刷新上个界面
    _visibleChange(data) {
      if (data === false) {
        this._search()
      }
    }
  }
}
</script>
