<template>
  <div>
    <Modal v-model="showSampleModal" v-drag @on-visible-change="_visibleChange" width="1200"
           class="zIndex-900 modal-footer-none">
      <p slot="header">数据审核</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-tabs>
<!--        <keep-alive>-->
<!--          &lt;!&ndash; eslint-disable-next-line vue/require-component-is &ndash;&gt;-->
<!--          <component ref="refModal" :is="currentComponent"></component>-->
<!--        </keep-alive>-->
      </div>
    </Modal>
  </div>
</template>
<script>
import WaitReceive from './item-tabs/ItemTabs'
import WaitScan from './sample-tabs/SampleTabs'
import ItemReportView from './ItemReportView'
import OriginalRecordView from './OriginalRecordView'

export default {
  components: {
    WaitReceive,
    WaitScan,
    ItemReportView,
    OriginalRecordView
  },
  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._issuedPage()
        this.$refs.recordModal._open(this.entrustId)
      } else if (tab.name === 'waitReceive') {
        // this._waitPage()
        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)
        // this._waitSend()
      } else if (tab.name === 'viewReport') {
        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>
