<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" inline v-show="showSearch" label-width="100px">
      <el-form-item label="匹配状态" prop="matchStatus">
        <el-select v-model="queryParams.matchStatus" @keyup.enter.native="handleQuery" clearable
                   placeholder="请选择匹配状态">
          <el-option v-for="dict in dict.type.match_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
        <!-- <el-input v-model="queryParams.submit" placeholder="请输入匹配状态" clearable @keyup.enter.native="handleQuery" />
       -->
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" @keyup.enter.native="handleQuery" clearable
                   placeholder="请选择审核状态">
          <el-option v-for="dict in dict.type.audit_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </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="infoIdCard">
        <el-input v-model="queryParams.infoIdCard" placeholder="请输入身份证号码" clearable
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" plain icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button plain icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-button type="primary" plain icon="el-icon-upload" size="mini" v-if="status == '1'" @click="handleUpload">
        导入教育局信息
      </el-button>
      <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出报名信息</el-button>
      <el-button type="success" plain icon="el-icon-success" size="mini" v-if="status == '1'" @click="handlePass"
                 :disabled="multiple">通过
      </el-button>
      <el-button type="danger" plain icon="el-icon-back" size="mini" v-if="status == '1'" @click="handleBack"
                 :disabled="multiple">退回修改
      </el-button>
      <el-button type="danger" icon="el-icon-s-release" size="mini" v-if="status == '1'" @click="handleReject"
                 :disabled="multiple">驳回
      </el-button>
      <el-button type="info" icon="el-icon-finished" size="mini" v-if="status == '1'" @click="handleFinished">结束
      </el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <!-- <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="['system:relation: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="['system:relation: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="['system:relation: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="['system:relation:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->
    <el-table :cell-style="setRowStyle" v-loading="loading" :data="relationList"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column type="index" label="序号" width="55" align="center"/>
      <el-table-column label="头像" align="center" width="100" prop="photo">
        <template slot-scope="scope">
          <ListImage :image-url="isEmptyAvatar(scope.row.photo, scope.row.sex)"></ListImage>
        </template>
      </el-table-column>
      <el-table-column label="身份证号码" align="center" min-width="180" prop="infoIdCard"/>
      <el-table-column label="匹配状态" min-width="110" align="center" prop="matchStatus">
        <template slot-scope="scope">
          <dict-tag v-if="scope.row.matchStatus == '1'" style="color:#47bb02; font-weight: bold"
                    :options="dict.type.match_status"
                    :value="scope.row.matchStatus"/>
          <dict-tag v-else style="color:red; font-weight: bold" :options="dict.type.match_status"
                    :value="scope.row.matchStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" min-width="80" max-width="100" prop="auditStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.audit_status" :value="scope.row.auditStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="studentName"/>
      <el-table-column label="学籍号" align="center" prop="studentNumber"/>
      <el-table-column label="初中学校" align="center" prop="schoolName"/>
      <el-table-column label="测试项目" align="center" prop="project" min-width="100" max-width="120"/>
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <!-- 教育局信息 -->
      <el-table-column label="姓名" align="center" width="120px" prop="eduStudentName"/>
      <el-table-column label="学籍号" align="center" prop="eduStudentNumber"/>
      <el-table-column label="初中学校" width="100" align="center" prop="eduSchoolName"/>
      <el-table-column label="测试项目" align="type" prop="eduProject" width="100"/>
      <!-- <el-table-column label="身份证号" align="type" prop="eduIdCard" width="80" v-if="0" /> -->
      <el-table-column label="性别" align="center" prop="eduSex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.eduSex"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="230"
                       max-width="300">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit"
                     v-if="scope.row.auditStatus == '3' && status == '1' &&scope.row.matchStatus != '2' "
                     @click="handleUpdate(scope.row)" v-hasPermi="['system:relation:edit']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-success"
                     v-if="scope.row.auditStatus == '3'&&scope.row.matchStatus != '0'&&scope.row.matchStatus != '2' && status == '1'"
                     @click="handlePassOne(scope.row)" v-hasPermi="['system:relation:remove']">通过
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-back" v-if="scope.row.auditStatus == '3' && status == '1'"
                     @click="handleBackOne(scope.row)" v-hasPermi="['system:relation:edit']">退回修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-s-release"
                     v-if="scope.row.auditStatus == '3' && status == '1'"
                     @click="handleRejectOne(scope.row)" v-hasPermi="['system:relation:remove']">驳回
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
                     v-if="scope.row.auditStatus != '3' && scope.row.auditStatus != null"
                     v-hasPermi="['system:relation:edit']">查看
          </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 :visible.sync="open" width="1200px" append-to-body @close="cancel">
      <div style="display:flex ;width: 950px;">
        <div>
          <!-- 个人信息 -->
          <div style="display:flex ;width:650px;margin: 18px 0 0 0;">
            <div style="width:320px">
              <div style="font-size: 18px; text-align: center">学生报名信息</div>
              <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                <el-form-item label="姓名" prop="studentName">
                  <el-input v-model="form.studentName" placeholder="请输入学生姓名" :readOnly="isHandle"/>
                </el-form-item>
                <el-form-item label="身份证号" prop="idCard">
                  <el-input v-model="form.idCard" placeholder="请输入身份证号" @change="searchInfo" readOnly/>
                </el-form-item>
                <el-form-item label="学籍号" prop="studentNumber">
                  <el-input v-model="form.studentNumber" placeholder="请输入学籍号" :readOnly="isHandle"/>
                </el-form-item>
                <el-form-item label="初中学校" prop="schoolName" v-show="!isHandle">
                  <el-input v-model="form.schoolName" placeholder="请输入初中学校"
                            @click.native="selectSchool(a = false)"/>
                </el-form-item>
                <el-form-item label="测试项目" prop="project" v-show="!isHandle">
                  <el-input v-model="form.project" placeholder="请选择测试项目" readonly
                            @click.native="selectProjectList(a = false)"/>
                </el-form-item>
                <el-form-item label="初中学校" prop="schoolName" v-show="isHandle">
                  <el-input v-model="form.schoolName" placeholder="请输入初中学校" readOnly/>
                </el-form-item>
                <el-form-item label="测试项目" prop="project" v-show="isHandle">
                  <el-input v-model="form.project" placeholder="请选择测试项目" readOnly/>
                </el-form-item>
                <el-form-item label="性别：" prop="sex">
                  <el-select v-model="form.sex" placeholder="请选择学生性别" :disabled="isHandle">
                    <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
                               :value="dict.value">
                      {{ dict.label }}
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="联系方式1" prop="telephone1">
                  <el-input v-model="form.telephone1" placeholder="请输入联系方式" :readOnly="isHandle"/>
                </el-form-item>
              </el-form>
            </div>
            <!-- 照片 -->
            <div style="width:320px;padding: 0 0 0 20px;">
              <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                <el-form-item>
                  <el-upload v-loading="uploadLoading" class="avatar-uploader" action="#" accept="image/*"
                             :disabled="isHandle" :show-file-list="false" :on-success="handleAvatarSuccess"
                             :before-upload="beforeAvatarUpload" :http-request="uploadImage">
                    <img v-if="form.photo" :src="baseUrl + form.photo" class="avatar" alt=""/>
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                  </el-upload>
                  <div slot="error">
                    <img :src="isEmptyAvatar(form.photo, form.sex)"
                         style="width: 178px; height: 178px; border-radius: 50%" alt="">
                  </div>
                </el-form-item>
                <el-form-item label="身高" prop="height">
                  <el-input v-model="form.height" placeholder="请输入身高" :readOnly="isHandle"/>
                </el-form-item>
                <el-form-item label="体重" prop="weight">
                  <el-input v-model="form.weight" placeholder="请输入体重" :readOnly="isHandle"/>
                </el-form-item>
                <el-form-item label="联系方式2" prop="telephone2">
                  <el-input v-model="form.telephone2" placeholder="请输入联系方式" :readOnly="isHandle"/>
                </el-form-item>
              </el-form>
            </div>
          </div>
          <div slot="footer" v-if="!isHandle" style="text-align: center;">
            <el-button type="primary" @click="submitForm">保 存</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
          <div slot="footer" v-if="isHandle" class="dialog-footer"
               style="z-index: 10;top: 0;position: relative;left: 0;">
            <el-button @click="cancel" style="pointer-events: auto;">取 消</el-button>
          </div>
        </div>
        <!-- 教育局信息 -->
        <div style="width:350px;padding:0 0 0 20px;">
          <div style="font-size: 18px;text-align: center">教育局信息</div>
          <el-form ref="form" :model="form" :rules="rules" label-width="80px" style="margin:18px 0 0 0 ;">
            <el-form-item label="姓名" prop="eduStudentName">
              <el-input v-model="form.eduStudentName" placeholder="请输入学生姓名"/>
            </el-form-item>
            <el-form-item label="身份证号" prop="eduIdCard">
              <el-input v-model="form.eduIdCard" readOnly placeholder="请输入身份证号"/>
            </el-form-item>
            <el-form-item label="学籍号" prop="eduStudentNumber">
              <el-input v-model="form.eduStudentNumber" placeholder="请输入学籍号"/>
            </el-form-item>
            <el-form-item label="初中学校" prop="eduSchoolName" v-show="!isHandle">
              <el-input v-model="form.eduSchoolName" placeholder="请输入初中学校"
                        @click.native="selectSchool(a = true)"/>
            </el-form-item>
            <el-form-item label="测试项目" prop="eduProject" v-show="!isHandle">
              <el-input v-model="form.eduProject" placeholder="请选择测试项目" readonly
                        @click.native="selectProjectList(a = true)"/>
            </el-form-item>
            <el-form-item label="初中学校" prop="eduSchoolName" v-show="isHandle">
              <el-input v-model="form.eduSchoolName" placeholder="请输入初中学校" readOnly/>
            </el-form-item>
            <el-form-item label="测试项目" prop="eduProject" v-show="isHandle">
              <el-input v-model="form.eduProject" placeholder="请选择测试项目" readOnly/>
            </el-form-item>
            <el-form-item label="性别：" prop="eduSex">
              <el-select v-model="form.eduSex" placeholder="请选择学生性别" :disabled="isHandle">
                <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
                           :value="dict.value">
                  {{ dict.label }}
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </el-dialog>
    <!--导入文件对话框 -->
    <el-dialog :title="title" :visible.sync="uploadOpen" width="520px" append-to-body inline @close="cancel">
      <el-form ref="uploadForm" :model="form" :rules="rules" label-width="70px">
        <el-form-item prop="dataUrl">
          <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 text-center" slot="tip">
              <!--<div class="el-upload__tip" slot="tip">-->
              <!--  <el-checkbox v-model="upload.updateSupport"/>-->
              <!--  是否更新已经存在的用户数据-->
              <!--</div>-->
              <span>仅允许导入xls、xlsx格式文件。</span>
              <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline"
                       @click="importTemplate">下载模板
              </el-link>
            </div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--选择学校 -->
    <el-dialog title="选择学校" :visible.sync="schoolOpen" width="650px" append-to-body style="padding: 0 0 0 0">
      <el-form :model="searchParams" ref="queryForm" size="small" inline v-show="showSearch" label-width="100px">
        <el-form-item label="学校名称" prop="schoolName">
          <el-input v-model="searchParams.schoolName" placeholder="请输入学校名称" clearable
                    @keyup.enter.native="searchProject"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" plain icon="el-icon-search" size="mini" @click="searchSchool">搜索</el-button>
          <el-button plain icon="el-icon-refresh" size="mini" @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table style="width:560px;margin:0 25px 0 25px" ref="schoolSelect" max-height="250" v-loading="loading"
                :data="schoolList" size="small" highlight-current-row @row-click="schoolChange"
                @selection-change="schoolSelect"
                @select-all="selectAll">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="学校名称" align="center" prop="schoolName"/>
        <el-table-column label="学校代码" align="center" prop="schoolCode"/>
        <!-- <el-table-column prop="deptName" label="部门" align="center">
        </el-table-column> -->
      </el-table>
      <div style="text-align: center; margin: 35px 0 0 0">
        <el-button type="primary" @click="confirmSchool" size="small" style="margin: 0 10px 0 0">确 定
        </el-button>
        <el-button @click="close" size="small" style="margin: 0 30px 0 10px">取 消
        </el-button>
      </div>
    </el-dialog>
    <!--选择项目 -->
    <el-dialog title="选择项目" :visible.sync="projectOpen" width="650px" append-to-body style="padding: 0 0 0 0">
      <el-form :model="searchParams" ref="queryForm" size="small" inline v-show="showSearch" label-width="100px">
        <el-form-item label="项目名称" prop="project">
          <el-input v-model="searchParams.project" placeholder="请输入学校名称" clearable
                    @keyup.enter.native="searchProject"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" plain icon="el-icon-search" size="mini" @click="searchProject">搜索</el-button>
          <el-button plain icon="el-icon-refresh" size="mini" @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table style="width:560px;margin:0 25px 0 25px" ref="projectSelect" max-height="250" v-loading="loading"
                :data="projectList" size="small" highlight-current-row @row-click="projectChange"
                @selection-change="projectSelect" @select-all="selectAll">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="项目名称" align="center" prop="project"/>
      </el-table>
      <div style="text-align: center; margin: 35px 0 0 0">
        <el-button type="primary" @click="confirmProject" size="small" style="margin: 0 10px 0 0">确 定
        </el-button>
        <el-button @click="close" size="small" style="margin: 0 30px 0 10px">取 消
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  pass,
  back,
  reject,
  checkEnd,
  checkList,
  getStudent,
  delRelation,
  addRelation,
  updateRelation,
  commonUpload,
  getProjectList,
  listSchool,
  getPerInfo,
  rejectOne,
  backOne,
  passOne
} from "@/api/smartSchool/examinationManage";
import {getToken} from "@/utils/auth";
import {Gender, Nations} from "@/enums/common";

