<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="4" :xs="24">
        <div class="head-container">
          <el-input
            v-model="deptName"
            placeholder="请输入部门名称"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"
          />
        </div>
        <div class="head-container">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            default-expand-all
            highlight-current
            @node-click="handleNodeClick"
          />
        </div>
      </el-col>
      <el-col :span="20" :xs="24">

        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
          <el-form-item label="教职工姓名" clearable prop="teacherName">
            <el-input v-model="queryParams.teacherName" placeholder="请输入教职工姓名" clearable
                      @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="性别" prop="sex">
            <el-select v-model="queryParams.sex" style="width: 100%" @keyup.enter.native="handleQuery"
                       placeholder="请选择性别">
              <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
                         :value="dict.value"></el-option>
            </el-select>
          </el-form-item>
          <!--<el-form-item label="工作编号" clearable prop="teacherCode">-->
          <!--  <el-input v-model="queryParams.teacherCode" placeholder="请输入工作编号" clearable-->
          <!--            @keyup.enter.native="handleQuery"/>-->
          <!--</el-form-item>-->
          <el-form-item label="学历" prop="education">
            <el-select v-model="queryParams.education" style="width: 100%" @keyup.enter.native="handleQuery" clearable
                       placeholder="请选择学历">
              <el-option v-for="dict in dict.type.education" :key="dict.value" :label="dict.label"
                         :value="dict.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="教职工电话" clearable prop="teacherTel">
            <el-input v-model="queryParams.teacherTel" 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="['teacherManage:inform:add']">新增
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="info" plain icon="el-icon-search" size="mini" :disabled="single" @click="handleDetail">详情
            </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="['teacherManage:inform: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="['teacherManage:inform:remove']">删除
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport">导入</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                       v-hasPermi="['teacherManage:inform:export']">导出
            </el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="informList" :cell-style="cellStyle"
                  @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" :selectable="isSelected"/>
          <el-table-column label="头像" v-if="columns[0].visible" align="center" prop="picUrl">
            <template slot-scope="scope">
              <ListImage :image-url="scope.row.picUrl"></ListImage>
            </template>
          </el-table-column>
          <el-table-column label="教职工姓名" min-width="150" align="center" prop="teacherName">
            <template slot-scope="scope">
              <el-link type="primary" @click="handleDetail(scope.row)" :underline="false">{{
                  scope.row.teacherName
                }}
              </el-link>
            </template>
          </el-table-column>
          <el-table-column label="性别" v-if="columns[5].visible" 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="民族" v-if="columns[9].visible" align="center" prop="nation">-->
          <!--</el-table-column>-->
          <el-table-column label="工作编号" v-if="columns[3].visible" width="110px" align="center" prop="teacherCode"/>
          <!--<el-table-column label="生日" v-if="columns[4].visible" align="center" prop="birthday" width="120px">-->
          <!--  <template slot-scope="scope">-->
          <!--    <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>-->
          <!--  </template>-->
          <!--</el-table-column>-->
          <el-table-column label="学历" v-if="columns[6].visible" align="center" prop="education">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.education" :value="scope.row.education"/>
            </template>
          </el-table-column>
          <el-table-column label="教职工电话" v-if="columns[2].visible" width="120px" align="center" prop="teacherTel"/>
          <el-table-column label="身份证号" v-if="columns[7].visible" width="200px" align="center" prop="idCard"/>
