<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="24">
                <el-card shadow="hover" class="mgb20">
                    <div class="flex-between">
                        <div class="per_title" @click="goback()">
                            <i class="el-icon-arrow-left"></i>
                            <span class="per_back">返回</span>
                            <span class="per_school" v-text="userId != '' ? '编辑用户信息' : '新增用户信息'"></span>
                        </div>
                        <el-button
                            type="primary"
                            size="small"
                            round
                            class="mag"
                            v-preventReClick
                            @click="saveAdd('form')"
                            v-show="userId == ''"
                        >确定</el-button>
                    </div>
                </el-card>

                <!-- 用户信息 -->
                <el-card shadow="hover" class="mgb20">
                    <div>
                        <div class="flex-between mgb20 user_header">
                            <div class="flex-center mgb20 user_header">
                                <p class="addhr_tag"></p>
                                <span>用户信息</span>
                            </div>
                            <el-button type="primary" size="small" round class="mag" @click="editUserInfo" v-preventReClick v-show="userId != ''">更新用户信息</el-button>
                        </div>

                        <div>
                            <div>
                                <p class="font_same">个人信息</p>
                                <el-form
                                    ref="form"
                                    :model="form"
                                    :rules="rules"
                                    label-width="120px"
                                >
                                    <el-col :span="6" :offset="5">
                                        <!-- 用户姓名 -->
                                        <el-form-item prop="userName" label="用户姓名">
                                            <el-input v-model="form.userName" placeholder="请输入"></el-input>
                                        </el-form-item>

                                        <!-- 证件类型 -->
                                        <el-form-item label="证件类型" prop="documentType">
                                            <el-select
                                                v-model="form.documentType"
                                                clearable
                                                placeholder="请选择证件类型"
                                            >
                                                <el-option
                                                    v-for="(item,index) in documentTypeList"
                                                    :key="index"
                                                    :label="item.name"
                                                    :value="item.value"
                                                ></el-option>
                                            </el-select>
                                        </el-form-item>

                                        <!-- 国家 -->
                                        <el-form-item label="国家">
                                            <el-select
                                                v-model="form.countries"
                                                clearable
                                                placeholder="请选择国家"
                                            >
                                                <el-option
                                                    v-for="(item,index) in countryList"
                                                    :key="index"
                                                    :label="item.name"
                                                    :value="item.value"
                                                ></el-option>
                                            </el-select>
                                        </el-form-item>

                                        <!-- 城市 -->
                                        <el-form-item label="城市">
                                            <el-select
                                                v-model="form.cityId"
                                                clearable
                                                placeholder="请选择城市"
                                                :disabled="form.provinceId ? false : true"
                                            >
                                                <el-option
                                                    v-for="(item,index) in cityList"
                                                    :key="index"
                                                    :label="item.cityName"
                                                    :value="item.cityId"
                                                ></el-option>
                                            </el-select>
                                        </el-form-item>

                                        <!-- 教育程度 -->
                                        <el-form-item label="教育程度">
                                            <el-select
                                                v-model="form.educationDegree"
                                                clearable
                                                placeholder="请选择教育程度"
                                            >
                                                <el-option
                                                    v-for="(item,index) in educationDegreeList"
                                                    :key="index"
                                                    :label="item.name"
                                                    :value="item.value"
                                                ></el-option>
                                            </el-select>
                                        </el-form-item>

                                        <!-- 所在院校 -->
                                        <el-form-item prop="schoolId" label="所在院校">
                                            <el-select v-model="form.schoolId" filterable clearable placeholder="请选择学校">
                                                <el-option v-for="(item,index) in schoolList" :key="index" :label="item.schoolName" :value="item.schoolId"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="6" :offset="2">
                                        <!-- 唯一识别码 -->
                                        <el-form-item label="唯一识别码">
                                            <el-input
                                                v-model="form.uniqueIdentificationAccount"
                                                placeholder="请输入"
                                                :disabled="true"
                                            ></el-input>
                                        </el-form-item>

                                        <!-- 证件号码 -->
                                        <el-form-item prop="IDNumber" label="证件号码">
                                            <el-input
                                                v-model="form.IDNumber"
                                                placeholder="请输入证件号码"
                                                maxlength="18"
                                                @change="numberChange"
                                            ></el-input>
                                        </el-form-item>

                                        <!-- 省份 -->
                                        <el-form-item label="省份">
                                            <el-select
                                                v-model="form.provinceId"
                                                clearable
                                                placeholder="请选择省份"
                                                @change="getCity"
                                            >
                                                <el-option
                                                    v-for="(item,index) in provinceList"
                                                    :key="index"
                                                    :label="item.provinceName"
                                                    :value="item.provinceId"
                                                ></el-option>
                                            </el-select>
                                        </el-form-item>

                                        <!-- 出生日期 -->
                                        <el-form-item label="出生日期">
                                            <el-date-picker
                                                type="date"
                                                placeholder="选择出生日期"
                                                v-model="form.dateBirth"
                                                style="width: 100%;"
                                                value-format="yyyy-MM-dd"
                                            ></el-date-picker>
                                        </el-form-item>

                                        <!-- 性别 -->
                                        <el-form-item label="性别">
                                            <el-select clearable
                                                v-model="form.sex"
                                                :disabled="IDdisabled"
                                                placeholder="请选择性别"
                                            >
                                                <el-option
                                                    v-for="(item,index) in sexList"
                                                    :key="index"
                                                    :label="item.name"
                                                    :value="item.value"
                                                ></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-form>
                            </div>

                            <div class="mgb20_top">
                                <p class="font_same">账号信息</p>
                                <el-form
                                    ref="form"
                                    :model="form"
                                    :rules="rules"
                                    label-width="120px"
                                >
                                    <el-col :span="24">
                                        <!-- <el-card shadow="hover" class="from_card"> -->
                                            <el-col :span="6" :offset="5">
                                                <!-- 个人手机 -->
                                                <el-form-item prop="phone" label="个人手机">
                                                    <el-input
                                                        v-model="form.phone"
                                                        placeholder="请输入手机号"
                                                        maxlength="11"
                                                        @change="phoneChange"
                                                    ></el-input>
                                                </el-form-item>

                                                <!-- 微信号 -->
                                                <el-form-item label="微信号">
                                                    <el-input v-model="form.WeChatID" placeholder="请输入微信号"></el-input>
                                                </el-form-item>                                              
                                            </el-col>

                                            <el-col :span="6" :offset="2">
                                                <!-- 邮箱 -->
                                                <el-form-item prop="email" label="邮箱">
                                                    <el-input v-model="form.email" placeholder="请输入邮箱地址"></el-input>
                                                </el-form-item>

                                                <!-- 账号 -->
                                                <el-form-item prop="account" label="账号">
                                                    <el-input
                                                        placeholder="请输入账号"
                                                        v-model="form.account"
                                                        @change="accountChange"
                                                    ></el-input>
                                                </el-form-item>                                               
                                            </el-col>
                                        <!-- </el-card> -->
                                    </el-col>
                                </el-form>
                            </div>
                        </div>
                    </div>
                </el-card>

                <!-- 个人档案 -->
                <el-card shadow="hover" class="mgb20">
                    <div>
                        <div class="flex-between mgb20 user_header">
                            <div class="flex-center">
                                <p class="addhr_tag"></p>
                                <span>个人档案</span>
                            </div>
                            <div>
                                <el-button type="primary" size="small" round class="mag" @click="editUserProfiles" v-preventReClick v-show="userId != ''">更新个人档案</el-button>
                                <el-button type="primary" size="small" round class="mag" @click="addArchives" v-preventReClick>添加档案</el-button>
                            </div>
                        </div>

                        <div>
                            <!-- <el-col :span="16" :offset="4"> -->
                            <div class="flex-center">
                                <el-col :span="16" :offset="4">
                                    <el-card shadow="hover" class="from_card">
                                        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                                            <div>
                                                <el-col :span="10">
                                                    <!-- 职业 -->
                                                    <el-form-item label="职业">
                                                        <el-select clearable
                                                            v-model="archivesForm.personalCareerId"
                                                            placeholder="请选择职业"
                                                        >
                                                            <el-option
                                                                v-for="item in occupationList"
                                                                :key="item.value"
                                                                :label="item.label"
                                                                :value="item.value"
                                                            ></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                    <!-- 院校 -->
                                                    <el-form-item label="院校">
                                                        <el-select v-model="archivesForm.schoolId" filterable clearable placeholder="请选择院校" @change="schoolChange">
                                                            <el-option v-for="(item,index) in schoolList" :key="index" :label="item.schoolName" :value="item.schoolId"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                    <!-- 专业类 -->
                                                    <el-form-item label="专业类">
                                                        <el-select
                                                            v-model="archivesForm.professionalClassId"
                                                            clearable
                                                            :disabled="archivesForm.disciplineId ? false : true"
                                                            placeholder="请选择专业类"
                                                            @change="getProfessional"
                                                            @clear="clearProfess()"
                                                        >
                                                            <el-option
                                                                v-for="(item,index) in ProfessionalClassList"
                                                                :key="index"
                                                                :label="item.professionalClassName"
                                                                :value="item.professionalClassId"
                                                            ></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                            </div>

                                            <div>
                                                <el-col :span="10" :offset="3">
                                                    <el-form-item>
                                                        <br />
                                                    </el-form-item>
                                                    <!-- 专业学科 -->
                                                    <el-form-item label="专业学科">
                                                        <el-select
                                                            v-model="archivesForm.disciplineId"
                                                            clearable
                                                            placeholder="请选择专业学科"
                                                            @change="getProfessionalClass"
                                                            @clear="clearClass()"
                                                        >
                                                            <el-option
                                                                v-for="(item,index) in subjectList"
                                                                :key="index"
                                                                :label="item.disciplineName"
                                                                :value="item.disciplineId"
                                                            ></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                    <!-- 专业 -->
                                                    <el-form-item label="专业">
                                                        <el-select
                                                            v-model="archivesForm.professionalId"
                                                            clearable
                                                            :disabled="archivesForm.professionalClassId ? false : true"
                                                            placeholder="请选择专业"
                                                            @change="getStuGrade"
                                                        >
                                                            <el-option
                                                                v-for="(item,index) in ProfessionalList"
                                                                :key="index"
                                                                :label="item.professionalName"
                                                                :value="item.professionalId"
                                                            ></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                            </div>
                                        </el-form>
                                    </el-card>
                                </el-col>
                                </div>

                                <!-- 循环档案 -->
                                <div class="flex-center" v-for="(item,index) in archivesList" :key="index">
                                    <el-col :span="16" :offset="4">
                                        <el-card shadow="hover" class="from_card">
                                            <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                                                <div>
                                                    <el-col :span="10">
                                                        <!-- 职业 -->
                                                        <el-form-item label="职业">
                                                            <el-select
                                                                v-model="item.personalCareerId"
                                                                placeholder="请选择职业"
                                                            >
                                                                <el-option
                                                                    v-for="item1 in occupationList"
                                                                    :key="item1.value"
                                                                    :label="item1.label"
                                                                    :value="item1.value"
                                                                ></el-option>
                                                            </el-select>
                                                        </el-form-item>
                                                        <!-- 院校 -->
                                                        <el-form-item label="院校">
                                                            <el-select v-model="item.schoolId" filterable clearable placeholder="请选择院校" @change="schoolitemChange">
                                                                <el-option v-for="(item,index) in schoolList" :key="index" :label="item.schoolName" :value="item.schoolId"></el-option>
                                                            </el-select>
                                                        </el-form-item>
                                                        <!-- 专业类 -->
                                                        <el-form-item label="专业类">
                                                            <el-select
                                                                v-model="item.professionalClassId"
                                                                :disabled="item.disciplineId ? false : true"
                                                                clearable
                                                                placeholder="请选择专业类"
                                                                @change="id => getItemProfessional(id,index)"
                                                                @clear="() => clearItemProfess(index)"
                                                            >
                                                                <el-option
                                                                    v-for="(item2,index) in item.ProfessionalClassList"
                                                                    :key="index"
                                                                    :label="item2.professionalClassName"
                                                                    :value="item2.professionalClassId"
                                                                ></el-option>
                                                            </el-select>
                                                        </el-form-item>
                                                    </el-col>
                                                </div>

                                                <div>
                                                    <el-col :span="10" :offset="3">
                                                        <el-form-item>
                                                            <br />
                                                        </el-form-item>
                                                        <!-- 专业学科 -->
                                                        <el-form-item label="专业学科">
                                                            <el-select
                                                                v-model="item.disciplineId"
                                                                clearable
                                                                placeholder="请选择专业学科"
                                                                @change="id => getItemProfessionalClass(id,index)"
                                                                @clear="() => clearItemClass(index)"
                                                            >
                                                                <el-option
                                                                    v-for="(item3,index) in item.subjectList"
                                                                    :key="index"
                                                                    :label="item3.disciplineName"
                                                                    :value="item3.disciplineId"
                                                                ></el-option>
                                                            </el-select>
                                                        </el-form-item>
                                                        <!-- 专业 -->
                                                        <el-form-item label="专业">
                                                            <el-select
                                                                v-model="item.professionalId"
                                                                :disabled="item.professionalClassId ? false : true"
                                                                clearable
                                                                placeholder="请选择专业"
                                                                @change="getItemStuGrade"
                                                            >
                                                                <el-option
                                                                    v-for="(item4,index) in item.ProfessionalList"
                                                                    :key="index"
                                                                    :label="item4.professionalName"
                                                                    :value="item4.professionalId"
                                                                ></el-option>
                                                            </el-select>
                                                        </el-form-item>
                                                    </el-col>
                                                </div>
                                            </el-form>
                                        </el-card>
                                    </el-col>

                                    <el-button type="primary" size="small" round class="magr50" @click="delItemArchives(index)">删除档案</el-button>
                                </div>
                        </div>                      
                    </div>
                </el-card>

                <!-- 已绑定系统 -->
                <el-card shadow="hover" class="mgb20">
                    <div class="flex-between mgb20">
                        <div class="flex-center">
                            <p class="addhr_tag"></p>
                            <span>已绑定系统</span>
                        </div>
                        <div>
                            <el-button
                                type="primary"
                                size="small"
                                round
                                class="mag"
                                @click="addUser"
                                :disabled="regionOption.length == 0"
                            >新增系统</el-button>

                            <el-dialog :title="region ? '编辑系统' : '新增系统'" :visible.sync="dialogFormVisible" :center="!isIE()" :close-on-click-modal="false" @close="regionclose">
                                <el-form :class="{region: !isIE()}" ref="chooseList" :rules="rules">
                                    <el-form-item label="系统选择" label-width="100px">
                                        <el-select
                                            v-model="region"
                                            placeholder="请选择系统"
                                        >
                                            <el-option
                                                v-for="(item,index) in regionOption"
                                                :key="index"
                                                :label="item.regionName"
                                                :value="item.regionId"
                                            ></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-form>
                                <div>
                                    <span class="radio">组织关系</span>
                                    <el-radio v-model="radio" label="1">绑定组织关系</el-radio>
                                    <el-radio v-model="radio" label="2" disabled>不绑定组织关系</el-radio>
                                </div>
                                <div class="flex">
                                    <el-button
                                        type="primary"
                                        size="small"
                                        round
                                        class="icon_btn"
                                        @click="addCustomer"
                                    >新增院校</el-button>
                                </div>
                                
                                <div>
                                <el-card shadow="hover" v-for="(item,index) in chooseList" :key="index" class="school_card">
                                    <p class="flex-between" style="font-weight: 600;">{{item.customerName}} <i class="el-icon-close remove-school" @click="removeSchool(item.customerId)"></i></p>
                                    <div class="flex_start">
                                        <span style="margin:20px 10px 20px 5px">角色选择</span>
                                        <el-checkbox-group v-for="item1 in item.checkList" :key="item1.id" v-model="item.roleIds">
                                            <el-checkbox :label="item1.id" class="checkboxItem">{{item1.label}}</el-checkbox>
                                        </el-checkbox-group>
                                    </div>

                                    <div class="card" :class="{isie: isIE()}">
                                        <!-- 管理员 -->
                                        <el-card shadow="hover" class="card_m" v-show="item.roleIds.indexOf(13) > -1">
                                            <div class="flex-between jobNumber">
                                                <span>管理员</span>
                                                <div class="numberInput">
                                                    <span>工号</span>
                                                    <el-input
                                                        placeholder="请输入工号"
                                                        v-model="item.staworkNumber"
                                                        @change="worknumberChange(item)"
                                                    ></el-input>
                                                </div>
                                            </div>

                                            <div class="flex_start jobNumber">
                                                <div class="flex_start">
                                                    <span>一级部门</span>
                                                    <el-select
                                                        v-model="item.staffProfessionalArchitectureId"
                                                        clearable
                                                        placeholder="请选择一级部门"
                                                        @clear="clearStaffPro" 
                                                        @change="getStaffGradeList"
                                                    >
                                                        <el-option
                                                            v-for="(item2,index2) in item.firstClassList"
                                                            :key="index2"
                                                            :label="item2.staffProfessionalArchitectureName"
                                                            :value="item2.staffProfessionalArchitectureId"
                                                        ></el-option>
                                                    </el-select>
                                                </div>
                                                <div class="flex_start secondaryDepartments">
                                                    <span>二级部门</span>
                                                    <el-select
                                                        v-model="item.staffGradeId"
                                                        clearable
                                                        placeholder="请选择二级部门"
                                                        :disabled="item.staffProfessionalArchitectureId ? false : true"
                                                        @change="StaffGradeChange"
                                                    >
                                                        <el-option
                                                            v-for="(item3,index3) in item.twoClassList"
                                                            :key="index3"
                                                            :label="item3.staffGradeName"
                                                            :value="item3.staffGradeId"
                                                        ></el-option>
                                                    </el-select>
                                                </div>
                                            </div>
                                        </el-card>
                                        <!-- 教师 -->
                                        <el-card shadow="hover" class="card_m" v-show="item.roleIds.indexOf(14) > -1">
                                            <div class="flex-between jobNumber">
                                                <span>教师</span>
                                                <div class="numberInput">
                                                    <span>工号</span>
                                                    <el-input
                                                        placeholder="请输入工号"
                                                        v-model="item.teaworkNumber"
                                                        @change="teaworknumberChange(item)"
                                                    ></el-input>
                                                </div>
                                            </div>
                                            <div class="flex_start jobNumber">
                                                <div class="flex_start">
                                                    <span>一级部门</span>
                                                    <el-select
                                                        v-model="item.teacherstaffProId"
                                                        clearable
                                                        placeholder="请选择一级部门"
                                                        @clear="clearteacherStaffPro" 
                                                        @change="teacherStaffGradeList"
                                                    >
                                                        <el-option
                                                            v-for="(item4,index4) in item.firstClassList"
                                                            :key="index4"
                                                            :label="item4.staffProfessionalArchitectureName"
                                                            :value="item4.staffProfessionalArchitectureId"
                                                        ></el-option>
                                                    </el-select>
                                                </div>
                                                <div class="flex_start secondaryDepartments">
                                                    <span>二级部门</span>
                                                    <el-select
                                                        v-model="item.teacherstaffGradeId"
                                                        clearable
                                                        placeholder="请选择二级部门"
                                                        :disabled="item.teacherstaffProId ? false : true"
                                                        @change="teacherStaffGradeChange"
                                                    >
                                                        <el-option
                                                            v-for="(item5,index5) in item.teachertwoClassList"
                                                            :key="index5"
                                                            :label="item5.staffGradeName"
                                                            :value="item5.staffGradeId"
                                                        ></el-option>
                                                    </el-select>
                                                </div>
                                            </div>
                                        </el-card>
                                        <!-- 学生 -->
                                        <el-card shadow="hover" class="card_m" v-show="item.roleIds.indexOf(4) > -1">
                                            <div class="flex-between jobNumber">
                                                <span>学生</span>
                                                <div class="numberInput">
                                                    <span>学号</span>
                                                    <el-input
                                                        placeholder="请输入学号"
                                                        v-model="item.stuworkNumber"
                                                        @change="stuworknumberChange(item)"
                                                    ></el-input>
                                                </div>
                                            </div>
                                            <div class="flex_start jobNumber">
                                                <div class="flex_start stu_input">
                                                    <span>专业</span>
                                                    <el-select
                                                        v-model="item.stuprofessionalId"
                                                        clearable
                                                        placeholder="请选择专业"
                                                        @clear="clearstuPro" 
                                                        @change="getStuPro"
                                                    >
                                                        <el-option
                                                            v-for="(item6,index6) in item.studentFirstList"
                                                            :key="index6"
                                                            :label="item6.stuProfessionalArchitectureName"
                                                            :value="item6.stuProfessionalArchitectureId"
                                                        ></el-option>
                                                    </el-select>
                                                </div>
                                                <div class="flex_start stu_input">
                                                    <span>年级</span>
                                                    <el-select
                                                        v-model="item.stugradeId"
                                                        clearable
                                                        :disabled="item.stuprofessionalId ? false : true"
                                                        placeholder="请选择年级"
                                                        @change="getStuClass" 
                                                        @clear="clearStuGrade"
                                                    >
                                                        <el-option
                                                            v-for="(item7,index7) in item.studentTwoList"
                                                            :key="index7"
                                                            :label="`${item7.gradeName}年级`"
                                                            :value="item7.gradeId"
                                                        ></el-option>
                                                    </el-select>
                                                </div>
                                                <div class="flex_start stu_input">
                                                    <span>班级</span>
                                                    <el-select
                                                        v-model="item.stuclassId"
                                                        :disabled="item.stugradeId ? false : true"
                                                        clearable
                                                        placeholder="请选择班级"
                                                        @change="StuClassChange"
                                                    >
                                                        <el-option
                                                            v-for="(item8,index8) in item.studentThreeClass"
                                                            :key="index8"
                                                            :label="`${item8.className}班`"
                                                            :value="item8.classId"
                                                        ></el-option>
                                                    </el-select>
                                                </div>
                                            </div>
                                        </el-card>
                                    </div>
                                </el-card>
                                </div>

                                <el-dialog
                                    width="30%"
                                    :visible.sync="innerVisible"
                                    append-to-body
                                    :close-on-click-modal="false"
                                    center
                                >
                                    <div class="flex-between mgb20">
                                        <div class="flex-center">
                                            <p class="addhr_tag"></p>
                                            <span>院校列表</span>
                                        </div>
                                        <div>
                                            <el-input placeholder="请输入系统名称" prefix-icon="el-icon-search" v-model="cusSearch" clearable @input="addCustomer"></el-input>
                                        </div>
                                    </div>

                                    <el-table :data="customerList" stripe header-align="center" @selection-change="SelectionCus" height="250">
                                        <el-table-column type="selection" width="55" align="center"></el-table-column>
                                        <el-table-column type="index" width="100" label="序号" align="center">
                                        </el-table-column>
                                        <el-table-column prop="customerName" label="客户名称" align="center">
                                        </el-table-column>
                                    </el-table>

                                    <div slot="footer" class="dialog-footer">
                                        <el-button @click="innerVisible = false">取 消</el-button>
                                        <el-button
                                            type="primary"
                                            v-preventReClick
                                            @click="cusSure"
                                        >确 定</el-button>
                                    </div>
                                </el-dialog>

                                <div slot="footer" class="dialog-footer">
                                    <el-button @click="dialogFormVisible = false">取 消</el-button>
                                    <el-button
                                        type="primary"
                                        v-preventReClick
                                        @click="ChooseListSure"
                                    >确 定</el-button>
                                </div>
                            </el-dialog>

                            <!-- <el-button
                                type="primary"
                                size="small"
                                round
                            >批量删除</el-button> -->
                        </div>
                    </div>

                    <el-table
                        :data="platformList"
                        class="table"
                        stripe
                        header-align="center"
                        @selection-change="handleSelectionChange"
                        :row-key="getRowKeys"
                    >
                        <el-table-column
                            type="selection"
                            width="55"
                            align="center"
                            :reserve-selection="true"
                        ></el-table-column>
                        <el-table-column type="index" width="100" label="序号" align="center"></el-table-column>
                        <el-table-column prop="platformName" label="系统名称" align="center"></el-table-column>
                        <el-table-column prop="domainName" label="域名" align="center"></el-table-column>
                        <el-table-column prop="createTime" label="创建时间" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <!-- <el-button type="text">查看</el-button> -->
                                <el-button v-show="userId != ''" type="text" @click="edit(scope.row)">编辑</el-button>
                                <el-button type="text" @click="handleDelete(scope.row,scope.$index)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>
