<template>
	<div>
		<el-row>
			<el-col :span="6">
				<el-card :body-style="cardBodyStyle">
					<el-input v-model="queryUserDesc" placeholder="请输入查询条件" clearable
						style="width: 200px; margin-right: 10px;"></el-input>
					<el-button type="primary" @click="search">查询</el-button>
					<el-button type="success" @click="syncOrg">组织同步</el-button>
				</el-card>
				<el-card :body-style="cardBodyStyle">
					<el-table :data="tableData" border highlight-current-row @header-dragend="handleDragend"
						@row-click="handleEditRow">
						<el-table-column type="index" label="序号" align="center" width="60">
							<template #default="scope">
								<span>{{ scope.$index + (currentPage - 1) * pageSize + 1 }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="userCode" label="用户编码" width="120" header-align="center" align="center"
							show-overflow-tooltip>
						</el-table-column>
						<el-table-column prop="userName" label="用户名" width="120" header-align="center" align="center"
							show-overflow-tooltip>
						</el-table-column>
						<el-table-column prop="userDesc" label="姓名" header-align="center" align="center"
							show-overflow-tooltip>
						</el-table-column>
						<!-- <el-table-column label="操作" header-align="center" align="center">
							<template #default="scope">
								<el-button type="warning" plain size="small" circle
									@click="handleEdit( scope.row )"><el-icon>
										<Edit />
									</el-icon></el-button>
								<el-button type="danger" plain size="small" circle
									@click="handleDelete( scope.row )"><el-icon>
										<Delete />
									</el-icon></el-button>
							</template>
						</el-table-column> -->
					</el-table>
				</el-card>
				<el-card :body-style="cardBodyStyle">
					<el-pagination small :current-page="currentPage" v-model:page-size="pageSize"
						:page-sizes="pageSizes" :total="totalRows" background="background"
						layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
						@current-change="handleCurrentChange">
					</el-pagination>
				</el-card>
			</el-col>
			<el-col :span="18">
				<el-card :body-style="cardBodyStyle">
					<el-button type="primary" plain @click="handleAdd">新增</el-button>
					<el-button type="success" @click="handleSave(ruleFormRef)">保存</el-button>
					<el-button type="danger" @click="handleDelete">删除</el-button>
				</el-card>
				<el-card :body-style="cardBodyStyle">
					<el-tabs v-model="activeName" type="border-card" @tab-click="handleTabsClick">
						<el-tab-pane label="基础信息" name="info">
							<el-form :model="user" label-width="80px" label-position="right" inline ref="ruleFormRef"
								:rules="rules">
								<el-form-item label="用户编码" prop="userCode">
									<el-input v-model="user.userCode" style="width: 200px;"></el-input>
								</el-form-item>
								<el-form-item label="用户名" prop="userName">
									<el-input v-model="user.userName" style="width: 200px;"></el-input>
								</el-form-item>
								<el-form-item label="用户姓名" prop="userDesc">
									<el-input v-model="user.userDesc" style="width: 200px;"></el-input>
								</el-form-item>
								<!-- 								<el-form-item label="用户密码" prop="password">
									<el-input v-model="user.password" style="width: 200px;" type="password"></el-input>
								</el-form-item> -->
								<el-form-item label="身份证号">
									<el-input v-model="user.idCard" style="width: 200px;"></el-input>
								</el-form-item>
								<el-form-item label="手机号">
									<el-input v-model="user.phone" style="width: 200px;"></el-input>
								</el-form-item>
								<el-form-item label="邮箱">
									<el-input v-model="user.email" style="width: 200px;"></el-input>
								</el-form-item>
                <el-form-item label="OA账号">
                  <el-input v-model="user.oaUserCode" style="width: 200px;"></el-input>
                </el-form-item>
								<el-form-item label="管理员">
									<el-radio-group v-model="user.adminFlag" style="width: 200px;">
										<el-radio label="1">是</el-radio>
										<el-radio label="0">否</el-radio>
									</el-radio-group>
								</el-form-item>
							</el-form>
						</el-tab-pane>
						<el-tab-pane label="角色" name="role">
							<el-row>
								<el-col :span="10">
									<el-card :body-style="cardBodyStyle">
										<el-input placeholder="角色名称或编码" v-model="queryRole">
											<el-button slot="append" icon="el-icon-search"
												@click="searchRole"></el-button>
										</el-input>
									</el-card>
									<el-card :body-style="cardBodyStyle">
										<el-table :data="noRoleTableData" border highlight-current-row
											@row-click="noRoleRowClick">
											<el-table-column label="未选列表">
												<el-table-column prop="id" label="编号" v-if="isShow">
												</el-table-column>
												<el-table-column prop="roleCode" label="角色编码" width="120"
													show-overflow-tooltip>
												</el-table-column>
												<el-table-column prop="roleName" label="用户名称" show-overflow-tooltip>
												</el-table-column>
											</el-table-column>
										</el-table>
										<el-pagination small @current-change="noRoleCurrentChange"
											:current-page="noRoleCurrentPage" :page-size="noRolePageSize"
											layout=" prev, pager, next" :total="noRoleTotalRows">
										</el-pagination>
									</el-card>
								</el-col>

								<el-col :span="4">
									<div
										style="width: 100%;height: 100%;display: flex;flex-direction: column;justify-content: space-around; align-items: center;">
										<div>
											<el-icon :size="40">
												<ArrowLeftBold @click="roleHandleRemove" />
											</el-icon>
										</div>
										<div>
											<el-icon :size="40">
												<ArrowRightBold @click="roleHandleSave" />
											</el-icon>
										</div>
									</div>
								</el-col>

								<el-col :span="10">
									<el-card :body-style="cardBodyStyle">
										<el-table :data="yesRoleTableData" border highlight-current-row
											@row-click="yesRoleRowClick">
											<el-table-column label="已选列表">
												<el-table-column prop="id" label="编号" width="60" v-if="isShow">
												</el-table-column>
												<el-table-column prop="roleCode" label="角色编码" width="120"
													show-overflow-tooltip>
												</el-table-column>
												<el-table-column prop="roleName" label="用户名称" show-overflow-tooltip>
												</el-table-column>
											</el-table-column>
										</el-table>
										<el-pagination small @current-change="yesRoleCurrentChange"
											:current-page="yesRoleCurrentPage" :page-size="yesRolePageSize"
											layout="  prev, pager, next" :total="yesRoleTotalRows">
										</el-pagination>
									</el-card>
								</el-col>
							</el-row>
						</el-tab-pane>
						<el-tab-pane label="部门" name="department">
							<el-row>
								<el-col :span="12">
									<el-card :body-style="cardBodyStyle" v-if="refreshTree">
										<el-tree :data="dataTree" :props="defaultProps" node-key="id"
											@node-click="handleNodeClick" :expand-on-click-node="true"
											:default-expanded-keys="expandedKeys" show-checkbox ref="treeRef"
											check-strictly auto-expand-parent>
										</el-tree>
									</el-card>
								</el-col>

								<el-col :span="12">
									<el-card :body-style="cardBodyStyle">
										<el-descriptions title="部门说明">
											<el-descriptions-item
												label="部门名称">{{userDeptSelect.deptName}}</el-descriptions-item>
											<el-descriptions-item
												label="部门编码">{{userDeptSelect.deptCode}}</el-descriptions-item>
											<el-descriptions-item
												label="部门说明">{{userDeptSelect.deptDesc}}</el-descriptions-item>
										</el-descriptions>
									</el-card>
								</el-col>
							</el-row>
						</el-tab-pane>
						<el-tab-pane label="岗位" name="post">
							<el-row>
								<el-col :span="10">
									<el-card :body-style="cardBodyStyle">
										<el-input placeholder="岗位名称或编码" v-model="queryPost">
											<el-button slot="append" icon="el-icon-search"
												@click="searchPost"></el-button>
										</el-input>
									</el-card>
									<el-card :body-style="cardBodyStyle">
										<el-table :data="noPostTableData" border highlight-current-row
											@row-click="noPostRowClick">
											<el-table-column label="未选列表">
												<el-table-column prop="id" label="编号" v-if="isShow">
												</el-table-column>
												<el-table-column prop="postCode" label="岗位编码" width="120"
													show-overflow-tooltip>
												</el-table-column>
												<el-table-column prop="postName" label="岗位名称" show-overflow-tooltip>
												</el-table-column>
											</el-table-column>
										</el-table>
										<el-pagination small @current-change="noPostCurrentChange"
											:current-page="noPostCurrentPage" :page-size="noPostPageSize"
											layout=" prev, pager, next" :total="noPostTotalRows">
										</el-pagination>
									</el-card>
								</el-col>
								<el-col :span="4">
									<div
										style="width: 100%;height: 100%;display: flex;flex-direction: column;justify-content: space-around; align-items: center;">
										<div>
											<el-icon :size="40">
												<ArrowLeftBold @click="postHandleRemove" />
											</el-icon>
										</div>
										<div>
											<el-icon :size="40">
												<ArrowRightBold @click="postHandleSave" />
											</el-icon>
										</div>
									</div>
								</el-col>
								<el-col :span="10">
									<el-card :body-style="cardBodyStyle">
										<el-table :data="yesPostTableData" border highlight-current-row
											@row-click="yesPostRowClick">
											<el-table-column label="已选列表">
												<el-table-column prop="id" label="编号" width="60" v-if="isShow">
												</el-table-column>
												<el-table-column prop="postCode" label="岗位编码" width="120"
													show-overflow-tooltip>
												</el-table-column>
												<el-table-column prop="postName" label="岗位名称" show-overflow-tooltip>
												</el-table-column>
											</el-table-column>
										</el-table>
										<el-pagination small @current-change="yesPostCurrentChange"
											:current-page="yesPostCurrentPage" :page-size="yesPostPageSize"
											layout="  prev, pager, next" :total="yesPostTotalRows">
										</el-pagination>
									</el-card>
								</el-col>
							</el-row>
						</el-tab-pane>

						<el-tab-pane label="账号" name="other">
							<el-card :body-style="cardBodyStyle">
								<el-form :model="form" label-width="auto">
									<el-form-item label="账号状态">
										<el-select v-model="account.lockFlag" style="width: 240px" disabled>
											<el-option label="正常" value="0" />
											<el-option label="自动锁定" value="1" />
											<el-option label="手动锁定" value="2" />
										</el-select>
									</el-form-item>
									<el-form-item label="密码错误次数">
										<el-input v-model="account.errCount" style="width: 240px" disabled> </el-input>
									</el-form-item>
									<el-form-item label="自动解锁时间">
										<el-date-picker v-model="account.unLockTime" type="datetime"
											style="width: 240px" disabled />
									</el-form-item>
									<el-form-item label=" ">
										<el-button type="primary" @click="resetPassword">重置密码</el-button>
										<el-button v-if="account.lockFlag=='0'" type="danger"
											@click="lock('2')">锁定账号</el-button>
										<el-button v-else type="success" @click="lock('0')">解锁账号</el-button>
									</el-form-item>
								</el-form>
							</el-card>
						</el-tab-pane>

					</el-tabs>
				</el-card>

			</el-col>
		</el-row>


		<el-dialog :close-on-click-modal="false" draggable title="编辑" v-model="dialogVisible" width="80%" top="5vh">
			<el-row :gutter="10">
				<el-col :span="6">
					<el-card :body-style="cardBodyStyle">
						<el-form :model="user" label-width="80px" label-position="right">
							<el-form-item label="用户编码" v-if="false">
								<el-input v-model="user.id"></el-input>
							</el-form-item>
							<el-form-item label="用户编码">
								<el-input v-model="user.userCode"></el-input>
							</el-form-item>
							<el-form-item label="用户名">
								<el-input v-model="user.userName"></el-input>
							</el-form-item>
							<el-form-item label="用户姓名">
								<el-input v-model="user.userDesc"></el-input>
							</el-form-item>
							<el-form-item label="用户密码">
								<el-input v-model="user.password"></el-input>
							</el-form-item>
							<el-form-item label="身份证号">
								<el-input v-model="user.idCard"></el-input>
							</el-form-item>
							<el-form-item label="手机号">
								<el-input v-model="user.phone"></el-input>
							</el-form-item>
							<el-form-item label="管理员">
								<el-radio-group v-model="user.adminFlag">
									<el-radio label="1">是</el-radio>
									<el-radio label="0">否</el-radio>
								</el-radio-group>
							</el-form-item>
						</el-form>
					</el-card>
				</el-col>

				<el-col :span="6">
					<el-card :body-style="cardBodyStyle">
						<el-input placeholder="角色名称或编码" v-model="queryRole">
							<el-button slot="append" icon="el-icon-search" @click="searchRole"></el-button>
						</el-input>
					</el-card>
					<el-card :body-style="cardBodyStyle">
						<el-table :data="noRoleTableData" border highlight-current-row @row-click="noRoleRowClick">
							<el-table-column label="未选列表">
								<el-table-column prop="id" label="编号" v-if="isShow">
								</el-table-column>
								<el-table-column prop="roleCode" label="角色编码" width="120" show-overflow-tooltip>
								</el-table-column>
								<el-table-column prop="roleName" label="用户名称" show-overflow-tooltip>
								</el-table-column>
							</el-table-column>
						</el-table>
						<el-pagination small @current-change="noRoleCurrentChange" :current-page="noRoleCurrentPage"
							:page-size="noRolePageSize" layout=" prev, pager, next" :total="noRoleTotalRows">
						</el-pagination>

						<el-row>
							<el-col :span="8" :offset="4">
								<el-icon :size="40">
									<ArrowUpBold @click="roleHandleRemove" />
								</el-icon>
								<!-- 							<i class="el-icon-arrow-down" @click="roleHandleSave"
								style="font-size: 50px;margin-right: 160px;"></i> -->
							</el-col>
							<el-col :span="8" :offset="4">
								<el-icon :size="40">
									<ArrowDownBold @click="roleHandleSave" />
								</el-icon>
								<!-- <i class="el-icon-arrow-up" @click="roleHandleRemove" style="font-size: 50px;"></i> -->
							</el-col>
						</el-row>

						<el-table :data="yesRoleTableData" border highlight-current-row @row-click="yesRoleRowClick">
							<el-table-column label="已选列表">
								<el-table-column prop="id" label="编号" width="60" v-if="isShow">
								</el-table-column>
								<el-table-column prop="roleCode" label="角色编码" width="120" show-overflow-tooltip>
								</el-table-column>
								<el-table-column prop="roleName" label="用户名称" show-overflow-tooltip>
								</el-table-column>
							</el-table-column>
						</el-table>
						<el-pagination small @current-change="yesRoleCurrentChange" :current-page="yesRoleCurrentPage"
							:page-size="yesRolePageSize" layout="  prev, pager, next" :total="yesRoleTotalRows">
						</el-pagination>
					</el-card>
				</el-col>

				<el-col :span="6">
					<el-card :body-style="cardBodyStyle">
						<el-tree :data="dataTree" :props="defaultProps" node-key="id" :expand-on-click-node="true"
							:default-expanded-keys="expandedKeys" show-checkbox accordion ref="treeRef" check-strictly>
						</el-tree>
					</el-card>
				</el-col>


				<el-col :span="6">
					<el-card :body-style="cardBodyStyle">
						<el-input placeholder="岗位名称或编码" v-model="queryPost">
							<el-button slot="append" icon="el-icon-search" @click="searchPost"></el-button>
						</el-input>
					</el-card>
					<el-card :body-style="cardBodyStyle">
						<el-table :data="noPostTableData" border highlight-current-row @row-click="noPostRowClick">
							<el-table-column label="未选列表">
								<el-table-column prop="id" label="编号" v-if="isShow">
								</el-table-column>
								<el-table-column prop="postCode" label="岗位编码" width="120" show-overflow-tooltip>
								</el-table-column>
								<el-table-column prop="postName" label="岗位名称" show-overflow-tooltip>
								</el-table-column>
							</el-table-column>
						</el-table>
						<el-pagination small @current-change="noPostCurrentChange" :current-page="noPostCurrentPage"
							:page-size="noPostPageSize" layout=" prev, pager, next" :total="noPostTotalRows">
						</el-pagination>
						<el-row>
							<el-col :span="8" :offset="4">
								<el-icon :size="40">
									<ArrowUpBold @click="postHandleRemove" />
								</el-icon>
							</el-col>
							<el-col :span="8" :offset="4">
								<el-icon :size="40">
									<ArrowDownBold @click="postHandleSave" />
								</el-icon>
							</el-col>
						</el-row>

						<el-table :data="yesPostTableData" border highlight-current-row @row-click="yesPostRowClick">
							<el-table-column label="已选列表">
								<el-table-column prop="id" label="编号" width="60" v-if="isShow">
								</el-table-column>
								<el-table-column prop="postCode" label="岗位编码" width="120" show-overflow-tooltip>
								</el-table-column>
								<el-table-column prop="postName" label="岗位名称" show-overflow-tooltip>
								</el-table-column>
							</el-table-column>
						</el-table>
						<el-pagination small @current-change="yesPostCurrentChange" :current-page="yesPostCurrentPage"
							:page-size="yesPostPageSize" layout="  prev, pager, next" :total="yesPostTotalRows">
						</el-pagination>
					</el-card>
				</el-col>

			</el-row>


			<template #footer>
				<div class="dialog-footer">
					<el-button type="success" @click="handleSave(ruleFormRef)">保存</el-button>
					<el-button type="danger" @click="handleCancelSave">取消</el-button>
				</div>
			</template>


		</el-dialog>


	</div>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted,
		getCurrentInstance,
		nextTick
	} from 'vue'
	const {
		proxy
	} = getCurrentInstance()

	import style from '@/tools/style'
	const cardBodyStyle = ref(style.card)

	onMounted(() => {
		search()
		getDataTree()
	})

	const activeName = ref('info')



	const rules = reactive({
		userName: [{
			required: true,
			message: '请输入用户名',
			trigger: 'change' | 'blur'
		}],
		userCode: [{
			required: true,
			message: '请输入用户编码',
			trigger: 'change' | 'blur'
		}],
		userDesc: [{
			required: true,
			message: '请输入用户姓名',
			trigger: 'change' | 'blur'
		}],
		password: [{
			required: true,
			message: '请输入密码',
			trigger: 'change' | 'blur'
		}]
	})






	/**
	 *   查询 
	 */
	const queryUserDesc = ref('')
	const tableData = ref([])
	const search = () => {
		currentPage.value = 1
		getTableData()
	}

	const syncOrg = () => {
		var url = '/workflow/process/syncOrg'
		proxy.$axios.post(url, {}).then(response => {
			console.log(response)
			if (response.data.code == '0') {
				ElMessage.success('操作成功！')
			} else {
				ElMessage.error('操作失败！')
			}
		})
	}

	const getTableData = () => {
		console.log(queryUserDesc.value)
		var url = 'framework/SysUser/query'
		var param = {
			page: currentPage.value,
			rows: pageSize.value,
			userDesc: queryUserDesc.value
		}
		proxy.$axios.get(url, param).then(response => {
			if (response.data.code == '0') {
				tableData.value = response.data.data.records
				totalRows.value = response.data.data.total
				// tableData.value = response.data.data.records
				// totalRows.value = response.data.data.total
			} else {
				ElMessage.error('操作失败！' + response.data.msg)
			}
		})
	}
	/**
	 *   查询 
	 */

	/**
	 * 分页 
	 */
	const currentPage = ref(1)
	const totalRows = ref(0)
	const pageSizes = ref([5, 10, 15, 20])
	const pageSize = ref(15)
	const handleSizeChange = (val) => {
		pageSize.value = val
		getTableData()
	}
	const handleCurrentChange = (val) => {
		currentPage.value = val
		getTableData()
	}
	/**
	 * 分页 
	 */


	/**
	 * 新增
	 */
	const dialogVisible = ref(false)
	const user = ref({
		id: '',
		adminFlag: '0'
	})
	const handleAdd = () => {
		// dialogVisible.value = true

		activeName.value = 'info'
		user.value = {
			id: '',
			adminFlag: '0'
		}
		// user.value.id = ''
		// user.value.adminFlag = '0'
		// user  = {
		// 	id: '',
		// 	adminFlag: '0'
		// }
		var url = 'framework/SysUser/queryNewCode'
		var param = {}
		proxy.$axios.get(url, param).then(response => {
			user.value.userCode = response.data.data.code

		});


		getNoPostTableData()
		getYesPostTableData()
		getNoRoleTableData()
		getYesRoleTableData()
	}
	/**
	 * 新增 
	 */
	const ruleFormRef = ref()
	const handleSave = (ruleFormRef) => {
		ruleFormRef.validate((valid, fields) => {
			if (valid) {

				checkedKeys.value = treeRef.value.getCheckedKeys(false)
				var url = 'framework/SysUser/saveAll'
				var param = {
					json: JSON.stringify(user.value),
					roles: JSON.stringify(yesRoleTableData.value),
					posts: JSON.stringify(yesPostTableData.value),
					departments: JSON.stringify(checkedKeys.value)
				}
				proxy.$axios.post(url, param).then(response => {
					if (response.data.code == 0) {
						ElMessage({
							message: '保存成功',
							type: 'success',
						})
						getTableData()
						dialogVisible.value = false
					} else {
						// ElMessage.error('操作失败！' + response.data.msg)  
						ElMessage({
							type: 'error',
							message: '操作失败' + response.data.msg
						})
					}
				});
			} else {
				console.log('error submit!', fields)
			}

		})
	}
	const handleCancelSave = () => {
		dialogVisible.value = false
	}


	const handleEdit = (row) => {
		// dialogVisible.value = true
		user.value = row
		getUserDepartment()
		getNoPostTableData()
		getYesPostTableData()
		getNoRoleTableData()
		getYesRoleTableData()

	}
	const handleEditRow = (row) => {
		// dialogVisible.value = true
		user.value = row
		getUserDepartment()
		getNoPostTableData()
		getYesPostTableData()
		getNoRoleTableData()
		getYesRoleTableData()
		getAccount()
	}



	const handleDelete = (row) => {
		ElMessageBox.confirm(
				'确定删除本条记录?',
				'提示', {
					confirmButtonText: '确认',
					cancelButtonText: '取消',
					type: 'warning',
					draggable: true,
				}
			)
			.then(() => {
				var url = 'framework/SysUser/remove'
				var param = {
					id: user.value.id
				}
				proxy.$axios.post(url, param).then(response => {
					if (response.data.code == 0) {
						ElMessage({
							type: 'success',
							message: '删除成功',
						})
						getTableData()
						user.value = {
							id: ''
						}
					} else {
						ElMessage({
							type: 'error',
							message: '删除失败' + response.data.msg
						});
					}
				});


			})
			.catch(() => {
				ElMessage({
					type: 'info',
					message: '已取消',
				})
			})
	}



	const handleDragend = () => {

	}

	/**
	 * 角色 
	 */
	const isShow = ref(false)
	const queryRole = ref('')

	const noRole = ref()
	const yesRole = ref()

	const noRoleTableData = ref([])
	const noRoleCurrentPage = ref(1)
	const noRolePageSize = ref(10)
	const noRoleTotalRows = ref(0)

	const yesRoleTableData = ref([])
	const yesRoleCurrentPage = ref(1)
	const yesRolePageSize = ref(10)
	const yesRoleTotalRows = ref(0)

	const searchRole = () => {
		noRoleCurrentPage.value = 1
		getNoRoleTableData()
	}

	const getNoRoleTableData = () => {
		var url = 'framework/SysRole/querySystemRolePage'
		var param = {
			page: noRoleCurrentPage.value,
			rows: noRolePageSize.value,
			userId: user.value.id,
			namecode: queryRole.value
		}
		proxy.$axios.get(url, param).then(response => {
			noRoleTableData.value = response.data.data.records
			noRoleTotalRows.value = response.data.data.total
		});
	}
	const getYesRoleTableData = () => {
		var url = 'framework/SysRole/queryUserRolePage'
		var param = {
			page: yesRoleCurrentPage.value,
			rows: yesRolePageSize.value,
			userId: user.value.id
		}
		proxy.$axios.get(url, param).then(response => {
			yesRoleTableData.value = response.data.data.records
			yesRoleTotalRows.value = response.data.data.total
		});
	}


	const noRoleRowClick = (row) => {
		noRole.value = row
	}

	const yesRoleRowClick = (row) => {
		yesRole.value = row
	}

	const roleHandleSave = () => {
		yesRoleTableData.value.push(noRole.value)
		noRoleTableData.value.forEach((item, index, arr) => {
			if (item.id === noRole.value.id) {
				noRoleTableData.value.splice(index, 1)
			}
		})
	}

	const roleHandleRemove = (row) => {
		yesRoleTableData.value.forEach((item, index, arr) => {
			if (item.id === yesRole.value.id) {
				yesRoleTableData.value.splice(index, 1)
			}
		})
		noRoleTableData.value.push(yesRole.value)
	}

	const noRoleCurrentChange = (val) => {
		noRoleCurrentPage.value = val
		getNoRoleTableData()
	}

	const yesRoleCurrentChange = (val) => {
		yesRoleCurrentPage.value = val
		getYesRoleTableData()
	}



	/**
	 * 部门
	 */
	import {
		ElTree
	} from 'element-plus'
	import Node from 'element-plus/es/components/tree/src/model/node'
	const treeRef = ref()
	const emptyTree = ref([])
	const dataTree = ref([])
	const defaultProps = reactive({
		children: 'children',
		label: 'deptName'
	})
	const expandedKeys = ref([])
	const checkedKeys = ref([])
	const refreshTree = ref(true)

	const getDataTree = () => {
		var url = 'framework/SysDepartment/queryTree'
		var param = {}
		proxy.$axios.get(url, param).then(response => {
			emptyTree.value = response.data.data
			dataTree.value = response.data.data
			if (dataTree.value.length == 1) {
				for (var node of dataTree.value) {
					expandedKeys.value.push(node.id)
				}
			}
		})
	}

	const getUserDepartment = () => {
		var url = 'framework/SysUserDept/queryByUserId'
		var param = {
			userId: user.value.id,
		}
		proxy.$axios.get(url, param).then(response => {
			if (response.data.code == 0) {
				//tree树形结构展开已选节点
				refreshTree.value = true
				var arr = []
				for (var userdept of response.data.data) {
					arr.push(userdept.dept.id)
				}
				treeRef.value.setCheckedKeys(arr)
				nextTick(() => {
					expandedKeys.value = arr
				})
			} else {
				ElMessage({
					message: '操作失败' + response.data.msg,
					type: 'error'
				})
			}
		})
	}
	const userDeptSelect = ref({
		deptName: '',
		deptCode: '',
		deptDesc: ''
	})
	const handleNodeClick = (data) => {
		var url = 'framework/SysDepartment/queryById'
		var param = {
			id: data.id
		}
		proxy.$axios.get(url, param).then(response => {
			userDeptSelect.value = response.data.data
		});
	}




	/**
	 * 岗位 
	 */
	const queryPost = ref('')

	const noPost = ref()
	const yesPost = ref()

	const noPostTableData = ref([])
	const noPostCurrentPage = ref(1)
	const noPostPageSize = ref(10)
	const noPostTotalRows = ref(0)

	const yesPostTableData = ref([])
	const yesPostCurrentPage = ref(1)
	const yesPostPageSize = ref(10)
	const yesPostTotalRows = ref(0)

	const searchPost = () => {
		noRoleCurrentPage.value = 1
		getNoPostTableData()
	}

	const getNoPostTableData = () => {
		var url = 'framework/SysPost/querySystemPostPage'
		var param = {
			page: noPostCurrentPage.value,
			rows: noPostPageSize.value,
			userId: user.value.id,
			namecode: queryPost.value
		}
		proxy.$axios.get(url, param).then(response => {
			noPostTableData.value = response.data.data.records
			noPostTotalRows.value = response.data.data.total
		});
	}
	const getYesPostTableData = () => {
		var url = 'framework/SysPost/queryUserPostPage'
		var param = {
			page: yesPostCurrentPage.value,
			rows: yesPostPageSize.value,
			userId: user.value.id
		}
		proxy.$axios.get(url, param).then(response => {
			yesPostTableData.value = response.data.data.records
			yesPostTotalRows.value = response.data.data.total
		});
	}


	const noPostRowClick = (row) => {
		noPost.value = row
	}

	const yesPostRowClick = (row) => {
		yesPost.value = row
	}

	const postHandleSave = (row) => {
		yesPostTableData.value.push(noPost.value)
		noPostTableData.value.forEach((item, index, arr) => {
			if (item.id === noPost.value.id) {
				noPostTableData.value.splice(index, 1);
			}
		});
	}

	const postHandleRemove = (row) => {
		yesPostTableData.value.forEach((item, index, arr) => {
			if (item.id === yesPost.value.id) {
				yesPostTableData.value.splice(index, 1);
			}
		});
		noPostTableData.value.push(yesPost.value)
	}

	const noPostCurrentChange = (row) => {

	}

	const yesPostCurrentChange = (row) => {

	}



	const resetPassword = () => {
		if (user.value.id == undefined || user.value.id == null || user.value.id == '') {
			ElMessage({
				message: '请先选择用户',
				type: 'error'
			})
			return
		}

		ElMessageBox.confirm(
				'确定重置用户: ' + user.value.userDesc + ' 的密码?',
				'提示', {
					confirmButtonText: '确认',
					cancelButtonText: '取消',
					type: 'warning',
					draggable: true,
				}
			)
			.then(() => {
				var url = 'framework/SysUser/resetPassword'
				var param = {
					userId: user.value.id,
				}
				proxy.$axios.post(url, param).then(response => {
					if (response.data.code == 0) {
						ElMessage({
							message: '重置密码成功',
							type: 'success'
						})
					} else {
						ElMessage({
							message: '重置密码失败',
							type: 'error'
						})
					}
				});
			})
			.catch(() => {
				ElMessage({
					type: 'info',
					message: '已取消',
				})
			})
	}

	const account = ref({})
	const getAccount = () => {
		var url = 'framework/SysUser/queryAccount'
		var param = {
			userId: user.value.id,
		}
		proxy.$axios.get(url, param).then(response => {
			if (response.data.code == 0) {
				account.value = response.data.data
			} else {
				ElMessage({
					message: '查询失败',
					type: 'error'
				})
			}
		});
	}



	const lock = (flag) => {
		if (user.value.id == undefined || user.value.id == null || user.value.id == '') {
			ElMessage({
				message: '请先选择用户',
				type: 'error'
			})
			return
		}


		var url = 'framework/SysUser/lockAccount'
		var param = {
			userId: user.value.id,
			flag: flag
		}
		proxy.$axios.post(url, param).then(response => {
			if (response.data.code == 0) {
				ElMessage({
					message: '操作成功',
					type: 'success'
				})
				getAccount()
			} else {
				ElMessage({
					message: '操作失败',
					type: 'error'
				})
			}
		});
	}
</script>

<style>
</style>