<template>
  <div class="app-warp">
    <div class="app-structure">
      <div class="app-search">
        <el-form ref="searchFrom" :model="searchFrom" label-width="80px">
          <el-row>
            <el-col :span="6">
              <el-form-item label="机构名称" prop="CORP_NAME">
                <el-input v-model="searchFrom.CORP_NAME" placeholder="请输入机构名称"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label-width="10px">
                <el-button v-waves type="primary" icon="el-icon-search" class="ml-10" @click="getQuery">
                  搜索
                </el-button>
                <el-button icon="el-icon-refresh" @click="goKeyReset">
                  重置
                </el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="app-tools">
        <div class="app-function">
          <el-button type="primary" icon="el-icon-plus" @click="fnAdd('','add')">新建</el-button>
        </div>
        <div class="app-minbtn">
          <span class="screening">
            <el-dropdown trigger="click">
              <el-button type="text" icon="el-icon-finished"/>
              <el-dropdown-menu slot="dropdown" style="margin-top:3px;">
                <div class="app-checkbox-group">
                  <el-checkbox-group v-model="checkList">
                    <el-checkbox v-for="item in checkboxList" :key="item" :label="item" style="display: block"/>
                  </el-checkbox-group>
                </div>
              </el-dropdown-menu>
            </el-dropdown>
          </span>
          <el-button type="text" icon="el-icon-refresh-left"/>
          <el-button type="text" icon="el-icon-full-screen"/>
        </div>
      </div>
      <div class="app-container">
        <el-table
          v-loading="listLoading"
          ref="multipleTable"
          :data="varList"
          :header-cell-style="{
            background:'#f5f7fa',
            'font-weight': 'bold',
            'color': '#000'
          }"
          tooltip-effect="dark"
          border
          fit
          highlight-current-row>
          <el-table-column type="index" label="序号" width="50" align="center"/>
          <el-table-column show-overflow-tooltip prop="CORP_NAME" label="机构名称"/>
          <el-table-column
            v-if="checkList.includes('域名')"
            :show-overflow-tooltip="true"
            prop="DOMAIN_NAME"
            label="域名"/>
          <el-table-column
            v-if="checkList.includes('有效期开始时间')"
            :show-overflow-tooltip="true"
            prop="START_TIME"
            label="有效期开始时间"/>
          <el-table-column
            v-if="checkList.includes('有效期结束时间')"
            :show-overflow-tooltip="true"
            prop="END_TIME"
            label="有效期结束时间"/>
          <el-table-column
            v-if="checkList.includes('最大企业数')"
            :show-overflow-tooltip="true"
            prop="ENTERPRISE_MAXIMUM"
            label="最大企业数"/>
          <el-table-column
            v-if="checkList.includes('最大学员数')"
            :show-overflow-tooltip="true"
            prop="STUDENT_MAXIMUM"
            label="最大学员数"/>
          <el-table-column label="操作" align="center" width="250">
            <template slot-scope="{row}">
              <el-button type="text" @click="fnAdd(row.OEM_MANAGE_ID,'edit')">编辑</el-button>
              <el-divider direction="vertical"/>
              <el-button type="text" @click="fnAdd(row.OEM_MANAGE_ID,'view')">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="page-btn-group">
          <div/>
          <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList"/>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive

export default {
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10
      },
      total: 0,
      varList: [],
      searchFrom: {
        CORP_NAME: ''
      },
      searchFromCollapse: true,
      checkList: ['机构名称', '域名', '有效期开始时间', '有效期结束时间', '最大企业数', '最大学员数'],
      checkboxList: ['机构名称', '域名', '有效期开始时间', '有效期结束时间', '最大企业数', '最大学员数']
    }
  },
  inject: ['setActiveName', 'setOemManageId', 'setType'],
  created() {
    this.listLoading = false
    this.getList()
  },
  methods: {
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    goKeyReset() {
      this.$refs.searchFrom.resetFields()
      this.listQuery = {
        page: 1,
        limit: 10
      }
      this.getList()
    },
    getList() {
      requestFN(`/oemmanage/list?showCount=${this.listQuery.limit}&currentPage=${this.listQuery.page}`, {
        ...this.searchFrom
      }).then(data => {
        this.varList = data.varList
        this.total = data.page.totalResult
        this.listLoading = false
      })
    },
    fnAdd(OEM_MANAGE_ID, TYPE) {
      this.setActiveName('Add')
      this.setOemManageId(OEM_MANAGE_ID)
      this.setType(TYPE)
    },
    fnRecordList(OEM_MANAGE_ID) {
      this.setActiveName('RecordList')
      this.setOemManageId(OEM_MANAGE_ID)
    }
  }
}

</script>
<style>
</style>