export default {
  name: "Relation",
  props: ['examId'],
  dicts: ["match_status", 'sys_user_sex', "registration_status", 'audit_status'],
  baseUrl: process.env.VUE_APP_BASE_API,
  created() {
    // this.getList();
    // this.getTestList()
    // this.getStatus()
  },
  data() {
    return {
      baseUrl: [process.env.VUE_APP_BASE_API],
      // 学校id
      schoolId: null,
      // 学校名称
      schoolName: null,
      // 项目id
      testId: null,
      // 项目名称
      project: null,
      // 遮罩层
      loading: true,
      //
      isEdu: null,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      relationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否修改
      isHandle: false,
      // 选择项目弹窗
      projectOpen: false,
      // 图片上传遮罩层
      uploadLoading: false,
      // 图片路径
      imageUrl: undefined,
      // 是否查看
      // isFullbg: false,
      // 导入对话框
      uploadOpen: false,
      // 选择学校
      schoolOpen: false,
      // 导出
      // exportType: '',
      //考试状态
      status: null,
      //个人信息审核状态状态
      auditStatus: null,
      //学校列表
      schoolList: null,
      // 测试项目
      projectList: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        examId: null,
        studentId: null,
        auditStatus: null,
        matchStatus: null,
        infoIdCard: null,
        submit: null,
        examNumber: null,
        inGroup: null,
        examDate: null,
        examTime: null,
        examAddress: null,
        score: null,
        result: null,
        passScore: null,
        step: null
      },
      // 查询参数
      searchParams: {},
      // 用户导入参数
      upload: {
        // 是否显示弹出层（学生导入）
        open: false,
        // 是否禁用上传
        //  isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + `/eduArtStudent/importData/${this.examId}`,
      },
      // 表单参数
      form: {
        eduStudentName: undefined
      },
      // 表单校验
      rules: {
        sex: [
          {required: true, message: "性别不能为空", trigger: "blur"}
        ],
        project: [
          {required: true, message: "测试项目不能为空", trigger: "blur"}
        ],
        schoolName: [
          {required: true, message: "初中学校不能为空", trigger: "blur"}
        ],
        studentNumber: [
          {required: true, message: "学籍号不能为空", trigger: "blur"}
        ],
        idCard: [
          {required: true, message: "身份证号不能为空", trigger: "blur"}
        ],
        studentName: [
          {required: true, message: "学生姓名不能为空", trigger: "blur"}
        ],
        telephone1: [
          {required: true, message: "联系电话1不能为空", trigger: "blur"}
        ],
        height: [
          {required: true, message: "身高不能为空", trigger: "blur"}
        ],
        weight: [
          {required: true, message: "体重不能为空", trigger: "blur"}
        ],
        telephone2: [
          {required: true, message: "联系电话2不能为空", trigger: "blur"}
        ],
        eduSex: [
          {required: true, message: "性别不能为空", trigger: "blur"}
        ],
        eduProject: [
          {required: true, message: "测试项目不能为空", trigger: "blur"}
        ],
        eduSchoolName: [
          {required: true, message: "初中学校不能为空", trigger: "blur"}
        ],
        eduStudentNumber: [
          {required: true, message: "学籍号不能为空", trigger: "blur"}
        ],
        eduStudentName: [
          {required: true, message: "学生姓名不能为空", trigger: "blur"}
        ],


      }
    };
  },

  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      checkList(this.examId, this.queryParams).then(response => {
        this.relationList = response.rows;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.uploadOpen = false;
      this.schoolOpen = false;
      this.projectOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        examId: null,
        studentId: null,
        auditStatus: "0",
        matchStatus: "0",
        infoIdCard: null,
        submit: null,
        examNumber: null,
        inGroup: null,
        examDate: null,
        examTime: null,
        examAddress: null,
        score: null,
        result: null,
        passScore: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        delFlag: null,
        step: null,
        photo: '',
      };
      this.imageUrl = ''
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 重置选择按钮操作 */
    resetSearch() {
      this.searchParams = {}
      this.searchSchool()
      this.searchProject()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.studentId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 导入按钮操作 */
    handleUpload(row) {
      this.reset();
      this.title = "导入"
      this.uploadOpen = true
    },
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
      // console.log(event, file, fileList);
    },

    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.uploadOpen = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + '</div>', '导入结果', {dangerouslyUseHTMLString: true})
      this.getList()
    },
    // 通过
    handlePass(row) {
      const examId = this.examId
      const id = row.studentId || this.ids
      let msg = ''
      this.$modal.confirm('是否确认通过审核？').then(function () {
        return pass(examId, id).then(res => {
          msg = res.msg
          // this.$modal.msgSuccess(res.msg);
        });
      }).then(() => {
        this.getList();
        this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + msg + '</div>', '通过结果', {dangerouslyUseHTMLString: true})
        // this.$modal.msgSuccess("审核通过");
      }).catch(() => {
      });

    },
    // 退回修改
    handleBack(row) {
      const examId = this.examId
      const id = row.studentId || this.ids
      let msg = ''
      this.$modal.confirm('是否确认退回修改数据？').then(function () {
        return back(examId, id).then(res => {
          // this.$modal.msgSuccess(res.msg);
          msg = res.msg
        });
        ;
      }).then(() => {
        this.getList();
        this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + msg + '</div>', '退回修改结果', {dangerouslyUseHTMLString: true})
      }).catch(() => {
      });
    },
    // 驳回
    handleReject(row) {
      const examId = this.examId
      const id = row.studentId || this.ids
      let msg = ''
      this.$modal.confirm('是否确认驳回？').then(function () {
        return reject(examId, id).then(res => {
          // this.$modal.msgSuccess(res.msg);
          // this.getList();
          msg = res.msg
        });
        ;
      }).then(() => {
        this.getList();
        this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + msg + '</div>', '驳回结果', {dangerouslyUseHTMLString: true})
        // this.$modal.msgSuccess("驳回成功");
      }).catch(() => {
      });
    },

    // 通过
    handlePassOne(row) {
      const examId = this.examId
      const id = row.studentId || this.ids
      // let msg = ''
      this.$modal.confirm('是否确认通过审核？').then(function () {
        return passOne(examId, id)
      }).then(() => {
        this.getList();
        // this.$modal.msgSuccess(msg);
        this.$modal.msgSuccess("审核通过");
      }).catch(() => {
      });

    },
    // 退回修改
    handleBackOne(row) {
      const examId = this.examId
      const id = row.studentId || this.ids

      this.$modal.confirm('是否确认退回修改该数据？').then(function () {
        return backOne(examId, id)
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("退回修改成功");
      }).catch(() => {
      });
    },
    // 驳回
    handleRejectOne(row) {
      const examId = this.examId
      const id = row.studentId || this.ids
      this.$modal.confirm('是否确认驳回？').then(function () {
        return rejectOne(examId, id)
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("驳回成功");
      }).catch(() => {
      });
    },

    // 结束
    handleFinished(row) {
      const examId = this.examId
      this.$confirm('是否确认结束该流程?').then(function () {
        return checkEnd(examId);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("结束成功");
        this.$emit("sendStatus")
      }).catch(() => {
      });

    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.isHandle = false
      // this.isFullbg = " "
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.isHandle = false
      this.reset();
      const id = row.studentId
      getStudent(id, this.examId).then(response => {
        this.form = response.data;
        this.imageUrl = this.isEmptyAvatar(this.form.photo, this.form.sex);
        this.open = true;
        this.title = "修改";
        // this.form.eduStudentName = row.eduStudentName
        this.$set(this.form, 'eduStudentName', row.eduStudentName)

        this.$set(this.form, 'eduIdCard', row.eduIdCard)
        // this.$set(this.form,'idCard',row.idCard)
        this.$set(this.form, 'eduStudentNumber', row.eduStudentNumber)
        this.$set(this.form, 'eduSchoolName', row.eduSchoolName)
        this.$set(this.form, 'eduProject', row.eduProject)
        this.$set(this.form, 'eduSex', row.eduSex)


        // this.form.eduIdCard = row.eduIdCard
        // this.form.idCard = row.infoIdCard
        // this.form.eduStudentNumber = row.eduStudentNumber
        // this.form.eduSchoolName = row.eduSchoolName
        // this.form.eduProject = row.eduProject
        // this.form.edusex = row.eduSex
      });
    },
    // 获取状态
    getStatus(statu) {
      this.getList();
      // 获取测试项目
      // getProjectList().then(response => {
      //   this.projectList = response.rows;
      // });
      this.status = statu
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.reset();
      this.isHandle = true
      const id = row.studentId
      getStudent(id, this.examId).then(response => {
        this.form = response.data;
        this.imageUrl = this.isEmptyAvatar(this.form.photo, this.form.sex);
        this.open = true;
        // this.isFullbg = "fullbg"
        this.title = "查看";
        this.form.eduStudentName = row.eduStudentName
        this.form.idCard = row.infoIdCard
        this.form.eduIdCard = row.eduIdCard
        this.form.eduStudentNumber = row.eduStudentNumber
        this.form.eduSchoolName = row.eduSchoolName
        this.form.eduProject = row.eduProject
        this.form.eduSex = row.eduSex
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        // this.form.eduSex = this.form.edusex
        if (valid) {
          if (this.form.id != null) {
            // this.form.eduIdCard = this.form.idCard
            updateRelation(this.examId, this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRelation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 获取个人信息
    searchInfo() {
      getPerInfo(this.form.idCard).then(res => {
        // this.form.studentName = res.data.studentName
        this.form.sex = res.data.sex
        // this.$nextTick(() => {
        //   this.$refs.form.clearValidate(['classAlias'])
        // })
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + ids + '"的数据项？').then(function () {
        return delRelation(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(`/artStudent/export/${this.examId}`, {
        ...this.queryParams
      }, `报名信息${Date.now()}.xlsx`)
    },
    // 下载模板
    importTemplate() {
      this.download(
        "/eduArtStudent/importTemplate",
        {},
        `导入教育局信息内模板_${Date.now()}.xlsx`
      );
    },
    // 上传图片
    uploadImage(file) {
      const fileData = file.file
      const formData = new FormData()
      formData.append('file', fileData)
      this.uploadLoading = true
      commonUpload(formData)
        .then(response => {
          this.uploadLoading = false
          this.$modal.msgSuccess('上传成功')
          this.imageUrl = this.pev + response.url
          console.log(response, 591);
          this.form.photo = response.fileName
        })
        .catch(error => {
          this.uploadLoading = false
        })
    },
    // 移除图片
    handleRemove() {
      this.imageUrl = undefined
    },
    // 上传前格式和图片大小限制
    beforeAvatarUpload(file) {
      const type = file.type === 'image/jpeg' || 'image/jpg' || 'image/webp' || 'image/png'
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!type) {
        this.$message.error('图片格式不正确!(只能包含jpg，png，webp，JPEG)')
      }
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 2MB!')
      }
      return type && isLt2M
    },
    // 上传成功回调
    handleAvatarSuccess(res, file) {
      this.imageUrl = res.data.url
      this.commonUpload(file)
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件`);
    },
    /** 判断学生头像是否为空 */
    isEmptyAvatar(imageUrl, sex) {
      if (!imageUrl) {
        let url = null;
        if (Gender.MALE === sex) {
          url = require('@/assets/images/boy.png');
        } else {
          url = require('@/assets/images/girl.png');
        }
        return url
      } else
        return this.baseUrl + imageUrl;
    },
    // 设置单元格样式
    setRowStyle(row, column, rowIndex, columnIndex) {
      if (row.columnIndex == "6") {
        if (row.row.studentName != row.row.eduStudentName) {
          return 'color: red;background-color: #D9EDF7'
        }
      }
      if (row.columnIndex == "7") {
        if (row.row.studentNumber != row.row.eduStudentNumber) {
          return 'color: red;background-color: #D9EDF7'
        }
      }
      if (row.columnIndex == "8") {
        if (row.row.schoolName != row.row.eduSchoolName) {
          return 'color: red;background-color: #D9EDF7'
        }
      }
      if (row.columnIndex == "9") {
        if (row.row.project != row.row.eduProject) {
          return 'color: red;background-color: #D9EDF7'
        }
      }
      if (row.columnIndex == "10") {
        if (row.row.sex != row.row.eduSex) {
          return 'color: red;background-color: #D9EDF7'
        }
      }
      if (row.columnIndex == "11") {
        if (row.row.studentName != row.row.eduStudentName) {
          return 'color: red;background-color: #F4CE98'
        }
      }
      if (row.columnIndex == "12") {
        if (row.row.studentNumber != row.row.eduStudentNumber) {
          return 'color: red;background-color: #F4CE98'
        }
      }
      if (row.columnIndex == "13") {
        if (row.row.schoolName != row.row.eduSchoolName) {
          return 'color: red;background-color: #F4CE98'
        }
      }
      if (row.columnIndex == "14") {
        if (row.row.project != row.row.eduProject) {
          return 'color: red;background-color: #F4CE98'
        }
      }
      if (row.columnIndex == "15") {
        if (row.row.sex != row.row.eduSex) {
          return 'color: red;background-color: #F4CE98'
        }
      }
      if (row.columnIndex == "6" || row.columnIndex == "7" || row.columnIndex == "8" || row.columnIndex == "9" || row.columnIndex == "10") {
        return 'background-color: #D9EDF7'
      }
      if (row.columnIndex == "11" || row.columnIndex == "12" || row.columnIndex == "13" || row.columnIndex == "14" || row.columnIndex == "15") {
        return 'background-color: #F4CE98'
      }


      // } else {
      //   return 'color: red'
      // }
    },
    // 关闭弹窗
    close() {
      this.schoolOpen = false;
      this.projectOpen = false;
    },
    // 选择学校
    selectSchool(a) {
      this.isEdu = a
      this.schoolOpen = true
      // listSchool().then(response => {
      //   this.schoolList = response.rows;
      // });
      this.searchSchool()
    },
    // 搜索学校
    searchSchool() {
      this.loading = true;
      listSchool(this.searchParams).then(response => {
        this.schoolList = response.rows;
        this.loading = false;
      });
    },
    // 选择测试项目
    selectProjectList(a) {
      this.isEdu = a
      this.projectOpen = true
      // getProjectList(this.examId).then(response => {
      //   this.projectList = response.rows;
      // });
      this.searchProject()
    },
    // 搜索项目
    searchProject() {
      this.loading = true;
      getProjectList(this.examId, this.searchParams).then(response => {
        this.projectList = response.rows;
        this.loading = false;
      });
    },
    //学校多选
    schoolSelect(selection) {
      if (selection.length > 1) {
        let del_row = selection.shift();
        this.$refs.schoolSelect.toggleRowSelection(del_row, false);

      }
      if (selection.length > 0) {
        this.schoolId = selection[0].id;
        this.schoolName = selection[0].schoolName
      }

    },
    //测试项目
    projectSelect(selection) {
      if (selection.length > 1) {
        let del_row = selection.shift();
        this.$refs.projectSelect.toggleRowSelection(del_row, false);

      }
      if (selection.length > 0) {
        this.testId = selection[0].id;
        this.project = selection[0].project
      }
    },
    // 点击全部复选框时触发
    selectAll(selection) {
      this.$refs.schoolSelect.clearSelection()  //清除勾选
      this.$refs.projectSelect.clearSelection()  //清除勾选
    },
    //项目单选
    projectChange(row) {
      this.testId = row.id;
      this.project = row.project
      this.$refs.projectSelect.toggleRowSelection(row)
    },
    //学校单选
    schoolChange(row) {
      this.schoolId = row.id;
      this.schoolName = row.schoolName
      this.$refs.schoolSelect.toggleRowSelection(row)
    },
    // 确认学校
    confirmSchool() {
      if (this.isEdu) {
        this.form.eduJuniorId = this.schoolId
        this.form.eduSchoolName = this.schoolName
        this.$nextTick(() => {
          this.$refs.form.clearValidate();
        })
      } else {
        this.form.juniorId = this.schoolId
        this.form.schoolName = this.schoolName
        this.$nextTick(() => {
          this.$refs.form.clearValidate();
        })
      }

      this.close()
    },
    // 确认项目
    confirmProject() {
      if (this.isEdu) {
        this.form.eduTestId = this.testId
        this.form.eduProject = this.project
        this.$nextTick(() => {
          this.$refs.form.clearValidate();
        })
      } else {
        this.form.testId = this.testId
        this.form.project = this.project
        this.$nextTick(() => {
          this.$refs.form.clearValidate();
        })
      }
      this.close()
    }
  }
};
</script>

<style scoped>
.fullbg {
  background-color: rgb(201, 201, 201);
  left: 0;
  opacity: 0.2;
  position: absolute;
  top: 0;
  z-index: 1;
  filter: alpha(opacity=50);
  width: 1000px;
  height: 800px;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
