<template>
  <div>
    <Modal v-model="showModal" width="900" class="modal-footer-none zIndex-1100">
      <p slot="header">
        选择原始记录
      </p>
      <div>
        <Row>
          <!--查询-->
          <Col span="24" />
          <Form id="search-original-record-append" inline onsubmit="return false" :label-width="70">
            <label class="label-sign" />
            <Form-item label="操作阶段:">
              <Input
                v-model="origin"
                name="origin"
                placeholder="请输入操作阶段"
                style="width: 200px"
                @on-enter="_search"
              />
            </Form-item>
            <Form-item class="search-btn">
              <Button type="primary" @click="_search">
                搜索
              </Button>
            </Form-item>
          </Form>
          </Col>
          <!-- 表格 -->
          <Col span="24" />
          <element-table
            ref="pageTable"
            :page-columns="pageColumns"
            :table-height="tableHeight"
            :get-page="getPage"
            :opt-col-width="140"
            @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>
                  {{ scope.row[item.key] }}
                </div>
              </template>
            </el-table-column>
          </element-table>
          </Col>
        </Row>
      </div>
    </Modal>
  </div>
</template>
<script>
/**
 * 操作日志-委托
 */
export default {
  data() {
    return {
      showModal: false,
      getPage: {},
      pageColumns: [
        { title: '样品编号', key: 'sampleNum' },
        { title: '检测项目', key: 'itemNames' },
        { title: '操作时间', key: 'ctime', datetime: true }
      ],
      origin: '',
      itemIds: []
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('tableModal')
    }
  },
  methods: {
    _open(itemIds) {
      this.showModal = true
      this.origin = ''
      this.itemIds = itemIds
      this._page()
    },
    _page() {
      const data = {
        itemIds: this.itemIds
      }
      console.log(data)
      // this.$refs.pageTable._page(
      //   'search-original-record-append',
      //   'FoodOriginalRecordForm/pageAppendOriginal',
      //   data
      // )
    },

    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'dbSelect':
          this.showModal = false
          this.$emit('on-result-change', data)
          break
        default:
          this._page()
      }
    },
    _search() {
      this.$refs.pageTable._pageChange(1)
    }
  }
}
</script>
