dictbiz.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <el-row>
  3. <el-col :span="11">
  4. <basic-container>
  5. <el-card class="box-card">
  6. <div slot="header" class="clearfix">
  7. <span>业务字典列表</span>
  8. </div>
  9. <div class="clearfix">
  10. <avue-crud
  11. :option="optionParent"
  12. :table-loading="loading"
  13. :data="dataParent"
  14. :page="pageParent"
  15. ref="crud"
  16. v-model="formParent"
  17. :permission="permissionList"
  18. :before-open="beforeOpen"
  19. @row-del="rowDel"
  20. @row-update="rowUpdate"
  21. @row-save="rowSave"
  22. @row-click="handleRowClick"
  23. @search-change="searchChange"
  24. @search-reset="searchReset"
  25. @selection-change="selectionChange"
  26. @current-change="currentChange"
  27. @size-change="sizeChange"
  28. @refresh-change="refreshChange"
  29. @on-load="onLoadParent"
  30. >
  31. <template slot="menuLeft">
  32. <el-button
  33. type="danger"
  34. size="small"
  35. icon="el-icon-delete"
  36. v-if="permission.dict_delete"
  37. plain
  38. @click="handleDelete"
  39. >删 除
  40. </el-button>
  41. </template>
  42. <template slot-scope="{row}" slot="isSealed">
  43. <el-tag>{{row.isSealed===0?'否':'是'}}</el-tag>
  44. </template>
  45. </avue-crud>
  46. </div>
  47. </el-card>
  48. </basic-container>
  49. </el-col>
  50. <el-col :span="13">
  51. <basic-container>
  52. <el-card class="box-card">
  53. <div slot="header" class="clearfix">
  54. <span>[{{dictValue}}] 业务字典详情</span>
  55. </div>
  56. <div class="clearfix">
  57. <avue-crud
  58. :option="optionChild"
  59. :table-loading="loadingChild"
  60. :data="dataChild"
  61. ref="crudChild"
  62. v-model="formChild"
  63. :permission="permissionList"
  64. :before-open="beforeOpenChild"
  65. :before-close="beforeCloseChild"
  66. @row-del="rowDelChild"
  67. @row-update="rowUpdateChild"
  68. @row-save="rowSaveChild"
  69. @search-change="searchChangeChild"
  70. @search-reset="searchResetChild"
  71. @selection-change="selectionChangeChild"
  72. @current-change="currentChangeChild"
  73. @size-change="sizeChangeChild"
  74. @refresh-change="refreshChangeChild"
  75. @on-load="onLoadChild"
  76. >
  77. <template slot="menuLeft">
  78. <el-button
  79. type="danger"
  80. size="small"
  81. icon="el-icon-delete"
  82. v-if="permission.dict_delete"
  83. plain
  84. @click="handleDelete"
  85. >删 除
  86. </el-button>
  87. </template>
  88. <template slot-scope="scope" slot="menu">
  89. <el-button
  90. type="text"
  91. icon="el-icon-circle-plus-outline"
  92. size="small"
  93. @click.stop="handleAdd(scope.row,scope.index)"
  94. v-if="userInfo.role_name.includes('admin')"
  95. >新增子项
  96. </el-button>
  97. </template>
  98. <template slot-scope="{row}" slot="isSealed">
  99. <el-tag>{{row.isSealed===0?'否':'是'}}</el-tag>
  100. </template>
  101. </avue-crud>
  102. </div>
  103. </el-card>
  104. </basic-container>
  105. </el-col>
  106. </el-row>
  107. </template>
  108. <script>
  109. import {
  110. getParentList,
  111. getChildList,
  112. remove,
  113. update,
  114. add,
  115. getDict,
  116. getDictTree
  117. } from "@/api/system/dictbiz";
  118. import {optionParent, optionChild} from "@/option/system/dictbiz";
  119. import {mapGetters} from "vuex";
  120. export default {
  121. data() {
  122. return {
  123. dictValue: '暂无',
  124. parentId: -1,
  125. formParent: {},
  126. formChild: {},
  127. selectionList: [],
  128. query: {},
  129. loading: true,
  130. loadingChild: true,
  131. pageParent: {
  132. pageSize: 10,
  133. pageSizes: [10, 30, 50, 100, 200],
  134. currentPage: 1,
  135. total: 0
  136. },
  137. pageChild: {
  138. pageSize: 10,
  139. pageSizes: [10, 30, 50, 100, 200],
  140. currentPage: 1,
  141. total: 0
  142. },
  143. dataParent: [],
  144. dataChild: [],
  145. optionParent: optionParent,
  146. optionChild: optionChild,
  147. };
  148. },
  149. computed: {
  150. ...mapGetters(["userInfo", "permission"]),
  151. permissionList() {
  152. return {
  153. addBtn: this.vaildData(this.permission.dictbiz_add, false),
  154. delBtn: this.vaildData(this.permission.dictbiz_delete, false),
  155. editBtn: this.vaildData(this.permission.dictbiz_edit, false),
  156. viewBtn: false,
  157. };
  158. },
  159. ids() {
  160. let ids = [];
  161. this.selectionList.forEach(ele => {
  162. ids.push(ele.id);
  163. });
  164. return ids.join(",");
  165. }
  166. },
  167. mounted() {
  168. this.initData();
  169. },
  170. methods: {
  171. initData() {
  172. getDictTree().then(res => {
  173. const column = this.findObject(this.optionChild.column, "parentId");
  174. column.dicData = res.data.data;
  175. });
  176. },
  177. handleAdd(row) {
  178. this.$refs.crudChild.value.parentId = row.id;
  179. this.$refs.crudChild.option.column.filter(item => {
  180. if (item.prop === "parentId") {
  181. item.value = row.id;
  182. }
  183. });
  184. this.$refs.crudChild.rowAdd();
  185. },
  186. rowSave(row, done, loading) {
  187. const form = {
  188. ...row,
  189. dictKey: -1,
  190. };
  191. add(form).then(() => {
  192. this.onLoadParent(this.pageParent);
  193. this.$message({
  194. type: "success",
  195. message: "操作成功!"
  196. });
  197. done();
  198. }, error => {
  199. window.console.log(error);
  200. loading();
  201. });
  202. },
  203. rowUpdate(row, index, done, loading) {
  204. update(row).then(() => {
  205. this.onLoadParent(this.pageParent);
  206. this.$message({
  207. type: "success",
  208. message: "操作成功!"
  209. });
  210. done();
  211. }, error => {
  212. window.console.log(error);
  213. loading();
  214. });
  215. },
  216. rowDel(row) {
  217. this.$confirm("确定将选择数据删除?", {
  218. confirmButtonText: "确定",
  219. cancelButtonText: "取消",
  220. type: "warning"
  221. })
  222. .then(() => {
  223. return remove(row.id);
  224. })
  225. .then(() => {
  226. this.onLoadParent(this.pageParent);
  227. this.$message({
  228. type: "success",
  229. message: "操作成功!"
  230. });
  231. });
  232. },
  233. handleRowClick(row) {
  234. this.query = {};
  235. this.parentId = row.id;
  236. this.dictValue = row.dictValue;
  237. this.$refs.crudChild.value.code = row.code;
  238. this.$refs.crudChild.value.parentId = row.id;
  239. this.$refs.crudChild.option.column.filter(item => {
  240. if (item.prop === "code") {
  241. item.value = row.code;
  242. }
  243. if (item.prop === "parentId") {
  244. item.value = row.id;
  245. }
  246. });
  247. this.onLoadChild(this.pageChild);
  248. },
  249. searchReset() {
  250. this.query = {};
  251. this.onLoadParent(this.pageParent);
  252. },
  253. searchChange(params, done) {
  254. this.query = params;
  255. this.pageParent.currentPage = 1;
  256. this.onLoadParent(this.pageParent, params);
  257. done();
  258. },
  259. selectionChange(list) {
  260. this.selectionList = list;
  261. },
  262. selectionClear() {
  263. this.selectionList = [];
  264. this.$refs.crud.toggleSelection();
  265. },
  266. handleDelete() {
  267. if (this.selectionList.length === 0) {
  268. this.$message.warning("请选择至少一条数据");
  269. return;
  270. }
  271. this.$confirm("确定将选择数据删除?", {
  272. confirmButtonText: "确定",
  273. cancelButtonText: "取消",
  274. type: "warning"
  275. })
  276. .then(() => {
  277. return remove(this.ids);
  278. })
  279. .then(() => {
  280. this.onLoadParent(this.pageParent);
  281. this.$message({
  282. type: "success",
  283. message: "操作成功!"
  284. });
  285. this.$refs.crud.toggleSelection();
  286. });
  287. },
  288. beforeOpen(done, type) {
  289. if (["edit", "view"].includes(type)) {
  290. getDict(this.formParent.id).then(res => {
  291. this.formParent = res.data.data;
  292. });
  293. }
  294. done();
  295. },
  296. currentChange(currentPage) {
  297. this.pageParent.currentPage = currentPage;
  298. },
  299. sizeChange(pageSize) {
  300. this.pageParent.pageSize = pageSize;
  301. },
  302. refreshChange() {
  303. this.onLoadParent(this.pageParent, this.query);
  304. },
  305. rowSaveChild(row, done, loading) {
  306. add(row).then(() => {
  307. this.onLoadChild(this.pageChild);
  308. this.$message({
  309. type: "success",
  310. message: "操作成功!"
  311. });
  312. done();
  313. }, error => {
  314. window.console.log(error);
  315. loading();
  316. });
  317. },
  318. rowUpdateChild(row, index, done, loading) {
  319. update(row).then(() => {
  320. this.onLoadChild(this.pageChild);
  321. this.$message({
  322. type: "success",
  323. message: "操作成功!"
  324. });
  325. done();
  326. }, error => {
  327. window.console.log(error);
  328. loading();
  329. });
  330. },
  331. rowDelChild(row) {
  332. this.$confirm("确定将选择数据删除?", {
  333. confirmButtonText: "确定",
  334. cancelButtonText: "取消",
  335. type: "warning"
  336. })
  337. .then(() => {
  338. return remove(row.id);
  339. })
  340. .then(() => {
  341. this.onLoadChild(this.pageChild);
  342. this.$message({
  343. type: "success",
  344. message: "操作成功!"
  345. });
  346. });
  347. },
  348. searchResetChild() {
  349. this.query = {};
  350. this.onLoadChild(this.pageChild);
  351. },
  352. searchChangeChild(params, done) {
  353. this.query = params;
  354. this.pageChild.currentPage = 1;
  355. this.onLoadChild(this.pageChild, params);
  356. done();
  357. },
  358. selectionChangeChild(list) {
  359. this.selectionList = list;
  360. },
  361. selectionClearChild() {
  362. this.selectionList = [];
  363. this.$refs.crudChild.toggleSelection();
  364. },
  365. handleDeleteChild() {
  366. if (this.selectionList.length === 0) {
  367. this.$message.warning("请选择至少一条数据");
  368. return;
  369. }
  370. this.$confirm("确定将选择数据删除?", {
  371. confirmButtonText: "确定",
  372. cancelButtonText: "取消",
  373. type: "warning"
  374. })
  375. .then(() => {
  376. return remove(this.ids);
  377. })
  378. .then(() => {
  379. this.onLoadChild(this.pageChild);
  380. this.$message({
  381. type: "success",
  382. message: "操作成功!"
  383. });
  384. this.$refs.crudChild.toggleSelection();
  385. });
  386. },
  387. beforeOpenChild(done, type) {
  388. if (["add", "edit"].includes(type)) {
  389. this.initData();
  390. }
  391. if (["edit", "view"].includes(type)) {
  392. getDict(this.formChild.id).then(res => {
  393. this.formChild = res.data.data;
  394. });
  395. }
  396. done();
  397. },
  398. beforeCloseChild(done) {
  399. this.$refs.crudChild.value.parentId = this.parentId;
  400. this.$refs.crudChild.option.column.filter(item => {
  401. if (item.prop === "parentId") {
  402. item.value = this.parentId;
  403. }
  404. });
  405. done();
  406. },
  407. currentChangeChild(currentPage) {
  408. this.pageChild.currentPage = currentPage;
  409. },
  410. sizeChangeChild(pageSize) {
  411. this.pageChild.pageSize = pageSize;
  412. },
  413. refreshChangeChild() {
  414. this.onLoadChild(this.pageChild, this.query);
  415. },
  416. onLoadParent(page, params = {}) {
  417. this.loading = true;
  418. getParentList(
  419. page.currentPage,
  420. page.pageSize,
  421. Object.assign(params, this.query)
  422. ).then(res => {
  423. const data = res.data.data;
  424. this.pageParent.total = data.total;
  425. this.dataParent = data.records;
  426. this.loading = false;
  427. this.selectionClear();
  428. });
  429. },
  430. onLoadChild(page, params = {}) {
  431. this.loadingChild = true;
  432. getChildList(
  433. page.currentPage,
  434. page.pageSize,
  435. this.parentId,
  436. Object.assign(params, this.query)
  437. ).then(res => {
  438. this.dataChild = res.data.data;
  439. this.loadingChild = false;
  440. this.selectionClear();
  441. });
  442. }
  443. }
  444. };
  445. </script>