dept.vue 20 KB

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