index.vue 19 KB

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