<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">

      <el-form-item label="身份证号" prop="idCard">
        <el-input v-model="queryParams.idCard" 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>
        <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="['system:turnover: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:turnover: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:turnover: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:turnover:export']"-->
      <!--        >导出-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="turnoverList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="studentName" minWidth="100" />
      <!-- <el-table-column label="性别" align="center" minWidth="55" prop="sex">
        <template slot-scope="scope">
          <div v-if="scope.row.sex == 0">男</div>
          <div v-if="scope.row.sex == 1">女</div> -->
          <!-- <el-select v-model="scope.row.sex" disabled  filterable remote >
            <el-option style="margin-left:5px " v-for="item in sex" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select> -->
        <!-- </template> -->
      <!-- </el-table-column> -->
      <!-- <el-table-column label="学生身份证" minWidth="160" align="center" prop="idCard" /> -->
      <el-table-column label="全国学籍号" minWidth="120" align="center" prop="nationalNumber" />
      <el-table-column label="变更类型" minWidth="80" align="center" prop="changeType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.change_type" :value="scope.row.changeType"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="applyTime" minWidth="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" minWidth="70" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.change_status" :value="scope.row.state"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="办结时间" align="center" prop="endTime" minWidth="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="附件地址" align="center" prop="dataUrl" /> -->
      <el-table-column label="操作" align="center" min-width="300" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-s-release" @click="handleStop(scope.row)"
            v-if="scope.row.state == 0" v-hasPermi="['system:turnover:remove']">终止
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-finished" v-if="scope.row.state == 0"
            @click="handleFinish(scope.row)" v-hasPermi="['system:turnover:remove']">办结
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-if="scope.row.state == 0" v-hasPermi="['system:turnover:edit']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-if="scope.row.state == 0" v-hasPermi="['system:turnover:remove']">删除
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
            v-hasPermi="['system:turnover:remove']">查看
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-download" @click="handleDownload(scope.row)"
            v-if="scope.row.state == 0" v-hasPermi="['system:turnover: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 inline @close="cancel">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="申请时间" prop="applyTime">
              <el-date-picker clearable v-model="form.applyTime" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择申请时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="变更类型" prop="changeType">
              <el-select v-model="form.changeType" placeholder="请选择变更类型">
                <el-option v-for="dict in dict.type.change_type" :key="dict.value" :label="dict.label"
                  :value="dict.value">
                  {{ dict.label }}
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- <el-col :span="12"> -->
          <!-- <el-form-item label="学生身份证" prop="idCard" style="width: 340px;">
              <el-input v-model="form.idCard" placeholder="请输入学生身份证" @change="searchInfo"/>
            </el-form-item> -->
          <!-- </el-col> -->
          <el-col :span="12">
            <el-form-item label="学生姓名" prop="studentName" style="width: 340px;">
              <el-input v-model="form.studentName" placeholder="请选择学生" readonly @focus="selectStudent" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="监护人关系" prop="relationship">
              <!-- <el-input v-model="form.relationship" placeholder="请输入监护人关系" /> -->
              <el-select v-model="form.relationship" placeholder="请选择监护人关系" @change="searchRelationship">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row> -->
        <!-- <el-col :span="12"> -->
        <!-- <el-form-item label="性别" prop="sex"> -->
        <!-- <el-input v-model="form.isSave" placeholder="请输入是否保留" /> -->
        <!-- <el-select v-model="form.sex" placeholder="请选择性别">
                <el-option v-for="item in sex" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item> -->
        <!-- </el-col> -->
        <!-- <el-col :span="12">
            <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-col> -->
        <!-- </el-row> -->
        <el-row>

          <el-col :span="12">
            <el-form-item label="家长姓名" prop="parentName" style="width: 340px;">
              <el-input v-model="form.parentName" placeholder="请输入家长姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年级班级" prop="classAlias" style="width: 340px;">
              <el-input v-model="form.classAlias" placeholder="请输入年级班级" @focus="selectClass" />
              <!-- <el-cascader v-model="value" :options="classTree" clearable @change="handleChange" ></el-cascader> -->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="全国学籍号" prop="nationalNumber" style="width: 340px;">
              <el-input v-model="form.nationalNumber" placeholder="请输入全国学籍号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="住址" prop="homeAddress" style="width: 340px;">
              <el-input v-model="form.homeAddress" placeholder="请输入住址" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="telephone" style="width: 340px;">
              <el-input v-model="form.telephone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否保留" prop="isSave">
              <!-- <el-input v-model="form.isSave" placeholder="请输入是否保留" /> -->
              <el-select v-model="form.isSave" placeholder="请选择是否保留">
                <el-option v-for="item in isSave" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>

          <el-col :span="12">
            <el-form-item label="转出（入）学校" prop="turnSchool" style="width: 340px;">
              <el-input v-model="form.turnSchool" placeholder="请输入转出（入）学校" />
            </el-form-item>
          </el-col>
        </el-row>

      </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="title" :visible.sync="openView" width="800px" append-to-body inline @close="cancel">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="申请时间" prop="applyTime">
              <el-date-picker clearable v-model="form.applyTime" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择申请时间" readonly>
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="变更类型" prop="changeType">
              <el-select v-model="form.changeType" placeholder="请选择变更类型" disabled>
                <el-option v-for="dict in dict.type.change_type" :key="dict.value" :label="dict.label"
                  :value="dict.value">
                  {{ dict.label }}
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="学生身份证" prop="idCard" style="width: 340px;">
              <el-input v-model="form.idCard" placeholder="请输入学生身份证" @change="searchInfo" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名" prop="studentName" style="width:340px;">
              <el-input v-model="form.studentName" placeholder="请输入姓名" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <!-- <el-input v-model="form.isSave" placeholder="请输入是否保留" /> -->
              <el-select v-model="form.sex" placeholder="请选择性别" disabled>
                <el-option v-for="item in sex" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生年月" prop="birthday">
              <el-date-picker clearable v-model="form.birthday" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择出生年月" readonly>
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="监护人关系" prop="relationship">
              <!-- <el-input v-model="form.relationship" placeholder="请输入监护人关系" /> -->
              <el-select v-model="form.relationship" placeholder="请选择监护人关系" @change="searchRelationship" disabled>
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="家长姓名" prop="parentName" style="width: 340px;">
              <el-input v-model="form.parentName" placeholder="请输入家长姓名" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="年级班级" prop="classAlias" style="width: 340px;">
              <el-input v-model="form.classAlias" placeholder="请输入年级班级" readonly />
              <!-- <el-cascader v-model="value" :options="classTree" clearable @change="handleChange" ></el-cascader> -->
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="全国学籍号" prop="nationalNumber" style="width: 340px;">
              <el-input v-model="form.nationalNumber" placeholder="请输入全国学籍号" readonly />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="住址" prop="homeAddress" style="width: 340px;">
              <el-input v-model="form.homeAddress" placeholder="请输入住址" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="telephone" style="width: 340px;">
              <el-input v-model="form.telephone" placeholder="请输入联系电话" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否保留" prop="isSave">
              <!-- <el-input v-model="form.isSave" placeholder="请输入是否保留" /> -->
              <el-select v-model="form.isSave" placeholder="请选择是否保留" disabled>
                <el-option v-for="item in isSave" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="转出（入）学校" prop="turnSchool" style="width: 340px;">
              <el-input v-model="form.turnSchool" placeholder="请输入转出（入）学校" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="附件" prop="dataUrl">
          <div style="display:flex ;">
            <div style="max-width: 200px; overflow: hidden;  white-space: nowrap; text-overflow: ellipsis; ">
              {{ form.dataName }}
            </div>
            <el-button size="small" type="primary" @click="imgDownload()">下载附件</el-button>
          </div>
        </el-form-item>
      </el-form>

    </el-dialog>
    <!-- 办结对话框 -->
    <el-dialog :title="title" :visible.sync="openFinished" width="520px" append-to-body inline @close="cancel">
      <el-form ref="finishedForm" :model="form" :rules="finishedRules" label-width="70px">
        <el-form-item v-if="this.title == '办结'" label="附 件：" prop="dataUrl">
          <el-upload class="upload-demo" drag ref="upload" action="#" :before-remove="beforeRemove" multiple :limit="1"
            accept="image/jpg,image/jpeg,image/png" :on-exceed="handleExceed" :on-remove="uploadRemove"
            :before-upload="beforeUpload" :http-request="uploadFile">
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFinished">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 选择班级 -->
    <ClassSelect v-if="classOptions.open" :openSelect.sync="classOptions.open" :title="classOptions.title"
      @getClassList="getClassList" @setClassInfo="setClassInfo"></ClassSelect>
    <!-- 选择学生 -->
    <StudentInfoSelect v-if="studentOptions.open" :openSelect.sync="studentOptions.open" :title="studentOptions.title"
      @getStudentList="getStudentList" @setStudentInfo="setStudentInfo"></StudentInfoSelect>
  </div>
