index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <basic-container class="page-crad">
  3. <avue-crud
  4. :option="option"
  5. :data="dataList"
  6. ref="crud"
  7. v-model="form"
  8. :page.sync="page"
  9. @row-del="rowDel"
  10. @row-update="rowUpdate"
  11. :before-open="beforeOpen"
  12. :before-close="beforeClose"
  13. @row-save="rowSave"
  14. @search-change="searchChange"
  15. @search-reset="searchReset"
  16. @selection-change="selectionChange"
  17. @current-change="currentChange"
  18. @size-change="sizeChange"
  19. @refresh-change="refreshChange"
  20. @on-load="onLoad"
  21. @tree-load="treeLoad"
  22. >
  23. <template slot-scope="scope" slot="menu">
  24. <el-button
  25. type="text"
  26. icon="el-icon-circle-plus-outline"
  27. size="small"
  28. @click.stop="handleAdd(scope.row, scope.index)"
  29. >新增子项
  30. </el-button>
  31. </template>
  32. </avue-crud>
  33. </basic-container>
  34. </template>
  35. <script>
  36. import option from "./configuration/mainList.json";
  37. import {
  38. customerList,
  39. typeSave,
  40. detail,
  41. deleteDetails,
  42. getTreeList
  43. } from "@/api/basicData/commodityCategory";
  44. export default {
  45. name: "customerInformation",
  46. data() {
  47. return {
  48. form: {},
  49. option: option,
  50. parentId: 0,
  51. dataList: [],
  52. page: {
  53. pageSize: 20,
  54. currentPage: 1,
  55. total: 0,
  56. pageSizes: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
  57. },
  58. query: {}
  59. };
  60. },
  61. created() {
  62. getTreeList({ parentId: 0 }).then(res => {
  63. const column = this.findObject(this.option.column, "parentId");
  64. column.dicData = res.data.data;
  65. });
  66. },
  67. methods: {
  68. //删除列表后面的删除按钮触发触发(row, index, done)
  69. rowDel(row, index, done) {
  70. this.$confirm("确定将选择数据删除?", {
  71. confirmButtonText: "确定",
  72. cancelButtonText: "取消",
  73. type: "warning"
  74. })
  75. .then(() => {
  76. return deleteDetails(row.id);
  77. })
  78. .then(() => {
  79. this.$message({
  80. type: "success",
  81. message: "操作成功!"
  82. });
  83. // 数据回调进行刷新
  84. done(row);
  85. });
  86. },
  87. //修改时的修改按钮点击触发
  88. rowUpdate(row, index, done, loading) {
  89. typeSave(row).then(
  90. () => {
  91. this.$message({
  92. type: "success",
  93. message: "操作成功!"
  94. });
  95. // 数据回调进行刷新
  96. done(row);
  97. },
  98. error => {
  99. window.console.log(error);
  100. loading();
  101. }
  102. );
  103. },
  104. //新增修改时保存触发
  105. rowSave(row, done, loading) {
  106. typeSave(row).then(res => {
  107. this.page.currentPage = 1;
  108. this.onLoad(this.page, { parentId: 0 });
  109. done();
  110. });
  111. },
  112. //新增子项触发
  113. handleAdd(row) {
  114. this.parentId = row.id;
  115. const column = this.findObject(this.option.column, "parentId");
  116. this.$set(this.form, "parentId", row.id);
  117. column.addDisabled = true;
  118. this.$refs.crud.rowAdd();
  119. },
  120. //新增子项和新增触发查询所有
  121. beforeOpen(done, type) {
  122. if (["add", "edit"].includes(type)) {
  123. }
  124. if (["edit", "view"].includes(type)) {
  125. detail(this.form.id).then(res => {
  126. this.form = res.data.data;
  127. });
  128. }
  129. done();
  130. },
  131. //点击新增时触发
  132. beforeClose(done) {
  133. this.parentId = "";
  134. const column = this.findObject(this.option.column, "parentId");
  135. column.value = "";
  136. column.addDisabled = false;
  137. done();
  138. },
  139. //点击搜索按钮触发
  140. searchChange(params, done) {
  141. this.query = params;
  142. this.page.currentPage = 1;
  143. this.onLoad(this.page, params);
  144. done();
  145. },
  146. searchReset() {
  147. console.log("1");
  148. },
  149. selectionChange() {
  150. console.log("1");
  151. },
  152. currentChange() {
  153. console.log("1");
  154. },
  155. sizeChange() {
  156. console.log("1");
  157. },
  158. refreshChange() {
  159. console.log("1");
  160. },
  161. onLoad(page, params = {}) {
  162. const { createTimeA } = this.query;
  163. let values = {
  164. ...params,
  165. size: this.page.pageSize,
  166. current: this.page.currentPage
  167. };
  168. if (createTimeA) {
  169. values = {
  170. ...params,
  171. createTime: createTimeA[0] + " 00:00:00",
  172. endTime: createTimeA[1] + " 23:59:59",
  173. size: this.page.pageSize,
  174. current: this.page.currentPage,
  175. ...this.query
  176. };
  177. values.createTimeA = null;
  178. }
  179. values.parentId = 0;
  180. customerList(values).then(res => {
  181. this.dataList = res.data.data.records;
  182. this.page.total = res.data.data.total;
  183. if (this.page.total || this.page.total === 0) {
  184. this.option.height = window.innerHeight - 210;
  185. }
  186. });
  187. },
  188. //树桩列点击展开触发
  189. treeLoad(tree, treeNode, resolve) {
  190. const parentId = tree.id;
  191. customerList({ parentId: parentId, size: 10000 }).then(res => {
  192. resolve(res.data.data.records);
  193. });
  194. }
  195. }
  196. };
  197. </script>
  198. <style scoped>
  199. .page-crad ::v-deep .basic-container__card {
  200. height: 94.8vh;
  201. }
  202. </style>