tree.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <el-card
  3. shadow="always"
  4. :body-style="{ padding: '20px' }"
  5. v-loading="loading"
  6. >
  7. <div class="tree-title">
  8. <div class="bk"></div>
  9. <div>{{ $t("purchase_management.subscribe.goodClassify") }}</div>
  10. </div>
  11. <el-row class="search" style="display: flex; align-items: center">
  12. <el-input :placeholder="$t('search')" v-model="filterText" size="small">
  13. </el-input>
  14. </el-row>
  15. <el-tree
  16. ref="tree"
  17. :data="treeData"
  18. :props="defaultProps"
  19. default-expand-all
  20. @node-click="handleNodeClick"
  21. :filter-node-method="filterNode"
  22. >
  23. <span class="custom-tree-node" slot-scope="{ node, data }">
  24. <span>{{ node.label }}</span>
  25. </span>
  26. </el-tree>
  27. </el-card>
  28. </template>
  29. <script>
  30. import * as API from "@/api/product-material/product/index.js";
  31. // import test from "@/components/form-test/index.vue";
  32. export default {
  33. name: "tree",
  34. props: {
  35. treeData: {
  36. type: Array,
  37. default: () => [],
  38. },
  39. },
  40. data() {
  41. return {
  42. loading: true,
  43. filterText: "",
  44. treeQuery: {
  45. type: "1",
  46. name: "",
  47. },
  48. // treeData: [],
  49. treeParams: {
  50. id: null,
  51. type: null,
  52. parentId: null,
  53. parentIdSet: null,
  54. name: null,
  55. },
  56. currentNode: {},
  57. treeForm: {
  58. loadingStatus: false,
  59. name: {
  60. label: this.$t("product_material.product.treeName"),
  61. type: "input",
  62. },
  63. otherButton: {
  64. align: "center",
  65. list: [
  66. {
  67. name: this.$t("cancelText"),
  68. methodsText: "cancel",
  69. cancel: () => {
  70. this.treeModal = false;
  71. },
  72. },
  73. {
  74. name: this.$t("submitText"),
  75. methodsText: "submit",
  76. type: "primary",
  77. submit: () => {
  78. this.treehandleSubmit();
  79. },
  80. },
  81. ],
  82. },
  83. },
  84. treeRules: {
  85. name: [
  86. {
  87. required: true,
  88. message: this.$t("product_material.product.nameRules"),
  89. trigger: "blur",
  90. },
  91. ],
  92. },
  93. treeModalType: "add",
  94. treeModal: false,
  95. defaultProps: {
  96. children: "children",
  97. label: "name",
  98. },
  99. };
  100. },
  101. watch: {
  102. filterText(val) {
  103. this.$refs.tree.filter(val);
  104. },
  105. },
  106. created() {
  107. // this.getTree();
  108. },
  109. methods: {
  110. handleMouseenter(data) {
  111. this.currentNode = data;
  112. },
  113. filterNode(value, data) {
  114. if (!value) return true;
  115. return data.name.indexOf(value) !== -1;
  116. },
  117. resetForm(formName) {},
  118. treehandleSubmit() {
  119. this.$refs.form.$refs["form"].validate((valid) => {
  120. if (valid) {
  121. this.treeForm.loadingStatus = true;
  122. if (!this.treeParams.id) {
  123. API.productClassifyAdd(this.treeParams).then(
  124. () => {
  125. this.msgSuccess(this.$t("addSuccess"));
  126. this.treeModal = false;
  127. this.treeForm.loadingStatus = false;
  128. this.getTree();
  129. },
  130. (err) => {
  131. console.log("productClassifyAdd: " + err);
  132. this.treeForm.loadingStatus = false;
  133. }
  134. );
  135. } else {
  136. API.productClassifyEdit(this.treeParams).then(
  137. () => {
  138. this.msgSuccess(this.$t("editSuccess"));
  139. this.treeModal = false;
  140. this.treeForm.loadingStatus = false;
  141. this.getTree();
  142. },
  143. (err) => {
  144. console.log("productClassifyEdit: " + err);
  145. this.treeForm.loadingStatus = false;
  146. }
  147. );
  148. }
  149. }
  150. });
  151. },
  152. handleNodeClick(row) {
  153. this.$emit("treeClick", row);
  154. },
  155. getTree() {
  156. this.loading = true;
  157. API.productTree(this.treeQuery).then(
  158. (res) => {
  159. this.treeData = res.data.data;
  160. this.loading = false;
  161. },
  162. (err) => {
  163. console.log("productTree: " + err);
  164. this.loading = false;
  165. }
  166. );
  167. },
  168. add(row) {
  169. this.treeParams = {
  170. parentIdSet: "",
  171. type: "1",
  172. parentId: "",
  173. name: "",
  174. };
  175. this.treeParams.parentId = row.id;
  176. this.treeModal = true;
  177. },
  178. edit(node, row) {
  179. this.treeModalType = "edit";
  180. this.treeParams = {
  181. type: "1",
  182. parentId: node.parent.data.id,
  183. name: row.name,
  184. id: row.id,
  185. };
  186. this.treeModal = true;
  187. },
  188. del(row) {
  189. this.$confirm(this.$t("askDeleteData"), {
  190. confirmButtonText: this.$t("submitText"),
  191. cancelButtonText: this.$t("cancelText"),
  192. type: "warning",
  193. })
  194. .then(() => {
  195. API.productClassifyDel({ id: row.id, type: "1" }).then(() => {
  196. this.msgSuccess(this.$t("deleteSuccess"));
  197. this.getTree();
  198. });
  199. })
  200. .catch((err) => {
  201. console.log(err);
  202. });
  203. },
  204. },
  205. };
  206. </script>
  207. <style lang="scss" scoped>
  208. .custom-tree-node {
  209. flex: 1;
  210. display: flex;
  211. align-items: center;
  212. justify-content: space-between;
  213. font-size: 14px;
  214. padding-right: 8px;
  215. }
  216. .tree-title {
  217. display: flex;
  218. font-size: 14px;
  219. margin-bottom: 15px;
  220. height: 20px;
  221. line-height: 20px;
  222. .bk {
  223. width: 4px;
  224. height: 100%;
  225. background: rgba(0, 132, 255, 1);
  226. margin-right: 8px;
  227. }
  228. }
  229. .search {
  230. margin-bottom: 10px;
  231. }
  232. </style>