itemTree.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <div class="treeList">
  3. <div class="tree-body">
  4. <a-spin :spinning="spinning">
  5. <Tree
  6. :multiple="true"
  7. :notNull="true"
  8. :returnParentNode="false"
  9. :data="treeData"
  10. @change="onChange"
  11. />
  12. <!-- <a-tree-->
  13. <!-- v-model="checkedKeys"-->
  14. <!-- show-checkbox-->
  15. <!-- checkable-->
  16. <!-- :expanded-keys="expandedKeys"-->
  17. <!-- :auto-expand-parent="autoExpandParent"-->
  18. <!-- :selected-keys="selectedKeys"-->
  19. <!-- :tree-data="treeData"-->
  20. <!-- node-key="id"-->
  21. <!-- @expand="onExpand"-->
  22. <!-- @select="onSelect"-->
  23. <!-- @check="onCheck"-->
  24. <!-- />-->
  25. </a-spin>
  26. </div>
  27. <div class="btn-list">
  28. <a-button type="link" @click="getSelectId('rest')">恢复默认</a-button>
  29. <a-button @click="getSelectId('cancel')">取消</a-button>
  30. <a-button type="primary" @click="getSelectId(checkedKeys)" style="margin-left: 10px;">确定</a-button>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import { queryInfoSystem} from "@/api/editer.js";
  36. const treeData = [];
  37. export default {
  38. data() {
  39. return {
  40. expandedKeys: ["", ""],
  41. autoExpandParent: true,
  42. checkedKeys: [],
  43. selectedKeys: [],
  44. treeData,
  45. spinning:false
  46. };
  47. },
  48. props:{
  49. categoryIdS:Array,
  50. // categoryId:String,
  51. drawerVisible:Boolean
  52. },
  53. watch: {
  54. checkedKeys(val) {
  55. this.checkedKeys = val;
  56. },
  57. drawerVisible(val){
  58. if(!val){
  59. this.checkedKeys =this.categoryIdS;
  60. }
  61. }
  62. },
  63. methods: {
  64. onExpand(expandedKeys) {
  65. console.log("onExpand", expandedKeys);
  66. // if not set autoExpandParent to false, if children expanded, parent can not collapse.
  67. // or, you can remove all expanded children keys.
  68. this.expandedKeys = expandedKeys;
  69. this.autoExpandParent = false;
  70. },
  71. onCheck(checkedKeys,b) {
  72. console.log("onCheck", checkedKeys,b.node);
  73. this.checkedKeys = checkedKeys;
  74. },
  75. onSelect(selectedKeys, info) {
  76. console.log("onSelect", info);
  77. this.selectedKeys = selectedKeys;
  78. },
  79. onChange(id){
  80. console.log(id);
  81. this.checkedKeys = id.checkedIds;
  82. },
  83. queryByGroup() {
  84. this.spinning = true;
  85. const data = {
  86. "Orders": "orderId asc",
  87. }
  88. queryInfoSystem(data).then(res => {
  89. this.spinning = false;
  90. this.treeData = this.mapTree(res.Content);
  91. this.checkedKeys = this.categoryIdS;
  92. });
  93. },
  94. mapTree(tree) {
  95. const newTree = [];
  96. tree.forEach(item => {
  97. if (item.Category && item.Category.length) {
  98. const children = this.mapTree(item.Category);
  99. newTree.push({
  100. title: item.Name,
  101. name: item.Name,
  102. id: item.Id,
  103. key:item.Id,
  104. checked: 'uncheck',
  105. children
  106. });
  107. } else {
  108. newTree.push({
  109. title: item.Name,
  110. name: item.Name,
  111. id: item.Id,
  112. key:item.Id,
  113. checked: 'uncheck',
  114. children: []
  115. });
  116. }
  117. });
  118. // newTree.push({
  119. // title: '其他分组',
  120. // name: '其他分组',
  121. // id: '#',
  122. // key:'#',
  123. // checked: 'uncheck',
  124. // children: []
  125. // })
  126. return newTree;
  127. },
  128. //确定
  129. getSelectId(data){
  130. if(data == 'cancel'){
  131. this.checkedKeys = this.categoryIdS;
  132. this.treeData.map(item=>{
  133. if(this.categoryIdS.indexOf(item.id)>-1){
  134. item.checked = 'checked'
  135. }else{
  136. item.checked = 'uncheck'
  137. }
  138. })
  139. }else if(data == 'rest'){
  140. // this.checkedKeys = [this.categoryId];
  141. this.checkedKeys = [];
  142. this.treeData.map(item=>{
  143. item.checked = 'uncheck'
  144. })
  145. }else{
  146. this.checkedKeys =data;
  147. }
  148. this.$emit('getSelectId',this.checkedKeys)
  149. }
  150. },
  151. created() {
  152. this.queryByGroup();
  153. }
  154. };
  155. </script>
  156. <style lang="less">
  157. .treeList {
  158. width: 240px;
  159. .tree-body {
  160. height: 420px;
  161. overflow-y: auto;
  162. /deep/ .p-tree-node-content{
  163. padding-left: 0 !important;
  164. }
  165. }
  166. }
  167. </style>