<!--          <el-table-column label="家庭住址" v-if="columns[8].visible" width="200px" align="center" prop="homeAddress"/>-->
          <el-table-column label="操作" v-if="columns[10].visible" align="center" class-name="small-padding fixed-width"
                           min-width="200" fixed="right">
            <template slot-scope="scope">
              <el-button v-if="!(scope.row.id == '1')" size="mini" type="text" icon="el-icon-edit"
                         @click="handleUpdate(scope.row)"
                         v-hasPermi="['teacherManage:inform:edit']">修改
              </el-button>
              <el-button v-if="!(scope.row.id == '1')" size="mini" type="text" icon="el-icon-delete"
                         @click="handleDelete(scope.row)" v-hasPermi="['teacherManage:inform:remove']">删除
              </el-button>
              <el-dropdown size="mini" @command="command => handleCommand(command, scope.row)"
                           v-hasPermi="['system:user:resetPwd', 'system:user:edit']">
                <span class="el-dropdown-link"> <i class="el-icon-d-arrow-right el-icon--right"></i>更多 </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item command="handleHonor">荣誉编辑</el-dropdown-item>
                  <el-dropdown-item command="handleResume">履历编辑</el-dropdown-item>
                  <!--<el-dropdown-item command="handleClassView">任课班级</el-dropdown-item>-->
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
        <ExPagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"/>
      </el-col>
    </el-row>


    <!-- 添加或修改学校老师对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" :disabled="isDisabled" label-width="100px"
               style="width: 90%; margin: auto">
        <el-row>
          <el-col :span="12">
            <el-form-item label="教职工姓名" prop="teacherName">
              <el-input v-model="form.teacherName" placeholder="请输入教职工姓名"/>
            </el-form-item>
            <el-form-item label="性别" prop="sex">
              <el-select v-model="form.sex" style="width: 100%" placeholder="请选择性别">
                <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
                           :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="身份证号" prop="idCard">
              <el-input v-model.trim="form.idCard" placeholder="请输入身份证号"/>
            </el-form-item>
            <el-form-item v-if="form.id" label="手机号码" prop="teacherTel">
              <el-input v-model="form.teacherTel" placeholder="请输入老师电话"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="picUrl">
              <template slot-scope="scope">
                <el-upload v-loading="uploadLoading" class="avatar-uploader" action="#" accept="image/*"
                           :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload"
                           :http-request="uploadImage">
                  <img v-if="imageUrl" :src="imageUrl" class="avatar"/>
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
              </template>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12" v-if="!form.id">
            <el-form-item label="手机号码" prop="teacherTel">
              <el-input v-model="form.teacherTel" placeholder="请输入老师电话"/>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="!form.id">
            <el-form-item label="登录密码" prop="password">
              <el-input v-model="form.password" placeholder="请输入登录密码" type="password" maxlength="20"
                        show-password/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工作编号" prop="teacherCode">
              <el-input v-model="form.teacherCode" placeholder="请输入工作编号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="归属部门" prop="deptId">
              <treeselect :disabled="isDisabled" v-model="form.deptId" :options="deptOptions" :show-count="true"
                          :defaultExpandLevel="2"
                          :placeholder="isDisabled ? '' : '请选择归属部门'"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="岗位" prop="postId">
              <el-select v-model="form.postIds" multiple placeholder="请选择岗位" style="width: 100%">
                <el-option v-for="item in postOptions" :key="item.postId" :label="item.postName"
                           :value="item.postId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="角色" prop="roleId">
              <el-select v-model="form.roleIds" multiple placeholder="请选择角色" style="width: 100%">
                <el-option v-for="item in roleOptions" :key="item.roleId" :label="item.roleName"
                           :value="item.roleId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="生日" prop="birthday">
              <el-date-picker clearable v-model="form.birthday" type="date" style="width: 100%"
                              value-format="yyyy-MM-dd" placeholder="请选择生日"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="民族" prop="nation">
              <el-select v-model="form.nation" style="width: 100%" placeholder="请选择民族">
                <el-option v-for="item in Nations" :key="item.label" :label="item.label"
                           :value="item.label"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="学历" prop="education">
              <el-select v-model="form.education" style="width: 100%" placeholder="请选择学历">
                <el-option v-for="dict in dict.type.education" :key="dict.value" :label="dict.label"
                           :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="家庭住址" prop="homeAddress">
              <el-input v-model="form.homeAddress" placeholder="请输入家庭住址"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-show="!isDisabled" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">{{ isDisabled ? '退 出' : '取 消' }}</el-button>
      </div>
    </el-dialog>

    <!--    履历编辑-->
    <el-dialog title="履历信息" :visible.sync="resumeDialog" width="1000px" append-to-body>
      <h4 class="form-header h4">老师信息</h4>
      <el-form :model="resumeQuery" ref="resumeQuery" size="small" :inline="true" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="教师名称" clearable prop="teacherName">
              <el-input v-model="resumeQuery.teacherName" disabled clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-select disabled v-model="resumeQuery.sex" style="width: 100%" placeholder="请选择性别">
                <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
                           :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="教师电话" clearable prop="teacherTel">
              <el-input disabled v-model="resumeQuery.teacherTel" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工作编号" clearable prop="teacherCode">
              <el-input disabled v-model="resumeQuery.teacherCode" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <h4 class="form-header h4">履历信息</h4>
      <el-row class="mb8">
        <el-button type="primary" plain size="mini" icon="el-icon-plus" @click="resumeAdd">增加</el-button>
        <el-button type="success" plain size="mini" icon="el-icon-edit" :disabled="resumeSingle" @click="resumeEdit">
          修改
        </el-button>
        <el-button type="danger" plain size="mini" icon="el-icon-delete" :disabled="resumeMultiple"
                   @click="resumeDelete">删除
        </el-button>
        <el-button type="info" plain size="mini" icon="el-icon-close" @click="resumeDialog = false">关闭</el-button>
      </el-row>
      <el-table v-loading="loading" height="256" :data="resumeList" :cell-style="{ padding: '5px' }"
                @selection-change="handleResumeSelectionChange">
        <el-table-column type="selection" align="center" width="55"/>
        <el-table-column label="学校/工作单位" width="200" align="center" prop="learnSchool"/>
        <el-table-column label="履历开始时间" :formatter="dateFormat" width="200" align="center"
                         prop="learnStart"></el-table-column>
        <el-table-column label="履历结束时间" :formatter="dateFormat" width="200" align="center"
                         prop="learnEnd"></el-table-column>
        <el-table-column label="备注" align="center" prop="remark"/>
      </el-table>
    </el-dialog>

    <!--    履历编辑修改，新增弹窗-->
    <el-dialog :title="resumeTitle" :visible.sync="resumeAddEditDialog" width="800px">
      <el-form :model="resumeForm" :rules="resumeRules" ref="resumeForm" size="small" label-width="110px">
        <el-form-item label="学校/工作单位" clearable prop="learnSchool">
          <el-input v-model="resumeForm.learnSchool" clearable style="width: 100%"/>
        </el-form-item>
        <el-form-item label="履历开始时间" prop="learnStart">
          <el-date-picker v-model="resumeForm.learnStart" type="date" style="width: 100%"
                          placeholder="履历开始时间"></el-date-picker>
        </el-form-item>
        <el-form-item label="履历结束时间" clearable prop="learnEnd">
          <el-date-picker v-model="resumeForm.learnEnd" type="date" style="width: 100%"
                          placeholder="履历结束时间"></el-date-picker>
        </el-form-item>
        <el-form-item label="备注" clearable prop="remark">
          <el-input type="textarea" v-model="resumeForm.remark" clearable/>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="primary" @click="resumeAddButton">提交</el-button>
        <el-button @click="closeResume">取消</el-button>
      </div>
    </el-dialog>

    <!--    荣耀编辑-->
    <el-dialog title="荣誉信息" :visible.sync="honorDialog" width="1000px" append-to-body>
      <h4 class="form-header h4">老师信息</h4>
      <el-form :model="honorQuery" ref="honorForm" size="small" :inline="true" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="教师名称" clearable prop="teacherName">
              <el-input v-model="honorQuery.teacherName" disabled clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-select disabled v-model="honorQuery.sex" style="width: 100%" placeholder="请选择性别">
                <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
                           :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="教师电话" clearable prop="teacherTel">
              <el-input disabled v-model="honorQuery.teacherTel" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工作编号" clearable prop="teacherCode">
              <el-input disabled v-model="honorQuery.teacherCode" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <h4 class="form-header h4">荣誉信息</h4>
      <el-row class="mb8">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="honorAdd">增加</el-button>
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="honorSingle" @click="honorEdit">修改
        </el-button>
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="honorMultiple" @click="honorDelete">
          删除
        </el-button>
        <el-button type="info" plain size="mini" icon="el-icon-close" @click="honorDialog = false">关闭</el-button>
      </el-row>
      <el-table v-loading="loading" :data="honorList" :cell-style="{ padding: '5px' }" height="256"
                @selection-change="handleHonorSelectionChange">
        <el-table-column type="selection" align="center" width="55"/>
        <el-table-column label="荣誉照片" align="center" width="100">
          <template slot-scope="scope">
            <ListImage :image-url="scope.row.picUrl"></ListImage>
          </template>
        </el-table-column>
        <el-table-column label="获奖时间" width="150" align="center" prop="awardTime"/>
        <el-table-column label="荣耀级别" width="100" align="center" prop="honor">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.honor" :value="scope.row.honor"/>
          </template>
        </el-table-column>
        <el-table-column label="获奖名称" align="center" prop="awardName" show-overflow-tooltip/>
        <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip/>
      </el-table>
    </el-dialog>

    <!--    荣耀编辑修改，新增弹窗-->
    <el-dialog :title="honorTitle" :visible.sync="honorAddEditDialog" width="800px">
      <el-form :model="honorQueryAdd" ref="honorForm" :rules="honorRules" size="small" label-width="100px">
        <el-row type="flex" justify="center">
          <el-form-item label-width="0">
            <AvatarUploud :imgSrc.sync="honorQueryAdd.picUrl"></AvatarUploud>
            <div style="text-align: center">
              <span>获奖证书照片</span>
            </div>
          </el-form-item>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="获奖时间" clearable prop="awardTime">
              <el-date-picker style="width: 100%" v-model="honorQueryAdd.awardTime" type="date"
                              placeholder="选择日期"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="获奖名称" prop="awardName">
              <el-input v-model="honorQueryAdd.awardName" aria-placeholder="获奖名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="荣誉级别" clearable prop="honor">
              <el-select v-model="honorQueryAdd.honor" style="width: 100%" placeholder="请选择荣誉级别">
                <el-option v-for="dict in dict.type.honor" :key="dict.value" :label="dict.label"
                           :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" clearable prop="remark">
              <el-input type="textarea" v-model="honorQueryAdd.remark"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer">
        <el-button type="primary" @click="honorAddButton">提交</el-button>
        <el-button @click="closeHonor">取消</el-button>
      </div>
    </el-dialog>

    <!-- 导入 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <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>
      <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>

    <!-- 导出对话框 -->
    <ExportTable :open-export.sync="exportOptions.open" :title="exportOptions.title" @export="exportFile"></ExportTable>
  </div>
