<template>
  <div>
    <!--内容-->
    <div class="layout-content-padding">
      <div class="layout-content-main">
        <Row>
          <!--查询-->
          <Col span="24">
            <Form id="search-form-query" :label-width="80" v-show="searchOpen" inline onsubmit="return false">
              <label class="label-sign"></label>
              <Form-item class="search-item" label="试样编号:" style="margin-left: 8px;">
                <Input @on-enter="_formSearch" v-model="formObj.sampleCode" name="sampleCode" placeholder="请输入试样编号" clearable/>
              </Form-item>
              <Form-item class="search-btn">
                <Button @click="_formSearch" type="primary">搜索</Button>
              </Form-item>
            </Form>
          </Col>
          <Col span="24">
            <btn-list :msg="btn" :open="searchOpen" @on-result-change="_btnClick" :showSearchBtn="true"
                     class="contHide"></btn-list>
          </Col>
          <!-- 表格 -->
          <Col span="24">
            <PTVXETableHeight ref="pageTable" :table-height="tableHeight" :loading="true"
                              :get-page="getPage" @on-result-change="_tableResultChange" select-data>
              <vxe-table-column
                v-for="item in pageColumns"
                :key="item.key"
                :field="item.key"
                :title="item.title"
                :min-width="item.width?item.width:200"
                :fixed="item.fixed?item.fixed:undefined" sortable>
                <template slot-scope="scope">
                  <span v-if="item.date">{{scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd'):''}}</span>
                  <span v-else-if="item.status">{{scope.row[item.key].display}}</span>
                  <span v-else>{{scope.row[item.key]}}</span>
                </template>
              </vxe-table-column>
            </PTVXETableHeight>
          </Col>
        </Row>
      </div>
    </div>
  </div>
</template>
<script>
import { soilEntrust } from '../../../../api'

export default {
  components: {},
  data() {
    return {
      currentComponent: '',
      selectIds: [],
      formObj: {},
      btn: [
        // { type: '', id: '', name: '导出' },
      ],
      pageColumns: [
        { title: '试样编号', key: 'sampleCode', width: 150 },
        { title: '状态', key: 'status', status: true, width: 100 },
        { title: '包装类型', key: 'samplePack', width: 100 },
        { title: '保存容器', key: 'keepContainer', width: 100 },
        { title: '制备数量', key: 'quantity', width: 100 },
        { title: '单位', key: 'unit', width: 70 },
        { title: '制备人', key: 'preparer', width: 130 },
        { title: '制备时间', key: 'prepareDate', date: true, width: 130 }
      ],
      searchOpen: false,
      getPage: {},
      selectData: [],
      endDateBegin: '',
      endDateEnd: ''
    }
  },
  computed: {
    tableHeight: function() {
      if (this.searchOpen) {
        return this.$tableHeight('', 255)
      } else {
        return this.$tableHeight('', 220)
      }
    }
  },
  methods: {
    _page: async function() {
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      console.log('this.formObj', this.formObj)
      const result = await soilEntrust.pageSurplusHandleCheckHis(
        this.$serializeForm(this.formObj)
      )
      if (result) {
        this.$refs.pageTable._hideLoading()
        this.getPage = result
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this.selectIds = []
          this._page()
          break
        case 'selectData':
          this.selectData = data
          this.selectIds = []
          for (let i = 0; i < data.length; i++) {
            this.selectIds.push(data[i].id)
          }
          break
        case 'changeSize':
          this._page()
          break
        // default :
        //   this._page();
      }
    },
    _formSearch() {
      this.$refs.pageTable._pageChange(1)
    },
    _dateChange(data) {
      this.endDateBegin = data[0]
      this.endDateEnd = data[1]
    },
    _btnClick(msg) {
      switch (msg) {
        case '导出':
          if (this.getPage.records.length === 0) {
            this.$Message.warning('暂无数据，不可导出')
          } else {
            this._export()
          }
          break
        case '导出样品贮存表':
          this._exportSampleStore()
          break
        case 'search':
          this.searchOpen = !this.searchOpen
          break
      }
    },
    // 参数
    _searchParams() {
      const data = this.$serialize('search-form-query')
      return this.$extend(data, { page: 1, rows: 5000 })
    }
    /** *********************************导出样品台账-end*********************************************/
  }
}
</script>
