<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" style="padding-left:0">
            <div class="txl">
              <div>课程名称：{{subjectObj.title}}</div>
              <div>开课日期：{{subjectObj.date}}</div>
              <div>类别：{{subjectObj.leibie}}</div>
            </div>
            <div class="searchwrap" style="display: flex;align-items: center;">
                <div>
                  <el-input v-model="select.name" placeholder="请输入姓名"></el-input>
                </div>
                <div>
                  <el-select v-model="select.status" placeholder="请选择状态" clearable>
                    <el-option v-for="item in apply_status_list" :key="item.id" :label="item.value"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </div>
              <div>
                <el-button type="primary" size="small" @click="getList">查询</el-button>
                <el-button type="primary" size="small">导入</el-button>
              </div>
            </div>
          </div>

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

    <div>
      <xy-table :list="list" :total="total" @pageIndexChange="pageIndexChange" @pageSizeChange="pageSizeChange" :table-item="table_item">
        <template v-slot:status>
          <el-table-column align='center' label="状态" width="120" header-align="center">
            <template slot-scope="scope">
              <div v-for="item in apply_status_list">
                <el-tag :type="item.type" v-if="scope.row.status===item.id">{{item.value}}</el-tag>
              </div>
            </template>
          </el-table-column>
        </template>
        <template v-slot:btns>
          <el-table-column align='center' fixed="right" label="操作" width="80" header-align="center">
            <template slot-scope="scope">
              <el-button type="primary" v-if="scope.row.status===0" size="small" @click="showDetail('check',scope.row)">审核</el-button>
            </template>
          </el-table-column>
        </template>
      </xy-table>
    </div>

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

<script>
  import studentDetail from '@/views/student/components/detail.vue';
  import myMixins from "@/mixin/selectMixin.js";
  import {
    index
  } from '@/api/apply/index.js'
  export default {
    mixins: [myMixins],
    components: {
      studentDetail
    },
    data() {
      return {
        subjectObj:{},
        select: {
          name: '',
          course_id:'',
          status:'',
          page: 1,
          page_size: 10,
        },
        list: [],
        total: 0,
        table_item: [{
          prop: 'user.username',
          label: '姓名',
          align: 'center',
          width: 120
        }, {
          prop: 'user.sex',
          label: '性别',
          align: 'center',
          width: 120
        },{
          prop: 'user.idcard',
          label: '身份证号',
          align: 'center',
          width: 180
        },{
          prop: 'user.company_name',
          label: '公司名称',
          align: 'left',
        }, {
          prop: 'user.company_position',
          label: '职务',
          align: 'center',
          width: 120,
        }, {
          prop: 'user.mobile',
          label: '联系电话',
          align: 'center',
          width: 120,
        },
        // {
        //   prop: 'company_type',
        //   label: '企业性质',
        //   align: 'center',
        //   width: 180,
        // }, {
        //   prop: 'company_industry',
        //   label: '所属行业',
        //   align: 'center',
        //   width: 120,
        // }, {
        //   prop: 'company_area',
        //   label: '所属区域',
        //   align: 'center',
        //   width: 120,
        // },
        {
          prop: 'created_at',
          label: '报名时间',
          align: 'center',
          width: 180,
        }, {
          prop: 'status',
          label: '审核状态',
          align: 'center',
          width: 180,
        }]
      }
    },
    mounted() {
      this.subjectObj = this.$route.query
      this.select.course_id = this.subjectObj.id
      this.select.status = this.subjectObj.status
      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 index({
          page: this.select.page,
          page_size: this.select.page_size,
          name:this.select.name,
          filter: [{
            key: 'course_id',
            op: 'eq',
            value: this.select.course_id
          }, {
            key: 'status',
            op: 'eq',
            value: this.select.status
          }]
        })
        this.list = res.data
        this.total = res.total
      },
      showDetail(type, row) {
        this.$refs.studentDetail.subjectObj = this.subjectObj
        this.$refs.studentDetail.id = row.id
        this.$refs.studentDetail.row = row
        this.$refs.studentDetail.type = type
        this.$refs.studentDetail.isShow = true
      },
    }
  }
</script>

<style lang="scss" scoped>
  .txl {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    font-size:18px;
    &>div {
      margin-right: 15px;

    }
  }

  .searchwrap {
    display: flex;
    align-items: center;

    &>div {
      display: flex;
      align-items: center;
      margin-right: 10px;

      span {
        min-width: 70px;
      }
    }
  }
</style>
