<template>
  <div>
    <ElTableNoPage ref="pageTable" :tableHeight="tableHeight"
                   @on-result-change="_tableResultChange" :getPage="getPage">
      <el-table-column
        :prop="item.key"
        :label="item.title"
        :width="item.width"
        :min-width="200"
        :fixed="item.fixed?item.fixed:undefined"
        v-for="item in pageColumns"
        :key="item.key" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{scope.row[item.key]}}</span>
        </template>
      </el-table-column>
    </ElTableNoPage>
  </div>
</template>

<script>
/**
 * 已选中
 */
import ElTableNoPage from '../table/ElTableNoPage'

export default {
  components: {
    ElTableNoPage
  },
  data() {
    return {
      // tableHeight: document.documentElement.clientHeight - 225,
      tableHeight: 500,
      getPage: {
        records: []
      },
      pageColumns: [
        { title: '仪器名称', key: 'name', width: 160 },
        { title: '仪器编号', key: 'labNum', width: 100 },
        { title: '品牌', key: 'brand', width: 100 },
        { title: '规格型号', key: 'spec', width: 100 },
        { title: '描述', key: 'remark' }
      ],
      selectIds: []
    }
  },
  mounted() {
    this.$refs.pageTable._hideLoading()
    this._empty()
  },
  methods: {
    // 添加
    _open(data) {
      for (let i = 0; i < data.length; i++) {
        this.getPage.records.push(data[i])
      }
      this.getPage.records = this.$uniqueArray(this.getPage.records, 'id')
      this.$emit('on-result-change', this.getPage.records, [])
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'selectIds':
          this.selectIds = data
          break
      }
      this.$emit('on-result-change', this.getPage.records, this.selectIds)
    },
    // 删除
    _delData() {
      for (let j = 0; j < this.selectIds.length; j++) {
        for (let i = 0; i < this.getPage.records.length; i++) {
          if (this.getPage.records[i].id === this.selectIds[j]) {
            this.getPage.records.splice(i, 1)
          }
        }
      }
      this.$emit('on-result-change', this.getPage.records, [])
    },
    _empty() {
      this.getPage.records = []
      this.$emit('on-result-change', [], [])
    }
  }
}
</script>
