<!--检测项目编辑列表（添加、导入检测项目）-->
<template>
  <div>
    <Modal
      v-model="showModal"
      v-drag
      :mask-closable="false"
      :width="800"
      title="证书模板选择"

    >
      <Row>
        <Col span="24" />
        <Form v-model="formObj" :label-width="90" inline onsubmit="return false">
          <Form-item class="search-item" label="证书模板名称:">
            <Input v-model="formObj.name" placeholder="请输入证书模板名称" clearable @on-enter="_formSearch" />
          </Form-item>
          <Form-item class="search-item" label="类别:">
            <Input v-model="formObj.classType" placeholder="请输入类别" clearable @on-enter="_formSearch" />
          </Form-item>
          <Form-item class="search-btn">
            <Button type="primary" @click="_formSearch">
              搜索
            </Button>
          </Form-item>
        </Form>
        </Col>
        <!--正常界面-->
        <Col span="24" />
        </Col>
        <!-- 表格 -->
        <Col span="24">
          <PTVXETable
            ref="pageTable"
            :form-id="formId"
            :table-height="500"
            :get-page="getPage"
            :icon-msg="iconMsg"
            :is-radio="true"
            select-data="true"
            hide-checkbox
            @on-result-change="_tableResultChange">
            <vxe-table-column
              v-for="item in pageColumns"
              :key="item.key"
              :field="item.key"
              :title="item.title"
              :width="item.width"
              :min-width="200"
              :fixed="item.fixed?item.fixed:undefined"
              sortable
            >
              <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.judged">{{scope.row[item.key]===1?'是':'否'}}</span>
                <span v-else>{{scope.row[item.key]}}</span>
              </template>
            </vxe-table-column>
          </PTVXETable>
        </Col>
      </Row>
      <div slot="footer">
        <modal-footer ref="footerModal" :footer="footerList" @on-result-change="_footerResult"></modal-footer>
      </div>
    </Modal>
    <DownloadTemplateImport ref="importModal" @on-result-change="_page" />
  </div>
</template>
<script>
// import { drugCatalogueItem } from '../../api'
// import SampleItemSelect from './SampleItemSelect'
import DownloadTemplateImport from '../../../components/import/DownloadTemplateImport'
import ModalFooter from '../../../components/base/modalFooter'
import { meterTemplate } from '../../../api'
export default {
  components: {
    ModalFooter,
    DownloadTemplateImport
    // SampleItemSelect
  },
  data() {
    return {
      formId: 'SampleItemListFormId',
      formObj: {
        name: '',
        classType: ''
      },
      showModal: false,
      searchOpen: false,
      btn: [],
      iconMsg: [],
      footerList: [
        { id: '', name: '取消', type: '' },
        { id: '', name: '确定', type: 'primary' }
      ],
      pageColumns: [
        { title: '证书名称', key: 'name', width: 220 },
        { title: '类别', key: 'classType', width: 140 },
        { title: '备注', key: 'remark' }
      ],
      sampleId: '',
      getPage: {},
      selectData: []
    }
  },
  methods: {
    _open(sampleId) {
      this.formObj = this.$resetFields(this.formObj)
      this.showModal = true
      this.sampleId = sampleId
      this._page()
    },
    _page: async function() {
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      const result = await meterTemplate.pageTemplate(this.formObj)
      if (result) {
        this.getPage = result
        this.$refs.pageTable._hideLoading()
      }
    },
    _footerResult(name) {
      switch (name) {
        case '取消':
          this._cancel()
          break
        case '确定':
          this._ok()
          break
      }
    },
    _ok() {
      if (this.selectData.length === 0) {
        this.$Message.warning('请选择一个原始记录模板！')
        // this._hideLoading()
        this.$refs.pageTable._hideLoading()
      } else {
        const data = this.selectData[0]
        data.sampleId = this.sampleId
        this.$emit('on-result-change', data)
        this.showModal = false
      }
    },
    _cancel() {
      this.showModal = false
    },
    // 操作的序号
    _handleRow(data) {
      this.currentRow = data.row
    },
    _formSearch() {
      this.$refs.pageTable._pageChange(1)
    },
    _btnClick(msg) {
      switch (msg) {
        case '导入检测项目':
          break
      }
    },

    // 操作列操作
    _iconClick(res, data) {
      switch (res) {
        case '删除':
          break
      }
    },
    _handleOrderValueEdit(id, value) {
      this._edit({ id: id, obj: { orderBy: value } })
    },
    _tableResultChange(msg, data) {
      console.log(msg)
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'changeSize':
          this._page()
          break
        case 'selectData':
          this.selectData = data
          break
        case 'singleSelect':
          this.selectData = [data]
          break
        case 'iconClick':
          this._iconClick(data.name, data.rowData)
          break
      }
    }
  }
}
</script>
