<template>
  <div>
    <div>
      <!--内容-->
      <Row>
        <!--查询-->
        <Col span="24" style="padding-bottom: 5px">
          <Form v-show="searchOpen" id="search-wait-scan" :label-width="90" inline onsubmit="return false">
            <label class="label-sign"></label>
            <Form-item label="试样编号:" class="search-item">
              <Input v-model="formObj.sampleCode" name="sampleCode" placeholder="请输入试样编号" clearable @on-enter="_formSearch"></Input>
              <input name="entrustId" type="hidden">
            </Form-item>
            <Form-item class="search-btn">
              <Button type="primary" @click="_formSearch">搜索</Button>
            </Form-item>
          </Form>
        </Col>
        <Col span="24">
          <btn-list :msg="btn" :open="searchOpen" :show-search-btn="true" class="contHide" @on-result-change="_btnClick">
          </btn-list>
        </Col>
        <Col span="24">
          <PTVXETableHeight
            ref="pageTable"
            :table-height="tableHeight"
            :get-page="getPage"
            select-data
            @on-result-change="_tableResultChange">
            <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">
                <div v-if="item.detail"><a @click.stop="_detailModal(scope.row.id)">{{scope.row[item.key]}}</a></div>
                <div v-else-if="item.key ==='shape'">{{scope.row['shape']}} {{scope.row['shapeRemark']}}</div>
                <div v-else-if="item.date">
                  {{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>
            </vxe-table-column>
          </PTVXETableHeight>
        </Col>
      </Row>
    </div>
    <!--选择领样人-->
  </div>
</template>
<script>
import { soilEntrust } from '../../../../api'

export default {
  components: {},
  data() {
    return {
      btn: [],
      selectIds: [],
      getPage: {},
      pageColumns: [
        { title: '试样编号', key: 'sampleCode', width: 100, fixed: 'left' },
        { title: '试样深度', key: 'sampleDepth', width: 95 },
        { title: '现场编号', key: 'siteNo', width: 100 },
        { title: '接收人', key: 'receiver', width: 120 },
        { title: '接收时间', key: 'receiveTime', width: 145, date: true },
        { title: '收样存储位置', key: 'receiveLocation', width: 140 },
        { title: '发放人', key: 'sender', width: 120 },
        { title: '发放时间', key: 'sendTime', width: 144, date: true },
        { title: '土质描述', key: 'sampleDescribe', width: 185 },
        { title: '样品包装类型', key: 'samplePack', width: 120 }
      ],
      iconMsg: [
        { type: 'md-create', id: '', name: '编辑' },
        { type: 'ios-copy', id: '', name: '复制' },
        { type: 'md-trash', id: '', name: '删除' },
        {
          type: 'ios-clock',
          id: '',
          name: '操作日志',
          componentName: 'SampleRecord'
        },
        { type: 'cloud', id: '', name: '附件', componentName: 'FileManage' }
      ],
      type: '',
      entrustId: '', // 合同id
      selectData: [],
      currentComponent: '',
      formObj: {
        sampleCode: undefined,
        entrustId: undefined
      },
      searchOpen: true
    }
  },
  computed: {
    tableHeight: function() {
      if (this.searchOpen) {
      } else {
      }
      return this.$tableHeight('tableModal')
    }
  },
  mounted() {
    // this._getStdList()
    // 样品接收是否选择人员
    // this.acceptSelectUserValue = localStorage.getItem('acceptSelectUserValue')
  },
  methods: {
    _selectSampleLink(data) {
      console.log(data)
    },
    // 组件返回值
    _componentResult(data, msg) {
      switch (this.currentComponent) {
        case 'SelectPrinter':
          this._printerResult(data)
          break
        case 'ReceiveScan':
          // 扫码接收
          this._searchTop()
          break
        default:
          this._search()
      }
    },
    _open(entrustId, type) {
      this.formObj = this.$resetFields(this.formObj)
      $('input[name=entrustId]').val(entrustId)
      this.formObj.entrustId = entrustId
      this.$nextTick(() => {
        this._page()
      })
    },
    _page: async function() {
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      const result = await soilEntrust.pageSendHis(this.formObj)
      console.log(this.formObj)
      if (result) {
        this.$refs.pageTable._hideLoading()
        this.getPage = result
      }
    },
    _formSearch() {
      this.$refs.pageTable._pageChange(1)
    },
    _iconClick(res, data, currentComponent) {
      this.currentComponent = currentComponent
      this.$nextTick(() => {
        switch (res) {
          case '编辑':
            this._editModal(true, data)
            break
          case '操作日志':
            this.$refs.refModal._open(data.id)
            break
          case '删除':
            this._deleteById(data.id)
            break
        }
      })
    },
    _btnClick(msg, currentComponent) {
      this.currentComponent = currentComponent
      this.$nextTick(() => {
        switch (msg) {
          case '打印标签':
            this._selectPrinter('print-label')
            break
          case 'search':
            this.searchOpen = !this.searchOpen
            break
        }
      })
    },
    _resultChange(msg) {
      this._page()
      this.$Message.success(msg)
      this.selectIds = []
    },
    _search() {
      this._page()
    },
    // 刷新上级页面
    _searchTop() {
      this._page()
      this.$emit('on-result-change')
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'selectData':
          this.selectData = data
          this.selectIds = []
          for (let i = 0; i < data.length; i++) {
            this.selectIds.push(data[i].id)
          }
          break
        case 'iconClick':
          this._iconClick(data.name, data.rowData, data.componentName)
          break
        case 'changeSize':
          this._page()
          break
      }
    },
    _stdResult(msg, data) {
      switch (msg) {
        case 'select':
          this.formObj.standard = data
          break
        case 'query':
          this.formObj.standard = data
          this._getStdList(data)
          break
        case 'focus':
          this._getStdList()
          break
      }
    }
  }
}
</script>
