dictbiz.vue 12 KB

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