Blame view

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