<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="searchwrap" style="display: flex;align-items: center;">
              <div>
                <div>
                  <el-input v-model="select.name" placeholder="请输入姓名"></el-input>
                </div>
                <div>
                  <el-input v-model="select.mobile" placeholder="请输入手机号"></el-input>
                </div>
                <div>
                  <el-input v-model="select.company_name" placeholder="请输入公司名称"></el-input>
                </div>
                <div>
                  <el-input v-model="select.company_position" placeholder="请输入职务"></el-input>
                </div>
                <div>
                  <el-select v-model="select.company_area" placeholder="请选择所属区域" clearable>
                    <el-option v-for="item in formSelect.company_area" :key="item.id" :label="item.value"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </div>
                <div>
                  <el-select v-model="select.company_type" placeholder="请选择企业性质" clearable>
                    <el-option v-for="item in formSelect.company_type" :key="item.id" :label="item.value"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </div>

                <div>
                  <el-select v-model="select.company_industry" placeholder="请选择所属行业" clearable>
                    <el-option v-for="item in formSelect.company_industry" :key="item.id" :label="item.value"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </div>
                <div>
                  <el-select v-model="select.type" placeholder="请选择人才类型" clearable>
                    <el-option v-for="item in formSelect.type" :key="item.id" :label="item.value" :value="item.value">
                    </el-option>
                  </el-select>
                </div>
                <div>
                  <el-select v-model="select.education" placeholder="请选择学历" clearable>
                    <el-option v-for="item in formSelect.education" :key="item.id" :label="item.value"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </div>
                <!-- <div>
                  <el-select v-model="select.apply_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="select.page=1,getList()">查询</el-button>
                  <el-button type="primary" size="small" @click="importTable">导入</el-button>
                  <el-button type="primary" size="small" @click="exportExcel">导出</el-button>
                </div>
              </div>

            </div>
          </div>

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

    <div>
      <div class="txl">
        <div>课程名称：{{subjectObj.title}}</div>
        <div>开课日期：{{subjectObj.date}}</div>
        <div>课程体系：{{subjectObj.leibie}}</div>
      </div>
      <xy-table :list="list" :total="total" :showIndexFixed="'left'" @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='left' fixed="right" label="操作" width="240" header-align="center">
            <template slot-scope="scope">
              <el-button type="primary" v-if="scope.row.status===1 " size="small"
                @click="showDetail('setPosition',scope.row)">设置班委</el-button>
              <el-button type="primary" size="small" @click="editSign('editor',scope.row)">编辑</el-button>
              <el-button type="primary" size="small" @click="showDetail('checkshow',scope.row)">查看</el-button>
            </template>
          </el-table-column>
        </template>
      </xy-table>
    </div>

    <student-detail ref="studentDetail" @refresh="getList"></student-detail>
    <editSign ref="editSign" @refresh="getList"></editSign>
    <imports ref="imports" :course_id="subjectObj.id" :table-name="'course_signs'" @refresh="getList"></imports>
  </div>
</template>

