<template>
	<div class="content-main">
		<el-row :gutter="20" class="box">
			<el-col :span="6">
				<div class="grid-content bg-purple asides">
					<div class="searchArea">
						<!-- <span>编号/名称</span> -->
						<el-select v-model="queryOrgType" placeholder="请选择单位类型" size="small" clearable class="query2">
							<el-option v-for="(item,index) in orgType" :key="index" :label="item.configName" :value="item.configCode">
							</el-option>
						</el-select>
						<el-input size="small" v-model="filterText" placeholder="请输入名称" class="query1" clearable></el-input>

					</div>
					<el-tree class="treeStyle" :data="deptTreeData" :props="defaultProps" @node-click="handleNodeClick" node-key="orgCode" :expand-on-click-node="false" v-loading="loading" highlight-current :filter-node-method="filterNode" :default-expanded-keys='this.defaultExpanded' ref="tree"></el-tree>
				</div>
			</el-col>
			<el-col :span="18">
				<div class="userIndex">
					<el-row>
						<el-form :model="queryFrom" :inline="true" ref="queryFrom">
							<el-col :span="10">
								<el-form-item label="用户名称">
									<el-input v-model="queryFrom.userName" clearable></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="10">
								<el-button type="primary" icon="search" @click="initUserInfo">查询</el-button>
								<el-button type="primary" icon='plus' @click='newAdd'>新增</el-button>
							</el-col>
						</el-form>
					</el-row>
					<!-- <el-row> -->
						<el-table :data="currencyData" border stripe style="width: 100%; margin-top: 10px;" v-loading.body="listloading">
							<el-table-column type='index' width='70' align="center" label="序号">
							</el-table-column>
							<el-table-column align="center" label="登录账号" width="100">
								<template slot-scope="scope">
									<span>
										{{scope.row.userLoginName}}
									</span>
								</template>
							</el-table-column>
							<el-table-column align="center" label="用户名称" width="120">
								<template slot-scope="scope">
									<span>
										{{scope.row.userName }}
									</span>
								</template>
							</el-table-column>
							<el-table-column align="center" label="用户手机号" width="100">
								<template slot-scope="scope">
									<span>
										{{scope.row.userMobile }}
									</span>
								</template>
							</el-table-column>
							<el-table-column align="center" label="用户类型" width="120">
								<template slot-scope="scope">
									<span>
										{{scope.row.userTypeName }}
									</span>
								</template>
							</el-table-column>
							<el-table-column align="center" label="性别" width="50">
								<template slot-scope="scope">
									<span>
										{{scope.row.userSex }}
									</span>
								</template>
							</el-table-column>
							<el-table-column align="center" label="所属组织" width="80" :show-overflow-tooltip="true">
								<template slot-scope="scope">
									<span>
										{{scope.row.orgName }}
									</span>
								</template>
							</el-table-column>
							<el-table-column align="center" label="所属角色" width="80" :show-overflow-tooltip="true">
								<template slot-scope="scope">
									<span>
										{{scope.row.userRoleName.join(",") }}
									</span>
								</template>
							</el-table-column>
							<el-table-column align="center" label="操作" fixed="right" width="350px">
								<template slot-scope="scope">
									<el-button size="small" type="success" @click="editDialogOpen(scope.row)">
										修改
									</el-button>
									<el-button size="small" type="warning" @click="resetPass(scope.row)">
										重置密码
									</el-button>
									<el-button size="small" type="danger" @click="handleDelete(scope.row)">
										删除
									</el-button>

								</template>
							</el-table-column>
						</el-table>
						<!-- 分页开始 -->
						<div class="pagination-container">
							<el-pagination :current-page.sync="limit.page" :page-size="limit.size" :page-sizes="[10,20,30,40]" :total="limit.total" @current-change="handleCurrentChange" @size-change="handleSizeChange" layout="total, sizes, prev, pager, next, jumper">
							</el-pagination>
						</div>
					<!-- </el-row> -->
					<!-- 新增/修改 -->
					<el-dialog title="基本信息" :visible.sync="dialogForm" class='dialogCon' :show-close='false'>
						<el-form :model="formData" :inline="true" ref="formData" :rules="rules">
							<el-row>
								<el-col :span="12">
									<el-form-item label="登录账号" prop="userLoginName">
										<el-input v-model="formData.userLoginName" auto-complete="off"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="用户姓名" prop="userName">
										<el-input v-model="formData.userName" auto-complete="off"></el-input>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row>
								<el-col :span="12">
									<el-form-item label="账号类型" prop="userType">
										<el-select v-model="formData.userType" placeholder="请选择" style="width: 100%;">
											<el-option v-for="(item,index) in usersType" :key="index" :label="item.configName" :value="item.configValue">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>

								<!--<el-col :span="12">
									<el-form-item label="所属部门" prop="deptCode">
										<el-select v-model="formData.deptCode" placeholder="请选择" style="width: 100%;">
											<el-option v-for="(item,index) in deptData" :key="index" :label="item.deptName" :value="item.deptCode">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>-->

								<el-col :span="12">
									<el-form-item label="所属部门" prop="deptLevel">
										<el-cascader :options="deptData" v-model="formData.deptLevel" change-on-select :show-all-levels="true" :props="departprops"></el-cascader>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row>
								<el-col :span="12">
								<el-form-item label="用户职务" prop="headship">
									<el-select
									clearable
									v-model="formData.headship"
									placeholder="请选择"
									style="width: 100%"
									>
									<el-option
										v-for="(item, index) in userTitleList"
										:key="index"
										:label="item.configName"
										:value="item.configCode"
									></el-option>
									</el-select>
									<!-- <el-input v-model="formData.userTitle" auto-complete="off"></el-input> -->
								</el-form-item>
								</el-col>

								<el-col :span="12">
								<el-form-item label="用户职级" prop="userTitle">
									<el-select
									clearable
									v-model="formData.userTitle"
									placeholder="请选择"
									style="width: 100%"
									>
									<el-option
										v-for="(item, index) in headship"
										:key="index"
										:label="item.configName"
										:value="item.configCode"
									></el-option>
									</el-select>
								</el-form-item>
								</el-col>
							</el-row>
							<!-- <el-row>
								<el-col :span="12">
									<el-form-item label="用户职务" prop="userTitle">
										<el-input v-model="formData.userTitle" auto-complete="off"></el-input>
									</el-form-item>
								</el-col>

								<el-col :span="12">
									<el-form-item label="职务级别" prop="headship">
										<el-select v-model="formData.headship" placeholder="请选择" style="width: 100%;">
											<el-option v-for="(item,index) in headship" :key="index" :label="item.configName" :value="item.configCode">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
							</el-row> -->
							<el-row>
								<el-col :span="12">
									<el-form-item label="用户手机" prop="userMobile">
										<el-input v-model="formData.userMobile" auto-complete="off"></el-input>
									</el-form-item>
								</el-col>

								<el-col :span="12">
									<el-form-item label="邮箱" prop="userMail">
										<el-input v-model="formData.userMail" auto-complete="off"></el-input>
									</el-form-item>
								</el-col>
							</el-row>

							<el-row>
								<el-col :span="12">
									<el-form-item label="教育水平" prop="userEducation">
										<el-select v-model="formData.userEducation" placeholder="请选择" style="width: 100%;">
											<el-option v-for="(item,index) in education" :key="index" :label="item.configName" :value="item.configCode">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="政治面貌" prop="politicalStatus">
										<el-select v-model="formData.politicalStatus" placeholder="请选择" style="width: 100%;">
											<el-option v-for="(item,index) in political" :key="index" :label="item.configName" :value="item.configCode">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row>
								<el-col :span="12">
									<el-form-item label="区域编码" prop="countyName">
										<el-cascader :options="options" v-model="formData.countyName" change-on-select :show-all-levels="true" @change="handleItemChange" :props="optionsprops" style="width: 100%;"></el-cascader>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="性别" prop="userSex">
										<el-select v-model="formData.userSex" placeholder="请选择" style="width: 100%;">
											<el-option v-for="(item,index) in sex" :key="index" :label="item.lable" :value="item.lable">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>

							</el-row>

							<el-row>
								<el-col :span="12">
									<el-form-item label="地址" prop="userAddress">
										<el-input v-model="formData.userAddress" auto-complete="off"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="所学专业" prop="speciality">
										<el-input v-model="formData.speciality" auto-complete="off"></el-input>
									</el-form-item>
								</el-col>

							</el-row>

							<el-row>
								<el-col :span="12">
									<el-form-item label="证件类型" prop="userCerttype">
										<el-select v-model="formData.userCerttype" placeholder="请选择" style="width: 100%;">
											<el-option v-for="(item,index) in userCerttypes" :key="index" :label="item.configName" :value="item.configCode">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="证件号码" prop="userCertno">
										<el-input v-model="formData.userCertno" auto-complete="off"></el-input>
									</el-form-item>
								</el-col>

							</el-row>

							<el-row>
								<el-col :span="22">
									<el-form-item label="角色" prop="userRoleNameTwo" style="position: relative;">
										<el-input v-model="formData.userRoleNameTwo" readonly></el-input>
										<el-button @click="roleInfoManage" type="primary" style="position: absolute;right: 3px;top: 5px;">角色管理</el-button>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row>
								<el-col :span='24'>
									<el-form-item label="工作职责" prop="buty">
										<el-input type="textarea" :autosize="{ minRows: 4, maxRows: 4}" placeholder="职责描述" v-model="formData.buty" style="height:90px;">
										</el-input>
									</el-form-item>
								</el-col>
							</el-row>
						</el-form>
						<div slot="footer" class="dialog-footer">
							<el-button size="small" type="primary" @click="saveFormData('formData')">保 存</el-button>
							<el-button size="small" @click="closedialogForm">取 消</el-button>
						</div>
					</el-dialog>
					<ChooseRoles :visibleFlag="visibleFlag" :rolesInfo='rolesInfo' :checkInfo='checkInfo' @changeVisible="changeVisible" @receiveData="receiveData"></ChooseRoles>
				</div>

			</el-col>
		</el-row>
	</div>
