dept.vue 17 KB

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