dept.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. ref="crud"
  7. v-model="form"
  8. :permission="permissionList"
  9. :before-open="beforeOpen"
  10. :before-close="beforeClose"
  11. @row-del="rowDel"
  12. @row-update="rowUpdate"
  13. @row-save="rowSave"
  14. @search-change="searchChange"
  15. @search-reset="searchReset"
  16. @selection-change="selectionChange"
  17. @current-change="currentChange"
  18. @size-change="sizeChange"
  19. @refresh-change="refreshChange"
  20. @on-load="onLoad">
  21. <template slot="menuLeft">
  22. <el-button type="danger"
  23. size="small"
  24. icon="el-icon-delete"
  25. v-if="permission.dept_delete"
  26. plain
  27. @click="handleDelete">删 除
  28. </el-button>
  29. </template>
  30. <template slot-scope="scope" slot="menu">
  31. <el-button
  32. type="text"
  33. icon="el-icon-circle-plus-outline"
  34. size="small"
  35. @click.stop="handleAdd(scope.row,scope.index)"
  36. >新增子项
  37. </el-button>
  38. </template>
  39. <template slot-scope="{row}"
  40. slot="deptCategory">
  41. <el-tag>{{row.deptCategoryName}}</el-tag>
  42. </template>
  43. </avue-crud>
  44. </basic-container>
  45. </template>
  46. <script>
  47. import {
  48. getList,
  49. remove,
  50. update,
  51. add,
  52. getDept,
  53. getDeptTree
  54. } from "@/api/system/dept";
  55. import {mapGetters} from "vuex";
  56. import website from '@/config/website';
  57. export default {
  58. data() {
  59. return {
  60. form: {},
  61. selectionList: [],
  62. query: {},
  63. loading: true,
  64. page: {
  65. pageSize: 10,
  66. currentPage: 1,
  67. total: 0
  68. },
  69. option: {
  70. tip: false,
  71. tree: true,
  72. border: true,
  73. index: true,
  74. selection: true,
  75. viewBtn: true,
  76. menuWidth: 300,
  77. column: [
  78. {
  79. label: "机构名称",
  80. prop: "deptName",
  81. search: true,
  82. rules: [{
  83. required: true,
  84. message: "请输入机构名称",
  85. trigger: "blur"
  86. }]
  87. },
  88. {
  89. label: "所属租户",
  90. prop: "tenantId",
  91. type: "tree",
  92. dicUrl: "/api/blade-system/tenant/select",
  93. addDisplay: false,
  94. editDisplay: false,
  95. viewDisplay: website.tenantMode,
  96. span: 24,
  97. props: {
  98. label: "tenantName",
  99. value: "tenantId"
  100. },
  101. hide: !website.tenantMode,
  102. search: website.tenantMode,
  103. rules: [{
  104. required: true,
  105. message: "请输入所属租户",
  106. trigger: "click"
  107. }]
  108. },
  109. {
  110. label: "机构全称",
  111. prop: "fullName",
  112. search: true,
  113. rules: [{
  114. required: true,
  115. message: "请输入机构全称",
  116. trigger: "blur"
  117. }]
  118. },
  119. {
  120. label: "上级机构",
  121. prop: "parentId",
  122. dicData: [],
  123. type: "tree",
  124. hide: true,
  125. props: {
  126. label: "title"
  127. },
  128. rules: [{
  129. required: false,
  130. message: "请选择上级机构",
  131. trigger: "click"
  132. }]
  133. },
  134. {
  135. label: "机构类型",
  136. type: "select",
  137. dicUrl: "/api/blade-system/dict/dictionary?code=org_category",
  138. props: {
  139. label: "dictValue",
  140. value: "dictKey"
  141. },
  142. width: 120,
  143. prop: "deptCategory",
  144. slot: true,
  145. rules: [{
  146. required: true,
  147. message: "请输入机构类型",
  148. trigger: "blur"
  149. }]
  150. },
  151. {
  152. label: "排序",
  153. prop: "sort",
  154. type: "number",
  155. align: "right",
  156. width: 80,
  157. rules: [{
  158. required: true,
  159. message: "请输入排序",
  160. trigger: "blur"
  161. }]
  162. },
  163. {
  164. label: "备注",
  165. prop: "remark",
  166. rules: [{
  167. required: false,
  168. message: "请输入备注",
  169. trigger: "blur"
  170. }],
  171. hide: true
  172. }
  173. ]
  174. },
  175. data: []
  176. };
  177. },
  178. computed: {
  179. ...mapGetters(["permission"]),
  180. permissionList() {
  181. return {
  182. addBtn: this.vaildData(this.permission.dept_add, false),
  183. viewBtn: this.vaildData(this.permission.dept_view, false),
  184. delBtn: this.vaildData(this.permission.dept_delete, false),
  185. editBtn: this.vaildData(this.permission.dept_edit, false)
  186. };
  187. },
  188. ids() {
  189. let ids = [];
  190. this.selectionList.forEach(ele => {
  191. ids.push(ele.id);
  192. });
  193. return ids.join(",");
  194. }
  195. },
  196. methods: {
  197. handleAdd(row) {
  198. this.$refs.crud.value.parentId = row.id;
  199. this.$refs.crud.option.column.filter(item => {
  200. if (item.prop === "parentId") {
  201. item.valueDefault = row.id;
  202. item.addDisabled = true;
  203. }
  204. });
  205. this.$refs.crud.rowAdd();
  206. },
  207. rowSave(row, loading, done) {
  208. add(row).then(() => {
  209. loading();
  210. this.onLoad(this.page);
  211. this.$message({
  212. type: "success",
  213. message: "操作成功!"
  214. });
  215. }, error => {
  216. done();
  217. console.log(error);
  218. });
  219. },
  220. rowUpdate(row, index, loading, done) {
  221. update(row).then(() => {
  222. loading();
  223. this.onLoad(this.page);
  224. this.$message({
  225. type: "success",
  226. message: "操作成功!"
  227. });
  228. }, error => {
  229. done();
  230. console.log(error);
  231. });
  232. },
  233. rowDel(row) {
  234. this.$confirm("确定将选择数据删除?", {
  235. confirmButtonText: "确定",
  236. cancelButtonText: "取消",
  237. type: "warning"
  238. })
  239. .then(() => {
  240. return remove(row.id);
  241. })
  242. .then(() => {
  243. this.onLoad(this.page);
  244. this.$message({
  245. type: "success",
  246. message: "操作成功!"
  247. });
  248. });
  249. },
  250. handleDelete() {
  251. if (this.selectionList.length === 0) {
  252. this.$message.warning("请选择至少一条数据");
  253. return;
  254. }
  255. this.$confirm("确定将选择数据删除?", {
  256. confirmButtonText: "确定",
  257. cancelButtonText: "取消",
  258. type: "warning"
  259. })
  260. .then(() => {
  261. return remove(this.ids);
  262. })
  263. .then(() => {
  264. this.onLoad(this.page);
  265. this.$message({
  266. type: "success",
  267. message: "操作成功!"
  268. });
  269. this.$refs.crud.toggleSelection();
  270. });
  271. },
  272. searchReset() {
  273. this.query = {};
  274. this.onLoad(this.page);
  275. },
  276. searchChange(params) {
  277. this.query = params;
  278. this.page.currentPage = 1;
  279. this.onLoad(this.page, params);
  280. },
  281. selectionChange(list) {
  282. this.selectionList = list;
  283. },
  284. selectionClear() {
  285. this.selectionList = [];
  286. this.$refs.crud.toggleSelection();
  287. },
  288. beforeOpen(done, type) {
  289. if (["edit", "view"].includes(type)) {
  290. getDept(this.form.id).then(res => {
  291. this.form = res.data.data;
  292. });
  293. }
  294. done();
  295. },
  296. beforeClose(done) {
  297. this.$refs.crud.value.parentId = "";
  298. this.$refs.crud.value.addDisabled = false;
  299. this.$refs.crud.option.column.filter(item => {
  300. if (item.prop === "parentId") {
  301. item.valueDefault = "";
  302. item.addDisabled = false;
  303. }
  304. });
  305. done();
  306. },
  307. currentChange(currentPage) {
  308. this.page.currentPage = currentPage;
  309. },
  310. sizeChange(pageSize) {
  311. this.page.pageSize = pageSize;
  312. },
  313. refreshChange() {
  314. this.onLoad(this.page, this.query);
  315. },
  316. onLoad(page, params = {}) {
  317. this.loading = true;
  318. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  319. this.data = res.data.data;
  320. getDeptTree().then(res => {
  321. const data = res.data.data;
  322. const index = this.$refs.crud.findColumnIndex("parentId");
  323. this.option.column[index].dicData = data;
  324. });
  325. this.loading = false;
  326. this.selectionClear();
  327. });
  328. }
  329. }
  330. };
  331. </script>
  332. <style>
  333. </style>