index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. <!--港口-->
  2. <template>
  3. <div>
  4. <basic-container v-if="isShow">
  5. <avue-crud :option="option"
  6. :table-loading="loading"
  7. :data="data"
  8. :page.sync="page"
  9. :permission="permissionList"
  10. id="out-table"
  11. :header-cell-class-name="headerClassName"
  12. :before-open="beforeOpen"
  13. :search.sync="search"
  14. v-model="form"
  15. ref="crud"
  16. @row-update="rowUpdate"
  17. @row-save="rowSave"
  18. @row-del="rowDel"
  19. @search-change="searchChange"
  20. @search-reset="searchReset"
  21. @selection-change="selectionChange"
  22. @current-change="currentChange"
  23. @size-change="sizeChange"
  24. @refresh-change="refreshChange"
  25. @resetColumn="resetColumnTwo('crud', 'option', 'optionBack', 298)"
  26. @saveColumn="saveColumnTwo('crud', 'option', 'optionBack', 298)"
  27. @on-load="onLoad">
  28. <template slot-scope="scope" slot="menuLeft">
  29. <el-button type="primary"
  30. size="small"
  31. icon="el-icon-plus"
  32. @click="addbtnfun()">新建港口
  33. </el-button>
  34. <el-button type="danger"
  35. size="small"
  36. icon="el-icon-delete"
  37. plain
  38. @click="handleDelete">删 除
  39. </el-button>
  40. <el-button type="warning" size="small" icon="el-icon-printer" @click="excelBox = true">导入
  41. </el-button>
  42. <el-button type="success" size="small" @click="handleExport" icon="el-icon-printer">导出</el-button>
  43. </template>
  44. <template slot-scope="scope" slot="menu">
  45. <el-button
  46. :type="scope.type"
  47. :size="scope.size"
  48. icon="el-icon-edit"
  49. @click.stop="rowCellfun(scope.row, scope.index)"
  50. >编辑
  51. </el-button>
  52. <el-button
  53. :type="scope.type"
  54. :size="scope.size"
  55. icon="el-icon-delete"
  56. @click.stop="rowDel(scope.row, scope.index)"
  57. >删除
  58. </el-button>
  59. </template>
  60. <template slot="remarks" slot-scope="scope">
  61. <avue-text-ellipsis :text="scope.row.remarks" :height="30" use-tooltip placement="top">
  62. <small slot="more">...</small>
  63. </avue-text-ellipsis>
  64. </template>
  65. <template slot="extendedDataArr" slot-scope="scope">
  66. <span style="color: #1e9fff">
  67. {{scope.row.extendedDataArr.length}}
  68. </span>
  69. </template>
  70. </avue-crud>
  71. </basic-container>
  72. <ports-terms ref="portsterms" v-if="!isShow" :detailData="detailData" @goBack="goBack"></ports-terms>
  73. <el-dialog title="导入往来单位" append-to-body :visible.sync="excelBox" width="555px" :close-on-click-modal="false"
  74. v-dialog-drag>
  75. <avue-form :option="excelOption" v-model="excelForm" :table-loading="excelLoading" :upload-before="uploadBefore"
  76. :upload-after="onSuccess">
  77. <template slot="excelTemplate">
  78. <el-button type="primary" @click="handleGet">
  79. 点击下载<i class="el-icon-download el-icon--right"></i>
  80. </el-button>
  81. </template>
  82. </avue-form>
  83. <p style="text-align: center;color: #DC0505">
  84. 温馨提示 第一次导入时请先下载模板
  85. </p>
  86. </el-dialog>
  87. </div>
  88. </template>
  89. <script>
  90. import {bportsList, bportsDetail, bportsSubmit, bportsRemove} from "@/api/iosBasicData/bports";
  91. import {mapGetters} from "vuex";
  92. import portsTerms from "@/views/iosBasicData/bports/portsTerms.vue";
  93. import { getToken } from "@/util/auth";
  94. export default {
  95. components: {portsTerms},
  96. data() {
  97. return {
  98. // 详情传递的数据
  99. detailData:{},
  100. form: {
  101. extendedDataArr:[]
  102. },
  103. isShow:true, // 详情和列表切换
  104. query: {},
  105. loading: true,
  106. excelBox: false,
  107. search: {},
  108. excelForm: {},
  109. excelLoading: false,
  110. excelOption: {
  111. submitBtn: false,
  112. emptyBtn: false,
  113. column: [
  114. {
  115. label: "模板下载",
  116. prop: "excelTemplate",
  117. formslot: true,
  118. span: 24
  119. },
  120. {
  121. label: "模板上传",
  122. prop: "excelFile",
  123. type: "upload",
  124. drag: true,
  125. loadText: "模板上传中,请稍等",
  126. span: 24,
  127. propsHttp: {
  128. res: "data"
  129. },
  130. tip: "请上传 .xls,.xlsx 标准格式文件",
  131. action: "/api/blade-los/bports/importBPorts"
  132. }
  133. ]
  134. },
  135. page: {
  136. pageSize: 10,
  137. currentPage: 1,
  138. total: 0
  139. },
  140. selectionList: [],
  141. option:{},
  142. optionBack: {
  143. addBtnText:'新建港口ss',
  144. addTitle:'新建港口',
  145. editBtnText:'编辑港口',
  146. editTitle:'编辑港口',
  147. viewBtnText:'查看港口',
  148. viewTitle:'查看港口',
  149. height:'auto',
  150. calcHeight: 30,
  151. tip: false,
  152. searchShow: true,
  153. searchMenuSpan: 6,
  154. border: true,
  155. index: true,
  156. viewBtn: true,
  157. selection: true,
  158. dialogClickModal: false,
  159. column: [
  160. {
  161. label: "港口编码",
  162. prop: "code",
  163. search: true,
  164. rules: [{
  165. required: true,
  166. message: "请输入港口编码",
  167. trigger: "blur"
  168. }]
  169. },
  170. {
  171. label: "国际编码",
  172. prop: "unCode",
  173. },
  174. {
  175. label: "中文名称",
  176. prop: "cnName",
  177. search: true,
  178. rules: [{
  179. required: true,
  180. message: "请输入中文名称",
  181. trigger: "blur"
  182. }]
  183. },
  184. {
  185. label: "英文名称",
  186. prop: "enName",
  187. search: true,
  188. rules: [{
  189. required: true,
  190. message: "请输入英文名称",
  191. trigger: "blur"
  192. }]
  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: "扩展数据",
  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. handleExport() {
  362. var condition = ''
  363. for (const key in this.search) {
  364. var value = this.search[key]
  365. if (value) {
  366. condition += `&${key}=${this.search[key]}`
  367. }
  368. }
  369. this.$confirm('是否导出港口?', '提示', {
  370. confirmButtonText: '确定',
  371. cancelButtonText: '取消',
  372. type: 'warning'
  373. }).then(() => {
  374. window.open(
  375. `/api/blade-los/bports/exportBPorts?${this.website.tokenHeader
  376. }=${getToken()}${condition}`
  377. );
  378. }).catch(() => {
  379. this.$message({
  380. type: 'info',
  381. message: '已取消' //
  382. });
  383. })
  384. },
  385. uploadBefore(file, done, loading) {
  386. done();
  387. loading = true;
  388. },
  389. // 上传成功
  390. onSuccess(res, done, loading, column) {
  391. this.excelBox = false;
  392. this.$message.success("导入成功!");
  393. loading = false;
  394. this.onLoad(this.page);
  395. done();
  396. },
  397. // 下载模板
  398. handleGet() {
  399. window.open(
  400. `/api/blade-los/bports/exportBPorts/template?${this.website.tokenHeader
  401. }=${getToken()}`
  402. );
  403. },
  404. // 详情的返回列表
  405. goBack(){
  406. // 初始化数据
  407. // this.detailData = this.$options.data().detailData;
  408. if (JSON.stringify(this.$route.query) != "{}") {
  409. this.$router.$avueRouter.closeTag();
  410. this.$router.push({
  411. path: "/iosBasicData/bports/index"
  412. });
  413. }
  414. this.isShow = true;
  415. this.onLoad(this.page, this.search);
  416. },
  417. // 添加弹窗开启
  418. addbtnfun(){
  419. this.detailData = {
  420. seeDisabled: false,
  421. };
  422. this.isShow = false
  423. },
  424. // 编辑详情打开
  425. rowCellfun(row,index){
  426. this.detailData = {
  427. seeDisabled: true,
  428. id: row.id
  429. };
  430. this.isShow = false
  431. this.$nextTick(()=>{
  432. this.$refs.portsterms.bportsDetailfun(row.id)
  433. })
  434. },
  435. // // 添加确认
  436. // rowSave(row, done, loading) {
  437. // row.extendedDataArr.map(item=>{
  438. // delete item.edit
  439. // })
  440. // row.extendedData = JSON.stringify(row.extendedDataArr)
  441. // delete row.extendedDataArr
  442. // bportsSubmit(row).then(() => {
  443. // this.onLoad(this.page);
  444. // this.$message({
  445. // type: "success",
  446. // message: "操作成功!"
  447. // });
  448. // done();
  449. // }, error => {
  450. // loading();
  451. // window.console.log(error);
  452. // });
  453. // },
  454. // // 编辑确认
  455. // rowUpdate(row, index, done, loading) {
  456. // row.extendedDataArr.map(item=>{
  457. // delete item.edit
  458. // })
  459. // row.extendedData = JSON.stringify(row.extendedDataArr)
  460. // delete row.extendedDataArr
  461. // bportsSubmit(row).then(() => {
  462. // this.onLoad(this.page);
  463. // this.$message({
  464. // type: "success",
  465. // message: "操作成功!"
  466. // });
  467. // done();
  468. // }, error => {
  469. // loading();
  470. // console.log(error);
  471. // });
  472. // },
  473. rowDel(row) {
  474. if (row.status === 1) {
  475. this.$confirm("确定将选择数据删除?", {
  476. confirmButtonText: "确定",
  477. cancelButtonText: "取消",
  478. type: "warning"
  479. })
  480. .then(() => {
  481. return bportsRemove(row.id);
  482. })
  483. .then(() => {
  484. this.onLoad(this.page);
  485. this.$message({
  486. type: "success",
  487. message: "操作成功!"
  488. });
  489. });
  490. }else {
  491. this.$message({
  492. message: '非禁用状态无法删除',
  493. type: 'warning'
  494. });
  495. }
  496. },
  497. handleDelete() {
  498. if (this.selectionList.length === 0) {
  499. this.$message.warning("请选择至少一条数据");
  500. return;
  501. }
  502. this.$confirm("确定将选择数据删除?", {
  503. confirmButtonText: "确定",
  504. cancelButtonText: "取消",
  505. type: "warning"
  506. })
  507. .then(() => {
  508. return bportsRemove(this.ids);
  509. })
  510. .then(() => {
  511. this.onLoad(this.page);
  512. this.$message({
  513. type: "success",
  514. message: "操作成功!"
  515. });
  516. this.$refs.crud.toggleSelection();
  517. });
  518. },
  519. // 详情
  520. beforeOpen(done, type) {
  521. if (["edit", "view"].includes(type)) {
  522. bportsDetail(this.form.id).then(res => {
  523. this.form = res.data.data;
  524. });
  525. }
  526. done();
  527. },
  528. searchReset() {
  529. this.query = {};
  530. this.onLoad(this.page);
  531. },
  532. searchChange(params, done) {
  533. this.query = params;
  534. this.page.currentPage = 1;
  535. this.onLoad(this.page, params);
  536. done();
  537. },
  538. selectionChange(list) {
  539. this.selectionList = list;
  540. },
  541. selectionClear() {
  542. this.selectionList = [];
  543. this.$refs.crud.toggleSelection();
  544. },
  545. currentChange(currentPage){
  546. this.page.currentPage = currentPage;
  547. },
  548. sizeChange(pageSize){
  549. this.page.pageSize = pageSize;
  550. },
  551. refreshChange() {
  552. this.onLoad(this.page, this.query);
  553. },
  554. onLoad(page, params = {}) {
  555. this.loading = true;
  556. bportsList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  557. const data = res.data.data;
  558. this.page.total = data.total;
  559. this.data = data.records;
  560. this.loading = false;
  561. this.selectionClear();
  562. });
  563. },
  564. //自定义列保存
  565. async saveColumnTwo(ref, option, optionBack, code) {
  566. /**
  567. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  568. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  569. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  570. */
  571. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  572. if (inSave) {
  573. this.$message.success("保存成功");
  574. //关闭窗口
  575. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  576. }
  577. },
  578. //自定义列重置
  579. async resetColumnTwo(ref, option, optionBack, code) {
  580. this[option] = this[optionBack];
  581. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  582. if (inSave) {
  583. this.$message.success("重置成功");
  584. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  585. }
  586. },
  587. // 更改表格颜色
  588. headerClassName(tab){
  589. //颜色间隔
  590. let back = ""
  591. if (tab.columnIndex >= 0 && tab.column.level === 1) {
  592. if (tab.columnIndex % 2 === 0) {
  593. back = "back-one"
  594. } else if (tab.columnIndex % 2 === 1) {
  595. back = "back-two"
  596. }
  597. }
  598. return back;
  599. },
  600. }
  601. };
  602. </script>
  603. <style scoped>
  604. ::v-deep#out-table .back-one {
  605. background: #ecf5ff !important;
  606. }
  607. ::v-deep#out-table .back-two {
  608. background: #ecf5ff !important;
  609. }
  610. </style>