<template>
  <div>
    <Modal v-model="showModal" width="1200" class="modal-footer-none">
      <p slot="header">{{modalTitle}}</p>
      <div>
        <!--内容-->
        <Row>
          <!--查询-->
          <Col span="24">
            <Form id="formId" :label-width="80" inline onsubmit="return false">
              <label class="label-sign"></label>
              <Form-item class="search-item" label="委托单位:" style="margin-left: -20px">
                <Input v-model="formObj.client" name="client" placeholder="请输入委托单位" clearable @on-enter="_formSearch"/>
              </Form-item>
              <Form-item class="search-item" label="委托编号:">
                <Input v-model="formObj.entrustCode"  name="entrustCode" placeholder="请输入委托编号" clearable @on-enter="_formSearch"/>
              </Form-item>
              <Form-item class="search-item" label="样品名称:">
                <Input v-model="formObj.name"  name="name" placeholder="请输入样品名称" clearable @on-enter="_formSearch"/>
              </Form-item>
              <Form-item class="search-item" label="样品编号:">
                <Input v-model="formObj.code"  name="code" placeholder="请输入样品编号" clearable @on-enter="_formSearch"/>
              </Form-item>

              <Form-item class="search-item" label="出厂编号:">
                <Input v-model="formObj.factoryNumber"  name="factoryNumber" placeholder="请输入出厂编号" clearable @on-enter="_formSearch"/>
              </Form-item>
              <Form-item class="search-btn" style="margin-left: -10px">
                <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">
            <PTVXETable ref="pageTable" :table-height="tableHeight" :form-id="formId" :get-page="getPage"
                        :icon-msg="iconMsg" 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.date">{{scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd'):''}}
                  </div>
                  <div v-else-if="item.key==='jobOut'">
                    {{scope.row[item.key]===1?'是':'否'}}
                  </div>
                  <div v-else-if="item.status">{{scope.row[item.key].display}}</div>
                  <div v-else-if="item.entrustType">
                      {{scope.row[item.key]===1?'出检':'送检'}}
                  </div>
                  <div v-else-if="item.key==='type'">
                    <Select v-model="scope.row.type">
                      <Option v-for="(item,index) in options" :key="item.name" :value="index">
                        {{ item.name }}
                      </Option>
                    </Select>
                  </div>
                  <div v-else>{{scope.row[item.key]}}</div>
                </template>
              </vxe-table-column>
            </PTVXETable>
          </Col>
        </Row>
      </div>
    </Modal>
  </div>
</template>
<script>
import { meterSample } from '../../../api'
export default {
  components: {
    // FoodSampleGovernDetail,
    // CopyModal,
    // FoodSampleGovernLYEdits
  },
  data() {
    return {
      currentComponent: '',
      searchOpen: true,
      iconMsg: [],
      btn: [],
      options: [
        {
          name: '检定'
        },
        {
          name: '校准'
        },
        {
          name: '外观检查'
        }
      ],
      formId: 'meterEntrustSampleProgressFormId',
      showModal: false,
      modalTitle: '管理样品',
      selectIds: [],
      selectData: [],
      getPage: {},
      pageColumns: [
        { title: '委托单位', key: 'client', width: 140 },
        { title: '委托单号', key: 'entrustCode', width: 130 },
        {
          title: '委托类型',
          key: 'entrustType',
          width: 110,
          entrustType: true
        },
        { title: '样品名称', key: 'name', width: 140 },
        { title: '样品编号', key: 'code', width: 130 },
        { title: '出厂编号', key: 'factoryNumber', width: 130 },
        { title: '处理进度', key: 'status', status: true, width: 120 },
        { title: '收样人', key: 'receiver', width: 120 },
        { title: '收样人时间', key: 'receiveTime', width: 120 },
        { title: '任务分配人', key: 'assignor', width: 120 },
        { title: '任务分配时间', key: 'allocateTime', width: 120 },
        { title: '领用人', key: 'flower', width: 120 },
        { title: '领用时间', key: 'flowTime', width: 120 },
        { title: '入库人', key: 'sampleInner', width: 120 },
        { title: '入库时间', key: 'sampleInnerTime', width: 120 },
        { title: '出库人', key: 'sampleOuter', width: 120 },
        { title: '出库时间', key: 'outTime', width: 120 }
      ],
      dateList: [],
      formObj: {
        entrustId: undefined,
        entrustCode: undefined,
        client: undefined,
        name: undefined,
        factoryNumber: undefined,
        code: undefined
      }
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('tableModal')
    }
  },
  methods: {
    _dateChange(data) {
      this.formObj.ctimeBegin = data[0]
      this.formObj.ctimeEnd = data[1]
    },
    _btnClick(msg, componentName) {
      this.currentComponent = componentName
      this.$nextTick(function() {
        switch (msg) {
          case '取消分包':
            break
        }
      })
    },
    _iconClick(res, data, componentName) {
      this.currentComponent = componentName
      this.$nextTick(function() {
        switch (res) {
          case '管理检测项目':
            this._sampleEditModal(data)
            break
        }
      })
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'selectData':
          const selectIds = []
          for (let i = 0; i < data.length; i++) {
            selectIds.push(data[i].id)
          }
          this.selectIds = selectIds
          this.selectData = data
          break
        case 'iconClick':
          this._iconClick(data.name, data.rowData, data.componentName)
          break
        case 'changeSize':
          this._page()
          break
      }
    },
    _open(id) {
      this.formObj.entrustId = id
      this.showModal = true
      this._page()
    },
    _formSearch() {
      this.$refs.pageTable._pageChange(1)
    },
    _page: async function() {
      this.selectIds = []
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      const result = await meterSample.pageSampleProgress(this.formObj)
      if (result) {
        this.getPage = result
        this.$refs.pageTable._hideLoading()
      }
    },
    _search() {
      this._page()
    },
    _resultChange(msg) {
      this._page()
      this.$Message.success(msg)
    }
  }
}
</script>
