<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <!--      <el-form-item label="学员编号" prop="studentNumber">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.studentNumber"-->
      <!--          placeholder="请输入学员编号"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="姓名" prop="studentName">
        <el-input v-model="queryParams.studentName" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable>
          <el-option v-for="dict in dict.type.tb_sex" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <!--      <el-form-item label="出生日期" prop="birthday">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.birthday"-->
      <!--          placeholder="请输入出生日期"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="电话/手机" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入电话/手机" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="身份证号" prop="identityCard">
        <el-input v-model="queryParams.identityCard" placeholder="请输入身份证号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学历" prop="education">
        <el-select v-model="queryParams.education" placeholder="请选择学历" clearable>
          <el-option v-for="dict in dict.type.tb_education" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <!--      <el-form-item label="毕业时间" prop="graduationTime">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.graduationTime"-->
      <!--          placeholder="请输入毕业时间"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="审核状态" prop="examineStatus">
        <el-select v-model="queryParams.examineStatus" placeholder="请选择审核状态" clearable>
          <el-option v-for="dict in dict.type.tb_examine_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="冻结状态" prop="frozenStatus">
        <el-select v-model="queryParams.frozenStatus" placeholder="请选择冻结状态" clearable>
          <el-option v-for="dict in dict.type.tb_frozen_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable v-model="queryParams.createTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['hezhi:student:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['hezhi:student:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['hezhi:student:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['hezhi:student:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" icon="el-icon-upload2" size="mini" @click="handleImport">导入</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="studentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--      <el-table-column label="学员主键ID" align="center" prop="studentId" />-->
      <el-table-column label="学员编号" align="center" prop="studentId" width="80px" />
      <!--      <el-table-column label="邀请人ID" align="center" prop="parentId" />-->
      <!--      <el-table-column label="邀请人编号" align="center" prop="parentNumber" />-->
      <el-table-column label="头像" align="center" prop="headPortrait" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.headPortrait" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="昵称" align="center" prop="nickName" width="100px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.nickName" />
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="studentName" width="80px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.studentName" />
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="sex" width="60px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_sex" :value="scope.row.sex === 2 ? '' : scope.row.sex" />
        </template>
      </el-table-column>
      <el-table-column label="出生日期" align="center" prop="birthday" width="100px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.birthday" />
        </template>
      </el-table-column>
      <el-table-column label="电话/手机" align="center" prop="phone" width="120px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.phone" />
        </template>
      </el-table-column>
      <el-table-column label="身份证号" align="center" prop="identityCard" width="160px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.identityCard" />
        </template>
      </el-table-column>
      <el-table-column label="身份证国徽面" align="center" prop="identityCardBadge" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.identityCardBadge" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="身份证人像面" align="center" prop="identityCardPortrait" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.identityCardPortrait" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="毕业证书" align="center" prop="graduationCertificate" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.graduationCertificate" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="学历" align="center" prop="education" width="100px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_education" :value="scope.row.education" />
        </template>
      </el-table-column>
      <!--      <el-table-column label="毕业院校ID" align="center" prop="graduationSchoolId" />-->
      <el-table-column label="毕业院校" align="center" prop="graduationSchool" width="100px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.graduationSchool" />
        </template>
      </el-table-column>
      <el-table-column label="毕业时间" align="center" prop="graduationTime" width="100px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.graduationTime" />
        </template>
      </el-table-column>
      <!--      <el-table-column label="登录类型" align="center" prop="loginType" />-->
      <!--      <el-table-column label="openId" align="center" prop="openid" />-->
      <!--      <el-table-column label="密码" align="center" prop="password" />-->
      <!--      <el-table-column label="密码未加密" align="center" prop="passwordUnencrypted" />-->
      <!--      <el-table-column label="邀请码图" align="center" prop="invitationCodeImg" />-->
      <!--      <el-table-column label="类型" align="center" prop="type" />-->
      <!--      <el-table-column label="市ID" align="center" prop="cityId" />-->
      <!--      <el-table-column label="省ID" align="center" prop="provinceId" />-->
      <!--      <el-table-column label="区" align="center" prop="areaId" />-->
      <!--      <el-table-column label="省名" align="center" prop="provinceName" />-->
      <!--      <el-table-column label="市名" align="center" prop="cityName" />-->
      <!--      <el-table-column label="区名" align="center" prop="areaName" />-->
      <!--      <el-table-column label="详细地址" align="center" prop="address" />-->
      <el-table-column label="审核状态" align="center" prop="examineStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_examine_status" :value="scope.row.examineStatus" />
        </template>
      </el-table-column>
      <!--      <el-table-column label="审核反馈" align="center" prop="examineFeedback" />-->
      <el-table-column label="冻结状态" align="center" prop="frozenStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_frozen_status" :value="scope.row.frozenStatus" />
        </template>
      </el-table-column>
      <!--      <el-table-column label="冻结状态反馈" align="center" prop="frozenFeedback" />-->
      <!--      <el-table-column label="排序" align="center" prop="sort" />-->
      <!--      <el-table-column label="备注" align="center" prop="remarks" />-->
      <!--      <el-table-column label="状态" align="center" prop="status" />-->
      <el-table-column label="创建时间" align="center" prop="createTime" width="150" show-overflow-tooltip />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="120px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['hezhi:student:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['hezhi:student:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改学员对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <!--        <el-form-item label="学员编号" prop="studentNumber">-->
        <!--          <el-input v-model="form.studentNumber" placeholder="请输入学员编号" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="邀请人ID" prop="parentId">-->
        <!--          <el-input v-model="form.parentId" placeholder="请输入邀请人ID" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="邀请人编号" prop="parentNumber">-->
        <!--          <el-input v-model="form.parentNumber" placeholder="请输入邀请人编号" />-->
        <!--        </el-form-item>-->
        <el-form-item label="头像" prop="headPortrait">
          <image-upload v-model="form.headPortrait" :limit="1" />
        </el-form-item>
        <el-form-item label="昵称" prop="nickName">
          <el-input v-model="form.nickName" placeholder="请输入昵称" />
        </el-form-item>
        <el-form-item label="姓名" prop="studentName">
          <el-input v-model="form.studentName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option v-for="dict in dict.type.tb_sex" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期" prop="birthday">
          <el-date-picker clearable v-model="form.birthday" type="date" value-format="yyyy-MM-dd" placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="电话/手机" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话/手机" />
        </el-form-item>
        <el-form-item label="身份证号" prop="identityCard">
          <el-input v-model="form.identityCard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="身份证国徽面" prop="identityCardBadge">
          <image-upload v-model="form.identityCardBadge" :limit="1" />
        </el-form-item>
        <el-form-item label="身份证人像面" prop="identityCardPortrait">
          <image-upload v-model="form.identityCardPortrait" :limit="1" />
        </el-form-item>
        <el-form-item label="毕业证书" prop="graduationCertificate">
          <image-upload v-model="form.graduationCertificate" :limit="1" />
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-select v-model="form.education" placeholder="请选择学历">
            <el-option v-for="dict in dict.type.tb_education" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <!--        <el-form-item label="毕业院校ID" prop="graduationSchoolId">-->
        <!--          <el-input v-model="form.graduationSchoolId" placeholder="请输入毕业院校ID" />-->
        <!--        </el-form-item>-->
        <el-form-item label="毕业院校" prop="graduationSchool">
          <el-input v-model="form.graduationSchool" placeholder="请输入毕业院校" />
        </el-form-item>
        <el-form-item label="毕业时间" prop="graduationTime">
          <el-date-picker clearable v-model="form.graduationTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <!--        <el-form-item label="openId" prop="openid">-->
        <!--          <el-input v-model="form.openid" placeholder="请输入openId" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="密码" prop="password">-->
        <!--          <el-input v-model="form.password" placeholder="请输入密码" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="密码未加密" prop="passwordUnencrypted">-->
        <!--          <el-input v-model="form.passwordUnencrypted" placeholder="请输入密码未加密" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="邀请码图" prop="invitationCodeImg">-->
        <!--          <el-input v-model="form.invitationCodeImg" type="textarea" placeholder="请输入内容" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="市ID" prop="cityId">-->
        <!--          <el-input v-model="form.cityId" placeholder="请输入市ID" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="省ID" prop="provinceId">-->
        <!--          <el-input v-model="form.provinceId" placeholder="请输入省ID" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="区" prop="areaId">-->
        <!--          <el-input v-model="form.areaId" placeholder="请输入区" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="省名" prop="provinceName">-->
        <!--          <el-input v-model="form.provinceName" placeholder="请输入省名" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="市名" prop="cityName">-->
        <!--          <el-input v-model="form.cityName" placeholder="请输入市名" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="区名" prop="areaName">-->
        <!--          <el-input v-model="form.areaName" placeholder="请输入区名" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="详细地址" prop="address">-->
        <!--          <el-input v-model="form.address" placeholder="请输入详细地址" />-->
        <!--        </el-form-item>-->
        <el-form-item label="审核状态" prop="examineStatus" v-if="this.title === '修改学员'">
          <el-radio-group v-model="form.examineStatus">
            <el-radio v-for="dict in dict.type.tb_examine_status" :key="dict.value" :label="parseInt(dict.value)">{{
              dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核反馈" prop="examineFeedback" v-if="form.examineStatus === 2">
          <el-input v-model="form.examineFeedback" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="冻结状态" prop="frozenStatus">
          <el-radio-group v-model="form.frozenStatus">
            <el-radio v-for="dict in dict.type.tb_frozen_status" :key="dict.value" :label="parseInt(dict.value)">{{
              dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <!--        <el-form-item label="冻结状态反馈" prop="frozenFeedback">-->
        <!--          <el-input v-model="form.frozenFeedback" placeholder="请输入冻结状态反馈" />-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px">
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-button type="primary" @click="importTemplate">下载模板</el-button>
        </div>
        <div class="el-upload__tip" style="color: red" slot="tip">
          提示：仅允许导入“xls”或“xlsx”格式文件！
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listStudent,
  getStudent,
  delStudent,
  addStudent,
  updateStudent,
  importTemplate,
} from "@/api/hezhi/student";
import { getToken } from "@/utils/auth";

export default {
  name: "Student",
  dicts: ["tb_education", "tb_examine_status", "tb_sex", "tb_frozen_status"],
  data() {
    return {
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/hezhi/student/importData",
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学员表格数据
      studentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentNumber: null,
        parentId: null,
        parentNumber: null,
        headPortrait: null,
        nickName: null,
        studentName: null,
        sex: null,
        birthday: null,
        phone: null,
        identityCard: null,
        identityCardBadge: null,
        identityCardPortrait: null,
        graduationCertificate: null,
        education: null,
        graduationSchoolId: null,
        graduationSchool: null,
        graduationTime: null,
        loginType: null,
        openid: null,
        password: null,
        passwordUnencrypted: null,
        invitationCodeImg: null,
        type: null,
        cityId: null,
        provinceId: null,
        areaId: null,
        provinceName: null,
        cityName: null,
        areaName: null,
        address: null,
        examineStatus: null,
        examineFeedback: null,
        frozenStatus: null,
        frozenFeedback: null,
        sort: null,
        remarks: null,
        status: null,
        publicationTime: null,
        publisher: null,
        createTime: null,
        deleteTime: null,
        deleteBy: null,
        delFlag: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        phone: [
          { required: true, message: "电话/手机不能为空", trigger: "blur" },
          {
            pattern: /^1\d{10}$/,
            message: "请输入11位的手机号码",
            trigger: "blur",
          },
        ],
        studentName: [
          { required: true, message: "姓名不能为空", trigger: "blur" },
        ],
        identityCard: [
          { required: true, message: "身份证不能为空", trigger: "blur" },
          {
            pattern:
              /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[0-9Xx]$/,
            message: "请输入正确的身份证号",
            trigger: "blur",
          },
        ],
        sex: [{ required: true, message: "性别不能为空", trigger: "blur" }],
        birthday: [
          { required: true, message: "出生日期不能为空", trigger: "blur" },
        ],
        identityCardBadge: [
          { required: true, message: "身份证国徽面不能为空", trigger: "blur" },
        ],
        identityCardPortrait: [
          { required: true, message: "身份证人像面不能为空", trigger: "blur" },
        ],
        graduationCertificate: [
          { required: true, message: "毕业证书不能为空", trigger: "blur" },
        ],
        // examineStatus: [
        //   { required: true, message: "审核状态不能为空", trigger: "blur" }
        // ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询学员列表 */
    getList() {
      this.loading = true;
      listStudent(this.queryParams).then((response) => {
        this.studentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        studentId: null,
        studentNumber: null,
        parentId: null,
        parentNumber: null,
        headPortrait: null,
        nickName: null,
        studentName: null,
        sex: null,
        birthday: null,
        phone: null,
        identityCard: null,
        identityCardBadge: null,
        identityCardPortrait: null,
        graduationCertificate: null,
        education: null,
        graduationSchoolId: null,
        graduationSchool: null,
        graduationTime: null,
        loginType: null,
        openid: null,
        password: null,
        passwordUnencrypted: null,
        invitationCodeImg: null,
        type: null,
        cityId: null,
        provinceId: null,
        areaId: null,
        provinceName: null,
        cityName: null,
        areaName: null,
        address: null,
        examineStatus: null,
        examineFeedback: null,
        frozenStatus: 0,
        frozenFeedback: null,
        sort: null,
        remarks: null,
        status: null,
        publicationTime: null,
        publisher: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        deleteTime: null,
        deleteBy: null,
        delFlag: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.studentId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const studentId = row.studentId || this.ids;
      getStudent(studentId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学员";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.studentId != null) {
            updateStudent(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudent(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const studentIds = row.studentId || this.ids;
      this.$modal
        .confirm('是否确认删除学员编号为"' + studentIds + '"的数据项？')
        .then(function () {
          return delStudent(studentIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "hezhi/student/export",
        {
          ...this.queryParams,
        },
        `学员导出.xlsx`
      );
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "学员导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download("hezhi/student/importTemplate", {}, `学员导入模板.xlsx`);
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
  },
};
</script>
