tenant.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :data="data"
  5. ref="crud"
  6. v-model="form"
  7. :page="page"
  8. :permission="permissionList"
  9. @row-del="rowDel"
  10. @row-update="rowUpdate"
  11. @row-save="rowSave"
  12. @search-change="searchChange"
  13. @search-reset="searchReset"
  14. @selection-change="selectionChange"
  15. @current-change="currentChange"
  16. @size-change="sizeChange"
  17. @on-load="onLoad">
  18. <template slot="menuLeft">
  19. <el-button type="danger"
  20. size="small"
  21. icon="el-icon-delete"
  22. v-if="permission.tenant_delete"
  23. plain
  24. @click="handleDelete">删 除
  25. </el-button>
  26. </template>
  27. </avue-crud>
  28. </basic-container>
  29. </template>
  30. <script>
  31. import {getList, remove, update, add} from "@/api/system/tenant";
  32. import {mapGetters} from "vuex";
  33. export default {
  34. data() {
  35. return {
  36. form: {},
  37. selectionList: [],
  38. query: {},
  39. page: {
  40. pageSize: 10,
  41. currentPage: 1,
  42. total: 0
  43. },
  44. option: {
  45. tip: false,
  46. border: true,
  47. index: true,
  48. selection: true,
  49. viewBtn: true,
  50. dialogWidth: 300,
  51. dialogHeight: 400,
  52. column: [
  53. {
  54. label: "租户ID",
  55. prop: "tenantId",
  56. search: true,
  57. addDisplay: false,
  58. editDisplay: false,
  59. span: 24,
  60. rules: [{
  61. required: true,
  62. message: "请输入租户ID",
  63. trigger: "blur"
  64. }]
  65. },
  66. {
  67. label: "租户名称",
  68. prop: "tenantName",
  69. search: true,
  70. span: 24,
  71. rules: [{
  72. required: true,
  73. message: "请输入参数名称",
  74. trigger: "blur"
  75. }]
  76. },
  77. {
  78. label: "联系人",
  79. prop: "linkman",
  80. search: true,
  81. span: 24,
  82. rules: [{
  83. required: true,
  84. message: "请输入联系人",
  85. trigger: "blur"
  86. }]
  87. },
  88. {
  89. label: "联系电话",
  90. prop: "contactNumber",
  91. span: 24,
  92. },
  93. {
  94. label: "联系地址",
  95. prop: "address",
  96. span: 24,
  97. minRows: 6,
  98. type: "textarea",
  99. }
  100. ]
  101. },
  102. data: []
  103. };
  104. },
  105. computed: {
  106. ...mapGetters(["permission"]),
  107. permissionList() {
  108. return {
  109. addBtn: this.vaildData(this.permission.tenant_add, false),
  110. viewBtn: this.vaildData(this.permission.tenant_view, false),
  111. delBtn: this.vaildData(this.permission.tenant_delete, false),
  112. editBtn: this.vaildData(this.permission.tenant_edit, false)
  113. };
  114. },
  115. ids() {
  116. let ids = [];
  117. this.selectionList.forEach(ele => {
  118. ids.push(ele.id);
  119. });
  120. return ids.join(",");
  121. }
  122. },
  123. methods: {
  124. rowSave(row, loading, done) {
  125. add(row).then(() => {
  126. loading();
  127. this.onLoad(this.page);
  128. this.$message({
  129. type: "success",
  130. message: "操作成功!"
  131. });
  132. }, error => {
  133. done();
  134. console.log(error);
  135. });
  136. },
  137. rowUpdate(row, index, loading, done) {
  138. update(row).then(() => {
  139. loading();
  140. this.onLoad(this.page);
  141. this.$message({
  142. type: "success",
  143. message: "操作成功!"
  144. });
  145. }, error => {
  146. done();
  147. console.log(error);
  148. });
  149. },
  150. rowDel(row) {
  151. this.$confirm("确定将选择数据删除?", {
  152. confirmButtonText: "确定",
  153. cancelButtonText: "取消",
  154. type: "warning"
  155. })
  156. .then(() => {
  157. return remove(row.id);
  158. })
  159. .then(() => {
  160. this.onLoad(this.page);
  161. this.$message({
  162. type: "success",
  163. message: "操作成功!"
  164. });
  165. });
  166. },
  167. searchReset() {
  168. this.onLoad(this.page);
  169. },
  170. searchChange(params) {
  171. this.query = params;
  172. this.onLoad(this.page, params);
  173. },
  174. selectionChange(list) {
  175. this.selectionList = list;
  176. },
  177. handleDelete() {
  178. if (this.selectionList.length === 0) {
  179. this.$message.warning("请选择至少一条数据");
  180. return;
  181. }
  182. this.$confirm("确定将选择数据删除?", {
  183. confirmButtonText: "确定",
  184. cancelButtonText: "取消",
  185. type: "warning"
  186. })
  187. .then(() => {
  188. return remove(this.ids);
  189. })
  190. .then(() => {
  191. this.onLoad(this.page);
  192. this.$message({
  193. type: "success",
  194. message: "操作成功!"
  195. });
  196. this.$refs.crud.toggleSelection();
  197. });
  198. },
  199. currentChange(currentPage){
  200. this.page.currentPage = currentPage;
  201. },
  202. sizeChange(pageSize){
  203. this.page.pageSize = pageSize;
  204. },
  205. onLoad(page, params = {}) {
  206. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  207. const data = res.data.data;
  208. this.page.total = data.total;
  209. this.data = data.records;
  210. });
  211. }
  212. }
  213. };
  214. </script>
  215. <style>
  216. </style>