<!--资质项目列表-->
<template>
  <div>
    <div>
      <Form inline onsubmit="return false" :label-width="65">
        <label class="label-sign" />
        <Form-item label="检测项目:" style="width:30%;margin-left: 5px;">
          <Input v-model="formObj.name" placeholder="请输入检测项目" @on-enter="_search" />
        </Form-item>
        <Form-item label="检测依据:" style="width:30%">
          <Input v-model="formObj.standardCode" placeholder="请输入检测依据" @on-enter="_search" />
        </Form-item>
        <Form-item style="margin-left: -40px">
          <Button type="primary" @click="_search">
            搜索
          </Button>
        </Form-item>
      </Form>
    </div>
    <element-table
      ref="pageTable"
      :table-height="tableHeight"
      select-data
      :get-page="getPage"
      hide-elevator
      hide-sizer
      show-check-box
      @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"
        :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>
  </div>
</template>

<script>
import { aptitudeItem } from '../../../../../api'

export default {
  data() {
    return {
      getPage: {},
      formObj: {
        name: '',
        standardCode: ''
      },
      pageColumns: [
        { title: '检测项目', key: 'name', width: 100 },
        { title: '检测依据', key: 'code', width: 120 },
        { title: '检测依据名称', key: 'standardName', width: 180 },
        { title: '检测科室', key: 'groupName', width: 100 }
      ]
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('searchTwo')
    }
  },
  methods: {
    _open() {
      this.formObj = this.$resetFields(this.formObj)
      this._page()
    },
    _page: async function() {
      const data = this.$serializeForm(this.formObj)
      Object.assign(data, this.$refs.pageTable._searchParams())
      const result = await aptitudeItem.materialTestItem(data)
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },
    _clearSelection() {
      this.$refs.pageTable._clearSelection()
    },
    _search() {
      this.$refs.pageTable._pageChange(1)
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          this.$emit('on-result-change', 'search', this.getPage)
          break
        case 'selectData':
          this.$emit('on-result-change', 'click', data)
          break
        case 'dbSelect':
          this.$emit('on-result-change', 'dbClick', data)
          break
        default:
          this._page()
      }
    }
  }
}
</script>
