| | |
| | | <el-form-item :label="$t('table.user.username')" prop="username"> |
| | | <el-input v-model="user.username" :readonly="user.userId === '' ? false : 'readonly'" /> |
| | | </el-form-item> |
| | | <el-form-item label="员工姓名" prop="nickName"> |
| | | <el-form-item label="姓名" prop="nickName"> |
| | | <el-select v-model="user.nickName" filterable placeholder="" style="width:100%" @change="nickName"> |
| | | <el-option |
| | | v-for="item in baseinfo" |
| | |
| | | <el-tree |
| | | ref="deptTree" |
| | | :data="deptTree" |
| | | :check-strictly="false" |
| | | :default-checked-keys="user.deptIdsArr" |
| | | show-checkbox |
| | | accordion |
| | |
| | | }) |
| | | }, |
| | | setUser(val) { |
| | | setTimeout(() => { |
| | | this.filterDate(val) |
| | | }, 1000) |
| | | }, |
| | | filterDate(val) { |
| | | var this_ = this |
| | | this.user = { ...val } |
| | | this.user.deptIds && (this.user.deptIdsArr = this.user.deptIds.split(',')) |
| | | var deptIdArrStr = [] |
| | | this.user.deptIds.split(',').forEach(element => { |
| | | const thisNode = this_.$refs.deptTree.getNode(element) // 获取当前节点 |
| | | if (thisNode.childNodes.length === 0) { |
| | | deptIdArrStr.push(thisNode.data.id) |
| | | return |
| | | } |
| | | }) |
| | | |
| | | this.user.deptIds && (this.user.deptIdsArr = deptIdArrStr) |
| | | }, |
| | | close() { |
| | | this.$emit('close') |
| | | }, |
| | | // 选中子节点,默认选中父节点 |
| | | checkeTree(data) { |
| | | let thisNode = this.$refs.deptTree.getNode(data.id) // 获取当前节点 |
| | | const keys = this.$refs.deptTree.getCheckedKeys() // 获取已勾选节点的key值 |
| | | if (thisNode.checked) { // 当前节点若被选中 |
| | | // if (thisNode.data.id !== '1') { |
| | | // this.checkAllChild(thisNode, keys) |
| | | // } |
| | | for (let i = thisNode.level; i > 1; i--) { // 判断是否有父级节点 |
| | | if (!thisNode.parent.checked) { // 父级节点未被选中,则将父节点替换成当前节点,往上继续查询,并将此节点key存入keys数组 |
| | | thisNode = thisNode.parent |
| | | keys.push(thisNode.data.id) |
| | | } |
| | | } |
| | | } |
| | | this.$refs.deptTree.setCheckedKeys(keys) // 将所有keys数组的节点全选中 |
| | | }, |
| | | checkAllChild(data, keys) { |
| | | if (data.childNodes.length === 0) { |
| | | return |
| | | } else { |
| | | for (let i = 0; i < data.childNodes.length; i++) { |
| | | if (!data.childNodes[i].checked) { |
| | | keys.push(data.childNodes[i].data.id) |
| | | } |
| | | this.checkAllChild(data.childNodes[i], keys) |
| | | } |
| | | } |
| | | }, |
| | | submitForm() { |
| | | this.$refs.form.validate((valid) => { |
| | | if (valid) { |
| | | this.buttonLoading = true |
| | | this.user.roleId = this.user.roleId.join(',') |
| | | this.user.deptIds = this.$refs.deptTree.getCheckedKeys() |
| | | this.user.deptIds = this.$refs.deptTree.getCheckedKeys().concat(this.$refs.deptTree.getHalfCheckedKeys()) |
| | | if (!this.user.userId) { |
| | | // create |
| | | this.$post('system/user', { ...this.user }).then(() => { |