</template>

<script>
import {
  listInform,
  getInform,
  delInform,
  addInform,
  updateInform
} from '@/api/smartSchool/teacherManage/teacherInformation'
import AvatarUploud from './avatarUploud'
import {listResume, getOneResume, addResume, editResume, deleteResume} from '@/api/smartSchool/teacherManage/resume'
import {
  addTeacherAward,
  listTeacherAward,
  getTeacherAward,
  updateTeacherAward,
  delTeacherAward
} from '@/api/smartSchool/teacherManage/teacherAward'
import {CustomCellStyle} from '@/enums/customStyle'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import {ExportType, Gender, Nations} from '@/enums/common'
import {checkIdcard} from '@/utils/utilLibrary/validate'
import {getToken} from '@/utils/auth'
import {uploadImage as commonUpload} from '@/api/common'

export default {
  name: 'Inform',
  dicts: ['education', 'sys_user_sex', 'honor'],
  components: {
    AvatarUploud,
    Treeselect
  },
  data() {
    return {
      // 民族
      Nations,
      honorQueryAdd: {},
      honorTitle: undefined,
      honorQuery: {},
      resumeTitle: undefined,
      teacherId: undefined,
      resumeQuery: {},
      // 图片路径
      imageUrl: undefined,
      // 遮罩层
      loading: true,
      resumeListLoading: false,
      honorListLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // resume选中数组
      resumeIds: [],
      // 非单个禁用
      resumeSingle: true,
      // 非多个禁用
      resumeMultiple: true,
      // honor选中数组
      honorIds: [],
      // 非单个禁用
      honorSingle: true,
      // 非多个禁用
      honorMultiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学校老师表格数据
      informList: [],
      // 简历数据表格
      resumeList: [],
      honorList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      //履历dialog
      resumeDialog: false,
      resumeAddEditDialog: false,
      // 荣耀dialog
      honorDialog: false,
      honorAddEditDialog: false,
      // 履历查询参数
      resumeForm: {},
      // 荣耀查询参数
      honorForm: {},
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        teacherName: null,
        teacherTel: null,
        teacherCode: null,
        idCard: null,
        homeAddress: null,
        nation: null,
        picUrl: null,
        birthday: null,
        education: null,
        sex: null,
        deptId: null
      },
      // 表单参数
      form: {},
      // 列信息
      columns: [
        {key: 0, label: `头像`, visible: true},
        {key: 1, label: `老师名称`, visible: true},
        {key: 2, label: `老师电话`, visible: true},
        {key: 3, label: `工作编号`, visible: true},
        {key: 4, label: `生日`, visible: true},
        {key: 5, label: `性别`, visible: true},
        {key: 6, label: `学历`, visible: true},
        {key: 7, label: `身份证号`, visible: true},
        {key: 8, label: `家庭住址`, visible: true},
        {key: 9, label: `民族`, visible: true},
        {key: 10, label: `操作`, visible: true}
      ],
      // 表单校验
      rules: {
        teacherName: [{required: true, message: '老师名称不能为空', trigger: 'blur'}],
        teacherTel: [
          {required: true, message: '手机号码不能为空', trigger: 'blur'},
          {pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: '请输入正确的手机号码', trigger: 'blur'}
        ],
        password: [{required: true, message: '登录密码不能为空', trigger: 'blur'}],
        teacherCode: [
          {required: true, message: '工作编号不能为空', trigger: 'blur'},
          {message: '工作编号格式不正确', trigger: 'blur', pattern: /[0-9]\d*/}
        ],
        idCard: [{required: true, validator: checkIdcard, trigger: 'blur'}],
        deptId: [{required: true, message: '归属部门不能为空', trigger: 'change'}],
        // nation: [
        //   { required: true, message: "民族不能为空", trigger: "blur" }
        // ],
        // education: [
        //   { required: true, message: "学历不能为空", trigger: "blur" }
        // ],
        // birthday: [
        //   { required: true, message: "生日信息不能为空", trigger: "blur" }
        // ],
        sex: [{required: true, message: '性别不能为空', trigger: 'change'}]
      },

      // 履历校验规则
      resumeRules: {
        learnSchool: [{required: true, message: '学校/工作单位不能为空', trigger: 'blur'}],
        learnStart: [{required: true, message: '履历开始时间不能为空', trigger: 'blur'}],
        learnEnd: [{required: true, message: '履历结束时间不能为空', trigger: 'blur'}]
      },

      // 荣誉校验规则
      honorRules: {
        awardTime: [{required: true, message: '获奖时间不能为空', trigger: 'blur'}],
        awardName: [{required: true, message: '获奖名称不能为空', trigger: 'blur'}],
        honor: [{required: true, message: '荣誉级别不能为空', trigger: 'blur'}]
      },

      // 自定义列表单元格样式
      cellStyle: CustomCellStyle,
      // 部门列表数据
      deptOptions: [],
      // 岗位列表
      postOptions: [],
      // 角色列表
      roleOptions: [],
      // 默认密码
      initPassword: undefined,
      //导入
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {Authorization: 'Bearer ' + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/school/teacher/importData'
      },
      // 导出选项
      exportOptions: {
        title: '选择导出类别',
        open: false
      },
      // 上传状态
      uploadLoading: false,
      defaultProps: {
        children: "children",
        label: "label"
      },
      deptName: '',
      // 是否禁用表单
      isDisabled: false
    }
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getList();
    this.getDeptTree();
    // this.getConfigKey('sys.user.initPassword').then(response => {
    //   this.initPassword = response.msg
    // })
  },
  methods: {
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.handleQuery();
    },

    /** 查询学校老师列表 */
    getList() {
      this.loading = true;
      listInform(this.queryParams).then(response => {
        this.informList = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        teacherName: null,
        // userName: null,
        teacherTel: null,
        // phonenumber: null,
        teacherCode: null,
        idCard: null,
        homeAddress: null,
        nation: null,
        picUrl: null,
        birthday: null,
        education: null,
        sex: null,
        postIds: null,
        roleIds: null,
        deptId: null,
        password: null
      };
      this.imageUrl = '';
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.throttle(() => {
        this.queryParams.pageNum = 1;
        this.getList();
      })
    },
    getResumelist() {
      this.resumeListLoading = true
      listResume({teacherId: this.teacherId}).then(res => {
        if (res.code == 200) {
          this.resumeList = res.rows
          this.resumeListLoading = false
        } else {
          this.$message.error('数据请求失败')
          this.resumeListLoading = false
        }
      })
    },
    getHonorlist() {
      this.honorListLoading = true
      listTeacherAward({teacherId: this.teacherId}).then(res => {
        if (res.code == 200) {
          this.honorList = res.rows
          this.honorListLoading = false
        } else {
          this.$message.error('数据请求失败')
          this.honorListLoading = false
        }
      })
    },
    handleResume(row) {
      // this.resumeDialog = true;
      // // 获取履历上面表单的被禁用的部分
      // this.resumeQuery = row;
      // //将老师的id保存下来
      // this.teacherId = row.id;
      // this.resumeQuery.teacherId = this.teacherId;
      // // 获取履历下面表格的部分
      // this.getResumelist();
      this.$router.push({
        path: '/teachManage/teacherresume',
        query: {
          teacherId: row.id
        }
      })
    },
    handleHonor(row) {
      // this.honorDialog = true;
      // // 获取履历上面表单的被禁用的部分
      // this.honorQuery = row;
      // //将老师的id保存下来
      // this.teacherId = row.id;
      // this.honorQueryAdd.teacherId = this.teacherId;
      // // 获取履历下面表格的部分
      // this.getHonorlist();

      // 进入下一个页面
      this.$router.push({
        path: '/teachManage/profileaward',
        query: {
          // name: row.teacherName,
          // sex: row.sex,
          // phonenumber: row.teacherTel,
          // code: row.teacherCode
          teacherId: row.id
        }
      })
    },
    handleClassView(row) {
      this.$router.push({
        path: '/teachManage/classView',
        query: {
          teacherId: row.id
        }
      })
    },
    /** 重置按钮操作 */
    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.isDisabled = false;
      this.reset();
      this.open = true;
      this.title = '添加教职工信息';
      this.getPostAndRoleList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getPostAndRoleList();
      const id = row.id || this.ids;
      this.$modal.loading('正在加载数据，请稍等...');
      getInform(id).then(response => {
        this.$modal.closeLoading();
        this.form = response.data;
        this.imageUrl = this.form.picUrl;
        this.open = true;
        this.isDisabled = false;
        this.title = '修改教职工信息';
      }).catch(error => {
        this.$modal.closeLoading();
      })
    },
    /** 查看详情 */
    handleDetail(row) {
      this.reset();
      this.getPostAndRoleList()
      const id = row.id || this.ids;
      this.$modal.loading('正在加载数据，请稍等...');
      getInform(id).then(response => {
        this.$modal.closeLoading();
        this.form = response.data;
        this.imageUrl = this.form.picUrl;
        this.open = true;
        this.isDisabled = true;
        this.title = '查看教职工信息';
      }).catch(error => {
        this.$modal.closeLoading();
      })
    },
    // 上传成功回调
    handleAvatarSuccess(res, file) {
      this.imageUrl = res.data.url
      this.commonUpload(file)
    },
    // 上传前格式和图片大小限制
    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
    },

    // 上传图片
    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 = process.env.VUE_APP_BASE_API + response.url
          this.form.avatar = process.env.VUE_APP_BASE_API + response.url
        })
        .catch(error => {
          this.uploadLoading = false
        })
    },
    /** 提交按钮 */
    submitForm() {
      if (!this.form.picUrl) {
        if (this.form.sex === Gender.FEMALE) {
          this.form.picUrl = 'https://eos-wuxi-1.cmecloud.cn/dy-pro/image/2022/08/09/b076ed42bfca4a8cae062dfffd5f3618.jpg';
        } else {
          this.form.picUrl = 'https://eos-wuxi-1.cmecloud.cn/dy-pro/image/2022/08/09/8a6c1334494d418d8a53cc7bf5abd668.jpg';
        }
      }
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInform(this.form).then(response => {
              this.$modal.msgSuccess('修改成功');
              this.open = false;
              this.getList();
            })
          } else {
            addInform(this.form).then(response => {
              this.$modal.msgSuccess('新增成功');
              this.open = false;
              this.getList();
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {


      const ids = row.id || this.ids
      this.$modal
        .confirm(`是否确认删除选中的${Object.hasOwnProperty.call(ids, 'length') ? ids.length : 1}条数据？`)
        .then(() => {
          this.$modal.loading('正在删除数据，请稍等...');
          return delInform(ids);
        })
        .then(() => {
          this.$modal.closeLoading();
          this.$modal.msgSuccess('删除成功');
          this.getList();
        })
        .catch(() => {
          this.$modal.closeLoading();
        })


    },
    /** 导出按钮操作 */
    handleExport() {
      // 导出选中，导出全部，根据查询条件导出
      this.exportOptions.open = true
      // this.$confirm(`是否确认导出${ !!this.ids.length ? this.ids.length + '条' : '所有' }数据？`, '提示', {
      //   confirmButtonText: '确定',
      //   cancelButtonText: '取消',
      //   type: 'warning'
      // }).then(() => {
      //   if (this.ids.length) {
      //     this.download('/school/teacher/export/' + this.ids, {
      //       ...this.queryParams
      //     }, `教师信息.xlsx`)
      //   } else {
      //     this.download('/school/teacher/export', {
      //       ...this.queryParams
      //     }, `教师信息.xlsx`)
      //   }
      //
      // }).catch(() => {
      //
      // });
    },

    /** 导入按钮 */
    handleImport() {
      this.upload.title = '用户导入'
      this.upload.open = true
    },
    restResume() {
      this.resumeForm = {
        teacherId: this.teacherId,
        learnSchool: null,
        learnStart: null,
        learnEnd: null,
        remark: null
      }
      this.resetForm('resumeForm')
    },
    restHonor() {
      this.honorQueryAdd = {
        teacherId: this.teacherId,
        awardTime: null,
        learnStart: null,
        honor: null,
        remark: null,
        id: null
      }
      this.resetForm('honorForm')
    },

    /** 履历提交按钮 */
    resumeAddButton() {
      this.$refs['resumeForm'].validate(valid => {
        if (valid) {
          if (this.resumeForm.id != null) {
            editResume(this.resumeForm).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.resumeAddEditDialog = false
              this.getResumelist()
            })
          } else {
            addResume(this.resumeForm).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.resumeAddEditDialog = false
              this.getResumelist()
            })
          }
        }
      })
    },
    /** 荣誉提交按钮 */
    honorAddButton() {
      console.log('this.honorQuery.id', this.honorQuery.id)
      this.$refs['honorForm'].validate(valid => {
        if (valid) {
          if (this.honorQueryAdd.id != null) {
            updateTeacherAward(this.honorQueryAdd).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.honorAddEditDialog = false
              this.getHonorlist()
            })
          } else {
            addTeacherAward(this.honorQueryAdd).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.honorAddEditDialog = false
              this.getHonorlist()
            })
          }
        }
      })
    },
    /** 关闭荣誉修改对话框 */
    closeHonor() {
      this.honorAddEditDialog = false
      this.restHonor()
    },
    /** 关于履历修改对话框 */
    closeResume() {
      this.resumeDialog = false
      this.restResume()
    },

    // resume Dialog中选择框
    handleResumeSelectionChange(selection) {
      this.resumeIds = selection.map(item => item.id)
      this.resumeSingle = selection.length !== 1
      this.resumeMultiple = !selection.length
    },
    // honor Dialog中选择框
    handleHonorSelectionChange(selection) {
      this.honorIds = selection.map(item => item.id)
      this.honorSingle = selection.length !== 1
      this.honorMultiple = !selection.length
    },
    resumeAdd() {
      this.restResume()
      this.resumeTitle = '履历新增'
      this.resumeAddEditDialog = true
    },
    resumeDelete() {
      const ids = this.resumeIds
      this.$modal
        .confirm('是否确认删除所选履历信息数据项？')
        .then(function () {
          return deleteResume(ids)
        })
        .then(() => {
          this.getResumelist()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {

        })
    },
    resumeEdit() {
      this.resumeTitle = '履历修改'
      this.resumeAddEditDialog = true
      const id = this.resumeIds[0]
      getOneResume(id).then(res => {
        this.resumeForm = res.data
      })
    },
    honorAdd() {
      this.restHonor()
      this.honorTitle = '荣誉新增'
      this.honorAddEditDialog = true
    },
    honorDelete() {
      const ids = this.honorIds
      this.$modal
        .confirm('是否确认删除所选荣誉信息数据项？')
        .then(function () {
          return delTeacherAward(ids)
        })
        .then(() => {
          this.getHonorlist()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {
        })
    },
    honorEdit() {
      this.honorTitle = '荣誉信息修改'
      this.honorAddEditDialog = true
      const id = this.honorIds[0]
      getTeacherAward(id).then(res => {
        this.honorQueryAdd = res.data
      })
    },
    dateFormat(row, column, cellValue, index) {
      const daterc = row[column.property]
      if (daterc) {
        if (daterc.indexOf('T') === -1) return daterc
        const arr = daterc.split('T')
        const d = arr[0]
        const darr = d.split('-')
        const t = arr[1]
        const tarr = t.split('.000')
        const marr = tarr[0].split(':')
        const dd = darr[0] + '-' + darr[1] + '-' + darr[2]
        return dd
      }
    },
    /** 更多下拉菜单 */
    handleCommand(command, row) {
      this[command].apply(undefined, [row])
    },

    /** 查询部门下拉树结构 */
    getDeptTree() {
      this.$store
        .dispatch('getDeptTree')
        .then(response => {
          this.deptOptions = response
        })
        .catch(error => {
          this.deptOptions = []
        })
    },
    /** 查询岗位列表,角色列表 */
    getPostAndRoleList() {
      this.$store
        .dispatch('getPostList')
        .then(response => {
          this.postOptions = response.posts
          this.roleOptions = response.roles
        })
        .catch(error => {
          this.postOptions = []
          this.roleOptions = []
        })
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('school/teacher/importTemplate', {}, `老师信息模板_${new Date().getTime()}.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("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + '</div>', '导入结果', {dangerouslyUseHTMLString: true})
      this.getList()
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit()
    },
    /** 导出 */
    exportFile(callback) {
      const ids = this.ids
      const options = [
        {type: ExportType.TOTAL, path: '/school/teacher/export', params: {}},
        {type: ExportType.SELECT, path: '/school/teacher/export/' + ids, params: {}},
        {type: ExportType.QUERY, path: '/school/teacher/export', params: this.queryParams}
      ]
      callback(options, `老师信息${new Date().getTime()}.xlsx`)
    },

    /** 是否可以被勾选 */
    isSelected(row, index) {
      if (row.id == 1) {
        return false
      }
      return true
    }
  }
}
</script>
