<template>
  <div>
    <Row>
      <!--<Col span="24" />-->
      <!--<btn-list :msg="btn" :open="searchOpen" show-search-btn="true" @on-result-change="_btnClick" />-->
      <!--</Col>-->
      <Col span="24">
      <element-table
        ref="pageTable"
        :page-columns="pageColumns"
        :table-height="tableHeight"
        :get-page="getPage"
        :opt-col-width="140"
        select-data
        @on-result-change="_tableResultChange"
      >
        <el-table-column
          v-for="item in pageColumns"
          :key="item.key"
          show-overflow-tooltip
          sortable
          :prop="item.key"
          :label="item.title"
          :align="item.align"
          :width="item.width"
          :min-width="200"
          :fixed="item.fixed?item.fixed:undefined"
        >
          <template slot-scope="scope">
            <span v-if="item.key === 'judged'">
              {{ scope.row[item.key]===0?'否':'是' }}
            </span>
            <span v-else-if="item.key === 'singleJudge'">
              {{ scope.row[item.key]?scope.row[item.key].display:''}}
            </span>
            <span v-else>
              {{ scope.row[item.key] }}
            </span>
          </template>
        </el-table-column>
      </element-table>
      </Col>
    </Row>
  </div>
</template>

<script>
import { drugItem } from '../../../../../api'
export default {
  name: 'SamplePreparation',
  components: {},
  data() {
    return {
      pageColumns: [
        {
          title: '检测项目',
          key: 'name',
          width: 120,
          fixed: 'left',
          align: 'center'
        },
        { title: '检测结果', key: 'testValue', width: 120, align: 'center' },
        { title: '单位', key: 'unit', width: 120, align: 'center' },
        {
          title: '判定结果',
          key: 'singleJudge',
          width: 140,
          singleJudge: true
        },
        { title: '检测类型', key: 'category', width: 120, align: 'center' },
        { title: '检测依据', key: 'code', width: 120, align: 'center' },
        {
          title: '检测依据名称',
          key: 'standardName',
          width: 120,
          align: 'center'
        },
        { title: '检测科室', key: 'groupName', width: 120, align: 'center' },
        { title: '比较符', key: 'compareSymbol', width: 150, align: 'center' },
        { title: '限值', key: 'limitValue', width: 120, align: 'center' },
        { title: '是否系统判定', key: 'judged', width: 135, align: 'center' },
        { title: '备注', key: 'remark', align: 'center' }
      ],
      nameList: [{ label: 123, value: 123 }, { label: 456, value: 4564 }],
      getPage: {},
      searchOpen: false,
      name: '',
      selectIds: [],
      selectData: [],
      sampleId: ''
    }
  },
  computed: {
    tableHeight() {
      if (this.searchOpen) {
        return this.$tableHeight('tabSearch')
      } else {
        return this.$tableHeight('tabNoSearch')
      }
    }
  },
  methods: {
    _open() {
      this._page()
    },
    async _page() {
      // const data = this.$serialize('report-detection-form')
      const data = {}
      if (this.sampleId) {
        data.sampleId = this.sampleId
      }
      Object.assign(data, this.$refs.pageTable._searchParams())
      const result = await drugItem.pageNotOkItem(data)
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },
    _clearPage() {
      $('#report-detection-form')
        .find('input')
        .each(function() {
          $(this).val('')
        })
      this.name = ''
    },
    _btnClick(msg, data) {
      switch (msg) {
        case 'search':
          this.searchOpen = !this.searchOpen
          break
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'selectData':
          this._selectData(data)
          break
        default:
          this._page()
      }
    },
    _selectData(data) {
      const selectIds = []
      for (let i = 0; i < data.length; i++) {
        selectIds.push(data[i].id)
      }
      this.selectIds = selectIds
      this.selectData = data
    },
    _formSearch() {
      this.$refs.pageTable._pageChange(1)
    }
  }
}
</script>

<style scoped>
</style>
