<!--资质项目列表-->
<template>
  <div>
    <div>
      <Form :label-width="65" inline onsubmit="return false">
        <label class="label-sign"></label>
        <Form-item label="检测项目:" class="search-item">
          <Input v-model="formObj.name" @on-enter="_search" placeholder="请输入检测项目" clearable />
        </Form-item>
        <Form-item>
          <Button @click="_search" type="primary">搜索</Button>
        </Form-item>
      </Form>
    </div>
    <PTVXETable ref="pageTable" :tableHeight="tableHeight"
                    @on-result-change="_tableResultChange" :getPage="getPage" select-data>
      <vxe-table-column
        :field="item.key"
        :title="item.title"
        :min-width="item.width?item.width:200"
        :fixed="item.fixed?item.fixed:undefined"
        v-for="item in pageColumns"
        :key="item.key" sortable>
        <template slot-scope="scope">
          <div v-if="item.judge">{{scope.row[item.key] === 0 ?'否':'是'}}</div>
          <div v-else-if="item.key==='testBasis'">
            {{(scope.row.testBasis?scope.row.testBasis:' ')+(scope.row.testBasisName?scope.row.testBasisName:'')}}
          </div>
          <div v-else>{{scope.row[item.key]}}</div>
        </template>
      </vxe-table-column>
    </PTVXETable>
  </div>
</template>

<script>
import { soilAptitude } from '../../../api'

export default {
  components: {},
  data() {
    return {
      getPage: {},
      formObj: {
        name: undefined,
        testBasis: undefined,
        aptitude: undefined
      },
      tableHeight: document.documentElement.clientHeight - 285,
      pageColumns: [
        { title: '检测项目', key: 'name', width: 100 },
        { title: '检测依据', key: 'testBasis', width: 260 },
        // {title: '检测依据名称', key: 'testBasisName', width: 330},
        { title: '检测方法', key: 'testMethod', width: 130 },
        { title: '检测科室', key: 'groupName', width: 140 },
        { title: '资质', key: 'aptitude', width: 130 },
        { title: '检出限类别', key: 'detectionType', width: 130 },
        { title: '检出限', key: 'detectionLimit', width: 130 },
        { title: '单位', key: 'unit', width: 130 }
      ],
      formId: '',
      itemList: [],
      testBasisList: []
    }
  },
  methods: {
    _open() {
      this.formObj = this.$resetFields(this.formObj)
      this._page()
    },
    // 获取检测项目
    _getItemList(data) {
      const obj = {}
      if (data) {
        obj.name = data
      }
      this.$store.dispatch('FoodAptitudeItem/getTestItem', obj).then(() => {
        this.itemList = this.$store.state.FoodAptitudeItem.list
      })
    },
    // 检测项目结果
    _testItemChange(msg, data) {
      switch (msg) {
        case 'select':
          this.formObj.name = data
          this._getItemList()
          break
        case 'query':
          this.formObj.name = data
          this._getItemList(data)
          break
        case 'focus':
          this._getItemList()
          break
        case 'enter':
          this._search()
          break
      }
    },
    _getTestBasisList(data) {
      const obj = { classify: 1, page: 1, rows: 20 }
      if (data) {
        obj.name = data.stdNum
      }
      this.$store.dispatch('StandardInfo/pageListByName', obj).then(() => {
        this.testBasisList = this.$store.state.StandardInfo.page.records
      })
    },
    _testBasisChange(msg, data) {
      switch (msg) {
        case 'select':
          this.formObj.testBasis = data.stdNum
          this._getTestBasisList()
          break
        case 'query':
          this.formObj.testBasis = data.stdNum
          this._getTestBasisList(data)
          break
        case 'focus':
          this._getTestBasisList()
          break
        case 'enter':
          this._search()
          break
      }
    },
    _page: async function() {
      const result = await soilAptitude.page(this.$serializeForm(this.formObj))
      if (result) {
        console.log(result)
        this.getPage = result
        this.$refs.pageTable._hideLoading()
      }
    },
    _clearSelection() {
      this.$refs.pageTable._clearSelection()
    },
    _search() {
      this.$refs.pageTable._pageChange(1)
    },
    _reset() {
      this.formObj = this.$resetFields(this.formObj)
    },
    _tableResultChange(msg, data, checked) {
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'selectAll':
          this.$emit('on-result-change', 'selectAll', data)
          break
        case 'selectData':
          this.$emit('on-result-change', 'selectData', data)
          break
        case 'dbSelect':
          this.$emit('on-result-change', 'dbClick', data)
          break
        case 'changeSize':
          this._page()
          break
      }
    }
  }
}
</script>