<script>
  import studentDetail from '@/views/student/components/detail.vue';
  import editSign from '@/views/course/components/editSign.vue';
  import myMixins from "@/mixin/selectMixin.js";
  import formMixin from "@/mixin/formMixin.js";
  import {
    index
  } from '@/api/apply/index.js'
  import {
    download
  } from "@/utils/downloadRequest";
  import imports from "@/views/component/imports.vue"
  import {
    index as formIndex
  } from "@/api/course/form";
  export default {
    mixins: [myMixins, formMixin],
    components: {
      studentDetail,
      editSign,
      imports
    },
    data() {
      return {
        subjectObj: {},
        select: {
          name: '',
          mobile: '',
          course_id: '',
          company_name: '',
          company_position: '',
          company_area: '',
          company_type: '',
          company_industry: '',
          education: '',
          status: '',
          apply_status: '',
          page: 1,
          page_size: 10
        },
        list: [],
        total: 0,
        formList: [], //自定义表单字段
        table_item: [{
            prop: 'user.username',
            label: '姓名',
            align: 'center',
            width: 120,
            fixed: 'left'
          }, {
            prop: 'user.sex',
            label: '性别',
            align: 'center',
            width: 120
          }, {
            prop: 'user.idcard',
            label: '身份证号',
            align: 'center',
            width: 180
          }, {
            prop: 'user.mobile',
            label: '联系方式',
            align: 'center',
            width: 120,
          }, {
            prop: 'user.birthday',
            label: '出生年月',
            align: 'center',
            width: 120,
          }, {
            prop: 'user.email',
            label: '邮箱',
            align: 'center',
            width: 120,
          }, {
            prop: 'user.company_name',
            label: '公司名称',
            align: 'left',
            width: 240,
          }, {
            prop: 'user.company_position',
            label: '职务',
            align: 'center',
            width: 120,
          }, {
            prop: 'position',
            label: '本班职务',
            align: 'center',
            width: 120,
          }, {
            prop: 'score',
            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.getAutoForm()
      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,
          mobile: this.select.mobile,
          company_name: this.select.company_name,
          company_position: this.select.company_position,
          company_area: this.select.company_area,
          company_type: this.select.company_type,
          company_industry: this.select.company_industry,
          education: this.select.education,
          filter: [{
            key: 'course_id',
            op: 'eq',
            value: this.select.course_id
          }, {
            key: 'status',
            op: 'eq',
            value: 1
          }, {
            key: 'fee_status',
            op: 'eq',
            value: this.subjectObj.is_fee === 0 ? '' : 1
          }]
        })
        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
      },
      importTable(row) {
        // this.$refs.imports.tableData = {
        //   'data[course_id]': row.course_id,
        //   'data[course_content_id]': row.id
        // }
        // this.$refs.imports.tableData = {
        //   'data[course_id]': this.subjectObj.id
        // }
        this.$refs.imports.show()

        // {"course_id":15,"course_content_id":188}
      },
      // 获取自定义表单内容
      async getAutoForm(){
        const res = await formIndex({
          page:1,
          page_size:999,
          sort_name: 'sort',
          sort_type: 'ASC',
          filter: [{
            key: 'course_id',
            op: 'eq',
            value:  this.select.course_id
          }],
        })
        this.formList = res.data
      },
      // 编辑
      editSign(type, row) {
        this.$refs.editSign.type = type
        this.$refs.editSign.row = row
        this.$refs.editSign.formList = this.formList
        this.$refs.editSign.isShow = true
      },
      exportExcel() {
        let _export = {}
        this.table_item.map(item => {
          if (item.prop === 'status') {
            _export['status_text'] = item.label
          } else {
            if (item.prop === 'created_at' || item.prop === 'score' || item.prop === 'position') {
              _export[item.prop] = item.label
            }

          }
        })

        download(
          '/api/admin/course-signs/index',
          'get', {
            name: this.select.name,
            mobile: this.select.mobile,
            company_name: this.select.company_name,
            company_position: this.select.company_position,
            company_area: this.select.company_area,
            company_type: this.select.company_type,
            company_industry: this.select.company_industry,
            education: this.select.education,
            export_fields: _export,
            filter: [{
              key: 'course_id',
              op: 'eq',
              value: this.select.course_id
            }, {
              key: 'status',
              op: 'eq',
              value: 1
            }, {
              key: 'fee_status',
              op: 'eq',
              value: this.subjectObj.is_fee === 0 ? '' : this.subjectObj.is_fee
            }],
            is_export: 1,
            page: 1,
            page_size: 999
          },
          `${this.subjectObj.title}通讯录.xlsx`)
      },
    }
  }
</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;
    flex-wrap: wrap;

    &>div {
      display: flex;
      align-items: center;
      // margin-bottom: 10px;
      flex-wrap: wrap;

      &>div {
        margin-right: 10px;
        margin-bottom: 10px;
        width: 150px;

        &:last-child {
          width: auto
        }
      }

    }
  }
</style>
