template.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <basic-container>
  3. <avue-crud
  4. :data="data"
  5. :option="option"
  6. :page.sync="page"
  7. @search-change="searchChange"
  8. @current-change="currentChange"
  9. @size-change="sizeChange"
  10. :table-loading="loading"
  11. @on-load="onLoad"
  12. @search-reset="searchReset"
  13. @row-update="rowUpdate"
  14. @row-save="rowSave"
  15. @row-del="rowDel"
  16. >
  17. <template
  18. slot-scope="scope"
  19. slot="menu"
  20. >
  21. <el-button
  22. type="text"
  23. icon="el-icon-edit"
  24. size="small"
  25. @click.stop="editUnit(scope.row, scope.index)"
  26. >编辑计量系统单元
  27. </el-button>
  28. </template>
  29. </avue-crud>
  30. </basic-container>
  31. </template>
  32. <script>
  33. import { getListPage,update,remove } from "@/api/measure/template.js";
  34. export default {
  35. data () {
  36. return {
  37. data: [],
  38. page: {
  39. pageSize: 10,
  40. currentPage: 1,
  41. total: 16
  42. },
  43. loading:true,
  44. option: {
  45. height: 'auto',
  46. calcHeight: 30,
  47. tip: false,
  48. searchShow: true,
  49. searchMenuSpan: 6,
  50. border: true,
  51. index: true,
  52. menuWidth: 400,
  53. dialogClickModal: false,
  54. column: [
  55. {
  56. label: "模版名称",
  57. prop: "name",
  58. search: true,
  59. rules: [{
  60. required: true,
  61. message: "请输入名称",
  62. trigger: "blur"
  63. }]
  64. },
  65. {
  66. label: "备注",
  67. prop: "remarks",
  68. editDisplay: true,
  69. addDisplay: true,
  70. rules: [{
  71. message: "请输入表数量",
  72. trigger: "blur",
  73. }]
  74. }
  75. ]
  76. },
  77. query: {},
  78. };
  79. },
  80. methods: {
  81. onLoad (page, params = {}) {
  82. this.loading = true;
  83. getListPage(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  84. const data = res.data.data;
  85. this.page.total = data.total;
  86. this.data = data.records;
  87. this.loading = false;
  88. });
  89. },
  90. searchChange (params, done) {
  91. console.log(params,'params');
  92. this.query = params;
  93. this.onLoad(this.page);
  94. done();
  95. },
  96. searchReset () {
  97. this.query = {};
  98. this.onLoad(this.page);
  99. },
  100. editUnit(row){
  101. console.log(row);
  102. this.$router.push({
  103. path: '/measure/template',
  104. query: {
  105. }
  106. })
  107. },
  108. currentChange (currentPage) {
  109. this.page.currentPage = currentPage;
  110. },
  111. sizeChange (pageSize) {
  112. this.page.pageSize = pageSize;
  113. },
  114. rowUpdate (row, index, done, loading) {
  115. update(row).then(() => {
  116. this.onLoad(this.page);
  117. this.$message({
  118. type: "success",
  119. message: "操作成功!"
  120. });
  121. done();
  122. }, error => {
  123. loading();
  124. console.log(error);
  125. });
  126. },
  127. rowSave (row, done, loading) {
  128. update(row).then(() => {
  129. this.onLoad(this.page);
  130. this.$message({
  131. type: "success",
  132. message: "操作成功!"
  133. });
  134. done();
  135. }, error => {
  136. loading();
  137. window.console.log(error);
  138. });
  139. },
  140. rowDel (row) {
  141. this.$confirm("确定将选择数据删除?", {
  142. confirmButtonText: "确定",
  143. cancelButtonText: "取消",
  144. type: "warning"
  145. })
  146. .then(() => {
  147. return remove(row.id);
  148. })
  149. .then(() => {
  150. this.onLoad(this.page);
  151. this.$message({
  152. type: "success",
  153. message: "操作成功!"
  154. });
  155. });
  156. },
  157. },
  158. }
  159. </script>
  160. <style>
  161. </style>