check.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <div class="cl-dept-check" v-loading="loading">
  3. <p v-if="title">{{ title }}</p>
  4. <div class="cl-dept-check__search">
  5. <el-input placeholder="输入关键字进行过滤" v-model="keyword" size="small"> </el-input>
  6. <el-switch
  7. :active-value="1"
  8. :inactive-value="0"
  9. v-model="form.relevance"
  10. @change="onCheckStrictlyChange"
  11. ></el-switch
  12. >是否关联上下级
  13. </div>
  14. <div class="cl-dept-check__tree" v-if="visible">
  15. <el-tree
  16. :data="list"
  17. :props="props"
  18. :default-checked-keys="checked"
  19. :filter-node-method="filterNode"
  20. :check-strictly="!form.relevance"
  21. highlight-current
  22. node-key="id"
  23. show-checkbox
  24. ref="tree"
  25. @check-change="onCheckChange"
  26. >
  27. </el-tree>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import { deepTree } from "cl-admin/utils";
  33. export default {
  34. name: "cl-dept-check",
  35. props: {
  36. value: Array,
  37. title: String
  38. },
  39. inject: ["form"],
  40. data() {
  41. return {
  42. list: [],
  43. checked: [],
  44. keyword: "",
  45. props: {
  46. label: "name",
  47. children: "children"
  48. },
  49. loading: false,
  50. visible: true
  51. };
  52. },
  53. watch: {
  54. keyword(val) {
  55. this.$refs["tree"].filter(val);
  56. },
  57. value(val) {
  58. this.refreshTree(val);
  59. }
  60. },
  61. mounted() {
  62. this.refresh();
  63. },
  64. methods: {
  65. refreshTree(val) {
  66. this.checked = val || [];
  67. },
  68. refresh() {
  69. this.$service.system.dept
  70. .list()
  71. .then((res) => {
  72. this.list = deepTree(res);
  73. this.refreshTree(this.value);
  74. })
  75. .catch((err) => {
  76. this.$message.error(err);
  77. });
  78. },
  79. filterNode(val, data) {
  80. if (!val) return true;
  81. return data.name.includes(val);
  82. },
  83. onCheckStrictlyChange() {
  84. this.visible = false;
  85. this.$nextTick(() => {
  86. this.visible = true;
  87. });
  88. },
  89. onCheckChange() {
  90. this.$emit("input", this.$refs["tree"].getCheckedKeys());
  91. }
  92. }
  93. };
  94. </script>
  95. <style lang="scss" scoped>
  96. .cl-dept-check {
  97. &__search {
  98. display: flex;
  99. align-items: center;
  100. .el-input {
  101. flex: 1;
  102. margin-right: 10px;
  103. }
  104. .el-switch {
  105. margin-right: 5px;
  106. }
  107. }
  108. &__tree {
  109. border: 1px solid #dcdfe6;
  110. margin-top: 5px;
  111. border-radius: 3px;
  112. max-height: 200px;
  113. box-sizing: border-box;
  114. overflow-x: hidden;
  115. padding: 5px 0;
  116. }
  117. }
  118. </style>