| | |
| | | </el-form-item> |
| | | <!-- 部门 --> |
| | | <el-form-item class="optionItems" label="所属部门:" prop="departId"> |
| | | <el-select v-model="form.departName" placeholder="请输入所属部门"> |
| | | <el-option :value="mylabel"> |
| | | <el-tree |
| | | ref="tree" |
| | | :check-strictly="true" |
| | | :data="departList" |
| | | :props="defaultProps" |
| | | show-checkbox |
| | | @check-change="handleCheck" |
| | | default-expand-all |
| | | node-key="id" |
| | | > |
| | | </el-tree> |
| | | </el-option> |
| | | </el-select> |
| | | <departTree |
| | | :depart="userDepart" |
| | | @selectDepart="selectDepart" |
| | | ></departTree> |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <div class="optionBtn"> |
| | |
| | | |
| | | import { createNamespacedHelpers } from "vuex"; |
| | | const { mapActions } = createNamespacedHelpers("handheldTerminal"); |
| | | |
| | | import departTree from "@/components/departTree/index.vue"; |
| | | export default { |
| | | components: { |
| | | departTree, |
| | | }, |
| | | data() { |
| | | const checkName = (rule, value, callback) => { |
| | | if (value) { |
| | |
| | | // } |
| | | // ] |
| | | }, |
| | | selectOrg: { |
| | | orgsid: [], |
| | | }, |
| | | userDepart: {}, |
| | | mylabel: "", |
| | | departList: [], |
| | | defaultProps: { |
| | |
| | | }; |
| | | }, |
| | | created() { |
| | | const { getDepartTree } = this; |
| | | // 初始化部门树 |
| | | getDepartTree(); |
| | | // 初始化数据 |
| | | this.form = this.info; |
| | | if (!this.form.departName) { |
| | | this.form.departName = this.form.pdepartName; |
| | | } |
| | | this.userDepart = { |
| | | departId: this.form.departId, |
| | | departName: this.form.departName, |
| | | }; |
| | | }, |
| | | |
| | | watch: { |
| | |
| | | } |
| | | }); |
| | | }, |
| | | // 部门修改 |
| | | handleCheck(data, checked) { |
| | | this.form.departId = data.id; |
| | | this.form.departName = data.departName; |
| | | // 获取当前选择的id在数组中的索引 |
| | | const indexs = this.selectOrg.orgsid.indexOf(data.id); |
| | | // 如果不存在数组中,并且数组中已经有一个id并且checked为true的时候,代表不能再次选择。 |
| | | if (indexs < 0 && this.selectOrg.orgsid.length === 1 && checked) { |
| | | this.$message({ |
| | | message: "只能选择一个部门!", |
| | | type: "warning", |
| | | showClose: true, |
| | | }); |
| | | // 设置已选择的节点为false 很重要 |
| | | this.$refs.tree.setChecked(data, false); |
| | | } else if (this.selectOrg.orgsid.length === 0 && checked) { |
| | | // 发现数组为空 并且是已选择 |
| | | // 防止数组有值,首先清空,再push |
| | | this.selectOrg.orgsid = []; |
| | | this.selectOrg.orgsid.push(data.id); |
| | | } else if ( |
| | | indexs >= 0 && |
| | | this.selectOrg.orgsid.length === 1 && |
| | | !checked |
| | | ) { |
| | | // 再次直接进行赋值为空操作 |
| | | this.selectOrg.orgsid = []; |
| | | this.form.departName = ""; |
| | | |
| | | selectDepart(depart) { |
| | | if (depart) { |
| | | this.form.departId = depart.departId; |
| | | this.form.departName = depart.departName; |
| | | } |
| | | }, |
| | | // 获取部门树 |
| | | getDepartTree() { |
| | | this.$axios.get("/sccg/depart/tree").then((res) => { |
| | | this.departList = res.data; |
| | | }); |
| | | }, |
| | | }, |
| | | props: ["info", "closeDialog"], |