index.vue 20 KB

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