<!--检测项目编辑列表（添加、导入检测项目）-->
<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" placeholder="请输入检测项目" clearable @on-enter="_formSearch" />
            <input v-model="formObj.catalogueId" type="hidden">
          </Form-item>
          <Form-item class="search-item" label="检测依据:">
            <Input v-model="formObj.code" placeholder="请输入检测依据" clearable @on-enter="_formSearch" />
          </Form-item>
          <Form-item class="search-item" label="检测依据名称:">
            <Input v-model="formObj.standardName" 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" />
          <Button type="primary" style="margin-bottom: 5px" @click="_importItem">导入检测项目</Button>
        </Col>
        <!-- 表格 -->
        <Col span="24">
          <PTVXETable
            ref="pageTable"
            :form-id="formId"
            :table-height="500"
            :get-page="getPage"
            :icon-msg="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-if="item.judged">{{scope.row[item.key]===1?'是':'否'}}</span>
                <span v-else>{{scope.row[item.key]}}</span>
              </template>
            </vxe-table-column>
          </PTVXETable>
        </Col>
        <div slot="footer">
          <ModalFooter ref="footerModal" :footer="footerList" @on-result-change="_footerResult"></ModalFooter>
        </div>
      </Row>

    </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 { meterManageItem } from '../../../api'
export default {
  components: {
    ModalFooter,
    DownloadTemplateImport
    // SampleItemSelect
  },
  data() {
    return {
      formId: 'SampleItemListFormId',
      formObj: {
        aptitudeId: '',
        name: '',
        code: '',
        standardName: ''
      },
      showModal: false,
      searchOpen: false,
      btn: [{ type: 'primary', id: '', name: '导入检测项目' }],
      iconMsg: [{ type: 'md-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, judged: true },
        { 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() {
      const data = {
        importUrl:
          '/meter/v1/aptitude_item/import_aptitude_item?aptitudeId=' +
          this.formObj.aptitudeId,
        downloadUrl: '/meter/v1/excel/template/MeterAptitudeItemImport',
        title: '导入'
      }
      this.$refs.importModal._open(data, '授权资质项目导入')
    },
    // 操作列操作
    _iconClick(res, data) {
      switch (res) {
        case '删除':
          this._deleteById(data.id)
          break
      }
    },
    // 删除
    _deleteById(id) {
      this.$Modal.confirm({
        title: '提示',
        content: '确定删除该数据？',
        onOk: () => {
          this._deleteOk(id)
        }
      })
    },
    _deleteOk: async function(id) {
      const result = await meterManageItem.deleteItemById(id)
      if (result) {
        await this._page()
        this.$Message.success('删除成功')
      }
    },
    _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>
