<template>
  <div>
    <Modal v-model="showSampleModal" @on-visible-change="_visibleChange" width="1200"
           class="zIndex-900 modal-footer-none">
      <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-tabs>
      </div>
    </Modal>
  </div>
</template>
<script>
import WaitReceive from './item-tabs/ItemTabs'
import WaitScan from './sample-tabs/SampleTabs'

export default {
  components: {
    WaitReceive,
    WaitScan
  },
  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
      this.activeName = 'waitReceive'
      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 === 'alreadyIssued') {
        // this._issuedPage()
      } else if (tab.name === 'waitReceive') {
        // this._waitPage()
        this.$refs.waitReceiveModal._open(this.entrustId)
      } else if (tab.name === 'waitScan') {
        this.$refs.waitScanModal._open(this.entrustId)
        // this._waitSend()
      }
    },
    _search() {
      this.$emit('on-result-change')
    },
    // 关闭弹框的时候刷新上个界面
    _visibleChange(data) {
      if (data === false) {
        this._search()
      }
    }
  }
}
</script>
