123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- <template>
- <div class="flex-box">
- <div class="treebox">
- <!-- <div class="tree-text">组织机构</div> -->
- <el-input placeholder="可按名字匹配所在部门" v-model="filterText">
- </el-input>
- <el-tree ref="tree" @node-click="handleNodeClick" :data="treeList" node-key="o" :indent="20"
- :default-checked-keys="defaultListc" :default-expanded-keys="defaultList">
- <span class="span-ellipsis" slot-scope="{ node, data }">
- <span :title="node.label"><i v-if="data.children.length === 0" class="el-icon-caret-right icon-right"></i>
- {{ node.label }}</span>
- </span>
- </el-tree>
- </div>
- <div class="flex-transfer">
- <el-transfer v-model="value" :titles="['待选人员', '已选人员']" @change="handleCheckChange"
- :data="transferList"></el-transfer>
- </div>
- </div>
- </template>
- <script>
- export default {
- props: ["defaultList", "type", "oneORmore","treeListType"],
- data() {
- return {
- filterTexts: "",
- filterText: "",
- transferList: [],
- treeList: [],
- treeLists: [],
- rightList: [],
- value: [],
- newArr: [],
- opt: [],
- treeId: 1,
- defaultProps: {
- children: "children",
- label: "label",
- },
- defaultListc: [],
- };
- },
- methods: {
- handleNodeClick(v) {
- for (let i = v.children.length - 1; i >= 0; i--) {
- if (v.children[i].haveUserFlag == "N") {
- v.children.splice(i, 1);
- }
- }
- // v.children.map((item,index) =>{
- // if(item.haveUserFlag == "N"){
- // v.children.splice(index, 1);
- // }
- // console.log(v.children);
- // })
- let list = {
- groupId: v.o,
- };
- if (this.filterTexts) {
- list.loginNameStr = this.filterTexts;
- }
- if (v.o !== this.treeId) {
- if (this.value.length !== 0) {
- let a = [];
- for (let i = 0; i <= this.transferList.length - 1; i++) {
- for (let y = 0; y <= this.value.length; y++) {
- if (this.transferList[i].key === this.value[y]) {
- console.log(this.transferList[i].key);
- console.log(this.value[y]);
- a.push(this.transferList[i]);
- }
- }
- }
- console.log(a);
- this.transferList = a;
- // console.log(this.transferList);
- } else {
- this.transferList = [];
- }
- }
- let s = false;
- if (v.children && v.children.length == 0) {
- s = true;
- }
- if (v.type) {
- return;
- }
- if (
- v.children &&
- v.children.length > 0 &&
- v.children[v.children.length - 1].type == 1
- ) {
- return;
- }
- if (v.o !== this.treeId) {
- this.$http({
- url: "/sysmgr/sysuserinfo/queryListByName",
- method: "post",
- headers: {
- "Content-Type": "application/json",
- },
- data: list
- }).then((res) => {
- v.children = v.children ? v.children : [];
- this.treeId = v.o;
- this.treeLists = res.data;
- res.data.map((item, index) => {
- this.transferList.push({
- label: item.loginNameStr,
- key: item.loginNoStr,
- groupName: item.groupName,
- });
- });
- const dalaoyang = (arr, key) => {
- let map = new Map()
- return arr.filter(item => !map.has(item[key]) && map.set(item[key], 1))
- }
- this.transferList = dalaoyang(this.transferList, "key")
- console.log(this.transferList);
- });
- } else {
- console.log(this.transferList);
- }
- },
- getTree(v, e) {
- let list = {
- parentorgId: v,
- type:this.treeListType,//* 1:全部传递 2:值传递第一层 3:值传递第一层之后数据
- };
- if (e) {
- list.name = e;
- }
- this.loading = true;
- this.$http({
- // url: "/sysmgr/csysdept/queryAllList",
- url: "/sysmgr/csysdept/queryAllListByParentorgId",
- method: "post",
- headers: {
- "Content-Type": "application/json",
- },
- data: list,
- }).then((res) => {
- this.loading = false;
- this.treeList = res.data;
- let list = res.data[0].children.filter((item, i, array) => {
- return item.haveUserFlag === "Y";
- });
- this.treeList[0].children = list;
- });
- },
- handleCheckChange(v) {
- // console.log(this.value);
- if (this.oneORmore == '2') {
- if (this.value.length > 1) {
- this.$message({
- message: '只能选择一人',
- type: 'error'
- });
- this.value = [this.value[0]]
- let opt = [];
- this.transferList.map((item) => {
- this.value.map((items) => {
- if (item.key === items) {
- opt.push(item);
- }
- });
- });
- // console.log(opt);
- this.$emit("treeCheck", opt);
- } else {
- let opt = [];
- this.transferList.map((item) => {
- this.value.map((items) => {
- if (item.key === items) {
- opt.push(item);
- }
- });
- });
- // console.log(opt);
- this.$emit("treeCheck", opt);
- }
- } else {
- let opt = [];
- this.transferList.map((item) => {
- this.value.map((items) => {
- if (item.key === items) {
- opt.push(item);
- }
- });
- });
- // console.log(opt);
- this.$emit("treeCheck", opt);
- }
- },
- },
- created() {
- this.getTree('00440063000000000000');
- this.defaultListc = this.defaultList;
- },
- watch: {
- filterText(val) {
- // this.$refs.tree.filter(val);
- console.log(val);
- this.filterTexts = val;
- this.getTree("00440063000000000000", this.filterTexts);
- },
- },
- };
- </script>
- <style scoped lang="scss">
- ::v-deep .el-checkbox.el-transfer-panel__item {
- display: block !important;
- }
- // ::v-deep .el-transfer-panel__list.is-filterable {
- // height: calc(100%);
- // }
- // ::v-deep .el-checkbox-group .el-transfer-panel__list {
- // height: 388px;
- // }
- .el-transfer-panel {
- height: 500px;
- }
- .el-transfer-panel__list.is-filterable {
- height: 400px;
- }
- ::v-deep .el-transfer-panel__body {
- height: 100%;
- }
- ::v-deep .el-transfer-panel__list{
- height: 100%;
- }
- .tree-text {
- font-size: 20px;
- color: black;
- padding: 15px;
- font-weight: 600;
- }
- .flex-box {
- display: flex;
- width: 100%;
- justify-content: center;
- height: 80%;
- }
- ::v-deep .el-icon-caret-right {
- font-size: 12px;
- background-size: cover;
- margin-left: px;
- }
- .icon-right {
- margin-left: 5px;
- color: #fff;
- }
- .treebox {
- width: 30%;
- border: 1px solid #ddd;
- height: 100%;
- background-color: #fff;
- overflow: scroll;
- overflow-x: hidden;
- max-height: 390px;
- height: 390px;
- }
- .flex-transfer {
- width: 50%;
- height: 390px;
- margin-left: 30px;
- }
- ::v-deep .el-transfer-panel {
- width: 35%;
- height: 100%;
- }
- ::v-deep .el-transfer {
- height: 100%;
- }
- </style>
|