dept.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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. @tree-load="treeLoad">
  22. <template slot="menuLeft">
  23. <el-button type="danger"
  24. size="small"
  25. icon="el-icon-delete"
  26. v-if="permission.dept_delete"
  27. plain
  28. @click="handleDelete">删 除
  29. </el-button>
  30. </template>
  31. <template slot-scope="scope" slot="menu">
  32. <el-button
  33. type="text"
  34. icon="el-icon-circle-plus-outline"
  35. size="small"
  36. @click.stop="handleAdd(scope.row,scope.index)"
  37. v-if="userInfo.role_name.includes('admin')"
  38. >新增子项
  39. </el-button>
  40. </template>
  41. <template slot-scope="{row}"
  42. slot="deptCategory">
  43. <el-tag>{{row.deptCategoryName}}</el-tag>
  44. </template>
  45. <template slot-scope="{row}"
  46. slot="polCnNameForm">
  47. <search-query :datalist="polData"
  48. :selectValue="form.polCnName"
  49. :filterable="true"
  50. :clearable="true"
  51. :remote="true"
  52. :buttonIf="false"
  53. :forParameter="{key:'id',label:'cnName',value:'cnName'}"
  54. @remoteMethod="polBportsListfun($event,'polCnName')"
  55. @corpChange="corpChange($event,'polCnName')"
  56. @corpFocus="polBportsListfun($event,'polCnName')" >
  57. </search-query>
  58. </template>
  59. </avue-crud>
  60. </basic-container>
  61. </template>
  62. <script>
  63. import {
  64. getLazyList,
  65. remove,
  66. update,
  67. add,
  68. getDept,
  69. getDeptTree
  70. } from "@/api/system/dept";
  71. import {mapGetters} from "vuex";
  72. import website from '@/config/website';
  73. import SearchQuery from "@/components/iosbasic-data/searchquery.vue";
  74. import {bportsList} from "@/api/iosBasicData/bports";
  75. export default {
  76. components: {SearchQuery},
  77. data() {
  78. return {
  79. // 装货港数据
  80. polData:[],
  81. form: {},
  82. selectionList: [],
  83. query: {},
  84. loading: true,
  85. parentId: 0,
  86. page: {
  87. pageSize: 10,
  88. currentPage: 1,
  89. total: 0,
  90. },
  91. option: {
  92. lazy: true,
  93. tip: false,
  94. simplePage: true,
  95. searchShow: true,
  96. searchMenuSpan: 6,
  97. tree: true,
  98. border: true,
  99. index: true,
  100. selection: true,
  101. viewBtn: true,
  102. menuWidth: 300,
  103. dialogClickModal: false,
  104. column: [
  105. {
  106. label: "机构名称",
  107. prop: "deptName",
  108. search: true,
  109. rules: [{
  110. required: true,
  111. message: "请输入机构名称",
  112. trigger: "blur"
  113. }]
  114. },
  115. {
  116. label: "所属租户",
  117. prop: "tenantId",
  118. type: "tree",
  119. dicUrl: "/api/blade-system/tenant/select",
  120. addDisplay: false,
  121. editDisplay: false,
  122. viewDisplay: website.tenantMode,
  123. span: 24,
  124. props: {
  125. label: "tenantName",
  126. value: "tenantId"
  127. },
  128. hide: !website.tenantMode,
  129. search: website.tenantMode,
  130. rules: [{
  131. required: true,
  132. message: "请输入所属租户",
  133. trigger: "click"
  134. }]
  135. },
  136. {
  137. label: "机构全称",
  138. prop: "fullName",
  139. search: true,
  140. rules: [{
  141. required: true,
  142. message: "请输入机构全称",
  143. trigger: "blur"
  144. }]
  145. },
  146. {
  147. label: "上级机构",
  148. prop: "parentId",
  149. dicData: [],
  150. type: "tree",
  151. hide: true,
  152. addDisabled: false,
  153. props: {
  154. label: "title"
  155. },
  156. rules: [{
  157. required: false,
  158. message: "请选择上级机构",
  159. trigger: "click"
  160. }]
  161. },
  162. {
  163. label: "机构类型",
  164. type: "select",
  165. dicUrl: "/api/blade-system/dict/dictionary?code=org_category",
  166. props: {
  167. label: "dictValue",
  168. value: "dictKey"
  169. },
  170. dataType: "number",
  171. width: 120,
  172. prop: "deptCategory",
  173. slot: true,
  174. rules: [{
  175. required: true,
  176. message: "请输入机构类型",
  177. trigger: "blur"
  178. }]
  179. },
  180. {
  181. label: "积分余额",
  182. prop: "pointsBalance",
  183. disabled:true,
  184. hide: true, // 表格里是否可见
  185. addDisplay:false,//当前行数据在新增表单中是否可见
  186. editDisplay:false,//当前行数据在编辑表单中是否可见
  187. viewDisplay:false, // 当前行数据在查看表单中是否可见
  188. value:0
  189. },
  190. {
  191. label: "装货港",
  192. prop: "polCnName",
  193. type: "select",
  194. formslot:true,
  195. disabled:true,
  196. hide: true, // 表格里是否可见
  197. addDisplay:false,//当前行数据在新增表单中是否可见
  198. editDisplay:false,//当前行数据在编辑表单中是否可见
  199. viewDisplay:false, // 当前行数据在查看表单中是否可见
  200. },
  201. {
  202. label: "排序",
  203. prop: "sort",
  204. type: "number",
  205. align: "right",
  206. width: 80,
  207. rules: [{
  208. required: true,
  209. message: "请输入排序",
  210. trigger: "blur"
  211. }]
  212. },
  213. {
  214. label: "备注",
  215. prop: "remark",
  216. rules: [{
  217. required: false,
  218. message: "请输入备注",
  219. trigger: "blur"
  220. }],
  221. hide: true
  222. }
  223. ]
  224. },
  225. data: []
  226. };
  227. },
  228. created() {
  229. // 判断是否是admin 权限
  230. let arr = localStorage.getItem('roleName').split(',')
  231. // 根据 租户好判断是否要显示 积分余额
  232. const content = JSON.parse(localStorage.getItem('saber-tenantId')).content
  233. this.$nextTick(()=>{
  234. if (arr.indexOf('admin') != -1) {
  235. this.findObject(this.option.column, "pointsBalance").disabled = false
  236. }
  237. this.findObject(this.option.column, "pointsBalance").hide = false
  238. this.findObject(this.option.column, "pointsBalance").addDisplay = true
  239. this.findObject(this.option.column, "pointsBalance").editDisplay = true
  240. this.findObject(this.option.column, "pointsBalance").viewDisplay = true
  241. })
  242. // if (content == 171757) {
  243. // this.$nextTick(()=>{
  244. // if (arr.indexOf('admin') != -1) {
  245. // this.findObject(this.option.column, "pointsBalance").disabled = false
  246. // }
  247. // this.findObject(this.option.column, "pointsBalance").hide = false
  248. // this.findObject(this.option.column, "pointsBalance").addDisplay = true
  249. // this.findObject(this.option.column, "pointsBalance").editDisplay = true
  250. // this.findObject(this.option.column, "pointsBalance").viewDisplay = true
  251. // })
  252. // }
  253. // 判断是否显示装货港
  254. if (content == 409341) {
  255. this.$nextTick(()=>{
  256. this.findObject(this.option.column, "polCnName").hide = false
  257. this.findObject(this.option.column, "polCnName").addDisplay = true
  258. this.findObject(this.option.column, "polCnName").editDisplay = true
  259. this.findObject(this.option.column, "polCnName").viewDisplay = true
  260. })
  261. }
  262. },
  263. computed: {
  264. ...mapGetters(["userInfo", "permission"]),
  265. permissionList() {
  266. return {
  267. addBtn: this.vaildData(this.permission.dept_add, false),
  268. viewBtn: this.vaildData(this.permission.dept_view, false),
  269. delBtn: this.vaildData(this.permission.dept_delete, false),
  270. editBtn: this.vaildData(this.permission.dept_edit, false)
  271. };
  272. },
  273. ids() {
  274. let ids = [];
  275. this.selectionList.forEach(ele => {
  276. ids.push(ele.id);
  277. });
  278. return ids.join(",");
  279. }
  280. },
  281. methods: {
  282. // 装货港数据
  283. polBportsListfun(enName){
  284. bportsList(1,10,{enName}).then(res=>{
  285. this.polData = res.data.data.records
  286. })
  287. },
  288. // 装货港回调数据
  289. corpChange(value,name){
  290. for(let item of this.polData) {
  291. if (item.cnName == value) {
  292. this.form.polId = item.id
  293. this.form.polCnName = item.cnName
  294. this.form.polEnName = item.enName
  295. this.form.polNamePrint = item.enName
  296. }
  297. }
  298. },
  299. initData() {
  300. getDeptTree().then(res => {
  301. const column = this.findObject(this.option.column, "parentId");
  302. column.dicData = res.data.data;
  303. });
  304. },
  305. handleAdd(row) {
  306. this.parentId = row.id;
  307. const column = this.findObject(this.option.column, "parentId");
  308. column.value = row.id;
  309. column.addDisabled = true;
  310. this.$refs.crud.rowAdd();
  311. },
  312. rowSave(row, done, loading) {
  313. add(row).then((res) => {
  314. // 获取新增数据的相关字段
  315. const data = res.data.data;
  316. row.id = data.id;
  317. row.deptCategoryName = data.deptCategoryName;
  318. row.tenantId = data.tenantId;
  319. this.$message({
  320. type: "success",
  321. message: "操作成功!"
  322. });
  323. // 数据回调进行刷新
  324. done(row);
  325. }, error => {
  326. window.console.log(error);
  327. loading();
  328. });
  329. },
  330. rowUpdate(row, index, done, loading) {
  331. update(row).then(() => {
  332. this.$message({
  333. type: "success",
  334. message: "操作成功!"
  335. });
  336. // 数据回调进行刷新
  337. done(row);
  338. }, error => {
  339. window.console.log(error);
  340. loading();
  341. });
  342. },
  343. rowDel(row, index, done) {
  344. this.$confirm("确定将选择数据删除?", {
  345. confirmButtonText: "确定",
  346. cancelButtonText: "取消",
  347. type: "warning"
  348. })
  349. .then(() => {
  350. return remove(row.id);
  351. })
  352. .then(() => {
  353. this.$message({
  354. type: "success",
  355. message: "操作成功!"
  356. });
  357. // 数据回调进行刷新
  358. done(row);
  359. });
  360. },
  361. handleDelete() {
  362. if (this.selectionList.length === 0) {
  363. this.$message.warning("请选择至少一条数据");
  364. return;
  365. }
  366. this.$confirm("确定将选择数据删除?", {
  367. confirmButtonText: "确定",
  368. cancelButtonText: "取消",
  369. type: "warning"
  370. })
  371. .then(() => {
  372. return remove(this.ids);
  373. })
  374. .then(() => {
  375. // 刷新表格数据并重载
  376. this.data = [];
  377. this.parentId = 0;
  378. this.$refs.crud.refreshTable();
  379. this.$refs.crud.toggleSelection();
  380. // 表格数据重载
  381. this.onLoad(this.page);
  382. this.$message({
  383. type: "success",
  384. message: "操作成功!"
  385. });
  386. });
  387. },
  388. searchReset() {
  389. this.query = {};
  390. this.parentId = 0;
  391. this.onLoad(this.page);
  392. },
  393. searchChange(params, done) {
  394. this.query = params;
  395. this.parentId = '';
  396. this.page.currentPage = 1;
  397. this.onLoad(this.page, params);
  398. done();
  399. },
  400. selectionChange(list) {
  401. this.selectionList = list;
  402. },
  403. selectionClear() {
  404. this.selectionList = [];
  405. this.$refs.crud.toggleSelection();
  406. },
  407. beforeOpen(done, type) {
  408. if (["add", "edit"].includes(type)) {
  409. this.initData();
  410. }
  411. if (["edit", "view"].includes(type)) {
  412. getDept(this.form.id).then(res => {
  413. this.form = res.data.data;
  414. });
  415. }
  416. done();
  417. },
  418. beforeClose(done) {
  419. this.parentId = "";
  420. const column = this.findObject(this.option.column, "parentId");
  421. column.value = "";
  422. column.addDisabled = false;
  423. done();
  424. },
  425. currentChange(currentPage) {
  426. this.page.currentPage = currentPage;
  427. },
  428. sizeChange(pageSize) {
  429. this.page.pageSize = pageSize;
  430. },
  431. refreshChange() {
  432. this.onLoad(this.page, this.query);
  433. },
  434. onLoad(page, params = {}) {
  435. this.loading = true;
  436. getLazyList(this.parentId, Object.assign(params, this.query)).then(res => {
  437. this.data = res.data.data;
  438. this.loading = false;
  439. this.selectionClear();
  440. });
  441. },
  442. treeLoad(tree, treeNode, resolve) {
  443. const parentId = tree.id;
  444. getLazyList(parentId).then(res => {
  445. console.log(res.data.data)
  446. resolve(res.data.data);
  447. });
  448. }
  449. }
  450. };
  451. </script>
  452. <style>
  453. </style>