<!--检测项目编辑列表（添加、导入检测项目）-->
<template>
  <div>
    <Modal
      v-model="showModal"
      v-drag
      :mask-closable="false"
      :width="1200"
      title="检测项目管理"

    >
      <Row>
        <Col span="24" />
        <Form v-model="formObj" :label-width="90" inline onsubmit="return false">
          <Form-item class="search-item" label="检测项目:" style="margin-left: -25px">
            <Input v-model="formObj.name" @on-enter="_formSearch" placeholder="请输入检测项目" clearable />
            <input v-model="formObj.catalogueId" type="hidden">
          </Form-item>
          <Form-item class="search-item" label="检测依据:">
            <Input v-model="formObj.code" @on-enter="_formSearch" placeholder="请输入检测依据" clearable />
          </Form-item>
          <Form-item class="search-item" label="检测依据名称:">
            <Input v-model="formObj.standardName" @on-enter="_formSearch" placeholder="请输入检测依据名称" clearable />
          </Form-item>
          <Form-item class="search-btn">
            <Button @click="_formSearch" type="primary">
              搜索
            </Button>
          </Form-item>
        </Form>
        </Col>
        <!--正常界面-->
        <Col span="24" />
          <Button @click="_importItem" type="primary" style="margin-bottom: 5px">导入检测项目</Button>
        </Col>
        <!-- 表格 -->
        <Col span="24">
          <PTVXETable
            ref="pageTable"
            :form-id="formId"
            :tableHeight="500"
            :getPage="getPage"
            :iconMsg="iconMsg"
            @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>{{scope.row[item.key]}}</span>
              </template>
            </vxe-table-column>
          </PTVXETable>
        </Col>
        <div slot="footer">
          <ModalFooter ref="footerModal" @on-result-change="_footerResult" :footer="footerList"></ModalFooter>
        </div>
      </Row>

    </Modal>
    <!--导入项目  左右关联的modal   单个导入项目-->
<!--    <SampleItemSelect ref="relItemModal" @on-result-change="_formSearch" />-->
  </div>
</template>
<script>
// import { drugCatalogueItem } from '../../api'
// import SampleItemSelect from './SampleItemSelect'
import ModalFooter from '../../../components/base/modalFooter'
import { meterManageItem } from '../../../api'
export default {
  components: {
    ModalFooter
    // SampleItemSelect
  },
  data() {
    return {
      formId: 'SampleItemListFormId',
      formObj: {
        aptitudeId: '',
        name: '',
        code: '',
        standardName: ''
      },
      showModal: false,
      searchOpen: false,
      btn: [{ type: 'primary', id: '', name: '导入检测项目' }],
      iconMsg: [{ type: 'pt-a-trash', id: '', name: '删除' }],
      footerList: [
        { id: '', name: '取消', type: '' },
        { id: '', name: '保存', type: 'primary' }
      ],
      pageColumns: [
        { title: '检测项目', key: 'name', width: 140 },
        { title: '比较符', key: 'compare', width: 140 },
        { title: '限量值', key: 'limitValue', width: 160 },
        { title: '单位', key: 'unit', width: 220 },
        { title: '是否判定', key: 'judged', width: 110 },
        { title: '备注', key: 'remark' }
      ],
      catalogueId: '',
      getPage: {},
      selectData: []
    }
  },
  methods: {
    _open(aptitudeId) {
      this.formObj = this.$resetFields(this.formObj)
      this.showModal = true
      this.formObj.aptitudeId = aptitudeId
      this._page()
    },
    _page: async function() {
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      console.log('this.formObj', this.formObj)
      const result = await meterManageItem.page(this.formObj)
      if (result) {
        this.getPage = result
        this.$refs.pageTable._hideLoading()
      }
    },
    _footerResult(name) {
      switch (name) {
        case '取消':
          this._cancel()
          break
        case '保存':
          this._ok()
          break
      }
    },
    _cancel() {
      this.showModal = false
    },
    // 操作的序号
    _handleRow(data) {
      this.currentRow = data.row
    },
    _formSearch() {
      this.$refs.pageTable._pageChange(1)
    },
    // _page: async function() {
    //   Object.assign(this.formObj, this.$refs.pageTable._searchParams())
    //   const result = await drugCatalogueItem.pageCatalogueItem(
    //     this.$serializeForm(this.formObj)
    //   )
    //   if (result) {
    //     this.getPage = result
    //     this.$refs.pageTable._initTable()
    //   }
    // },
    _btnClick(msg) {
      switch (msg) {
        case '导入检测项目':
          this.$refs.relItemModal._open(this.catalogueId)
          break
      }
    },
    _importItem() {
      this.$refs.relItemModal._open(this.catalogueId)
    },
    // 操作列操作
    _iconClick(res, data) {
      switch (res) {
        case '删除':
          this._deleteById(data.id)
          break
      }
    },
    // 删除
    _deleteById(id) {
      this.$Modal.confirm({
        title: '提示',
        content: '确定删除该数据？',
        onOk: () => {
          this._deleteOk(id)
        }
      })
    },

    _handleOrderValueEdit(id, value) {
      this._edit({ id: id, obj: { orderBy: value } })
    },

    // _edit: async function(data) {
    //   const result = await drugCatalogueItem.edit(data)
    //   if (result) {
    //     this._page()
    //   }
    // },

    // _deleteOk: async function(id) {
    //   const result = await drugCatalogueItem.deleteById(id)
    //   if (result) {
    //     this.$Message.success('删除成功')
    //     this._page()
    //   }
    // },
    // table结果  返回整行
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'selectData':
          this.selectData = data
          break
        case 'iconClick':
          this._iconClick(data.name, data.rowData)
          break
      }
    }
  }
}
</script>
