<template>
  <div>
    <Row>
      <Form
        v-show="searchOpen"
        id="his-sample-form"
        inline
        onsubmit="return false"
        :label-width="100"
        class="search-form"
      >
        <label class="label-sign" />
        <Form-item class="search-item" label="样本编号:">
          <Input name="sampleNum" 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-item" label="生产日期:">
          <Date-picker
            ref="pcTime"
            type="datetimerange"
            placeholder="生产日期"
            style="width: 100%;"
            transfer
            :editable="false"
            @on-change="_histDateChange"
          />
          <input type="hidden" name="pcTimeBegin">
          <input type="hidden" name="pcTimeEnd">
        </Form-item>
        <!--<Form-item class="search-item" label="报检单位:">-->
        <!--<Input name="declarationInspection" placeholder="请输入报检单位" clearable @on-enter="_formSearch" />-->
        <!--</Form-item>-->

        <Form-item class="search-item" label="接收时间:">
          <Date-picker
            ref="receiveTime"
            type="datetimerange"
            placeholder="送样人接收时间"
            style="width: 100%;"
            transfer
            :editable="false"
            @on-change="_labTimeChange"
          />
          <input type="hidden" name="receiveTimeBegin">
          <input type="hidden" name="receiveTimeEnd">
        </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">
              {{ 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>
<!--        <el-table-column-->
<!--          slot="col"-->
<!--          label="操作"-->
<!--          align="center"-->
<!--          :width="120"-->
<!--          fixed="right"-->
<!--        >-->
<!--          <template slot-scope="scope">-->
<!--            <icon-list-->
<!--              :msg="iconMsg"-->
<!--              :row-data="scope.row"-->
<!--              :row-index="scope.$index"-->
<!--              @on-result-change="_iconClick"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->
      </element-table>
      </Col>
    </Row>

    <fileManage ref="fileManageModal" @on-result-change="_fileResult" />
  </div>
</template>

<script>
import { drugSample } from '../../../api'
import fileManage from '../../base-manage/fileManage'
export default {
  name: 'PreparationManage',
  components: { fileManage },
  data() {
    return {
      name: '',
      pageColumns: [
        {
          title: '样本编号',
          key: 'sampleCode',
          width: 140,
          fixed: 'left',
          align: 'center'
        },
        { title: '牌号', key: 'name', width: 120, align: 'center' },
        {
          title: '卷制标准版本号',
          key: 'standard',
          width: 140,
          align: 'center'
        },
        {
          title: '流转检测科室',
          key: 'groupName',
          align: 'center',
          width: 120
        },
        {
          title: '流转数量',
          key: 'flowQuantity',
          align: 'center',
          width: 120
        },
        {
          title: '单位',
          key: 'unit',
          align: 'center',
          width: 120
        },
        {
          title: '流转人',
          key: 'flower',
          align: 'center',
          width: 120
        },
        {
          title: '流转时间',
          key: 'flowTime',
          align: 'center',
          datetime: true,
          width: 150
        },

        { title: '价类', key: 'category', width: 140, align: 'center' },
        { title: '机台', key: 'samplePoint', width: 140, align: 'center' },
        { title: '班别', key: 'classBan', width: 130, align: 'center' },
        {
          title: '生产日期',
          key: 'pcTime',
          align: 'center',
          datetime: true,
          width: 150
        }
      ],
      sendTime: '',
      getPage: {},
      searchOpen: true,
      currentIndex: '',
      selectIds: [],
      iconMsg: [
        // { id: '', type: 'pt-a-cloud', name: '附件' }
        // { id: '', type: 'md-egg', name: '操作日志' }
      ]
    }
  },
  computed: {
    tableHeight() {
      if (this.searchOpen) {
        return this.$tableHeight('searchTwoNoBtn')
      } else {
        return this.$tableHeight('tabNoSearch')
      }
    }
  },
  methods: {
    async _page() {
      const data = this.$serialize('his-sample-form')
      Object.assign(data, this.$refs.pageTable._searchParams())
      const result = await drugSample.pageSampleFlowHis(data)
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },
    _clearPage() {
      $('#his-sample-form')
        .find('input')
        .each(function() {
          $(this).val('')
        })
      this.$refs.pcTime.handleClear()
      this.$refs.receiveTime.handleClear()
    },
    _btnClick(msg, data) {
      switch (msg) {
        case 'search':
          this.searchOpen = !this.searchOpen
          break
      }
    },
    _iconClick(name, data) {
      switch (name) {
        case '附件':
          this._eRecord(data.id)
          break
      }
    },
    _uploadByIds() {},
    _handleIndex(data) {
      this.currentIndex = data.$index
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'selectIds':
          this.selectIds = data
          break
        default:
          this._page()
      }
    },
    _eRecord(id) {
      const tempData = {
        id: id,
        uploadFileUrl: '/v1/sample_annex/upload/',
        downloadFileUrl: '/v1/sample_annex/download/'
      }
      this.$refs.fileManageModal._open(tempData, 'sampleId')
    },
    // 文件返回的数据
    _fileResult(msg, data) {
      switch (msg) {
        case 'file-page':
          this.$refs.fileManageModal._openFile(data)
          break
        case 'delete-page':
          this.$refs.fileManageModal._delPage('', data)
          break
        case 'success':
          this.$Message.success('删除成功！')
          this.$refs.fileManageModal._page()
          break
        default:
          this.$refs.fileManageModal._page()
      }
    },

    _histDateChange(data) {
      $('input[name="pcTimeBegin"]').val(data[0])
      $('input[name="pcTimeEnd"]').val(data[1])
    },
    _labTimeChange(data) {
      $('input[name="receiveTimeBegin"]').val(data[0])
      $('input[name="receiveTimeEnd"]').val(data[1])
    },
    _formSearch() {
      this.$refs.pageTable._pageChange(1)
    }
  }
}
</script>

<style scoped>
</style>