</template>

<script>
import {
  listStudent,
} from "@/api/smartSchool/teachAffairAdministration/stuEssentialInfAlert/index.js";
import {
  listTurnover,
  getTurnover,
  delTurnover,
  addTurnover,
  updateTurnover,
  finished,
  stop,
  commonUpload,
  getInfo,
  getRelationship,
} from "@/api/smartSchool/teachAffairAdministration/alterManage/index.js";
import ClassSelect from '@/views/smartSchool/teachAffairAdministration/alterManage/components/classSelect'
import { getClassList } from '@/api/smartSchool/classManage'
import StudentInfoSelect from '@/views/components/moduleComponets/studentInfoSelect/index';
export default {
  name: "alterManage",
  dicts: ["change_status", "change_type", "grade_type", "Grade"],
  components: {
    ClassSelect,
    StudentInfoSelect
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      turnoverList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //
      openView: false,
      openFinished: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        applyTime: null,
        changeType: null,
        idCard: null,
        studentName: null,
        relationship: null,
        sex: null,
        birthday: null,
        classId: null,
        nationalNumber: null,
        parentName: null,
        homeAddress: null,
        telephone: null,
        isSave: null,
        turnSchool: null,
        endTime: null,
        state: null,
        dataUrl: null
      },
      // 选择班级对话框
      classOptions: {
        open: false,
        title: '选择班级'
      },
      // 选择学生对话框
      studentOptions: {
        open: false,
        title: '选择学生'
      },
      // 行信息
      rowData: {},
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        studentName: [
          { required: true, message: "学生姓名不能为空", trigger: "blur" }
        ],
        // idCard: [
        //   { required: true, message: "身份证不能为空", trigger: "blur" }
        // ],
        applyTime: [
          { required: true, message: "申请时间不能为空", trigger: "blur" }
        ],
        changeType: [
          { required: true, message: "申请时间不能为空", trigger: "change" }
        ],
        // sex: [
        //   { required: true, message: "性别不能为空", trigger: "change" }
        // ],
        // birthday: [
        //   { required: true, message: "出生日期不能为空", trigger: "change" }
        // ],
        relationship: [
          { required: true, message: "监护人关系不能为空", trigger: "change" }
        ],
        parentName: [
          { required: true, message: "家长姓名不能为空", trigger: "blur" }
        ],
        classAlias: [
          { required: true, message: "年级班级不能为空", trigger: "change" }
        ],
        // nationalNumber: [
        //   { required: true, message: "全国学籍号不能为空", trigger: "blur" }
        // ],
        // homeAddress: [
        //   { required: true, message: "住址不能为空", trigger: "blur" }
        // ],
        telephone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        isSave: [
          { required: true, message: "请选择是否保留", trigger: "change" }
        ],
        turnSchool: [
          { required: true, message: "转出入学校不能为空", trigger: "blur" }
        ],
        dataUrl: [
          { required: true, message: "请上传附件", trigger: "change" }
        ],
      },
      finishedRules: {
        // dataUrl: [
        //   {required: true, message: "请上传附件", trigger: "change"}
        // ],
      },
      options: [{
        value: "0",
        label: "父亲 "
      }, {
        value: "1",
        label: "母亲 "
      }, {
        value: "2",
        label: "爷爷 "
      }, {
        value: "3",
        label: "奶奶 "
      }, {
        value: "4",
        label: "叔叔 "
      }, {
        value: "5",
        label: "姑姑 "
      }],
      isSave: [{
        value: "0",
        label: "是 "
      }, {
        value: "1",
        label: "否 "
      }],
      sex: [{
        value: "0",
        label: "男 "
      }, {
        value: "1",
        label: "女 "
      }],
      // 是否显示附件名称
      isShow: true
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listTurnover(this.queryParams).then(response => {
        this.turnoverList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 选择学生
    selectStudent() {
      this.studentOptions.open = true;
    },
    /** 获取学生信息列表 */
    getStudentList(queryForm, callback) {
      listStudent({ ...queryForm, gradeId: this.gradeId }).then(response => {
        callback(response.rows, response.total);
      }).catch(error => {
        callback([], 0);
      })
    },
    /** 设置学生信息 */
    setStudentInfo(item) {
      this.$set(this.form, 'studentName', item.studentName);
      this.$set(this.form, 'idCard', item.idCard);
      this.$set(this.form, 'studentId', item.id);
      this.$set(this.form, 'nation', item.nation);
      this.$set(this.form, 'newIdCard', item.idCard);
      this.$set(this.form, 'newNation', item.nation);
      this.$set(this.form, 'newStudentName', item.studentName);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openView = false;
      this.openFinished = false;
      this.reset();
      // this.$refs['upload'].clearFiles()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        applyTime: null,
        changeType: null,
        idCard: null,
        studentName: null,
        relationship: null,
        sex: null,
        birthday: null,
        classId: null,
        nationalNumber: null,
        parentName: null,
        homeAddress: null,
        telephone: null,
        isSave: null,
        turnSchool: null,
        endTime: null,
        state: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        dataUrl: null
      };
      this.isShow = true
      this.rowData = {}
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.throttle(() => {
        this.queryParams.pageNum = 1;
        this.getList();
      }, 1000)
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTurnover(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改";
      });
    },
    /** 终止按钮操作 */
    handleStop(row) {
      this.reset();
      const id = row.id
      this.$modal.confirm('是否确认终止？').then(function () {
        return stop(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("终止成功");
      }).catch(() => {
      });
    },
    /** 办结按钮操作 */
    handleFinish(row) {
      this.reset();
      this.rowData = row
      this.title = "办结"
      this.openFinished = true
    },
    // 确定办结
    submitFinished() {
      this.$refs["finishedForm"].validate(valid => {
        if (valid) {
          let query = {
            dataUrl: this.form.dataUrl,
            dataName: this.form.dataName,
          }
          finished(this.rowData.id, query).then(response => {
            this.$modal.msgSuccess("办结成功");
            this.openFinished = false;
            this.getList();
            this.$refs['upload'].clearFiles()
          });
        }
      });

    },
    // 下载
    handleDownload(row) {
      this.$router.push({
        path: '/teachAffairAdministration/alterCheck',
        query: {
          id: row.id,
          name: row.studentName,
        }
      })
    },
    // 查看
    handleView(row) {
      this.reset();
      const id = row.id || this.ids
      getTurnover(id).then(response => {
        this.form = response.data;
        this.openView = true;
        this.title = "查看";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.title == "修改") {
            updateTurnover(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.$refs['upload'].clearFiles()
            });
          } else {
            addTurnover(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.$refs['upload'].clearFiles()
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + ids + '"的数据项？').then(function () {
        return delTurnover(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/turnover/export', {
        ...this.queryParams
      }, `turnover_${new Date().getTime()}.xlsx`)
    },
    // 图片上传
    uploadFile(file) {
      const fileData = file.file
      const formData = new FormData()
      formData.append('file', fileData)
      this.uploadLoading = true
      commonUpload(formData)
        .then(response => {
          console.log(response)
          this.uploadLoading = false
          this.$modal.msgSuccess('上传成功')
          this.form.dataUrl = response.fileName
          this.form.dataName = response.newFileName
          this.isShow = false
        })
        .catch(error => {
          this.uploadLoading = false
        })
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件`);
    },
    /** 上传前 */
    beforeUpload(file) {
      //1MB=1024*1024(1MB=1024KB 1KB=1024MB)
      // const is1M = file.size / 1024 / 1024 < 1;
      // //限制文件上传大小
      // if (!is1M) {
      //   this.$message.error("上传文件大小不能超过 1MB!");
      //   return false
      // }
      // this.isUpload = true
      // return is1M
    },
    beforeRemove(file, fileList) {

    },
    //删除图片
    uploadRemove() {
      this.form.dataUrl = null
    },
    // 下载附件
    imgDownload() {
      if (this.form.dataName) {
        this.download(`studentTurnover/downloadPic/${this.form.id}`, {}, this.form.dataName)
      } else {
        this.$message('没有附件可下载');
      }
    },
    // 获取个人信息
    searchInfo() {
      getInfo(this.form.idCard).then(res => {
        this.form.studentName = res.data.studentName
        this.form.sex = res.data.sex
        this.form.birthday = res.data.birthday
        this.form.classAlias = res.data.classAlias
        this.$set(this.form, this.form.classAlias, res.data.classAlias)
        this.form.classId = res.data.classId
        this.form.nationalNumber = res.data.nationalNumber
        this.form.homeAddress = res.data.homeAddress
        this.form.telephone1 = res.data.telephone1
        this.form.studentId = res.data.id
        // this.$nextTick(() => {
        //   this.$refs.form.clearValidate(['classAlias'])
        // })
      });
    },
    searchRelationship() {
      getRelationship(this.form.studentId, this.form.relationship).then(res => {
        this.form.telephone = res.data.telephone
        this.form.parentName = res.data.parentName
      });
    },
    /** 选择班级(打开对话框) */
    selectClass() {
      this.classOptions.open = true
    },
    /** 设置班级信息 */
    setClassInfo(item) {
      console.log('item', item)
      this.$set(this.form, 'classId', item.id)
      this.$set(this.form, 'classAlias', item.classAlias)
      this.$nextTick(() => {
        this.$refs.form.clearValidate(['classAlias'])
      })
    },
    /** 获取班级信息列表 */
    getClassList(queryForm, callback) {
      getClassList(queryForm)
        .then(response => {
          callback(response.rows, response.total)
        })
        .catch(error => {
          callback([], 0)
        })
    },
  }
};
</script>