</template>
<script>
	//组织树
	import {
		orgainztionTree, getParaConfigList,areaProvince,areaCity,areaCounty,departByCode,orgAndDepartTreeNew,getUserInfo,getUserInfoNew,reportPassWord,deleteUserInfoNew,saveUserInfoNew,getRoleList,updateUserRoles
	} from '@/api/grainCoManage/userManage/index.js'
	// import { orgainztionTree } from '@/api/tree/tree'
	// import { getParaConfigList } from '@/api/admin/para'
	// import { areaProvince, areaCity, areaCounty } from '@/api/dict/index'
	// import { departByCode,orgAndDepartTreeNew } from '@/api/admin/organization'
	// import { getUserInfo, saveUserInfoNew,reportPassWord, getUserInfoNew, deleteUserInfoNew } from '@/api/admin/user'
	// import { getRoleList, updateUserRoles } from '@/api/admin/roleManage'

	import { validateEMail, validatePhone, postalCode, validateFax } from '@/directives/validate'
	import ChooseRoles from '@/components/ChooseRoles/index'
	export default {
		name: "userManager",
		data() {
			return {
				userTitleList: [],
				options: [],
				sex: [{
						lable: '男'
					},
					{
						lable: '女'
					}
				],
				departprops: {
					label: 'deptName',
					value: 'deptCode',
					children: 'children'
				},
				optionsprops: {
					label: 'countyName',
					value: 'countyCode',
					children: 'children'
				},
				education: [],
				usersType: [
					{
					configValue: "1",
					configName: "管理端",
					},
					{
					configValue: "0",
					configName: "企业端",
					},
				],
				political: [],
				headship: [],
				queryOrgType: '', //查询用机构类型
				deptTreeData: [],
				orgType: [],
				userCerttypes: [],
				//树结构控制
				defaultProps: {
					children: 'children',
					label: 'orgName'
				},
				listloading: false,
				currencyData: [],
				limit: {
					page: 1,
					size: 10,
					total: 0
				},
				visibleFlag: false,
				rules: {
					userLoginName: [{
						required: true,
						message: '请输入账号',
						trigger: 'blur'
					}],
					userName: [{
						required: true,
						message: '请输入姓名',
						trigger: 'blur'
					}],
					userType: [{
						required: true,
						message: '请选择用户类型',
						trigger: 'blur'
					}],
					deptLevel: [{
						required: true,
						message: '请选择部门',
						trigger: 'blur'
					}],
					userTitle: [{
						required: true,
						message: '请输入用户职务',
						trigger: 'blur'
					}],
					countyName: [{
						required: true,
						message: '请选择地区编码',
						trigger: 'blur'
					}],
					headship: [{
						required: true,
						message: '请选择职务级别',
						trigger: 'blur'
					}],
					userMobile: [{
						required: true,
						message: '请输入手机号',
						trigger: 'blur'
					}],

					//					orgEmail: [{
					//						validator: validateEMail,
					//						trigger: "blur"
					//					}],
					//					orgPhone: [{
					//						validator: validateTelphone,
					//						trigger: "blur"
					//					}],
					//					orgMobile: [{
					//						validator: validatePhone,
					//						trigger: "blur"
					//					}],
					//					orgPost: [{
					//						validator: postalCode,
					//						trigger: "blur"
					//					}],
				},
				queryFrom: {},
				formData: {},
				deptData: [], //部门
				//弹出框开关
				filterText: '',
				//nodeData:null,
				newNodeName: '新增节点',
				type: 'edit',
				loading: false,
				//nodeId:'',
				defaultExpanded: [],
				dialogForm: false, //新增/修改 弹框开关
				rolesInfo: [],
				checkInfo: [],
				checkRoles: [],
				yesRoles: [],
				selectUser: []
			}
		},
		components: {
			ChooseRoles
		},
		methods: {
			//获取职务或职级
			getZwOrZj(orgCode) {
				console.log(orgCode, "orgCode");
				// 职级//1024市级/区级  1025信息中心/批发市场  1027储备公司
				if (orgCode == "LS001021" || orgCode == "LS001020") {
					getParaConfigList("1025")
					.then((res) => {
						this.headship = res.data;
					})
					.catch((err) => {
						console.log(err);
					});
				} else if (orgCode == "LS001019") {
					getParaConfigList("1027")
					.then((res) => {
						this.headship = res.data;
					})
					.catch((err) => {
						console.log(err);
					});
				} else {
					getParaConfigList("1024")
					.then((res) => {
						this.headship = res.data;
					})
					.catch((err) => {
						console.log(err);
					});
				}

				//职务  市级1023 公司/区粮办1026
				if (orgCode && orgCode.length == 5) {
					getParaConfigList("1023")
					.then((res) => {
						this.userTitleList = res.data;
					})
					.catch((err) => {
						console.log(err);
					});
				} else {
					getParaConfigList("1026")
					.then((res) => {
						this.userTitleList = res.data;
					})
					.catch((err) => {
						console.log(err);
					});
				}
				},
			//子组件回调数据
			receiveData(val) {
				console.log(val)
				this.yesRoles = val
				let roles = val.join(",")
				this.checkRoles = []//选择角色为空
				for(let i = 0; i < this.rolesInfo.length; i++) {
					if(roles.indexOf(this.rolesInfo[i].roleCode) > -1) {
						this.checkRoles.push(this.rolesInfo[i].roleName) //添加角色名称
					}
				}
				this.formData.userRoleNameTwo = this.checkRoles.join(",")
			},
			//事件回调
			changeVisible(val) {
				this.visibleFlag = val;
				this.checkInfo = []
			},
			roleInfoManage() {
				this.rolesInfo = []
				this.checkInfo = this.formData.userRole
				getRoleList().then((res) => {
					this.rolesInfo = res.data
					this.visibleFlag = true;
				}).catch((err) => {
					console.log(err)
				})

			},
			closedialogForm() {
				this.dialogForm = false
				this.formData = {}
			},
			handleItemChange(val) {
				if(val.length == 1) {
					for(let i = 0; i < this.options.length; i++) {
						if(val[0] == this.options[i].countyCode && !this.options[i].children.length) {
							//获取市级数据
							areaCity(val[0]).then((res) => {
								for(let x = 0; x < res.data.length; x++) {
									res.data[x].children = []
								}
								this.options[i].children = res.data;
							}).catch((err) => {
								console.log(err)
							})
						}
					}
				} else {
					for(let i = 0; i < this.options.length; i++) {
						for(let x = 0; x < this.options[i].children.length; x++) {
							if(val[1] == this.options[i].children[x].countyCode && !this.options[i].children[x].children.length) {
								//获取县级数据
								areaCounty(val[1]).then((res) => {
									this.options[i].children[x].children = res.data;
								}).catch((err) => {
									console.log(err)
								})
							}
						}

					}
				}
			},
			editDialogOpen(row) { //修改弹窗
				this.type = 'edit';
				this.getDepartLists(row.orgCode) //获取部门列表
				getUserInfoNew([row.userCode]).then((res) => {
					if(res.infoCode == 200) {
						if(res.data[0].countyCode != null) {
							let countyCode = res.data[0].countyCode;
							res.data[0].countyCode = [];
							this.formData = res.data[0];
							this.handCaseInfo(countyCode)
						}
						this.getZwOrZj(res.data[0].orgCode);
						this.formData.userRoleNameTwo = row.userRoleName.join(",")
						this.formData.userRole = row.userRole
						if(res.data[0].deptCode != null) {
							//处理部门级联
							this.handCaseDepart(res.data[0].deptCode)
						}

					}
				})
			},
			handleDelete(row) {
				this.$confirm('您确定要删除该用户吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let userCode = [row.userCode];
					deleteUserInfoNew(userCode).then(res => {
						if(res.infoCode == 200) {
							this.$message({
								type: 'success',
								message: '删除成功!'
							});
							this.initUserInfo();
						}
					}).catch(error => {
						console.log(error)
					})
				})

			},
			resetPass(row) {
				this.$confirm('您确定要重置该用户吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					reportPassWord(row.userCode).then(res => {
						if(res.infoCode == 200) {
							this.$message({
								type: 'success',
								message: '重置成功!'
							});
							this.initUserInfo();
						}
					}).catch(error => {
						console.log(error)
					})
				})

			},
			handleNodeClick(data) {
				this.deptData = [] //初始化部门列表
				if (data.isDept===2) {//表示部门信息
					this.queryFrom.deptCode = data.orgCode
					this.queryFrom.orgCode = null
				} else{//表示组织信息
					this.queryFrom.orgCode = data.orgCode
					this.queryFrom.deptCode = null
				}
				this.getDepartList() //获取部门列表
				this.getZwOrZj(this.queryFrom.orgCode); //获取职务职级
				this.limit.page=1
				this.initUserInfo()
			},
			handleCurrentChange(val) { //改变当前页
				this.limit.page = val
				this.initUserInfo()
			},
			handleSizeChange(val) { //改变每页展示条数
				this.limit.size = val
				this.initUserInfo()
			},
			//树节点过滤
			filterNode(value, data) {
				if(!value) return true;
				return data.orgName.indexOf(value.inputCon) !== -1 && data.orgType.indexOf(value.orgType) !== -1;
			},
			newAdd() {
				this.type = 'new';
				if(this.queryFrom.orgCode == undefined) {
					this.$message({
						type: 'warning',
						message: '请在左边选择一个组织!'
					});
				} else {
					this.getZwOrZj(this.queryFrom.orgCode);
					this.dialogForm = true;
				}

			},
			saveFormData(formName) {
				this.$refs[formName].validate((valid) => {
					if(valid) {
						let data = this.formData;
					if(this.formData.countyName.length > 0) {
						data.countyCode = this.formData.countyName.slice(-1)[0]
					}
					if(this.formData.deptLevel.length > 0) {
						data.deptCode = this.formData.deptLevel.slice(-1)[0]
					}
					console.log(data)
					let type = this.type
					if(type == 'new') {
						data.userPassword = 'e10adc3949ba59abbe56e057f20f883e'
						data.isDisavled = '0'
					}
						saveUserInfoNew(type, data).then(res => {
							if(res.infoCode == 200) {
								this.$message({
									type: 'success',
									message: '保存成功!'
								});
								//拼接用户角色信息
								console.log(res.data)
								let formInfo = {}
								if(this.formData.userCode) {
									formInfo.userCode = this.formData.userCode
								} else {
									formInfo.userCode = res.data
								}
								if(this.yesRoles) {
									formInfo.roleCode = this.yesRoles
									updateUserRoles(formInfo).then(res => {
										if(res.infoCode == 200) {
											this.$message({
												type: 'success',
												message: '保存成功!'
											});
											this.formData = {};
											this.dialogForm = false
											this.initUserInfo();
											updateUserRoles
										} else {
											this.$message({
												type: 'error',
												message: '角色授权失败'
											})
										}
									}).catch(error => {

										console.log(error)
									})
								}

								this.formData = {};
								this.dialogForm = false
								this.initUserInfo();

							}
						}).catch(error => {
							console.log(error)
						})

					} else {
						return false;
					}
				});

			},
			//初始化树
			initTreeData() {
				this.loading = true;
				orgAndDepartTreeNew('LS').then(response => {
					if(response.infoCode === 200) {
						this.deptTreeData = []
						this.defaultExpanded = []
						this.deptTreeData = response.data;
						this.defaultExpanded.push(response.data[0].orgCode);
					} else {
						this.$message({
							type: 'error',
							message: response.msg
						})

					}
					this.loading = false;
				}).catch(error => {
					this.loading = false;
					console.log(error)
				})
			},
			initUserInfo() {
				this.listloading = true;
				getUserInfo(this.limit, this.queryFrom).then(response => {
					if(response.infoCode === 200) {
						this.currencyData = response.data.content;
						this.limit.total = response.data.totalElements
						console.log(response)
					} else {
						this.$message({
							type: 'error',
							message: response.msg
						})
						this.currencyData = [];
						this.limit.total = 0
					}
					this.listloading = false;
				}).catch(error => {
					this.listloading = false;
					console.log(error)
				})
			},
			//初始化选择框数据
			getOrgTypeList() {
				//组织类型
				getParaConfigList('1019').then((res) => {
					this.orgType = res.data;
				}).catch((err) => {
					console.log(err)
				})
				//用户类型
//				getParaConfigList('1004').then((res) => {
//					this.usersType = res.data;
//				}).catch((err) => {
//					console.log(err)
//				})
				//教育水平
				getParaConfigList('1020').then((res) => {
					this.education = res.data;
				}).catch((err) => {
					console.log(err)
				})
				//政治面貌
				getParaConfigList('1021').then((res) => {
					this.political = res.data;
				}).catch((err) => {
					console.log(err)
				})
				areaProvince().then((res) => {
					for(let i = 0; i < res.data.length; i++) {
						res.data[i].children = []
					}
					this.options = res.data;
				}).catch((err) => {
					console.log(err)
				})
				//政治面貌
				getParaConfigList('1023').then((res) => {
					this.headship = res.data;
				}).catch((err) => {
					console.log(err)
				})
				//政治面貌
				getParaConfigList('1043').then((res) => {
					this.userCerttypes = res.data;
				}).catch((err) => {
					console.log(err)
				})

			},
			getDepartList() {
				departByCode(this.queryFrom.orgCode).then(response => {
					if(response.infoCode === 200) {
						this.deptData = response.data
					} else {
						this.$message({
							type: 'error',
							message: response.msg
						})

					}
				}).catch(error => {
					console.log(error)
				})
			},
			getDepartLists(orgCode) {
				departByCode(orgCode).then(response => {
					if(response.infoCode === 200) {
						this.deptData = response.data
						console.log(response.data)
						this.dialogForm = true
					} else {
						this.$message({
							type: 'error',
							message: '部门信息获取失败'
						})

					}
				}).catch(error => {
					this.$message({
						type: 'error',
						message: '部门信息获取失败'
					})
					console.log(error)
				})
			},
			handCaseDepart(deptCode) {
				let deptLevel = []
				if(deptCode != null) {
					deptLevel[0] = deptCode.substring(0, 5);
					deptCode = deptCode.slice(5)
					for(let i = 0; i < deptCode.length / 3; i++) {
						deptLevel.push(deptLevel[0] + deptCode.substring(0, (i + 1) * 3))
					}
				}
				this.formData.deptLevel = deptLevel
			},
			//处理选择组织区域编码问题
			handCaseInfo(countyCode) {
				if(countyCode.indexOf("0000") > -1) { //代表传过来的为省编码
					this.formData.countyName = [countyCode]
				} else if(countyCode.indexOf("00") > -1) { //市编码
					let code = countyCode.substring(0, 2) + "0000";
					for(let i = 0; i < this.options.length; i++) {
						if(code == this.options[i].countyCode && !this.options[i].children.length) {
							//获取市级数据
							areaCity(code).then((res) => {
								for(let x = 0; x < res.data.length; x++) {
									res.data[x].children = []
								}
								this.options[i].children = res.data;
							}).catch((err) => {
								console.log(err)
							})
						}
					}
					this.formData.countyName = [code, countyCode]
				} else { //县编码
					let code = countyCode.substring(0, 2) + "0000";
					let citycode = countyCode.substring(0, 4) + "00";
					//获取市数据
					for(let i = 0; i < this.options.length; i++) {
						if(code == this.options[i].countyCode && !this.options[i].children.length) {
							//获取市级数据
							areaCity(code).then((res) => {
								for(let x = 0; x < res.data.length; x++) {
									res.data[x].children = []
								}
								//添加市级数据
								this.options[i].children = res.data;
								//获取县级数据
								for(let x = 0; x < this.options[i].children.length; x++) {
									if(citycode == this.options[i].children[x].countyCode && !this.options[i].children[x].children.length) {
										//获取县级数据
										areaCounty(citycode).then((res) => {
											this.options[i].children[x].children = res.data;
										}).catch((err) => {
											console.log(err)
										})
									}
								}
							}).catch((err) => {
								console.log(err)
							})
						}
					}
					this.formData.countyName = [code, citycode, countyCode]
				}
			}

		},
		created() {
			this.initTreeData();
			this.getOrgTypeList();
			this.initUserInfo();
		},
		watch: {
			filterText(val) {
				let queryObj
				if(!val && !this.queryOrgType) {
					queryObj = null
				} else {
					queryObj = {
						orgType: this.queryOrgType,
						inputCon: val
					}
				}
				this.$refs.tree.filter(queryObj);
			},
			queryOrgType(val) {
				let queryObj
				if(!val && !this.filterText) {
					queryObj = null
				} else {
					queryObj = {
						orgType: val,
						inputCon: this.filterText
					}
				}
				this.$refs.tree.filter(queryObj);
			}
		}

	}
</script>
<style>
	
	.box {
		height: 100%;
	}
	
	.asides {
		margin-left: 10px;
	}
	
	.contain {
		width: 100%;
		height: 100%;
		padding-top: 10px;
	}
	
	.el-dialog--small {
		width: 100%;
	}
	
	.query1 {
		width: calc(100% - 10px - 50%);
		box-sizing: border-box;
	}
	
	.query2 {
		width: calc(100% - 10px - 50%);
		box-sizing: border-box;
	}
	
	.userIndex .queryForm .el-form-item__content {
		width: calc(100% - 68px);
	}
	
	.userIndex .el-dialog__header,
	.userIndex .el-dialog__footer {
		text-align: center;
	}
	
	.userIndex .dialogCon .el-form-item__content {
		width: calc(100% - 100px);
	}
	
	.userIndex .dialogCon .el-form-item__label {
		width: 100px;
	}
	
	.userIndex .dialogCon .el-form--inline .el-form-item {
		width: 100%;
	}
	
	.userIndex .dialogCon .el-select {
		width: 100%;
	}
	
	.userIndex .el-tree {
		margin-top: 10px;
	}
</style>