export default {
    name: 'baseform',
    data() {
        return {
            //管理员
            jobNumber: '', //工号
            primaryDepartment: '', //一级部门
            secondaryDepartments: '', //二级部门
            // 教师
            jobNumber_T: '', //工号
            primaryDepartment_T: '', //一级部门
            secondaryDepartments_T: '', //二级部门
            //学生
            stuNumber: '', //学号
            major: '', //专业
            year: '', //年级
            class: '', //班级
            region: '', // 系统选择
            checkList: [{
                label: '管理员',
                id: 13
            },
            {
                label: '教师',
                id: 14
            },
            {
                label: '学生',
                id: 4
            }], //角色选择
            radio: '1', //组织关系
            innerVisible: false,
            dialogFormVisible: false,
            form: {
                //个人信息
                userId: this.$store.state.userId,
                userName: '', //用户姓名
                uniqueIdentificationAccount: '', //唯一识别码
                documentType: 1, //证件类型
                IDNumber: '', //证件号码
                cityId: '', //省份
                countries: '中国', //国家
                provinceId: '', //城市
                dateBirth: '', //出生日期
                educationDegree: '', //教育程度
                sex: '', //性别
                schoolId: '', //学校

                //账号信息
                phone: '', //手机号码
                WeChatID: '', //微信
                email: '', //邮箱
                account: '' //账号
            },
            occupationList: [{
                value: 1,
                label: '学生'
            },
            {
                value: 2,
                label: '老师'
            }],
            roleIds: [],
            archivesForm: {
                //个人档案
                personalCareerId: '', //职业
                schoolId: '', //院校
                schoolName: '', //院校名称
                professionalClassId: '', //专业类
                professionalClassName: '', //专业类名称
                disciplineId: '', //专业学科
                disciplineName: '', //专业学科名称
                professionalId: '', //专业
                professionalName: '', //专业名称
                userId: this.$store.state.userId
            },
            archivesList: [],
            rules: {
                userName: [{ required: true, message: '请输入用户姓名', trigger: 'blur' }],
                schoolId: [{ required: true, message: '请选择所在院校', trigger: 'change' }],
                account: [
                    { required: true, message: '请输入账号', trigger: 'blur' },
                    // {
                    //     pattern: /^[0-9]*$/,
                    //     message: '账号必须为数字',
                    //     trigger: 'blur'
                    // }
                ],
                phone: [
                    // { required: true, message: '请输入手机号', trigger: 'blur' },
                    {
                        pattern: /^1[3456789]\d{9}$/,
                        message: '请输入正确的手机号',
                        trigger: 'blur'
                    }
                ],
                IDNumber: [
                    // { required: true, message: '请输入证件号码', trigger: 'blur' },
                    {
                        pattern: /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)/,
                        message: '请输入正确的证件号码',
                        trigger: 'blur'
                    }
                ],
                email: [
                    // { required: true, message: '请输入邮箱', trigger: 'blur' },
                    {
                        pattern: /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/,
                        message: '请输入正确的邮箱',
                        trigger: 'blur'
                    }
                ]
            },
            sexList: [
                {
                    name: '男',
                    value: 1
                },
                {
                    name: '女',
                    value: 2
                }
            ],
            documentTypeList: [
                {
                    name: '居民身份证',
                    value: 1
                }
            ],
            // 教育程度
            educationDegreeList: [
                {
                    name: '专科',
                    value: 1
                },
                {
                    name: '本科',
                    value: 2
                },
                {
                    name: '硕士',
                    value: 3
                },
                {
                    name: '博士',
                    value: 4
                },
                {
                    name: '其他',
                    value: 5
                }
            ],
            subjectList: [], //专业学科
            ProfessionalClassList: [], //专业类
            ProfessionalList: [], //专业
            //国家
            countryList: [
                {
                    name: '中国'
                }
            ],
            schoolList: [],
            cityList: [], //城市
            provinceList: this.$store.state.provinceList, //省份
            userId: this.$store.state.userId,
            IDdisabled: false,
            regionOption: [{
                regionName: '教学平台',
                regionId: 1
            },
            {
                regionName: '数据平台',
                regionId: 2
            }], //系统选择
            secondaryDepartmentsList: [], //二级部门
            secondaryDepartmentsList_T: [], //二级部门
            majorList: [], //学生—专业
            yearList: [], //学生—年级
            classList: [], //学生—班级
            multipleSelection: [],
            customerList: [], //客户列表
            cusSearch: '',
            chooseCusList: [],
            choosecusArr: '',
            chooseList: [],
            NoAdd: true,
            AccountNoAdd: true,
            NumberNoAdd: true,
            teaNumberNoAdd: true,
            stuNumberNoAdd: true,
            platformList: [], //平台系统列表
            saveList: [],
            roldform: {

            },
            clickFlag: true,
            searchTimer: null
        };
    },
    mounted() {
        this.getSchoolData()
        this.getSubject()
        if(this.userId){
            this.$get(this.api.queryUserInfoDetails,{ userId: this.userId }).then(res => {
                        this.form.userName = res.message.userInfo.userName,
                        this.form.uniqueIdentificationAccount = res.message.userInfo.uniqueIdentificationAccount,
                        this.form.documentType = res.message.userInfo.documentType,
                        this.form.IDNumber = res.message.userInfo.iDNumber,
                        this.form.cityId = res.message.userInfo.cityId,
                        this.form.countries = res.message.userInfo.countries,
                        this.form.provinceId = res.message.userInfo.provinceId,
                        this.form.dateBirth = res.message.userInfo.dateBirth,
                        this.form.educationDegree = res.message.userInfo.educationDegree,
                        this.form.sex = res.message.userInfo.sex,
                        this.form.schoolId = res.message.userInfo.schoolId,
                        this.form.phone = res.message.userInfo.phone,
                        this.form.WeChatID = res.message.userInfo.weChatID,
                        this.form.email = res.message.userInfo.email,
                        this.form.account = res.message.userInfo.account
                        if(res.message.userInfo.provinceId){
                            this.getCityData()
                        }
                        // 个人档案
                        if(res.message.userProfilesList[0]){
                            this.archivesForm = res.message.userProfilesList[0]
                            if(res.message.userProfilesList[0].disciplineId){
                                this.getProfessionalClassData(res.message.userProfilesList[0].disciplineId)
                            }
                            if(res.message.userProfilesList[0].professionalClassId){
                                this.getProfessionalData(res.message.userProfilesList[0].professionalClassId)
                            }
                        }else{
                            this.archivesForm = {}
                        }
                        // 循环档案
                        this.archivesList = res.message.userProfilesList.splice(1, 2)
                        if(this.archivesList.length != 0){
                            this.archivesList.map(e =>{
                                this.$set(e, 'subjectList', this.subjectList);
                                if(e.disciplineId){
                                    this.$get(this.api.queryCourseProfessionalClass,{ disciplineId: e.disciplineId }).then(res => {
                                        this.$set(e, 'ProfessionalClassList', res.message);
                                    }).catch(res => {});
                                }
                                if(e.professionalClassId){
                                    this.$get(this.api.queryCourseProfessional,{ professionalClassId: e.professionalClassId }).then(res => {
                                        this.$set(e, 'ProfessionalList', res.message);
                                    }).catch(res => {});
                                }
                            })
                        }

                        // 平台系统 edit
                        // this.platformList = res.message.platformList
                        let staffPlatformList = res.message.staffPlatformList
                        let studentPlatformList = res.message.studentPlatformList
                        this.platformList = staffPlatformList
                        if(this.platformList.length == 1){
                            studentPlatformList.forEach((n,k) => {
                                if(n.platformId != this.platformList[0].platformId){
                                    this.platformList.push(n)
                                }
                            })
                        }else if(!this.platformList.length){
                            this.platformList = studentPlatformList
                        }
                        this.platformList.map(e =>{
                            this.regionOption.map((r,index) =>{
                                if(r.regionId == e.platformId){
                                    this.regionOption.splice(index,1)
                                }
                            })
                        })

                }).catch((res) => {
            })
        }
    },
    methods: {
        async getInfo(item ,index){
            let res = await this.$get(this.api.queryUserOR, { userId: this.userId, platformId: item.platformId})
            return (res.message)
        },
        // 获取城市
        getCity(){
            if(this.form.provinceId){
                this.getCityData()
            }
        },
        getCityData(){
            this.$get(this.api.queryCity,{provinceId: this.form.provinceId}).then(res => {
                this.cityList = res.message
            }).catch(res => {});
        },
        // 获取学校名称
        schoolChange(val){
            if(val){
                let obj = {};
                obj = this.schoolList.find(r =>{
                    return r.schoolId === val;
                });
                this.archivesForm.schoolName = obj.schoolName
            }
        },
        // 获取列表学校名称
        schoolitemChange(item){
            if(item){
                this.archivesList.map(e =>{
                    if(e.schoolId == item){
                        let obj = {};
                        obj = this.schoolList.find(r =>{
                            return r.schoolId === item;
                        });
                        e.schoolName = obj.schoolName
                    }
                })
            }
        },
        // 获取学科类别
        getSubject(){
            this.$get(this.api.queryCourseDiscipline).then(res => {
                this.subjectList = res.message
            }).catch(res => {});
        },
        // 清除学科类别
        clearClass(){
            this.archivesForm.professionalClassId = '',
            this.archivesForm.professionalId = ''
        },
        // 获取专业类
        getProfessionalClass(val){
            this.clearClass()
            if(val){
                let obj = {};
                obj = this.subjectList.find((item)=>{
                    return item.disciplineId === val;
                });
                this.archivesForm.disciplineName = obj.disciplineName
                this.getProfessionalClassData(val)
            }
        },
        clearItemClass(index){
            this.archivesList[index].professionalClassId = ''
            this.archivesList[index].professionalClassName = ''
            this.archivesList[index].professionalId = ''
            this.archivesList[index].professionalName = ''
            // this.archivesList.map(e =>{
            //     if(e.disciplineId == item){
            //         e.professionalClassId = '',
            //         e.professionalClassName = '',
            //         e.professionalId = '',
            //         e.professionalName = ''
            //     }
            // })
        },
        getItemProfessionalClass(item,index){
            this.clearItemClass(index)
            if(item){
                let obj = {};
                obj = this.subjectList.find(r =>{
                    return r.disciplineId === item;
                });
                this.$get(this.api.queryCourseProfessionalClass,{ disciplineId: item }).then(res => {
                    this.archivesList.map(e =>{
                        if(e.disciplineId == item){
                            e.ProfessionalClassList = res.message
                            e.disciplineName = obj.disciplineName
                        }
                    })
                }).catch(res => {});
            }
        },
        getProfessionalClassData(value){
            this.$get(this.api.queryCourseProfessionalClass,{ disciplineId: value }).then(res => {
                this.ProfessionalClassList = res.message
            }).catch(res => {});
        },
        // 清除专业类
        clearProfess(){
            this.archivesForm.professionalId = ''
        },
        // 获取专业
        getProfessional(val){
            this.clearProfess()
            if(val){
                let obj = {};
                obj = this.ProfessionalClassList.find((item)=>{
                    return item.professionalClassId === val;
                });
                this.archivesForm.professionalClassName = obj.professionalClassName
                this.getProfessionalData(val)
            }
        },
        clearItemProfess(index){
            this.archivesList[index].professionalId = ''
            this.archivesList[index].professionalName = ''
            // this.archivesList.map(e =>{
            //     if(e.professionalClassId == item){
            //         e.professionalId = '',
            //         e.professionalName = ''
            //     }
            // })
        },
        getItemProfessional(item,index){
            this.clearItemProfess(index)
            if(item){
                this.$get(this.api.queryCourseProfessional,{ professionalClassId: item }).then(res => {
                    this.archivesList.map(e =>{
                        if(e.professionalClassId == item){
                            let obj = {};
                            obj = e.ProfessionalClassList.find(r =>{
                                return r.professionalClassId === item;
                            });
                            e.ProfessionalList = res.message
                            e.professionalClassName = obj.professionalClassName
                        }
                    })
                }).catch(res => {});
            }
        },
        getProfessionalData(value){
            this.$get(this.api.queryCourseProfessional,{professionalClassId: value}).then(res => {
                this.ProfessionalList = res.message
            }).catch(res => {});
        },
        // 获取专业名称
        getStuGrade(val){
            if(val){
                let obj = {};
                obj = this.ProfessionalList.find(r =>{
                    return r.professionalId === val;
                });
                this.archivesForm.professionalName = obj.professionalName
            }
        },
        getItemStuGrade(item){
            if(item){
                this.archivesList.map(e =>{
                    if(e.professionalId == item){
                        let obj = {};
                        obj = e.ProfessionalList.find(r =>{
                            return r.professionalId === item;
                        });
                        e.professionalName = obj.professionalName
                    }
                })
            }
        },
        // 获取学校名称
        getSchoolData(){
            this.$get(this.api.querySchoolData,{
                schoolName: '',
                provinceId: '',
                cityId: ''
            }).then(res => {
                this.schoolList = res.message
            }).catch(res => {});
        },
        // 清除一级部门
        clearStaffPro(item){
            this.chooseList.map(e =>{
                if(e.staffProfessionalArchitectureId == item){
                    e.staffGradeId = '',
                    e.staffGradeName = ''
                }
            })
        },
        // 清除教师一级部门
        clearteacherStaffPro(item){
            this.chooseList.map(e =>{
                if(e.staffProfessionalArchitectureId == item){
                    e.teacherstaffGradeId = ''
                    e.teacherstaffProName = ''
                }
            })
        },
        // 获取二级部门
        getStaffGradeList(item){
            this.clearStaffPro(item)
            if(item){
                this.$get(this.api.queryStaffGrade,{ staffProfessionalArchitectureId: item }).then(res => {
                    this.chooseList.map(e =>{
                        if(e.staffProfessionalArchitectureId == item){
                            let obj = {};
                            obj = e.firstClassList.find(r =>{
                                return r.staffProfessionalArchitectureId === item;
                            });
                            e.twoClassList = res.message
                            e.staffProfessionalArchitectureName = obj.staffProfessionalArchitectureName
                        }
                    })
                }).catch(res => {});
            }
        },
        // 获取教师二级部门
        teacherStaffGradeList(item){
            this.clearteacherStaffPro(item)
            if(item){
                this.$get(this.api.queryStaffGrade,{ staffProfessionalArchitectureId: item }).then(res => {
                    this.chooseList.map(e =>{
                        if(e.teacherstaffProId == item){
                            let obj = {};
                            obj = e.firstClassList.find(r =>{
                                return r.staffProfessionalArchitectureId === item;
                            });
                            e.teachertwoClassList = res.message
                            e.teacherstaffProName = obj.staffProfessionalArchitectureName
                        }
                    })
                }).catch(res => {});
            }
        },
        // 获取二级部门名称
        StaffGradeChange(item){
            if(item){
                this.chooseList.map(e =>{
                    if(e.staffGradeId == item){
                        let obj = {};
                        obj = e.twoClassList.find((r)=>{
                            return r.staffGradeId === item;
                        });
                        e.staffGradeName = obj.staffGradeName
                    }
                })
            }
        },
        // 获取教师二级部门名称
        teacherStaffGradeChange(item){
            if(item){
                this.chooseList.map(e =>{
                    if(e.teacherstaffGradeId == item){
                        let obj = {};
                        obj = e.teachertwoClassList.find((r)=>{
                            return r.staffGradeId === item;
                        });
                        e.teacherstaffGradeName = obj.staffGradeName
                    }
                })
            }
        },
        // 清除学生专业
        clearstuPro(item){
            this.chooseList.map(e =>{
                if(e.stuprofessionalId == item){
                    e.stugradeId = '',
                    e.stugradeName = '',
                    e.stuclassId = '',
                    e.stuclassName = ''
                }
            })
        },
        // 获取学生年级
        getStuPro(item){
            this.clearstuPro(item)
            if(item){
                this.$get(this.api.queryStuGrade,{ stuProfessionalArchitectureId: item }).then(res => {
                    this.chooseList.map(e =>{
                        if(e.stuprofessionalId == item){
                            let obj = {};
                            obj = e.studentFirstList.find(r =>{
                                return r.stuProfessionalArchitectureId === item;
                            });
                            e.studentTwoList = res.message
                            e.stuprofessionalName = obj.stuProfessionalArchitectureName
                        }
                    })
                }).catch(res => {});
            }
        },
        // 清除学生年级
        clearStuGrade(item){
            this.chooseList.map(e =>{
                if(e.stugradeId == item){
                    e.stuclassId = '',
                    e.stuclassName = ''
                }
            })
        },
        // 获取学生班级
        getStuClass(item){
            this.clearStuGrade(item)
            if(item){
                this.$get(this.api.queryStuClass,{ gradeId: item }).then(res => {
                    this.chooseList.map(e =>{
                        if(e.stugradeId == item){
                            let obj = {};
                            obj = e.studentTwoList.find(r =>{
                                return r.gradeId === item;
                            });
                            e.studentThreeClass = res.message
                            e.stugradeName = obj.gradeName
                        }
                    })
                }).catch(res => {});
            }
        },
        // 获取学生班级名称
        StuClassChange(item){
            if(item){
                this.chooseList.map(e =>{
                    if(e.stuclassId == item){
                        let obj = {};
                        obj = e.studentThreeClass.find(r =>{
                            return r.classId === item;
                        });
                        e.stuclassName = obj.className
                    }
                })
            }
        },
        // 新增系统
        addArchives(){
            let isEmpty = true;
            let object = this.archivesForm
            Object.keys(object).forEach(function(x) {
                if(object[x] != null && object[x] != ""){
                    isEmpty = false;
                }
            });
            if(isEmpty){//值全为空
                this.$message.warning('请先填写个人档案其中一项信息！');
                return true;
            }
            this.archivesList = this.archivesList.concat({
                personalCareerId: '', //职业
                schoolId: '', //院校
                schoolName: '', //院校名称
                subjectList: this.subjectList, //专业学科
                disciplineId: '', //专业学科
                disciplineName: '', //专业学科名称
                ProfessionalClassList: [], //专业类
                professionalClassId: '', //专业类
                professionalClassName: '', //专业类名称
                ProfessionalList: [], //专业
                professionalId: '', //专业
                professionalName: '', //专业名称
                userId: this.userId
            })
            return false;
        },
        saveAdd(formName){
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    if(!this.form.userName) return this.$message.warning('请填写用户姓名');
                    if(!this.form.schoolId) return this.$message.warning('请选择所在院校');
                    if(!this.form.account) return this.$message.warning('请填写账号');
                    if(!this.NoAdd) return this.$message.warning('该手机号已存在');
                    if(!this.AccountNoAdd) return this.$message.warning('该账号已存在');
                    if(!this.NumberNoAdd) return this.$message.warning('该员工工号已存在');
                    if(!this.teaNumberNoAdd) return this.$message.warning('该教师工号已存在');
                    if(!this.stuNumberNoAdd) return this.$message.warning('该学生学号已存在');
                    if(!this.saveList.length) return this.$message.warning('请绑定系统');
                    if(this.form.uniqueIdentificationAccount == ''){
                        let timestamp = Date.parse(new Date()); 
                        this.form.uniqueIdentificationAccount = timestamp
                    }
                    let staffLIst = []
                    let student = {}
                    this.saveList.forEach( e =>{
                        // 管理员数据
                        if(e.roleIds.indexOf(13) > -1){
                            staffLIst.push({
                                platformId: e.platformId,
                                workNumber: e.staworkNumber,
                                roleId: 13,
                                schoolId: e.schoolId,
                                customerId: e.customerId,
                                schoolName: e.customerName,
                                staffProfessionalArchitectureId: e.staffProfessionalArchitectureId,
                                staffProfessionalArchitectureName: e.staffProfessionalArchitectureName,
                                staffGradeId: e.staffGradeId,
                                staffGradeName: e.staffGradeName
                            })
                        }
                        // 教师数据
                        if(e.roleIds.indexOf(14) > -1){
                            staffLIst.push({
                                platformId: e.platformId,
                                workNumber: e.teaworkNumber,
                                roleId: 14,
                                schoolId: e.schoolId,
                                customerId: e.customerId,
                                schoolName: e.customerName,
                                staffProfessionalArchitectureId: e.teacherstaffProId,
                                staffProfessionalArchitectureName: e.teacherstaffProName,
                                staffGradeId: e.teacherstaffGradeId,
                                staffGradeName: e.teacherstaffGradeName
                            })
                        }
                        // 学生数据
                        if(e.roleIds.indexOf(4) > -1){
                            student = {
                                platformId: e.platformId,
                                workNumber: e.stuworkNumber,
                                roleId: 4,
                                schoolId: e.schoolId,
                                customerId: e.customerId,
                                schoolName: e.customerName,
                                professionalId: e.stuprofessionalId,
                                professionalName: e.stuprofessionalName,
                                gradeId: e.stugradeId,
                                gradeName: e.stugradeName,
                                classId: e.stuclassId,
                                className: e.stuclassName
                            }
                        }
                        
                    })
                    let userProfilesList = []
                    let newarchivesList = [this.archivesForm, ...this.archivesList]
                    newarchivesList.forEach(e =>{
                        userProfilesList.push({
                            personalCareerId: e.personalCareerId,
                            schoolId: e.schoolId,
                            schoolName: e.schoolName,
                            disciplineId: e.disciplineId,
                            disciplineName: e.disciplineName,
                            professionalClassId: e.professionalClassId,
                            professionalClassName: e.professionalClassName,
                            professionalId: e.professionalId,
                            professionalName: e.professionalName,
                            userId: this.userId
                        })
                    })
                    this.form.roleId = this.saveList[0].roleIds.join(',')
                    let params = {
                        UserInfo : this.form,
                        userProfilesList,
                        staffLIst,
                        student
                    }
                    this.$post(this.api.addUser,params).then((res) => {
                            this.$message.success('添加成功');
                            this.$router.go(-1)
                        }).catch((res) => {
                    })
                }
            })
        },
        goback(){
            if(this.clickFlag){
                let msg = ''
                if(this.userId){
                    msg = '请确定信息是否进行更新完毕，再返回用户首页。'
                    
                }else{
                    msg = '确定返回？未更新的信息将不会保存。'
                }
                this.$confirm(msg, '提示', {
                    type: 'warning'
                })
                .then(() => {
                    this.clickFlag = false
                    this.$router.go(-1)
                })
                .catch(() => {});
            }
        },
        async phoneChange(){
            let res = await this.$get(this.api.queryPhone, { phone: this.form.phone });
            if(res.message.length != 0){
                this.$message.warning('该手机号已存在');
                this.NoAdd = false
            }else{
                this.NoAdd = true
            }
        },
        async accountChange(){
            let res = await this.$get(this.api.queryAccountIsExist, { account: this.form.account });
            if(res.message.length != 0){
                this.$message.warning('该账号已存在');
                this.AccountNoAdd = false
            }else{
                this.AccountNoAdd = true
            }
        },
        async worknumberChange(item){
            let res = await this.$get(this.api.queryWorkNumberIsExist, { 
                workNumber: item.staworkNumber, 
                roleId: 13,
                schoolId: item.schoolId
            });
            if(JSON.stringify(res.message) != '{}'){
                this.$message.warning('该员工工号已存在');
                this.NumberNoAdd = false
            }else{
                this.NumberNoAdd = true
            }
        },
        async teaworknumberChange(item){
            let res = await this.$get(this.api.queryWorkNumberIsExist, { 
                workNumber: item.teaworkNumber, 
                roleId: 14,
                schoolId: item.schoolId
            });
            if(JSON.stringify(res.message) != '{}'){
                this.$message.warning('该教师工号已存在');
                this.teaNumberNoAdd = false
            }else{
                this.teaNumberNoAdd = true
            }
        },
        async stuworknumberChange(item){
            let res = await this.$get(this.api.queryWorkNumberIsExist, { 
                workNumber: item.stuworkNumber, 
                roleId: 4,
                schoolId: item.schoolId
            });
            if(JSON.stringify(res.message) != '{}'){
                this.$message.warning('该学生学号已存在');
                this.stuNumberNoAdd = false
            }else{
                this.stuNumberNoAdd = true
            }
        },
        numberChange(){
            let reg = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)/
            if(reg.test(this.form.IDNumber)){
                let idCard = this.form.IDNumber
                let birthday = "";
                if(idCard != null && idCard != ""){
                if(idCard.length == 15){
                    birthday = "19"+idCard.slice(6,12);
                } else if(idCard.length == 18){
                    birthday = idCard.slice(6,14);
                }	
                birthday = birthday.replace(/(.{4})(.{2})/,"$1-$2-");
                }	
                this.form.dateBirth = birthday

                let sexStr = '';
                if (parseInt(idCard.slice(-2, -1)) % 2 == 1) {
                    sexStr = 1;
                }
                else {
                    sexStr = 2;
                }
                this.form.sex = sexStr
                this.IDdisabled = true
            }else{
                this.IDdisabled = false
                this.form.dateBirth = ''
                this.form.sex = ''
            }
        },
        getRowKeys(row) {
            return row.id;
        },
        // 新增用户
        addUser(){
            this.dialogFormVisible = true
            this.region = ''
            this.choosecusArr = ''
            this.chooseCusList = []
            this.chooseList = []
        },
        // 多选操作
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        // 客户列表
        addCustomer(){
            clearTimeout(this.searchTimer)
            if(this.region == '') return this.$message.warning('请选择系统');
            this.innerVisible = true
            this.searchTimer = setTimeout(() => {
                let res = this.$get(this.api.userQueryCustomer, { 
                    customerIds: this.choosecusArr,
                    searchContent: this.cusSearch
                }).then(res => {
                    this.customerList = res.message
                })
            },100)
        },
        // 选择客户
        SelectionCus(val){
            this.chooseCusList = val;
        },
        // 选择客户确定
        cusSure(){
            this.innerVisible = false
            if(this.chooseCusList){
                let arr = this.chooseCusList
                let result = arr.map(e => e.customerId).join()
                this.choosecusArr = this.choosecusArr.concat(`,${result}`)
                if (this.choosecusArr.substr(0,1)==','){
                    this.choosecusArr = this.choosecusArr.substr(1);
                }
                // 新增学校列表数据
                arr.map(e =>{
                    this.$set(e, 'checkList', this.checkList);
                    this.$set(e, 'roleIds', []);
                    this.$set(e, 'platformId', this.region);
                    this.$set(e, 'staworkNumber', '');
                    this.$set(e, 'teaworkNumber', '');
                    this.$set(e, 'stuworkNumber', '');
                    // 获取学生专业
                    this.$get(this.api.queryStuPro,{ schoolId: e.schoolId }).then(res => {
                        // 专业
                        this.$set(e, 'studentFirstList', res.message);
                        this.$set(e, 'stuprofessionalId', '');
                        this.$set(e, 'stuprofessionalName', '');
                        // 年级
                        this.$set(e, 'studentTwoList', []);
                        this.$set(e, 'stugradeId', '');
                        this.$set(e, 'stugradeName', '');
                        // 班级
                        this.$set(e, 'studentThreeClass', []);
                        this.$set(e, 'stuclassId', '');
                        this.$set(e, 'stuclassName', '');
                    }).catch(res => {});
                    // 获取一级部门
                    this.$get(this.api.queryStaffPro,{ schoolId: e.schoolId }).then(res => {
                        // 一级部门
                        this.$set(e, 'firstClassList', res.message);
                        this.$set(e, 'staffProfessionalArchitectureId', '');
                        this.$set(e, 'staffProfessionalArchitectureName', '');
                        // 二级部门
                        this.$set(e, 'twoClassList', []);
                        this.$set(e, 'staffGradeId', '');
                        this.$set(e, 'staffGradeName', '');
                        // 教师一级部门
                        this.$set(e, 'teacherstaffProId', '');
                        this.$set(e, 'teacherstaffProName', '');
                        // 教师二级部门
                        this.$set(e, 'teachertwoClassList', []);
                        this.$set(e, 'teacherstaffGradeId', '');
                        this.$set(e, 'teacherstaffGradeName', '');
                    }).catch(res => {});
                })
                this.saveList = this.saveList.concat(arr)
                this.chooseList = this.chooseList.concat(arr)
            }
        },
        async updateUserRoleId() {
            let res = await this.$post(this.api.updateUserRoleId, {
                userId: this.userId,
                roleId: this.chooseList[0].roleIds.join(',')
            });
        },
        removeSchool(customerId) {
            this.saveList.map((n,k) => {
                if(n.customerId == customerId) this.saveList.splice(k,1)
            })
            this.chooseList.map((n,k) => {
                if(n.customerId == customerId) {
                    this.chooseList.splice(k,1)
                    this.chooseCusList.splice(k,1)
                }
            })
            let choosecusArr = this.choosecusArr.split(',')
            choosecusArr.splice(choosecusArr.findIndex(val => val == customerId),1)
            this.choosecusArr = choosecusArr.join()
        },
        // 选择完信息之后确定
        async ChooseListSure(){
            if(this.region == '') return this.$message.warning('请选择系统');
            if(this.chooseList.length != 0){
                let isroleIdEmpty = false;
                this.chooseList.map(e =>{
                    if(!e.roleIds.length){
                        isroleIdEmpty = true;
                    }
                })
                if(isroleIdEmpty){
                    this.$message.warning('请选择角色');
                    return true
                }
            }else return this.$message.warning('请选择学校');

            if(this.userId){
                let stuStaffList = {
                    staffList: [],
                    studentList: []
                }
                let isEmpty = false
                this.chooseList.forEach(e =>{
                    // 管理员数据
                    if(e.roleIds.indexOf(13) > -1){
                        for(let i in e) {
                            if(i.startsWith('sta') && e[i] == ''){
                                isEmpty = true
                                break
                            }
                        }
                        stuStaffList.staffList.push({
                            platformId: e.platformId,
                            workNumber: e.staworkNumber,
                            roleId: 13,
                            schoolId: e.schoolId,
                            customerId: e.customerId,
                            schoolName: e.customerName,
                            staffProfessionalArchitectureId: e.staffProfessionalArchitectureId,
                            staffProfessionalArchitectureName: e.staffProfessionalArchitectureName,
                            staffGradeId: e.staffGradeId,
                            staffGradeName: e.staffGradeName,
                            userId: this.userId
                        })
                    }
                    // 教师数据
                    if(e.roleIds.indexOf(14) > -1){
                        for(let i in e) {
                            if(i.startsWith('tea') && e[i] == ''){
                                isEmpty = true
                                break
                            }
                        }
                        stuStaffList.staffList.push({
                            platformId: e.platformId,
                            workNumber: e.teaworkNumber,
                            roleId: 14,
                            schoolId: e.schoolId,
                            customerId: e.customerId,
                            schoolName: e.customerName,
                            staffProfessionalArchitectureId: e.teacherstaffProId,
                            staffProfessionalArchitectureName: e.teacherstaffProName,
                            staffGradeId: e.teacherstaffGradeId,
                            staffGradeName: e.teacherstaffGradeName,
                            userId: this.userId
                        })
                    }
                    // 学生数据
                    if(e.roleIds.indexOf(4) > -1){
                        for(let i in e) {
                            if(i.startsWith('stu') && e[i] == ''){
                                isEmpty = true
                                break
                            }
                        }
                        stuStaffList.studentList.push({
                            platformId: e.platformId,
                            workNumber: e.stuworkNumber,
                            roleId: 4,
                            schoolId: e.schoolId,
                            customerId: e.customerId,
                            schoolName: e.customerName,
                            professionalId: e.stuprofessionalId,
                            professionalName: e.stuprofessionalName,
                            gradeId: e.stugradeId,
                            gradeName: e.stugradeName,
                            classId: e.stuclassId,
                            className: e.stuclassName,
                            userId: this.userId
                        })
                    }                        
                })
                if(isEmpty) return this.$message.warning('请填写必填项');
                await this.$post(this.api.updateOR, stuStaffList);
                this.getplatformList()
                this.updateUserRoleId()
                this.dialogFormVisible = false
            }else{
                if(!this.NumberNoAdd) return this.$message.warning('该员工工号已存在');
                if(!this.teaNumberNoAdd) return this.$message.warning('该教师工号已存在');
                if(!this.stuNumberNoAdd) return this.$message.warning('该学生学号已存在');
                let list = this.saveList
                let isEmpty = false
                for(let e of list){
                    if(e.roleIds.includes(13)){
                        for(let i in e) {
                            if(i.startsWith('sta') && e[i] == ''){
                                isEmpty = true
                                break
                            }
                        }
                    }
                    if(e.roleIds.includes(14)){
                        for(let i in e) {
                            if(i.startsWith('tea') && e[i] == ''){
                                isEmpty = true
                                break
                            }
                        }
                    }
                    if(e.roleIds.includes(4)){
                        for(let i in e) {
                            if(i.startsWith('stu') && e[i] == ''){
                                isEmpty = true
                                break
                            }
                        }
                    }
                }
                if(isEmpty) return this.$message.warning('请填写必填项');
                let result = this.saveList.map(e => e.platformId).join()
                let res = await this.$get(this.api.queryPlatform, { platformId: result });
                this.platformList = res.message
                this.dialogFormVisible = false

                if(this.platformList.length != 0){
                    this.platformList.map(e =>{
                        this.regionOption.map((r,index) =>{
                            if(r.regionId == e.platformId){
                                this.regionOption.splice(index,1)
                            }
                        })
                    })
                }
            }
        },
        getplatformList(){
            this.regionOption = [{
                regionName: '教学平台',
                regionId: 1
            },
            {
                regionName: '数据平台',
                regionId: 2
            }], //系统选择
            this.$get(this.api.queryUserInfoDetails,{ userId: this.userId }).then(res => {
            // this.platformList = res.message.platformList
            let staffPlatformList = res.message.staffPlatformList
            let studentPlatformList = res.message.studentPlatformList
            this.platformList = staffPlatformList
            if(this.platformList.length == 1){
                studentPlatformList.forEach((n,k) => {
                    if(n.platformId != this.platformList[0].platformId){
                        this.platformList.push(n)
                    }
                })
            }else if(!this.platformList.length){
                this.platformList = studentPlatformList
            }
            this.platformList.map(e =>{
                this.regionOption.map((r,index) =>{
                    if(r.regionId == e.platformId){
                        this.regionOption.splice(index,1)
                    }
                })
                })
            }).catch((res) => {})
        },
        // 关闭弹框
        regionclose(){
            if(this.userId){
                this.getplatformList()
            }
        },
        //编辑平台
        async edit(row){
            let obj = {}
            Object.assign(obj,
            {
                regionName: row.platformName,
                regionId: row.platformId,
            })
            this.regionOption = [obj, ...[]]
            this.region = row.platformId
            this.dialogFormVisible = true
            this.choosecusArr = ''
            this.chooseCusList = []
            this.chooseList = []

            let res = await this.$get(this.api.queryUserOR, { userId: this.userId, platformId: row.platformId});
            res.message = [...res.message.staff,...res.message.student]
            res.message.map(e =>{
                    this.$set(e, 'checkList', this.checkList)
                    this.$set(e, 'customerName', e.schoolName)
                    // 专业
                    this.$set(e, 'studentFirstList', []);
                    this.$set(e, 'stuprofessionalId', '');
                    this.$set(e, 'stuprofessionalName', '');
                    this.$set(e, 'stuclassId', '');
                    this.$set(e, 'stuclassName', '');
                    // 年级
                    this.$set(e, 'studentTwoList', []);
                    this.$set(e, 'stugradeId', '');
                    this.$set(e, 'stugradeName', '');
                    // 班级
                    this.$set(e, 'studentThreeClass', []);
                    this.$set(e, 'stuworkNumber', '');
                    // 一级部门
                    this.$set(e, 'firstClassList', []);
                    this.$set(e, 'staworkNumber', '');
                    e.staffProfessionalArchitectureId || this.$set(e, 'staffProfessionalArchitectureId', '');
                    e.staffProfessionalArchitectureName || this.$set(e, 'staffProfessionalArchitectureName', '');
                    e.staffGradeId || this.$set(e, 'staffGradeId', '');
                    e.staffGradeName || this.$set(e, 'staffGradeName', '');
                    // 二级部门
                    this.$set(e, 'twoClassList', []);
                    // 教师二级部门
                    this.$set(e, 'teachertwoClassList', []);
                    this.$set(e, 'teaworkNumber', '');
                    this.$set(e, 'teacherstaffProId', '');
                    this.$set(e, 'teacherstaffProName', '');
                    this.$set(e, 'teacherstaffGradeId', '');
                    this.$set(e, 'teacherstaffGradeName', '');
                    if (e.roleId) {
                        switch (e.roleId) {
                            case 13:
                                e.staworkNumber = e.workNumber
                                break;
                            case 14:
                                e.teaworkNumber = e.workNumber,
                                e.teacherstaffProId = e.staffProfessionalArchitectureId, 
                                e.teacherstaffProName = e.staffProfessionalArchitectureName, 
                                e.teacherstaffGradeId = e.staffGradeId,
                                e.teacherstaffGradeName = e.staffGradeName
                                break;
                            case 4:
                                e.stuworkNumber = e.workNumber
                                e.stuprofessionalId = e.professionalId
                                e.stuprofessionalName = e.professionalName
                                e.stugradeId = e.gradeId
                                e.stugradeName = e.gradeName
                                e.stuclassId = e.classId
                                e.stuclassName = e.className
                                break;
                        }
                    }
            })
            let arr1 = res.message;
            function f(arr) {
                let mp= {}
                let ret = []
                arr.forEach(item => {
                    if (typeof mp[item.schoolId] === 'number') {
                        ret[mp[item.schoolId]].push(item)
                    } else {
                        mp[item.schoolId] = ret.length
                        ret.push([item])
                    }
                })
                return ret
            }
            let setArr = f(arr1)
            setArr.map(e =>{
                e.map(c => {
                    this.$set(c, 'roleIds', e.map(c => c.roleId))
                })
            })
            // this.chooseList  = setArr.map(a => Object.assign.apply(null,a));
            let arr2 = setArr

            function deepMerge(data) {
                let result = []
                data.forEach((item,index) => {
                    result[index] = {}
                    item.forEach((k,i) => {
                        for(let j in k){
                            if(!result[index][j] || (result[index][j] && k[j])){
                                result[index][j] = k[j]
                            }
                        }
                    })
                })
                return result
            }
            this.chooseList = deepMerge(arr2)

            this.chooseList.map(e =>{
                e.roleIds = Array.from(new Set(e.roleIds))
                // 获取一级部门
                this.$get(this.api.queryStaffPro,{ schoolId: e.schoolId }).then(res => {
                    // this.$set(e, 'firstClassList', res.message);
                    e.firstClassList = res.message
                }).catch(res => {});
                // 获取管理员二级部门
                if(e.staffProfessionalArchitectureId){
                    this.$get(this.api.queryStaffGrade,{ staffProfessionalArchitectureId: e.staffProfessionalArchitectureId }).then(res => {
                        // this.$set(e, 'twoClassList', res.message);
                        e.twoClassList = res.message
                    }).catch(res => {});
                }
                // 获取教师二级部门
                if(e.teacherstaffProId){
                    this.$get(this.api.queryStaffGrade,{ staffProfessionalArchitectureId: e.teacherstaffProId }).then(res => {
                        // this.$set(e, 'teachertwoClassList', res.message);
                        e.teachertwoClassList = res.message
                    }).catch(res => {});
                }
                // 获取学生专业
                this.$get(this.api.queryStuPro,{ schoolId: e.schoolId }).then(res => {
                    // this.$set(e, 'studentFirstList', res.message);
                    e.studentFirstList = res.message
                }).catch(res => {});
                // 获取学生年级
                if(e.stuprofessionalId){
                    this.$get(this.api.queryStuGrade,{ stuProfessionalArchitectureId: e.stuprofessionalId }).then(res => {
                        // this.$set(e, 'studentTwoList', res.message);
                        e.studentTwoList = res.message
                    }).catch(res => {});
                }
                // 获取学生班级
                if(e.stugradeId){
                    this.$get(this.api.queryStuClass,{ gradeId: e.stugradeId }).then(res => {
                        // this.$set(e, 'studentThreeClass', res.message);
                        e.studentThreeClass = res.message
                    }).catch(res => {});
                }
            })
            
            let nwarr = this.chooseList
            let result = nwarr.map(e => e.schoolId).join()
            this.choosecusArr = this.choosecusArr.concat(`,${result}`)
            if (this.choosecusArr.substr(0,1)==','){
                this.choosecusArr = this.choosecusArr.substr(1);
            }

        },
        // 删除平台
        handleDelete(row,index){
            this.$confirm('确定要删除吗？', '提示', {
                type: 'warning'
            })
            .then(() => {
                // 系统列表
                let obj = {}
                Object.assign(obj,
                {
                    regionName: row.platformName,
                    regionId: row.platformId,
                })
                this.regionOption = [obj, ...this.regionOption]           
                
                this.saveList = this.saveList.filter(function(obj){
                    return row.platformId !== obj.platformId;
                });
                this.chooseList = this.chooseList.filter(function(obj){
                    return row.platformId !== obj.platformId;
                });
                this.platformList.splice(index, 1);
                this.$message.success('删除成功');
                if(this.userId){
                    this.$post(this.api.deletePlatform,{ platformId: row.platformId, userId: this.userId }).then(res => {                       
                    }).catch(res => {});
                }
            })
            .catch(() => {});
        },
        // 更新用户信息
        async editUserInfo(){
            await this.$post(this.api.updateUserInfo, this.form );
            this.$message.success('更新用户成功');
            this.$router.go(-1)
        },
        //删除个人档案
        delItemArchives(index){
            this.$confirm('确定要删除该档案吗？', '提示', {
                type: 'warning'
            })
            .then(() => {
                this.archivesList.splice(index, 1);
                this.$message.success('删除成功');
            })
            .catch(() => {});
        },
        // 更新个人档案
        async editUserProfiles(){
            let userProfilesList = []
            let newarchivesList = [this.archivesForm, ...this.archivesList]
            newarchivesList.forEach(e =>{
                userProfilesList.push({
                    personalCareerId: e.personalCareerId,
                    schoolId: e.schoolId,
                    schoolName: e.schoolName,
                    disciplineId: e.disciplineId,
                    disciplineName: e.disciplineName,
                    professionalClassId: e.professionalClassId,
                    professionalClassName: e.professionalClassName,
                    professionalId: e.professionalId,
                    professionalName: e.professionalName,
                    userId: this.userId
                })
            })
            await this.$post(this.api.updateUserProfiles, userProfilesList );
            this.$message.success('更新个人档案成功');
        },
    }
};
</script>


