<template>
  <div>
    <Row>
      <Form
        v-show="searchOpen"
        id="sample-his-form"
        inline
        onsubmit="return false"
        :label-width="70"
        class="search-form"
      >
        <label class="label-sign" />
        <Form-item class="search-item" label="样本编号:">
          <Input name="sampleCode" placeholder="请输入样本编号" clearable @on-enter="_formSearch" />
        </Form-item>
        <Form-item class="search-item" label="牌号:">
          <Input name="name" placeholder="请输入牌号" clearable @on-enter="_formSearch" />
        </Form-item>
        <Form-item class="search-btn">
          <Button type="primary" @click="_formSearch">
            搜索
          </Button>
        </Form-item>
      </Form>
      <Col />
      <!--<btn-list :msg="btn" :open="searchOpen" show-search-btn="true" @on-result-change="_btnClick" />-->
      </Col>
      <Col />
      <element-table
        ref="pageTable"
        :page-columns="pageColumns"
        :table-height="tableHeight"
        :get-page="getPage"
        @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" @click.stop="_handleIndex(scope)">
            <span v-if="item.datetime" @click="_handleIndex(scope)">
              {{ scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd HH:MM:ss'):'' }}
            </span>
            <span v-else-if="item.data">
              {{ scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd HH:MM:ss'):'' }}
            </span>
            <span v-else-if="item.key === 'status'">
              {{ 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 { drugSampleKeep } from '../../../api'
export default {
  name: 'PreparationManage',
  data() {
    return {
      pageColumns: [
        {
          title: '样本编号',
          key: 'sampleCode',
          width: 120,
          fixed: 'left',
          align: 'center'
        },
        { title: '牌号', key: 'name', width: 120, align: 'center' },
        { title: '价类', key: 'category', width: 120, align: 'center' },
        {
          title: '卷制标准版本号',
          key: 'standard',
          width: 160,
          align: 'center'
        },
        { title: '机台', key: 'samplePoint', width: 110, align: 'center' },
        {
          title: '留样数量',
          key: 'quantity',
          width: 120,
          align: 'center'
        },
        {
          title: '单位',
          key: 'unit',
          width: 160,
          align: 'center'
        },
        {
          title: '开始留样时间',
          key: 'ctime',
          width: 160,
          data: true,
          align: 'center'
        },
        {
          title: '存储期限(天)',
          key: 'timeLimit',
          width: 160,
          align: 'center'
        },
        {
          title: '存储位置',
          key: 'position',
          align: 'center'
        },
        { title: '处理人', key: 'handler', width: 160, align: 'center' },
        {
          title: '处理时间',
          key: 'handleTime',
          width: 160,
          align: 'center',
          datetime: true
        }
      ],
      getPage: {},
      searchOpen: true,
      currentIndex: '',
      selectIds: []
    }
  },
  computed: {
    tableHeight() {
      if (this.searchOpen) {
        return this.$tableHeight('tabNoSearch')
      } else {
        return this.$tableHeight('tabNoSearch')
      }
    }
  },
  methods: {
    async _page() {
      const data = this.$serialize('sample-his-form')
      Object.assign(data, this.$refs.pageTable._searchParams())
      const result = await drugSampleKeep.pageSampleKeepHis(data)
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },
    _clearPage() {
      $('#sample-his-form')
        .find('input')
        .each(function() {
          $(this).val('')
        })
      this.typeName = ''
    },
    _btnClick(msg, data) {
      switch (msg) {
        case 'search':
          this.searchOpen = !this.searchOpen
          break
      }
    },
    _handleIndex(data) {
      console.log(data)
      this.currentIndex = data.$index
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'selectIds':
          this.selectIds = data
          break
        default:
          this._page()
      }
    },
    _formSearch() {
      this.$refs.pageTable._pageChange(1)
    }
  }
}
</script>

<style scoped>
</style>
