<template>
  <div>
    <ElementTable ref="pageTable" :pageColumns="pageColumns" :tableHeight="tableHeight"
                  @on-result-change="_tableResultChange" :getPage="getPage">
      <el-table-column
        :prop="item.key"
        :label="item.title"
        :min-width="item.width?item.width:200"
        :fixed="item.fixed?item.fixed:undefined"
        v-for="item in pageColumns"
        :key="item.key"
        sortable show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{scope.row[item.key]}}</span>
        </template>
      </el-table-column>
    </ElementTable>
  </div>
</template>
<script>
// import global from '../../../api/config'
import { meterSample } from '../../../api'
import ElementTable from './ElementTable'
export default {
  components: {
    ElementTable
  },
  data() {
    return {
      tableHeight: '400',
      pageColumns: [{ title: '报告模板名称', key: 'name' }],
      getPage: {},
      modalTitle: '报告模板',
      tempId: '',
      formObj: {
        // classifyName: '食品报告模板',
        // service: 'meter',
        // rows: 20
      }
    }
  },
  methods: {
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this.getPage = this.$store.state.SysFileTemplate.page
          if (this.tempId) {
            this.$refs.pageTable.templateRadio = this.tempId
            this.$emit('on-result-change', { id: this.tempId })
          }
          break
        case 'radioSelect':
          this.$emit('on-result-change', data)
          break
        default:
          this._page()
      }
    },
    _open(tempId) {
      this.tempId = tempId || ''
      this._page()
    },
    _page: async function() {
      // this.$refs.pageTable._page(
      //   'report-template-list',
      //   'SysFileTemplate/page',
      //   {
      //     classifyName: '食品报告模板',
      //     service: global.getCode()
      //   }
      // )
      const result = await meterSample.pageReport(this.formObj)
      console.log('模板结果', result)
      if (result) {
        this.getPage = result
      }
    }
  }
}
</script>
