<!--资质项目包列表-->
<template>
  <div>
    <div>
      <Form  inline onsubmit="return false" :label-width="40">
        <label class="label-sign" />
        <Form-item label="包名">
          <Input v-model="formObj.name" name="name" placeholder="请输入包名" style="width: 90px" @on-enter="_search" />
        </Form-item>
        <Form-item style="margin-left: -40px">
          <Button type="primary" @click="_search">
            搜索
          </Button>
        </Form-item>
      </Form>
    </div>
    <div>
      <element-table
        ref="pageTable"
        :table-height="tableHeight"
        :get-page="getPage"
        hide-checkbox
        hide-elevator
        hide-sizer
        hide-total
        click
        @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.key==='type'">{{ scope.row[item.key]===0 ? '产品包' : '临时包' }}</span>
            <span v-else>{{ scope.row[item.key] }}</span>
          </template>
        </el-table-column>
      </element-table>
    </div>
  </div>
</template>
<script>
import { drugSample } from '../../../../../api'
export default {
  data() {
    return {
      getPage: {},
      pageColumns: [{ title: '包名称', key: 'name', width: 100 }],
      formObj: {
        name: ''
      }
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('tabNoBtn')
    }
  },
  methods: {
    _open() {
      this._page()
    },
    _page: async function() {
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      const result = await drugSample.page(this.$serializeForm(this.formObj))
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },
    _search() {
      this.$refs.pageTable._pageChange(1)
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'select':
          this.$emit('on-result-change', data.id)
          break
        case 'click':
          this.$emit('on-result-change', data.id)
          break
      }
    }
  }
}
</script>
