<template>
  <div>

    <div>
      <div ref="lxHeader">
        <lx-header icon="md-apps" :text="$route.meta.title" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
          <div slot="content">

            <div class="searchwrap" style="display: flex;align-items: center;">
              <div v-if="path==2">
                <div>
                  <el-input v-model="select.course_name" placeholder="请输入课程名称"></el-input>
                </div>
              </div>
              <div v-else>
                <div>
                  <el-input v-model="select.name" placeholder="请输入姓名"></el-input>
                </div>
                <div>
                  <el-input v-model="select.company_name" placeholder="请输入公司名称"></el-input>
                </div>
                <div>
                  <el-select v-model="select.company_position" placeholder="请选择职务" clearable>
                    <el-option v-for="item in company_position_list" :key="item.id" :label="item.value"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </div>
                <div>
                  <el-select v-model="select.company_type" placeholder="请选择企业性质" clearable>
                    <el-option v-for="item in company_type_list" :key="item.id" :label="item.value" :value="item.id">
                    </el-option>
                  </el-select>
                </div>
                <div>
                  <el-select v-model="select.company_area" placeholder="请选择所属区域" clearable>
                    <el-option v-for="item in company_area_list" :key="item.id" :label="item.value" :value="item.id">
                    </el-option>
                  </el-select>
                </div>
                <div>
                  <el-select v-model="select.company_industry" placeholder="请选择所属行业" clearable>
                    <el-option v-for="item in company_industry_list" :key="item.id" :label="item.value"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div>
                <el-button type="primary" size="small" @click="getList">查询</el-button>
                <el-button v-if="path==2" type="primary" size="small">导出</el-button>
              </div>
            </div>
          </div>

        </lx-header>
      </div>
    </div>

    <div>
      <div v-if="path==2" style="margin-bottom:10px">统计：本年度学员共计{{year_total}}人；累计学员{{alltotal}}人。</div>
      <xy-table :list="list" @pageIndexChange="pageIndexChange" @pageSizeChange="pageSizeChange" :total="total" :table-item="table_item">
        <template v-slot:btns>
          <el-table-column align='center' label="操作" fixed="right" width="80" header-align="center">
            <template slot-scope="scope">
              <el-button type="primary" size="small" @click="showDetail('show',scope.row.id)">查看</el-button>
            </template>
          </el-table-column>
        </template>
      </xy-table>
    </div>

    <student-detail ref="studentDetail"></student-detail>
  </div>
</template>

<script>
  import studentDetail from './components/detail.vue';
  import myMixins from "@/mixin/selectMixin.js";
  import {
    indexStudy
  } from '@/api/student/index.js'
  export default {
    mixins: [myMixins],
    components: {
      studentDetail
    },
    data() {
      return {
        path: '',
        select: {
          name: '',
          course_name: '',
          company_name: '',
          company_position: '',
          company_area: '',
          company_type: '',
          company_industry: '',
          page: 1,
          page_size: 10,
        },
        company_position_list: [],
        company_type_list: [],
        company_industry_list: [],
        company_area_list: [],
        list: [],
        year_total:0,
        alltotal:0,
        total: 0,
        table_item: [{
          prop: 'username',
          label: '姓名',
          align: 'center',
          width: 120
        }, {
          prop: 'sex',
          label: '性别',
          align: 'center',
          width: 120
        },{
          prop: 'idcard',
          label: '身份证号',
          align: 'center',
          width: 180
        },{
          prop: 'company_name',
          label: '公司名称',
          align: 'left',
        }, {
          prop: 'company_position',
          label: '职务',
          align: 'center',
          width: 120,
        }, {
          prop: 'mobile',
          label: '联系电话',
          align: 'center',
          width: 120,
        },]

      }
    },
    created() {
      const _path = this.$route.path.split("_")
      console.log("_path", this.$route, _path)
      this.path = _path[1]
      if (this.path == 2) {
        this.table_item.unshift({
          prop: 'subject',
          label: '课程名称',
          align: 'left',
          width: 200,
        })
      }
      this.getList()
    },
    methods: {
      pageIndexChange(e){
        this.select.page = e
        this.getList()
      },
      pageSizeChange(e){
        this.select.page_size = e
        this.select.page = 1
        this.getList()
      },
      async getList() {
        const res = await indexStudy({
          page: this.select.page,
          page_size: this.select.page_size,
          filter: [{
            key: 'course_name',
            op: 'like',
            value: this.select.course_name
          }, {
            key: 'name',
            op: 'like',
            value: this.select.name
          }, {
            key: 'company_name',
            op: 'like',
            value: this.select.company_name
          }, {
            key: 'company_position',
            op: 'eq',
            value: this.select.company_position
          }, {
            key: 'company_area',
            op: 'eq',
            value: this.select.company_area
          }, {
            key: 'company_type',
            op: 'eq',
            value: this.select.company_type
          }, {
            key: 'company_industry',
            op: 'eq',
            value: this.select.company_industry
          }]
        })
        this.list = res.list.data
        this.total = res.list.total
        this.year_total = res.year_total
        this.alltotal = res.total
      },
      showDetail(type, id) {
        this.$refs.studentDetail.id = id
        this.$refs.studentDetail.type = type
        this.$refs.studentDetail.isShow = true
      }
    }
  }
</script>

<style lang="scss" scoped>
  .searchwrap {
    display: flex;
    align-items: center;

    &>div {
      display: flex;
      align-items: center;

      &>div {

        margin-right: 10px;
      }

    }
  }
</style>
