Blame view

src/views/home/components/addProject.vue 2.8 KB
蔡俊立 committed
1 2
<template>
  <dialogBox title="配置常办项目" @submitForm="submitForm" saveButton="保存" :isFullscreen="false" width="50%"
任超 committed
3 4 5
    @closeDialog="closeDialog" v-model="myValue">
    <el-tree :data="projectList" show-checkbox node-key="id" :default-checked-keys="defaultCheckeds" ref="tree"
      default-expand-all :props="defaultProps" @check-change="handleClick"></el-tree>
蔡俊立 committed
6 7 8
  </dialogBox>
</template>
<script>
任超 committed
9
import { getMenuInfo } from "@/api/user.js";
任超 committed
10
import { saveFrequentProjectsList, getHomeFrequentProjects } from "@/api/user.js";
蔡俊立 committed
11 12 13
export default {
  props: {
    value: { type: Boolean, default: false },
任超 committed
14
    bindItem: { type: Array, default: [] }
蔡俊立 committed
15 16 17
  },
  data () {
    return {
任超 committed
18 19
      myValue: false,
      defaultCheckeds: [],
蔡俊立 committed
20 21 22 23 24
      projectList: [],
      checkedItem: [],
      defaultProps: {
        children: "children",
        label: "name",
任超 committed
25 26 27 28 29 30
        disabled: function (data, node) {
          if (data.children && data.children.length > 0) {
            return true
          } else {
            return false
          }
蔡俊立 committed
31 32
        }
      },
任超 committed
33
      uniqueValue: ''//最后拿到的唯一选择的moduldCode值,相当于id
蔡俊立 committed
34 35
    }
  },
任超 committed
36 37 38 39 40 41 42 43
  watch: {
    value (val) {
      this.myValue = val
      if (val) {
        this.queryClick()
      }
    }
  },
任超 committed
44
  mounted () {
蔡俊立 committed
45 46 47 48
    this.dealCheckedItem();
  },
  methods: {
    submitForm () {
任超 committed
49 50 51 52 53 54 55 56 57 58 59 60
      var checkedNodes = this.$refs.tree.getCheckedNodes();
      if (checkedNodes.length > 6) {
        this.$message.error("最多选择6个项目!");
        return
      }
      saveFrequentProjectsList(checkedNodes).then(res => {
        if (res.code == 200) {
          this.$parent.queryProjectList();
          this.$message.success("保存成功");
          this.$emit("input", false);
        } else {
          this.$message.error(res.message);
蔡俊立 committed
61
        }
任超 committed
62
      })
蔡俊立 committed
63
    },
任超 committed
64
    queryClick () {
任超 committed
65
      let that = this
任超 committed
66
      getMenuInfo().then(res => {
任超 committed
67
        this.projectList = res.result.slice(0, -2)
任超 committed
68
      })
任超 committed
69 70 71 72 73 74 75 76 77
      function lookForAllId (arr = []) {
        for (let item of that.bindItem) {
          arr.push(item.id)
          if (item.children && item.children.length) lookForAllId(item.children, arr)
        }
        return arr
      }
      that.defaultCheckeds = lookForAllId()
      console.log(that.defaultCheckeds);
蔡俊立 committed
78
    },
任超 committed
79
    dealCheckedItem () {
蔡俊立 committed
80 81 82 83 84 85
    },
    //关闭窗口
    closeDialog () {
      this.$emit("input", false);
    },
    //节点选择状态发生改变时
任超 committed
86 87 88 89 90 91 92
    handleClick (data, checked, node) {
      var checkedNodes = this.$refs.tree.getCheckedNodes();
      if (checked) {
        checkedNodes.push(data);
      }
      this.$refs.tree.setCheckedNodes(checkedNodes);
      console.log(this.$refs.tree.getCheckedNodes());
蔡俊立 committed
93 94 95 96 97
    },
  }
}
</script>
<style scoped lang='scss'>
任超 committed
98 99 100 101
/deep/.el-tree-node.is-expanded>.el-tree-node__children {
  display: flex;
  flex-wrap: wrap;
}
蔡俊立 committed
102
</style>