fourClass.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="物料分类选择"
  5. width="500px"
  6. :close-on-click-modal="false"
  7. :append-to-body="true"
  8. v-dialogDrag
  9. class="userDialog"
  10. :visible.sync="visible"
  11. >
  12. <el-container style="height: 500px">
  13. <el-container>
  14. <el-main>
  15. <el-row :gutter="10" class="content">
  16. <el-col :span="12">
  17. <el-input
  18. placeholder="输入关键字进行过滤"
  19. size="small"
  20. v-model="filterText">
  21. </el-input>
  22. <el-tree
  23. class="filter-tree"
  24. :data="threedata"
  25. :props="defaultProps"
  26. node-key="id"
  27. highlight-current
  28. @node-click="clickTree"
  29. :filter-node-method="filterNode"
  30. ref="tree">
  31. </el-tree>
  32. </el-col>
  33. </el-row>
  34. </el-main>
  35. </el-container>
  36. </el-container>
  37. <span slot="footer" class="dialog-footer">
  38. <el-button
  39. size="small"
  40. @click="visible = false"
  41. icon="el-icon-circle-close"
  42. >关闭</el-button
  43. >
  44. <el-button
  45. size="small"
  46. type="primary"
  47. icon="el-icon-circle-check"
  48. @click="doSubmit()"
  49. >确定</el-button
  50. >
  51. </span>
  52. </el-dialog>
  53. </div>
  54. </template>
  55. <script>
  56. import { getTree } from '@/api/classify/basic';
  57. export default {
  58. data() {
  59. return {
  60. loading: false,
  61. visible: false,
  62. filterText: '',
  63. threedata: [],
  64. defaultProps: {
  65. children: 'childrens',
  66. label: 'materialType'
  67. },
  68. // 判断是否为最末级节点
  69. isLast: false,
  70. // 选中的节点
  71. choosePoint: {}
  72. };
  73. },
  74. props: {},
  75. methods: {
  76. init() {
  77. this.visible = true;
  78. this.$nextTick(() => {
  79. this.refreshList()
  80. });
  81. },
  82. // 获取数据列表
  83. refreshList(data) {
  84. this.loading = true;
  85. getTree(data).then(res => {
  86. console.log('res',res)
  87. if(res.code === 200) {
  88. this.threedata = res.rows
  89. }
  90. this.loading = false;
  91. });
  92. },
  93. clickTree(data) {
  94. console.log('树形节点信息:',data)
  95. if (data.childrens.length == 0) {
  96. this.isLast = true
  97. } else {
  98. this.isLast = false
  99. }
  100. this.choosePoint = data
  101. },
  102. filterNode(value, data) {
  103. console.log('value', value)
  104. console.log('data', data)
  105. if (!value) return true;
  106. return data.label.indexOf(value) !== -1;
  107. },
  108. doSubmit() {
  109. if(this.isLast == false) {
  110. this.$message({
  111. message: '请选择最末级节点',
  112. type: 'warning'
  113. });
  114. } else {
  115. console.log('子组件选择的数据',this.choosePoint)
  116. this.$emit("doSubmit", this.choosePoint);
  117. this.visible = false;
  118. }
  119. },
  120. },
  121. };
  122. </script>
  123. <style lang="scss">
  124. .userDialog {
  125. .el-dialog__body {
  126. padding: 10px 0px 0px 10px;
  127. color: #606266;
  128. font-size: 14px;
  129. word-break: break-all;
  130. }
  131. .el-main {
  132. padding: 20px 20px 5px 20px;
  133. .el-pagination {
  134. margin-top: 5px;
  135. }
  136. }
  137. }
  138. </style>