project.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <el-row>
  3. <el-col :span="4">
  4. <div class="box">
  5. <el-scrollbar>
  6. <basic-container>
  7. <avue-tree
  8. :option="treeOption"
  9. :data="treeData"
  10. @node-click="nodeClick"
  11. />
  12. </basic-container>
  13. </el-scrollbar>
  14. </div>
  15. </el-col>
  16. <el-col :span="20">
  17. <basic-container>
  18. <avue-crud
  19. ref="crud"
  20. :data="data"
  21. :option="tableOption"
  22. :page.sync="page"
  23. :table-loading="loading"
  24. @size-change="sizeChange"
  25. @current-change="currentChange"
  26. @search-change="searchChange"
  27. @refresh-change="refreshChange"
  28. @row-save="rowSave"
  29. @row-del="rowDel"
  30. @row-update="rowUpdate"
  31. @cell-dblclick="cellDblclick"
  32. @on-load="getList"
  33. @tree-load="treeLoad"
  34. @saveColumn="saveColumn">
  35. <template slot="menuLeft">
  36. <el-button type="primary"
  37. size="small"
  38. icon="el-icon-upload2"
  39. plain
  40. @click="">导 出
  41. </el-button>
  42. </template>
  43. </avue-crud>
  44. </basic-container>
  45. </el-col>
  46. </el-row>
  47. </template>
  48. <script>
  49. import option from "./configuration/mainList.json";
  50. import {
  51. getList,
  52. remove,
  53. update,
  54. add,
  55. getServerTree
  56. } from "@/api/basicData/commodityType";
  57. export default {
  58. data() {
  59. return {
  60. loading: false,
  61. data: [],
  62. tableOption: option,
  63. treeDeptId:"",
  64. page: {
  65. currentPage: 1,
  66. total: 0,
  67. pageSize: 10
  68. },
  69. treeOption: {
  70. nodeKey: "id",
  71. lazy: true,
  72. treeLoad: function(node, resolve) {
  73. const parentId = node.level === 0 ? 0 : node.data.id;
  74. getServerTree(parentId).then(res => {
  75. resolve(
  76. res.data.data.records.map(item => {
  77. return {
  78. ...item,
  79. leaf: !item.hasChildren
  80. };
  81. })
  82. );
  83. });
  84. },
  85. addBtn: false,
  86. menu: false,
  87. size: "small",
  88. props: {
  89. labelText: "标题",
  90. label: "cname",
  91. value: "id",
  92. children: "children"
  93. }
  94. }
  95. };
  96. },
  97. methods: {
  98. getList(page, params = {}) {
  99. getList(page.currentPage, page.pageSize, params, this.treeDeptId).then(res => {
  100. this.data = res.data.data.records
  101. this.page.total = res.data.data.total
  102. })
  103. },
  104. searchChange(params, done) {
  105. this.getList(this.page, params);
  106. done();
  107. },
  108. sizeChange(val) {
  109. this.page.pageSize = val;
  110. this.getList();
  111. },
  112. currentChange(val) {
  113. this.page.currentPage = val;
  114. this.getList();
  115. },
  116. refreshChange() {
  117. this.page.currentPage = 1;
  118. this.getList();
  119. },
  120. rowSave(row, done, loading) {
  121. row.sort = 1;
  122. add(row).then(res => {
  123. this.page.currentPage = 1;
  124. this.getList(this.page);
  125. this.$message.success("保存成功");
  126. done()
  127. }, error => {
  128. window.console.log(error);
  129. loading();
  130. });
  131. },
  132. rowUpdate(row, index, done, loading) {
  133. update(row).then(() => {
  134. this.$message({
  135. type: "success",
  136. message: "操作成功!"
  137. });
  138. // 数据回调进行刷新
  139. done(row);
  140. }, error => {
  141. window.console.log(error);
  142. loading();
  143. });
  144. },
  145. rowDel(row, index,done) {
  146. this.$confirm("确定将选择数据删除?", {
  147. confirmButtonText: "确定",
  148. cancelButtonText: "取消",
  149. type: "warning"
  150. }).then(() => {
  151. return remove(row.id);
  152. }).then(() => {
  153. this.$message({
  154. type: "success",
  155. message: "操作成功!"
  156. });
  157. // 数据回调进行刷新
  158. done(row);
  159. });
  160. },
  161. cellDblclick(row, column, cell, event) {
  162. console.log(row, column, cell, event);
  163. this.$refs.crud.rowEdit(row);
  164. },
  165. saveColumn(row, column) {
  166. console.log(row, column);
  167. },
  168. //展开主页左边类型
  169. nodeClick(data) {
  170. this.treeDeptId = data.id;
  171. this.page.currentPage = 1;
  172. this.getList(this.page);
  173. },
  174. treeLoad(tree, treeNode, resolve) {
  175. const parentId = tree.id;
  176. getList({parentId:parentId}).then(res => {
  177. resolve(res.data.data.records);
  178. });
  179. },
  180. }
  181. };
  182. </script>
  183. <style></style>