<template>
  <div>
    <Row>
      <!--查询-->
      <Col span="24">
      <Form
        v-show="searchOpen"
        inline
        onsubmit="return false"
        :label-width="70"
        class="search-form"
      >
        <label class="label-sign" />
        <Form-item class="search-item" label="样本编号:">
          <Input v-model="formObj.sampleCode" placeholder="请输入样本编号" clearable @on-enter="_formSearch" />
        </Form-item>
        <Form-item class="search-item" label="物料名称:">
          <Input v-model="formObj.name" placeholder="请输入物料名称" clearable @on-enter="_formSearch" />
        </Form-item>
        <Form-item label="检测类型:" class="search-item" prop="category">
          <Input v-model="formObj.category" placeholder="请输入检测类型" clearable @on-enter="_formSearch" />
        </Form-item>
        <Form-item class="search-btn">
          <Button type="primary" @click="_formSearch">
            搜索
          </Button>
        </Form-item>
      </Form>
      </Col>
      <!--table-->
      <Col span="24">
      <element-table
        ref="pageTable"
        :page-columns="pageColumns"
        :table-height="tableHeight"
        :get-page="getPage"
        :opt-col-width="140"
        :icon-msg="iconMsg"
        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"
          :width="item.width"
          :min-width="200"
          :fixed="item.fixed?item.fixed:undefined"
        >
          <template slot-scope="scope">
            <div v-if="item.dateTime">
              {{ scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd HH:MM:ss'):'' }}
            </div>
            <div v-else-if="item.status">
              {{scope.row[item.key] === undefined ? '': scope.row[item.key].display}}
            </div>
            <div v-else>
              {{ scope.row[item.key] }}
            </div>
          </template>
        </el-table-column>
      </element-table>
      </Col>
    </Row>
    <ItemList ref="testItemModal"></ItemList>

    <!--操作日志-->
    <sampleRecord ref="recordModal" />
  </div>
</template>
<script>
import { drugSample } from '../../../../api'
import sampleRecord from '../../../record/sampleRecord'
import ItemList from '../../../sample-item/ItemList'
export default {
  components: { ItemList, sampleRecord },
  data() {
    return {
      searchOpen: true,
      formObj: {
        sampleCode: '',
        name: '',
        category: ''
      },
      selectIds: [],
      pageColumns: [
        { title: '样本编号', key: 'sampleCode', width: 200, fixed: 'left' },
        { title: '状态', key: 'status', width: 200, status: true },
        { title: '物品名称', key: 'name', width: 200 },
        { title: '物品编码', key: 'code', width: 200 },
        { title: '检测类型', key: 'category' }
      ],
      getPage: {},
      iconMsg: [
        { type: 'pt-a-chemistry', id: '', name: '查看检测项目' },
        { type: 'pt-a-clock', id: '', name: '操作日志' }
      ],
      typeList: [
        { value: 'ORIGINAL', label: '进场原料' },
        { value: 'OTHER', label: '其他原料' }
      ]
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('', 262)
    }
  },
  methods: {
    _formSearch() {
      this.$refs.pageTable._pageChange(1)
    },
    _page: async function() {
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      const result = await drugSample.pageSampleWaitTest(
        this.$serializeForm(this.formObj)
      )
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },
    _searchParams(formId) {
      return this.$refs.pageTable._searchParams(formId)
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'iconClick':
          this._iconClick(data.name, data.rowData)
          break
        case 'selectIds':
          this.selectIds = data
          break
      }
    },
    _iconClick(res, data) {
      switch (res) {
        case '查看检测项目':
          this._testItem(data.id)
          break
        case '操作日志':
          this._record(data.id)
          break
      }
    },
    // 检测项目
    _testItem(id) {
      this.$refs.testItemModal._open(id)
    },
    // 操作日志
    _record(id) {
      this.$refs.recordModal._open(id)
    }
  }
}
</script>
