<template>
  <div class="app-warp">
    <div class="app-structure">
      <div class="app-search">
        <el-form ref="searchFrom" :model="searchFrom" label-width="60px">
          <el-row>
            <el-col :span="6">
              <el-form-item label="机构（企业）名称" prop="NAME" label-width="130px">
                <el-input v-model="searchFrom.NAME" placeholder="请输入机构（企业）名称"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="类型" prop="TYPE">
                <el-select v-model="searchFrom.TYPE" style="width: 100%;">
                  <el-option value="0" label="机构"/>
                  <el-option value="1" label="企业"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="状态" prop="STATE">
                <el-select v-model="searchFrom.STATE" style="width: 100%;">
                  <el-option value="1" label="启用"/>
                  <el-option value="0" label="禁用"/>
                </el-select>
              </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-container">
        <el-table
          v-loading="listLoading"
          ref="multipleTable"
          :data="varList"
          :row-key="getRowKey"
          :header-cell-style="{
            background:'#f5f7fa',
            'font-weight': 'bold',
            'color': '#000'
          }"
          tooltip-effect="dark"
          border
          fit
          highlight-current-row>
          <el-table-column :reserve-selection="true" type="selection" width="55" align="center"/>
          <el-table-column type="index" label="序号" width="50" align="center"/>
          <el-table-column show-overflow-tooltip prop="NAME" label="机构（企业）名称"/>
          <el-table-column
            v-if="checkList.includes('主要负责人')"
            :show-overflow-tooltip="true"
            prop="COMMANDER"
            label="主要负责人"/>
          <el-table-column
            v-if="checkList.includes('电话')"
            :show-overflow-tooltip="true"
            prop="COMMANDER_PHONE"
            label="电话"/>
          <el-table-column
            v-if="checkList.includes('属地')"
            :show-overflow-tooltip="true"
            prop="dependency"
            label="属地"/>
          <el-table-column
            v-if="checkList.includes('状态')"
            :show-overflow-tooltip="true"
            prop="STATE"
            width="auto"
            label="状态">
            <template slot-scope="{row}">
              {{ row.STATE === '1' ? '启用' : '禁用' }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="checkList.includes('类型')"
            :show-overflow-tooltip="true"
            prop="TYPE"
            width="auto"
            label="类型">
            <template slot-scope="{row}">
              {{ row.TYPE === '0' ? '机构' : '企业' }}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="320px">
            <template slot-scope="{row}">
              <el-button type="text" @click="addCurriculum(row.CORPINFO_ID)">机构专用课程配置</el-button>
              <el-divider direction="vertical"/>
              <el-button type="text" @click="addStageExamPaper(row.CORPINFO_ID)">机构专用试卷配置</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'

export default {
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      goType: '',
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10
      },
      total: 0,
      varList: [],
      searchFrom: {
        NAME: '',
        TYPE: '',
        STATE: ''
      },
      searchFromCollapse: true,
      checkList: ['主要负责人', '电话', '属地', '状态', '类型', '专用课程数', '专用试卷数'],
      checkboxList: ['主要负责人', '电话', '属地', '状态', '类型', '专用课程数', '专用试卷数']
    }
  },
  inject: ['setActiveName', 'setCorpInfoId'],
  created() {
    this.listLoading = false
    this.getList()
  },
  methods: {
    // 详情
    goInfo(CORPINFO_ID) {
      this.setActiveName('Curandpaper')
      this.setCorpInfoId(CORPINFO_ID)
    },
    // 添加课程
    addCurriculum(CORPINFO_ID) {
      this.setActiveName('curriculumList')
      this.setCorpInfoId(CORPINFO_ID)
    },
    // 添加考试试卷
    addStageExamPaper(CORPINFO_ID) {
      this.setActiveName('stageexampaperList')
      this.setCorpInfoId(CORPINFO_ID)
    },
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    goKeyReset() {
      this.$refs.searchFrom.resetFields()
      this.listQuery = {
        page: 1,
        limit: 10
      }
      this.getList()
    },
    getRowKey(row) {
      return row.CORPINFO_ID
    },
    getList() {
      requestFN(`/training/list?showCount=${this.listQuery.limit}&currentPage=${this.listQuery.page}`, {
        ...this.searchFrom
      }).then(data => {
        this.varList = data.list
        this.total = data.page.totalResult
        this.listLoading = false
      })
    }
  }
}

</script>
<style>
</style>
