<!--CollapseMulti 关联框  modal弹框-->
<template>
  <div>
    <Modal v-model="showModal" width="100" :mask-closable="false" :styles="{top: '0px'}" class="zIndex-1200 full-screen modal-header-none">
      <div>
        <Collapse left-title="项目包" right-title="检测项目列表" :left-width="5" @on-result-change="_optionResult">
          <template slot="left">
            <AptitudeItemPackage ref="packageModal" @on-result-change="_packageResult" />
          </template>
          <template slot="right">
            <Row>
              <Col span="24">
              <Form inline onsubmit="return false" :label-width="70">
                <label class="label-sign" />
                <Form-item label="检测项目" style="width:200px;">
                  <Input v-model="formObj.itemName" placeholder="请输入检测项目" @on-enter="_search" />
                  <input v-model="formObj.packageId" type="hidden" />
                </Form-item>
                <Form-item label="检测依据:">
                  <Input v-model="formObj.testBasis" placeholder="请输入检测依据" @on-enter="_search" />
                </Form-item>
                <Form-item label="判定依据:">
                  <Input v-model="formObj.judgeBasis" placeholder="请输入判定依据" @on-enter="_search" />
                </Form-item>
                <Form-item style="margin-left: -60px">
                  <Button type="primary" @click="_search">
                    搜索
                  </Button>
                </Form-item>
              </Form>
              </Col>
              <Col span="24">
              <element-table
                ref="pageTable"
                :table-height="tableHeight"
                select-data
                :get-page="getPage"
                show-check-box
                @on-result-change="_tableResultChange"
              >
                <el-table-column
                  v-for="item in pageColumns"
                  :key="item.id"
                  show-overflow-tooltip
                  :prop="item.key"
                  :label="item.title"
                  :min-width="item.width"
                  :fixed="item.fixed?item.fixed:undefined"
                >
                  <template slot-scope="scope">
                    <span v-if="item.judge">
                      {{ scope.row[item.key] === 0 ?'否':'是' }}
                    </span>
                    <span v-else>
                      {{ scope.row[item.key] }}
                    </span>
                  </template>
                </el-table-column>
              </element-table>
              </Col>
            </Row>
          </template>
        </Collapse>
      </div>
      <div slot="footer">
        <modal-footer
          ref="footerModal"
          :footer="footerList"
          @on-result-change="_footerResult"
        />
      </div>
    </Modal>
  </div>
</template>
<script>
import { drugSample } from '../../../../../api'
import AptitudeItemPackage from './AptitudeItemPackage'
import Collapse from './Collapse'

export default {
  components: {
    Collapse,
    AptitudeItemPackage
  },
  data() {
    return {
      formObj: {
        itemName: '',
        testBasis: '',
        judgeBasis: '',
        packageId: ''
      },
      addIds: [],
      addPage: [],
      selectedData: [],
      selectIds: [],
      showModal: false,
      getPage: {},
      pageColumns: [
        { title: '检测项目', key: 'name', width: 160 },
        { title: '检测依据', key: 'standardCode', width: 120 },
        { title: '检测依据名称', key: 'standardName', width: 180 },
        // { title: '判定依据', key: 'judgeBasis', width: 120 },
        // { title: '判定依据名称', key: 'judgeBasisName', width: 180 },
        { title: '检测科室', key: 'groupName', width: 100 }
        // { title: '检测方法', key: 'testMethod', width: 100 }
      ],
      footerList: [
        { name: '取消', type: '' },
        { name: '确定', type: 'primary' }
      ],
      sampleIds: '',
      packageId: ''
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('tabNoBtn')
    }
  },
  methods: {
    _open(sampleIds) {
      this.formObj.itemName = ''
      this.formObj.testBasis = ''
      this.formObj.judgeBasis = ''
      this.formObj.packageId = ''
      this.sampleIds = sampleIds
      this.packageId = ''
      this.getPage = {}
      this.addIds = []
      this.addPage = []
      this.showModal = true
      this.$refs.packageModal._open()
      this.$refs.pageTable._hideLoading()
    },
    _page: async function() {
      if (this.packageId !== '') {
        this.formObj.packageId = this.packageId
      }
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      const result = await drugSample.testPackagePage(
        this.$serializeForm(this.formObj)
      )
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },
    _search() {
      if (this.packageId !== '') {
        this._page()
      } else {
        this.$Message.warning('请先选择项目')
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'selectData':
          this.selectData = data
          break
        default:
          if (this.packageId !== '') {
            this._page()
          }
      }
    },
    _optionResult(name) {
      switch (name) {
        case '添加':
          this._add()
          break
        case '删除':
          this._deleteSelected()
          break
      }
    },
    _packageResult(id) {
      this.packageId = id
      this._page()
    },
    _footerResult(name) {
      switch (name) {
        case '取消':
          this._cancel()
          break
        case '确定':
          this._ok()
          break
      }
    },
    _cancel() {
      this.$refs.footerModal._hideLoading()
      this.showModal = false
    },
    _ok() {
      if (!this.sampleIds) {
        this.$emit('on-result-change', this.selectData)
        this.showModal = false
        this.$refs.footerModal._hideLoading()
      }
    }
  }
}
</script>
