index.vue 18 KB

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