<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 class="search-item" label="录入时间:">
          <Date-picker
            ref="testDate"
            type="daterange"
            split-panels
            style="width:100%;"
            placeholder="请选择录入时间"
            :editable="false"
            @on-change="_signDateChange"/>
          <input v-model="formObj.testDateBegin" type="hidden" name="testDateBegin">
          <input v-model="formObj.testDateEnd" type="hidden" name="testDateEnd">
        </Form-item>
        <Form-item class="search-item" label="审核时间:">
          <Date-picker
            ref="auditorDate"
            type="daterange"
            split-panels
            style="width:100%;"
            placeholder="请选择审核时间"
            :editable="false"
            @on-change="_auditDateChange"/>
          <input v-model="formObj.auditorDateBegin" type="hidden" name="auditorDateBegin">
          <input v-model="formObj.auditorDateEnd" type="hidden" name="auditorDateEnd">
        </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="100"
        :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">
            <span v-if="item.dateTime">
              {{ scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd HH:MM:ss'):'' }}
            </span>
            <span v-else-if="item.status">
              {{ scope.row[item.key] === undefined ? '': scope.row[item.key].display}}
            </span>
            <div v-else-if="item.key==='judged'">
              {{ scope.row[item.key]===1?'是':'否' }}
            </div>
            <span v-else-if="item.key === 'singleJudge'">
              {{ scope.row[item.key]?scope.row[item.key].display:'' }}
            </span>
            <span v-else-if="item.key==='recordWriiten'">
                {{ scope.row[item.key]==='t'?'是':'否' }}
            </span>
            <span v-else>
              {{ scope.row[item.key] }}
            </span>
          </template>
        </el-table-column>
      </element-table>
      </Col>
    </Row>
    <!--操作日志-->
    <itemRecord ref="recordModal" />

  </div>
</template>
<script>
import { drugItem } from '../../../../api'
import itemRecord from '../../../record/itemRecord'
export default {
  components: { itemRecord },
  data() {
    return {
      searchOpen: true,
      formObj: {
        sampleCode: '',
        name: '',
        testDateBegin: '',
        testDateEnd: '',
        auditorDateBegin: '',
        auditorDateEnd: ''
      },
      selectIds: [],
      pageColumns: [
        { title: '样本编号', key: 'sampleCode', width: 150, fixed: true },
        { title: '检测项目', key: 'name', width: 120 },
        { title: '状态', key: 'status', width: 120, status: true },
        { title: '检测结果', key: 'testValue', width: 120 },
        { title: '单位', key: 'unit', width: 100 },
        { title: '是否系统判定', key: 'judged', width: 120, judged: true },
        {
          title: '判定结果',
          key: 'singleJudge',
          width: 140,
          singleJudge: true
        },
        { title: '是否填写原始记录', key: 'recordWriiten', width: 160 },
        { title: '仪器设备', key: 'equipName', width: 160 },
        { title: '检测类型', key: 'category', width: 150 },
        { title: '检测依据', key: 'standardCode', width: 160 },
        { title: '检测依据名称', key: 'standardName', width: 200 },
        { title: '检测科室', key: 'groupName', width: 200 },
        { title: '比较符', key: 'compareSymbol', width: 200 },
        { title: '限值', key: 'limitValue', width: 200 },
        { title: '检测人', key: 'tester', width: 200 },
        { title: '录入时间', key: 'testDate', dateTime: true },
        { title: '复核人', key: 'checker' },
        { title: '复核时间', key: 'checkerDate', dateTime: true }
      ],
      getPage: {},
      iconMsg: [
        { type: 'pt-a-original', id: '', name: '查看原始记录' },
        { type: 'pt-a-clock', id: '', name: '操作日志' }
      ]
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('search')
    }
  },
  methods: {
    // 录入时间
    _signDateChange(data) {
      this.formObj.testDateBegin = data[0]
      this.formObj.testDateEnd = data[1]
    },
    // 审核时间
    _auditDateChange(data) {
      this.formObj.auditorDateBegin = data[0]
      this.formObj.auditorDateEnd = data[1]
    },
    _formSearch() {
      this.$refs.pageTable._pageChange(1)
    },
    _open() {
      this._clear()
      this._page()
    },
    _clear() {
      this.formObj.sampleCode = ''
      this.formObj.name = ''
      this.$refs.testDate.handleClear()
      this.$refs.auditorDate.handleClear()
    },
    _page: async function() {
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      const result = await drugItem.pageItemAuditEnvHis(
        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._itemOriginalRecordLook(data)
          break
        case '操作日志':
          this._record(data.id)
          break
      }
    },
    // 查看原始记录
    _itemOriginalRecordLook(data) {
      if (
        data.recordId === null ||
        undefined === data.recordId ||
        data.recordId === ''
      ) {
        this.$Message.warning('该检测项目暂无原始记录！')
      } else {
        this.$refs.itemOriginalRecordLookModal._open(data.recordId, 'only')
      }
    },
    // 操作日志
    _record(id) {
      this.$refs.recordModal._open(id)
    }
  }
}
</script>