<style lang="scss" scoped>
// 新增系统
.card ::v-deep .el-card {
    border-radius: 15px;
}
.card_m {
    margin: 10px 0 20px 0;
}
::v-deep .el-dialog__title {
    font-weight: 600;
}
.region ::v-deep .el-form-item__label {
    font-weight: 600;
}
.region ::v-deep .el-input {
    width: 30%;
}
.numberInput{
    display: inline-flex;
    align-items: center;
    span{
        white-space: nowrap;
    }
}
.numberInput ::v-deep .el-input {
    width: 80%;
}
.stu_input ::v-deep .el-input {
    width: 80%;
}
.radio {
    margin: 0 15px 0 30px;
    font-weight: 600;
}
.jobNumber {
    margin: 10px 0;
}
.jobNumber ::v-deep .el-input {
    margin-left: 20px;
}
.icon_btn {
    margin: 5px 5px 15px 0;
}
.secondaryDepartments {
    margin-left: 90px;
}
.flex_start {
    display: flex;
    justify-content: flex-start;
    align-items: center;
}
.flex {
    display: flex;
    justify-content: flex-end;
}
.from_card {
    margin-bottom: 20px;
}
.mgb20_top {
    margin-top: 400px;
}
.mag {
    margin-right: 20px;
}
.magr50 {
    margin-left: 50px;
}
.font_same {
    margin-left: 40px;
    color: rgb(155, 179, 245);
    font-size: 14px;
}
.school_card:first-child{
    margin-top: 0;
}
.school_card{
    margin-top: 20px;
}
.checkboxItem{
    margin-left: 20px;
}

// 滚动条的宽度
.scrollbar ::-webkit-scrollbar {
    width: 2px; // 横向滚动条
    height: 6px; // 纵向滚动条 必写
}
// 滚动条的滑块
.scrollbar ::-webkit-scrollbar-thumb {
    background-color: #9278ff;
    border-radius: 3px;
    box-shadow: inset 0 0 5px #dddddd;
}
.scrollbar ::-webkit-scrollbar-track {
    /*滚动条里面轨道*/
    box-shadow: inset 0 0 5px #dddddd;
    border-radius: 0;
    background: #dddddd;
}
/deep/.el-input__inner{
    height: 40px !important;
}
.remove-school{
    cursor: pointer;
    font-size: 20px;
}
</style>