index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. <!--港口-->
  2. <template>
  3. <div>
  4. <basic-container v-if="isShow">
  5. <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" :permission="permissionList"
  6. id="out-table" :header-cell-class-name="headerClassName" :before-open="beforeOpen" :search.sync="search"
  7. v-model="form" ref="crud" @row-update="rowUpdate" @row-save="rowSave" @row-del="rowDel"
  8. @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
  9. @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange"
  10. @resetColumn="resetColumnTwo('crud', 'option', 'optionBack', 298)"
  11. @saveColumn="saveColumnTwo('crud', 'option', 'optionBack', 298)" @on-load="onLoad">
  12. <template slot-scope="scope" slot="menuLeft">
  13. <el-button type="primary" size="small" icon="el-icon-plus" @click="addbtnfun()">新建港口
  14. </el-button>
  15. <el-button type="danger" size="small" icon="el-icon-delete" plain @click="handleDelete">删 除
  16. </el-button>
  17. <el-button type="warning" size="small" icon="el-icon-printer" @click="excelBox = true">导入
  18. </el-button>
  19. <el-button type="success" size="small" @click="handleExport" icon="el-icon-printer">导出</el-button>
  20. </template>
  21. <template slot-scope="scope" slot="menu">
  22. <el-button :type="scope.type" :size="scope.size" icon="el-icon-edit"
  23. @click.stop="rowCellfun(scope.row, scope.index)">编辑
  24. </el-button>
  25. <el-button :type="scope.type" :size="scope.size" icon="el-icon-delete"
  26. @click.stop="rowDel(scope.row, scope.index)">删除
  27. </el-button>
  28. <el-button v-if="scope.row.status == 1" type="text" icon="el-icon-turn-off" style="color: #85e967" size="small"
  29. @click.stop="statusfun(scope.row.id, 0)">
  30. 启用
  31. </el-button>
  32. <el-button v-if="scope.row.status == 0" type="text" icon="el-icon-turn-off" style="color: #e83c3a" size="small"
  33. @click.stop="statusfun(scope.row.id, 1)">
  34. 停用
  35. </el-button>
  36. </template>
  37. <template slot="extendedDataArr" slot-scope="scope">
  38. <span style="color: #1e9fff">
  39. {{ scope.row.extendedDataArr.length }}
  40. </span>
  41. </template>
  42. </avue-crud>
  43. </basic-container>
  44. <ports-terms ref="portsterms" v-if="!isShow" :detailData="detailData" @goBack="goBack"></ports-terms>
  45. <el-dialog title="导入港口" append-to-body :visible.sync="excelBox" width="555px" :close-on-click-modal="false"
  46. v-dialog-drag>
  47. <avue-form :option="excelOption" v-model="excelForm" :table-loading="excelLoading" :upload-before="uploadBefore"
  48. :upload-after="onSuccess">
  49. <template slot="excelTemplate">
  50. <el-button type="primary" @click="handleGet">
  51. 点击下载<i class="el-icon-download el-icon--right"></i>
  52. </el-button>
  53. </template>
  54. </avue-form>
  55. <p style="text-align: center;color: #DC0505">
  56. 温馨提示 第一次导入时请先下载模板
  57. </p>
  58. </el-dialog>
  59. </div>
  60. </template>
  61. <script>
  62. import { bportsList, bportsDetail, bportsSubmit, bportsRemove } from "@/api/iosBasicData/bports";
  63. import { mapGetters } from "vuex";
  64. import portsTerms from "@/views/iosBasicData/bports/portsTerms.vue";
  65. import { getToken } from "@/util/auth";
  66. export default {
  67. components: { portsTerms },
  68. data() {
  69. return {
  70. // 详情传递的数据
  71. detailData: {},
  72. form: {
  73. extendedDataArr: []
  74. },
  75. isShow: true, // 详情和列表切换
  76. query: {},
  77. loading: true,
  78. excelBox: false,
  79. search: {},
  80. excelForm: {},
  81. excelLoading: false,
  82. excelOption: {
  83. submitBtn: false,
  84. emptyBtn: false,
  85. column: [
  86. {
  87. label: "模板下载",
  88. prop: "excelTemplate",
  89. formslot: true,
  90. span: 24
  91. },
  92. {
  93. label: "模板上传",
  94. prop: "excelFile",
  95. type: "upload",
  96. drag: true,
  97. loadText: "模板上传中,请稍等",
  98. span: 24,
  99. propsHttp: {
  100. res: "data"
  101. },
  102. tip: "请上传 .xls,.xlsx 标准格式文件",
  103. action: "/api/blade-los/bports/importBPorts"
  104. }
  105. ]
  106. },
  107. page: {
  108. pageSize: 20,
  109. currentPage: 1,
  110. total: 0,
  111. pageSizes: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
  112. },
  113. selectionList: [],
  114. option: {
  115. dialogDrag: true,
  116. },
  117. optionBack: {
  118. dialogDrag: true,
  119. addBtnText: '新建港口',
  120. addTitle: '新建港口',
  121. editBtnText: '编辑港口',
  122. editTitle: '编辑港口',
  123. viewBtnText: '查看港口',
  124. viewTitle: '查看港口',
  125. height: 'auto',
  126. calcHeight: 30,
  127. tip: false,
  128. searchShow: true,
  129. searchMenuSpan: 24,
  130. border: true,
  131. index: true,
  132. viewBtn: false,
  133. selection: true,
  134. dialogClickModal: false,
  135. menuWidth: 220,
  136. column: [
  137. {
  138. label: "编码",
  139. prop: "code",
  140. width: "180",
  141. search: true,
  142. rules: [{
  143. required: true,
  144. message: "请输入港口编码",
  145. trigger: "blur"
  146. }],
  147. overHidden: true,
  148. },
  149. {
  150. label: "中文名称",
  151. prop: "cnName",
  152. width: "180",
  153. search: true,
  154. rules: [{
  155. required: true,
  156. message: "请输入中文名称",
  157. trigger: "blur"
  158. }],
  159. overHidden: true,
  160. },
  161. {
  162. label: "英文名称",
  163. prop: "enName",
  164. width: "180",
  165. search: true,
  166. rules: [{
  167. required: true,
  168. message: "请输入英文名称",
  169. trigger: "blur"
  170. }],
  171. overHidden: true,
  172. },
  173. {
  174. label: "国际编码",
  175. prop: "unCode",
  176. overHidden: true,
  177. },
  178. {
  179. label: "国家编码",
  180. prop: "cntyCode",
  181. overHidden: true,
  182. },
  183. {
  184. label: "国家名称",
  185. prop: "cntyName",
  186. overHidden: true,
  187. },
  188. {
  189. label: "是否海港",
  190. prop: "isSeaPort",
  191. type: 'select',
  192. dicData: [{
  193. label: '否',
  194. value: 0
  195. }, {
  196. label: '是',
  197. value: 1
  198. }],
  199. overHidden: true,
  200. },
  201. {
  202. label: "是否空港",
  203. prop: "isAirPort",
  204. type: 'select',
  205. dicData: [{
  206. label: '否',
  207. value: 0
  208. }, {
  209. label: '是',
  210. value: 1
  211. }],
  212. overHidden: true,
  213. },
  214. {
  215. label: "是否内陆港",
  216. prop: "isInlandPort",
  217. width: 100,
  218. type: 'select',
  219. dicData: [{
  220. label: '否',
  221. value: 0
  222. }, {
  223. label: '是',
  224. value: 1
  225. }],
  226. overHidden: true,
  227. },
  228. {
  229. label: "EDI CODE",
  230. prop: "extendedDataArr",
  231. formslot: true,
  232. overHidden: true,
  233. // rules: [{
  234. // required: true,
  235. // message: "请输入JSON 对象数组,用于不查询的扩展数据, 例如:[{name: key1, value: value1}]",
  236. // trigger: "blur"
  237. // }]
  238. },
  239. // INTTRA,MAEU,OOCL,APL,PIL,HJ,HMM,ESL,ZIM,PO,MSC,CSAV,QQCT,CTM,SML
  240. {
  241. label: "INTTRA",
  242. prop: "INTTRA",
  243. overHidden: true,
  244. },
  245. {
  246. label: "MAEU",
  247. prop: "MAEU",
  248. overHidden: true,
  249. },
  250. {
  251. label: "OOCL",
  252. prop: "OOCL",
  253. overHidden: true,
  254. },
  255. {
  256. label: "APL",
  257. prop: "APL",
  258. overHidden: true,
  259. },
  260. {
  261. label: "PIL",
  262. prop: "PIL",
  263. overHidden: true,
  264. },
  265. {
  266. label: "HJ",
  267. prop: "HJ",
  268. overHidden: true,
  269. },
  270. {
  271. label: "HMM",
  272. prop: "HMM",
  273. overHidden: true,
  274. },
  275. {
  276. label: "ESL",
  277. prop: "ESL",
  278. overHidden: true,
  279. },
  280. {
  281. label: "ZIM",
  282. prop: "ZIM",
  283. overHidden: true,
  284. },
  285. {
  286. label: "PO",
  287. prop: "PO",
  288. overHidden: true,
  289. },
  290. // MSC,CSAV,QQCT,CTM,SML
  291. {
  292. label: "MSC",
  293. prop: "MSC",
  294. overHidden: true,
  295. },
  296. {
  297. label: "CSAV",
  298. prop: "CSAV",
  299. overHidden: true,
  300. },
  301. {
  302. label: "QQCT",
  303. prop: "QQCT",
  304. overHidden: true,
  305. },
  306. {
  307. label: "CTM",
  308. prop: "CTM",
  309. overHidden: true,
  310. },
  311. {
  312. label: "SML",
  313. prop: "SML",
  314. overHidden: true,
  315. },
  316. {
  317. label: "版本",
  318. prop: "version",
  319. hide: true,
  320. display: false,
  321. overHidden: true,
  322. },
  323. {
  324. label: "状态",
  325. prop: "status",
  326. type: 'select',
  327. search: true,
  328. dicData: [{
  329. label: '启用',
  330. value: 0
  331. }, {
  332. label: '停用',
  333. value: 1
  334. }],
  335. overHidden: true,
  336. },
  337. {
  338. label: "是否已删除(0 否 1是)",
  339. prop: "isDeleted",
  340. hide: true,
  341. display: false,
  342. overHidden: true,
  343. },
  344. {
  345. label: "创建人",
  346. prop: "createUserName",
  347. display: false,
  348. overHidden: true,
  349. },
  350. {
  351. label: "创建部门",
  352. prop: "createDeptName",
  353. display: false,
  354. overHidden: true,
  355. },
  356. {
  357. label: "创建时间",
  358. prop: "createTime",
  359. width: 160,
  360. display: false,
  361. overHidden: true,
  362. },
  363. {
  364. label: "修改人",
  365. prop: "updateUserName",
  366. display: false,
  367. overHidden: true,
  368. },
  369. {
  370. label: "修改时间",
  371. prop: "updateTime",
  372. width: 160,
  373. display: false,
  374. overHidden: true,
  375. },
  376. {
  377. label: "备注",
  378. prop: "remarks",
  379. span: 24,
  380. type: 'textarea',
  381. width: "180",
  382. slot: true,
  383. minRows: 3,
  384. overHidden: true,
  385. },
  386. ]
  387. },
  388. data: []
  389. };
  390. },
  391. computed: {
  392. ...mapGetters(["permission"]),
  393. permissionList() {
  394. return {
  395. addBtn: this.vaildData(this.permission.bports_add, false),
  396. viewBtn: this.vaildData(this.permission.bports_view, false),
  397. delBtn: this.vaildData(this.permission.bports_delete, false),
  398. editBtn: this.vaildData(this.permission.bports_edit, false)
  399. };
  400. },
  401. ids() {
  402. let ids = [];
  403. this.selectionList.forEach(ele => {
  404. ids.push(ele.id);
  405. });
  406. return ids.join(",");
  407. }
  408. },
  409. async created() {
  410. this.option = await this.getColumnData(this.getColumnName(298), this.optionBack);
  411. if (this.$route.query.type == 'new') {
  412. setTimeout(() => {
  413. this.detailData = {
  414. seeDisabled: false,
  415. };
  416. this.isShow = false
  417. }, 200);
  418. }
  419. },
  420. methods: {
  421. // 禁用启用按钮
  422. statusfun(id, status) {
  423. this.$confirm("确定将选择数据更改状态?", {
  424. confirmButtonText: "确定",
  425. cancelButtonText: "取消",
  426. type: "warning"
  427. }).then(() => {
  428. bportsDetail(id).then(res => {
  429. let obj = res.data.data;
  430. obj.status = status
  431. bportsSubmit(obj).then(() => {
  432. this.onLoad(this.page);
  433. this.$message({
  434. type: "success",
  435. message: "操作成功!"
  436. });
  437. })
  438. })
  439. })
  440. },
  441. // 导出
  442. handleExport() {
  443. var condition = ''
  444. for (const key in this.search) {
  445. var value = this.search[key]
  446. if (value) {
  447. condition += `&${key}=${this.search[key]}`
  448. }
  449. }
  450. this.$confirm('是否导出港口?', '提示', {
  451. confirmButtonText: '确定',
  452. cancelButtonText: '取消',
  453. type: 'warning'
  454. }).then(() => {
  455. window.open(
  456. `/api/blade-los/bports/exportBPorts?${this.website.tokenHeader
  457. }=${getToken()}${condition}`
  458. );
  459. }).catch(() => {
  460. this.$message({
  461. type: 'info',
  462. message: '已取消' //
  463. });
  464. })
  465. },
  466. uploadBefore(file, done, loading) {
  467. done();
  468. loading = true;
  469. },
  470. // 上传成功
  471. onSuccess(res, done, loading, column) {
  472. this.excelBox = false;
  473. this.$message.success("导入成功!");
  474. loading = false;
  475. this.onLoad(this.page);
  476. done();
  477. },
  478. // 下载模板
  479. handleGet() {
  480. window.open(
  481. `/api/blade-los/bports/exportBPorts/template?${this.website.tokenHeader
  482. }=${getToken()}`
  483. );
  484. },
  485. // 详情的返回列表
  486. goBack() {
  487. // 初始化数据
  488. // this.detailData = this.$options.data().detailData;
  489. if (JSON.stringify(this.$route.query) != "{}") {
  490. this.$router.$avueRouter.closeTag();
  491. this.$router.push({
  492. path: "/iosBasicData/bports/index"
  493. });
  494. }
  495. this.isShow = true;
  496. this.onLoad(this.page, this.search);
  497. },
  498. // 添加弹窗开启
  499. addbtnfun() {
  500. this.detailData = {
  501. seeDisabled: false,
  502. };
  503. this.isShow = false
  504. },
  505. // 编辑详情打开
  506. rowCellfun(row, index) {
  507. this.detailData = {
  508. seeDisabled: true,
  509. id: row.id
  510. };
  511. this.isShow = false
  512. this.$nextTick(() => {
  513. this.$refs.portsterms.bportsDetailfun(row.id)
  514. })
  515. },
  516. // // 添加确认
  517. // rowSave(row, done, loading) {
  518. // row.extendedDataArr.map(item=>{
  519. // delete item.edit
  520. // })
  521. // row.extendedData = JSON.stringify(row.extendedDataArr)
  522. // delete row.extendedDataArr
  523. // bportsSubmit(row).then(() => {
  524. // this.onLoad(this.page);
  525. // this.$message({
  526. // type: "success",
  527. // message: "操作成功!"
  528. // });
  529. // done();
  530. // }, error => {
  531. // loading();
  532. // window.console.log(error);
  533. // });
  534. // },
  535. // // 编辑确认
  536. // rowUpdate(row, index, done, loading) {
  537. // row.extendedDataArr.map(item=>{
  538. // delete item.edit
  539. // })
  540. // row.extendedData = JSON.stringify(row.extendedDataArr)
  541. // delete row.extendedDataArr
  542. // bportsSubmit(row).then(() => {
  543. // this.onLoad(this.page);
  544. // this.$message({
  545. // type: "success",
  546. // message: "操作成功!"
  547. // });
  548. // done();
  549. // }, error => {
  550. // loading();
  551. // console.log(error);
  552. // });
  553. // },
  554. rowDel(row) {
  555. if (row.status === 1) {
  556. this.$confirm("确定将选择数据删除?", {
  557. confirmButtonText: "确定",
  558. cancelButtonText: "取消",
  559. type: "warning"
  560. })
  561. .then(() => {
  562. return bportsRemove(row.id);
  563. })
  564. .then(() => {
  565. this.onLoad(this.page);
  566. this.$message({
  567. type: "success",
  568. message: "操作成功!"
  569. });
  570. });
  571. } else {
  572. this.$message({
  573. message: '非禁用状态无法删除',
  574. type: 'warning'
  575. });
  576. }
  577. },
  578. handleDelete() {
  579. if (this.selectionList.length === 0) {
  580. this.$message.warning("请选择至少一条数据");
  581. return;
  582. }
  583. for (const selection of this.selectionList) {
  584. if (selection.status == 0) {
  585. this.$message.warning("选中的数据中有启用数据,启用数据不可删除!");
  586. return;
  587. }
  588. }
  589. this.$confirm("确定将选择数据删除?", {
  590. confirmButtonText: "确定",
  591. cancelButtonText: "取消",
  592. type: "warning"
  593. })
  594. .then(() => {
  595. return bportsRemove(this.ids);
  596. })
  597. .then(() => {
  598. this.onLoad(this.page);
  599. this.$message({
  600. type: "success",
  601. message: "操作成功!"
  602. });
  603. this.$refs.crud.toggleSelection();
  604. });
  605. },
  606. // 详情
  607. beforeOpen(done, type) {
  608. if (["edit", "view"].includes(type)) {
  609. bportsDetail(this.form.id).then(res => {
  610. this.form = res.data.data;
  611. });
  612. }
  613. done();
  614. },
  615. searchReset() {
  616. this.query = {};
  617. this.onLoad(this.page);
  618. },
  619. searchChange(params, done) {
  620. this.query = params;
  621. this.page.currentPage = 1;
  622. this.onLoad(this.page, params);
  623. done();
  624. },
  625. selectionChange(list) {
  626. this.selectionList = list;
  627. },
  628. selectionClear() {
  629. this.selectionList = [];
  630. this.$refs.crud.toggleSelection();
  631. },
  632. currentChange(currentPage) {
  633. this.page.currentPage = currentPage;
  634. },
  635. sizeChange(pageSize) {
  636. this.page.pageSize = pageSize;
  637. },
  638. refreshChange() {
  639. this.onLoad(this.page, this.query);
  640. },
  641. onLoad(page, params = {}) {
  642. this.loading = true;
  643. bportsList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  644. const data = res.data.data;
  645. this.page.total = data.total;
  646. console.log('ports', data.records);
  647. // INTTRA,MAEU,OOCL,APL,PIL,HJ,HMM,ESL,ZIM,PO,MSC,CSAV,QQCT,CTM,SML
  648. var cols = 'INTTRA,MAEU,OOCL,APL,PIL,HJ,HMM,ESL,ZIM,PO,MSC,CSAV,QQCT,CTM,SML'.split(',');
  649. data.records.forEach(r=>{
  650. cols.forEach(col=>{
  651. r[col]=''
  652. })
  653. if(Array.isArray(r.extendedDataArr)){
  654. r.extendedDataArr.forEach(d=>{
  655. r[d.name]=d.value
  656. })
  657. }
  658. })
  659. this.data = data.records;
  660. this.loading = false;
  661. this.selectionClear();
  662. });
  663. },
  664. //自定义列保存
  665. async saveColumnTwo(ref, option, optionBack, code) {
  666. /**
  667. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  668. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  669. * 一定要执行异步操作,要等接口成功返回,才能执行下一行编码
  670. */
  671. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  672. if (inSave) {
  673. this.$message.success("保存成功");
  674. //关闭窗口
  675. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  676. }
  677. },
  678. //自定义列重置
  679. async resetColumnTwo(ref, option, optionBack, code) {
  680. this[option] = this[optionBack];
  681. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  682. if (inSave) {
  683. this.$message.success("重置成功");
  684. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  685. }
  686. },
  687. // 更改表格颜色
  688. headerClassName(tab) {
  689. //颜色间隔
  690. let back = ""
  691. if (tab.columnIndex >= 0 && tab.column.level === 1) {
  692. if (tab.columnIndex % 2 === 0) {
  693. back = "back-one"
  694. } else if (tab.columnIndex % 2 === 1) {
  695. back = "back-two"
  696. }
  697. }
  698. return back;
  699. },
  700. }
  701. };
  702. </script>
  703. <style scoped>
  704. ::v-deep#out-table .back-one {
  705. background: #ecf5ff !important;
  706. }
  707. ::v-deep#out-table .back-two {
  708. background: #ecf5ff !important;
  709. }
  710. </style>