mouldChoose.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <!-- 角色权限分配弹窗 -->
  2. <template>
  3. <ele-modal width="460px" title="选择模具" :visible="visible" :append-to-body="true" @update:visible="updateVisible">
  4. <el-scrollbar style="height: 60vh" wrap-style="overflow-x: hidden;">
  5. <el-tree :data="treeList" :props="defaultProps" v-loading="treeLoading" :node-key="nodeKey" ref="tree"
  6. :highlight-current="true" :expand-on-click-node="false" @check-change="handleCheckChange" v-bind="$attrs"
  7. :default-expand-all="defaultExpandAll" show-checkbox :default-checked-keys="checkedKeys" check-strictly>
  8. </el-tree>
  9. </el-scrollbar>
  10. <template v-slot:footer>
  11. <el-button type="primary" @click="save">确定</el-button>
  12. <el-button @click="updateVisible(false)">取消</el-button>
  13. </template>
  14. </ele-modal>
  15. </template>
  16. <script>
  17. import { getTreeByPid } from '@/api/classifyManage';
  18. export default {
  19. props: {
  20. // treeList私有化处理
  21. treeFormate: {
  22. type: Function,
  23. default: null
  24. },
  25. defaultProps: {
  26. type: Object,
  27. default: function () {
  28. return {
  29. children: 'children',
  30. value: 'id',
  31. label: 'name'
  32. };
  33. }
  34. },
  35. defaultExpandAll: {
  36. type: Boolean,
  37. default: function () {
  38. return true;
  39. }
  40. },
  41. id: {
  42. type: String,
  43. default: '0'
  44. },
  45. nodeKey: {
  46. type: String,
  47. default: 'id'
  48. }
  49. },
  50. data() {
  51. return {
  52. treeList: [],
  53. treeLoading: false,
  54. current: null,
  55. checkedKeys: [],
  56. visible: false,
  57. idx: null
  58. };
  59. },
  60. mounted() {
  61. },
  62. methods: {
  63. open(item,idx) {
  64. this.getTreeData();
  65. this.current= {
  66. id: item.modelCategoryLevelId,
  67. code: item.modelCategoryLevelCode,
  68. name: item.modelCategoryLevelName,
  69. }
  70. this.checkedKeys.push(item.modelCategoryLevelId)
  71. this.idx = idx
  72. this.visible = true
  73. },
  74. // 获取树结构数据
  75. async getTreeData() {
  76. try {
  77. this.treeLoading = true;
  78. const res = await getTreeByPid(this.id);
  79. this.treeLoading = false;
  80. if (res?.code === '0') {
  81. this.treeList = res.data;
  82. if (this.treeFormate) {
  83. this.treeList = this.treeFormate(this.treeList);
  84. }
  85. return this.treeList;
  86. }
  87. } catch (error) { }
  88. this.treeLoading = false;
  89. },
  90. handleCheckChange(data, checked) {
  91. if (checked) {
  92. this.current = data
  93. this.$refs.tree.setCheckedKeys([data.id])
  94. }
  95. },
  96. // 获取树的选中状态
  97. getSelectList() {
  98. const selectList = this.$refs.tree.getCurrentNode();
  99. return selectList;
  100. },
  101. /* 更新visible */
  102. updateVisible(value) {
  103. this.visible = value
  104. },
  105. save() {
  106. this.$emit('saveMould', this.current, this.idx)
  107. this.updateVisible(false)
  108. },
  109. },
  110. };
  111. </script>
  112. <style lang="scss" scoped>
  113. .tree-wrapper {
  114. width: 100%;
  115. height: 100%;
  116. overflow: auto;
  117. :deep(.el-tree) {
  118. display: inline-block;
  119. min-width: 100%;
  120. }
  121. }
  122. </style>