Blame view

src/views/home/components/addProject.vue 3.38 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"
11
import { saveFrequentProjectsList, getHomeFrequentProjects } from "@/api/home.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
    this.dealCheckedItem();
  },
  methods: {
yuanbo committed
52 53 54 55
    /**
     * @description: submitForm
     * @author: renchao
     */
蔡俊立 committed
56
    submitForm () {
任超 committed
57 58 59 60 61 62 63 64 65 66 67 68
      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
69
        }
任超 committed
70
      })
蔡俊立 committed
71
    },
yuanbo committed
72 73 74 75
    /**
     * @description: queryClick
     * @author: renchao
     */
任超 committed
76
    queryClick () {
任超 committed
77
      let that = this
任超 committed
78
      getMenuInfo().then(res => {
任超 committed
79
        this.projectList = res.result.slice(0, -2)
任超 committed
80
      })
任超 committed
81 82 83 84 85 86 87
      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
88
      this.defaultCheckeds = lookForAllId()
蔡俊立 committed
89
    },
yuanbo committed
90 91 92 93
    /**
     * @description: dealCheckedItem
     * @author: renchao
     */
任超 committed
94
    dealCheckedItem () {
蔡俊立 committed
95 96
    },
    //关闭窗口
yuanbo committed
97 98 99 100
    /**
     * @description: 关闭窗口
     * @author: renchao
     */
蔡俊立 committed
101 102 103 104
    closeDialog () {
      this.$emit("input", false);
    },
    //节点选择状态发生改变时
yuanbo committed
105 106 107 108 109 110 111
    /**
     * @description: 节点选择状态发生改变时
     * @param {*} data
     * @param {*} checked
     * @param {*} node
     * @author: renchao
     */
任超 committed
112 113
    handleClick (data, checked, node) {
      var checkedNodes = this.$refs.tree.getCheckedNodes();
任超 committed
114 115 116 117 118 119 120
      if (checkedNodes.length > 6) {
        this.$message({
          message: '最后选择6条数据',
          type: 'warning',
          customClass: 'messageIndex'
        })
        this.$refs.tree.setChecked(data, false) // 取消当前节点的选中状态
任超 committed
121
      }
任超 committed
122
    }
蔡俊立 committed
123 124 125 126
  }
}
</script>
<style scoped lang='scss'>
任超 committed
127 128 129 130
/deep/.el-tree-node.is-expanded>.el-tree-node__children {
  display: flex;
  flex-wrap: wrap;
}
yuanbo committed
131
</style>