index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. :table-loading="loading"
  14. @row-save="rowSave"
  15. @search-change="searchChange"
  16. @search-reset="searchReset"
  17. @selection-change="selectionChange"
  18. @current-change="currentChange"
  19. @size-change="sizeChange"
  20. @refresh-change="refreshChange"
  21. @saveColumn="saveColumn"
  22. @resetColumn="resetColumn"
  23. @on-load="onLoad"
  24. @tree-load="treeLoad"
  25. >
  26. <template slot-scope="scope" slot="menu">
  27. <el-button
  28. type="text"
  29. icon="el-icon-circle-plus-outline"
  30. size="small"
  31. @click.stop="handleAdd(scope.row, scope.index)"
  32. >新增子项
  33. </el-button>
  34. </template>
  35. </avue-crud>
  36. </basic-container>
  37. </template>
  38. <script>
  39. import option from "./configuration/mainList.json";
  40. import {
  41. customerList,
  42. typeSave,
  43. detail,
  44. deleteDetails
  45. } from "@/api/basicData/customerCategory";
  46. import { customerParameter } from "@/enums/management-type";
  47. export default {
  48. name: "customerInformation",
  49. data() {
  50. return {
  51. form: {},
  52. option: option,
  53. loading: false,
  54. parentId: 0,
  55. dataList: [],
  56. page: {
  57. pageSize: 20,
  58. currentPage: 1,
  59. total: 0,
  60. pageSizes: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
  61. },
  62. query: {}
  63. };
  64. },
  65. async created() {
  66. this.option = await this.getColumnData(this.getColumnName(141), option);
  67. },
  68. methods: {
  69. //删除列表后面的删除按钮触发触发(row, index, done)
  70. rowDel(row, index, done) {
  71. this.$confirm("确定将选择数据删除?", {
  72. confirmButtonText: "确定",
  73. cancelButtonText: "取消",
  74. type: "warning"
  75. })
  76. .then(() => {
  77. return deleteDetails(row.id);
  78. })
  79. .then(() => {
  80. this.$message({
  81. type: "success",
  82. message: "操作成功!"
  83. });
  84. // 数据回调进行刷新
  85. done(row);
  86. });
  87. },
  88. //修改时的修改按钮点击触发
  89. rowUpdate(row, index, done, loading) {
  90. row.corpType = customerParameter.code;
  91. typeSave(row).then(
  92. () => {
  93. this.$message({
  94. type: "success",
  95. message: "操作成功!"
  96. });
  97. // 数据回调进行刷新
  98. done(row);
  99. this.onLoad(this.page);
  100. },
  101. error => {
  102. window.console.log(error);
  103. loading();
  104. }
  105. );
  106. },
  107. //新增修改时保存触发
  108. rowSave(row, done, loading) {
  109. row.corpType = customerParameter.code;
  110. typeSave(row).then(
  111. res => {
  112. this.$message({
  113. type: "success",
  114. message: "操作成功!"
  115. });
  116. done(row);
  117. this.onLoad(this.page);
  118. },
  119. error => {
  120. window.console.log(error);
  121. loading();
  122. }
  123. );
  124. },
  125. //查询全部
  126. initData() {
  127. customerList({ corpType: customerParameter.code }).then(res => {
  128. const column = this.findObject(this.option.column, "parentId");
  129. column.dicData = res.data.data.records;
  130. });
  131. },
  132. //新增子项触发
  133. handleAdd(row) {
  134. this.parentId = row.id;
  135. const column = this.findObject(this.option.column, "parentId");
  136. column.value = row.id;
  137. column.addDisabled = true;
  138. this.$refs.crud.rowAdd();
  139. },
  140. //新增子项和新增触发查询所有
  141. beforeOpen(done, type) {
  142. if (["add", "edit"].includes(type)) {
  143. this.initData();
  144. }
  145. if (["edit", "view"].includes(type)) {
  146. detail(this.form.id).then(res => {
  147. this.form = res.data.data;
  148. });
  149. }
  150. done();
  151. },
  152. //点击新增时触发
  153. beforeClose(done) {
  154. this.parentId = "";
  155. const column = this.findObject(this.option.column, "parentId");
  156. column.value = "";
  157. column.addDisabled = false;
  158. done();
  159. },
  160. //点击搜索按钮触发
  161. searchChange(params, done) {
  162. this.query = params;
  163. this.page.currentPage = 1;
  164. params.parentId = 0;
  165. this.onLoad(this.page, params);
  166. done();
  167. },
  168. searchReset() {
  169. console.log("1");
  170. },
  171. selectionChange() {
  172. console.log("1");
  173. },
  174. currentChange() {
  175. console.log("1");
  176. },
  177. sizeChange() {
  178. console.log("1");
  179. },
  180. refreshChange() {
  181. console.log("1");
  182. },
  183. onLoad(page, params = {}) {
  184. this.loading = true;
  185. const { createTimeA } = this.query;
  186. let values = {
  187. ...params,
  188. corpType: customerParameter.code,
  189. size: this.page.pageSize,
  190. current: this.page.currentPage
  191. };
  192. if (createTimeA) {
  193. values = {
  194. ...params,
  195. createTime: createTimeA[0] + " 00:00:00",
  196. endTime: createTimeA[1] + " 23:59:59",
  197. ...this.query,
  198. size: this.page.pageSize,
  199. current: this.page.currentPage
  200. };
  201. values.createTimeA = null;
  202. }
  203. values.parentId = 0;
  204. customerList(values)
  205. .then(res => {
  206. this.dataList = res.data.data.records;
  207. this.page.total = res.data.data.total;
  208. if (this.page.total || this.page.total === 0) {
  209. this.option.height = window.innerHeight - 210;
  210. }
  211. })
  212. .finally(() => {
  213. this.loading = false;
  214. });
  215. },
  216. async saveColumn() {
  217. /**
  218. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  219. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  220. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  221. */
  222. const inSave = await this.saveColumnData(
  223. this.getColumnName(141),
  224. this.option
  225. );
  226. if (inSave) {
  227. this.$nextTick(() => {
  228. this.$refs.crud.doLayout();
  229. });
  230. this.$message.success("保存成功");
  231. //关闭窗口
  232. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  233. }
  234. },
  235. async resetColumn() {
  236. this.option = option;
  237. const inSave = await this.delColumnData(this.getColumnName(141), option);
  238. if (inSave) {
  239. this.$nextTick(() => {
  240. this.$refs.crud.doLayout();
  241. });
  242. this.$message.success("重置成功");
  243. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  244. }
  245. },
  246. //树桩列点击展开触发
  247. treeLoad(tree, treeNode, resolve) {
  248. const parentId = tree.id;
  249. customerList({ parentId: parentId }).then(res => {
  250. resolve(res.data.data.records);
  251. });
  252. }
  253. }
  254. };
  255. </script>
  256. <style scoped>
  257. .page-crad ::v-deep .basic-container__card {
  258. height: 94.8vh;
  259. }
  260. </style>