index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <!-- 数据 -->
  2. <template>
  3. <basic-container>
  4. <avue-crud
  5. :option="option"
  6. :table-loading="loading"
  7. :data="data"
  8. :page.sync="page"
  9. id="out-table"
  10. :header-cell-class-name="headerClassName"
  11. :search.sync="query"
  12. v-model="form"
  13. ref="crud"
  14. @row-update="rowUpdate"
  15. @row-save="rowSave"
  16. @search-change="searchChange"
  17. @search-reset="searchReset"
  18. @selection-change="selectionChange"
  19. @current-change="currentChange"
  20. @size-change="sizeChange"
  21. @refresh-change="refreshChange"
  22. @resetColumn="resetColumn('crud', 'option', 'optionBack', 535)"
  23. @saveColumn="saveColumn('crud', 'option', 'optionBack', 535)"
  24. @on-load="onLoad"
  25. >
  26. <template slot="menuLeft">
  27. <el-button type="primary" size="small" icon="el-icon-plus" @click="addRow()">新增</el-button>
  28. <!-- <el-button type="danger" size="small" icon="el-icon-delete" plain @click="handleDelete">删 除</el-button> -->
  29. <!-- <el-button type="warning" size="small" icon="el-icon-printer" @click="excelBox = true">导入 </el-button>
  30. <el-button type="success" size="small" @click="handleExport" icon="el-icon-printer">导出</el-button> -->
  31. </template>
  32. <template slot-scope="{ row, index }" slot="menu">
  33. <!-- <el-button type="text" size="small" @click.stop="rowView(row, index)">查看
  34. </el-button> -->
  35. <el-button type="text" size="small" @click.stop="rowEdit(row, index)">编辑 </el-button>
  36. <el-button type="text" size="small" @click.stop="rowDel(row, index)">删除 </el-button>
  37. </template>
  38. <template slot="branchNameForm" slot-scope="{ type, disabled }">
  39. <dic-select
  40. v-model="form.branchName"
  41. placeholder="所属公司"
  42. key="id"
  43. label="deptName"
  44. url="/blade-system/dept/top-list"
  45. :filterable="true"
  46. :remote="true"
  47. dataName="deptName"
  48. :disabled="disabled"
  49. @selectChange="dicChange('branchName', $event)"
  50. ></dic-select>
  51. </template>
  52. <tempalte slot="vesselCnNameForm" slot-scope="{ type, disabled }">
  53. <dic-select
  54. v-model="form.vesselCnName"
  55. placeholder="船名"
  56. key="id"
  57. label="cnName"
  58. res="records"
  59. url="/blade-los/bvessels/list?status=0&current=1&size=10"
  60. :filterable="true"
  61. :remote="true"
  62. dataName="cnName"
  63. @selectChange="dicChange('vesselCnName', $event)"
  64. :slotRight="true"
  65. rightLabel="code"
  66. :disabled="disabled"
  67. ></dic-select>
  68. </tempalte>
  69. <tempalte slot="polCnNameForm" slot-scope="{ type, disabled }">
  70. <dic-select
  71. v-model="form.polCnName"
  72. placeholder="港口"
  73. key="id"
  74. label="cnName"
  75. res="records"
  76. url="/blade-los/bports/list?status=0&current=1&size=10"
  77. :filterable="true"
  78. :remote="true"
  79. dataName="cnName"
  80. @selectChange="dicChange('polCnName', $event)"
  81. :slotRight="true"
  82. rightLabel="code"
  83. :disabled="disabled || !(roleName.includes('admin') || roleName.includes('总部'))"
  84. ></dic-select>
  85. </tempalte>
  86. </avue-crud>
  87. <el-dialog title="导入数据" append-to-body :visible.sync="excelBox" width="555px" :close-on-click-modal="false" v-dialog-drag>
  88. <avue-form :option="excelOption" v-model="excelForm" :table-loading="excelLoading" :upload-before="uploadBefore" :upload-after="onSuccess">
  89. <template slot="excelTemplate">
  90. <el-button type="primary" @click="handleGet"> 点击下载<i class="el-icon-download el-icon--right"></i> </el-button>
  91. </template>
  92. </avue-form>
  93. <p style="text-align: center;color: #DC0505">
  94. 温馨提示 第一次导入时请先下载模板
  95. </p>
  96. </el-dialog>
  97. </basic-container>
  98. </template>
  99. <script>
  100. import { getList, getDetail, submit, remove } from "@/api/iosBasicData/sailingSchedule.js";
  101. import dicSelect from "@/components/dicSelect/main";
  102. import { getToken } from "@/util/auth";
  103. export default {
  104. name: "船期管理",
  105. components: {
  106. dicSelect
  107. },
  108. data() {
  109. return {
  110. roleName: localStorage.getItem("roleName").split(","), // 当前的角色权限
  111. form: {
  112. branchId: JSON.parse(localStorage.getItem("sysitemData")).deptId,
  113. branchName: JSON.parse(localStorage.getItem("sysitemData")).deptName
  114. },
  115. query: {},
  116. loading: true,
  117. excelBox: false,
  118. excelForm: {},
  119. excelLoading: false,
  120. excelOption: {
  121. submitBtn: false,
  122. emptyBtn: false,
  123. column: [
  124. {
  125. label: "模板下载",
  126. prop: "excelTemplate",
  127. formslot: true,
  128. span: 24
  129. },
  130. {
  131. label: "模板上传",
  132. prop: "excelFile",
  133. type: "upload",
  134. drag: true,
  135. loadText: "模板上传中,请稍等",
  136. span: 24,
  137. propsHttp: {
  138. res: "data"
  139. },
  140. tip: "请上传 .xls,.xlsx 标准格式文件",
  141. action: "/api/blade-los/btrademodes/importBTradeModes"
  142. }
  143. ]
  144. },
  145. page: {
  146. pageSize: 20,
  147. currentPage: 1,
  148. total: 0,
  149. pageSizes: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
  150. },
  151. selectionList: [],
  152. option: {},
  153. optionBack: {
  154. height: "auto",
  155. align: "center",
  156. stripe: true,
  157. calcHeight: 30,
  158. searchIcon: true,
  159. searchIndex: 3,
  160. tip: false,
  161. searchShow: true,
  162. searchMenuSpan: 24,
  163. border: true,
  164. index: true,
  165. addBtn:false,
  166. viewBtn: false,
  167. delBtn: false,
  168. editBtn: false,
  169. selection: true,
  170. dialogDrag: true,
  171. dialogClickModal: false,
  172. menuWidth: 100,
  173. column: [
  174. {
  175. label: "所属公司",
  176. prop: "branchId",
  177. display: false,
  178. hide: true,
  179. type: "select",
  180. filterable: true,
  181. dicUrl: "/api/blade-system/dept/lazy-list",
  182. props: {
  183. label: "deptName",
  184. value: "id"
  185. },
  186. search: true
  187. },
  188. {
  189. label: "所属公司",
  190. prop: "branchName",
  191. width: 120,
  192. rules: [
  193. {
  194. required: true,
  195. message: "请选择所属公司",
  196. trigger: "blur"
  197. }
  198. ],
  199. overHidden: true
  200. },
  201. {
  202. label: "船名",
  203. prop: "vesselId",
  204. display: false,
  205. hide: true,
  206. search: true,
  207. type: "select",
  208. filterable: true,
  209. remote: true,
  210. dicUrl: "/api/blade-los/bvessels/list?status=0&current=1&size=10&cnName={{key}}",
  211. props: {
  212. label: "cnName",
  213. value: "id",
  214. res: "data.records"
  215. },
  216. overHidden: true
  217. },
  218. {
  219. label: "船名",
  220. prop: "vesselCnName",
  221. width: 100,
  222. rules: [
  223. {
  224. required: true,
  225. message: "请选择船名",
  226. trigger: "blur"
  227. }
  228. ],
  229. overHidden: true
  230. },
  231. {
  232. label: "航次",
  233. prop: "voyageNo",
  234. width: 100,
  235. search: true,
  236. rules: [
  237. {
  238. required: true,
  239. message: "请输入航次",
  240. trigger: "blur"
  241. }
  242. ],
  243. overHidden: true
  244. },
  245. {
  246. label: "开船日期",
  247. prop: "etd",
  248. type: "date",
  249. format: "yyyy-MM-dd",
  250. valueFormat: "yyyy-MM-dd 00:00:00",
  251. rules: [
  252. {
  253. required: true,
  254. message: "请选择日期",
  255. trigger: "blur"
  256. }
  257. ],
  258. overHidden: true
  259. },
  260. {
  261. label: "装货港",
  262. prop: "polId",
  263. display: false,
  264. hide: true,
  265. search: true,
  266. type: "select",
  267. filterable: true,
  268. remote: true,
  269. dicUrl: "/api/blade-los/bports/list?status=0&current=1&size=10&cnName={{key}}",
  270. props: {
  271. label: "cnName",
  272. value: "id",
  273. res: "data.records"
  274. },
  275. overHidden: true
  276. },
  277. {
  278. label: "装货港",
  279. prop: "polCnName",
  280. width: 100,
  281. rules: [
  282. {
  283. required: true,
  284. message: "请选择装货港",
  285. trigger: "blur"
  286. }
  287. ],
  288. overHidden: true
  289. },
  290. {
  291. label: "创建人",
  292. prop: "createUserName",
  293. display: false,
  294. overHidden: true
  295. },
  296. {
  297. label: "创建时间",
  298. prop: "createTime",
  299. width: 150,
  300. display: false,
  301. overHidden: true
  302. },
  303. {
  304. label: "修改人",
  305. prop: "updateUserName",
  306. display: false,
  307. overHidden: true
  308. },
  309. {
  310. label: "修改时间",
  311. prop: "updateTime",
  312. width: 150,
  313. display: false,
  314. overHidden: true
  315. },
  316. {
  317. label: "是否已删除(0 否 1是)",
  318. prop: "isDeleted",
  319. hide: true,
  320. display: false,
  321. overHidden: true
  322. },
  323. {
  324. label: "备注",
  325. prop: "remarks",
  326. type: "textarea",
  327. width: 180,
  328. span: 12,
  329. minRows: 2,
  330. slot: true,
  331. overHidden: true
  332. }
  333. ]
  334. },
  335. data: []
  336. };
  337. },
  338. async created() {
  339. this.option = await this.getColumnData(this.getColumnName(535), this.optionBack);
  340. },
  341. computed: {
  342. ids() {
  343. let ids = [];
  344. this.selectionList.forEach(ele => {
  345. ids.push(ele.id);
  346. });
  347. return ids.join(",");
  348. }
  349. },
  350. methods: {
  351. dicChange(name, row) {
  352. if (name == "branchName") {
  353. if (row) {
  354. this.form.branchId = row.id;
  355. } else {
  356. this.form.branchId = null;
  357. this.form.branchName = null;
  358. }
  359. }
  360. if (name == "polCnName") {
  361. if (row) {
  362. this.form.polId = row.id;
  363. this.form.polCode = row.code;
  364. this.form.polEnName = row.enName;
  365. } else {
  366. this.form.polId = null;
  367. this.form.polCode = null;
  368. this.form.polEnName = null;
  369. this.form.polCnName = null;
  370. }
  371. }
  372. if (name == "vesselCnName") {
  373. if (row) {
  374. this.form.vesselId = row.id;
  375. this.form.vesselEnName = row.enName;
  376. } else {
  377. this.form.vesselId = null;
  378. this.form.vesselEnName = null;
  379. this.form.vesselCnName = null;
  380. }
  381. }
  382. },
  383. // 导出
  384. handleExport() {
  385. var condition = "";
  386. for (const key in this.query) {
  387. var value = this.query[key];
  388. if (value) {
  389. condition += `&${key}=${this.query[key]}`;
  390. }
  391. }
  392. this.$confirm("是否导出数据?", "提示", {
  393. confirmButtonText: "确定",
  394. cancelButtonText: "取消",
  395. type: "warning"
  396. })
  397. .then(() => {
  398. window.open(`/api/blade-los/btrademodes/exportBTradeModes?${this.website.tokenHeader}=${getToken()}${condition}`);
  399. })
  400. .catch(() => {
  401. this.$message({
  402. type: "info",
  403. message: "已取消" //
  404. });
  405. });
  406. },
  407. uploadBefore(file, done, loading) {
  408. done();
  409. loading = true;
  410. },
  411. // 上传成功
  412. onSuccess(res, done, loading, column) {
  413. if (res.length > 0) {
  414. this.$message.success("上传成功!");
  415. }
  416. this.excelBox = false;
  417. loading = false;
  418. this.onLoad(this.page);
  419. done();
  420. },
  421. // 下载模板
  422. handleGet() {
  423. window.open(`/api/blade-los/btrademodes/exportBTradeModes/template?${this.website.tokenHeader}=${getToken()}`);
  424. },
  425. addRow() {
  426. this.form = {
  427. branchId: JSON.parse(localStorage.getItem("sysitemData")).deptId,
  428. branchName: JSON.parse(localStorage.getItem("sysitemData")).deptName
  429. };
  430. this.$refs.crud.rowAdd();
  431. },
  432. // 编辑
  433. rowEdit(row, index) {
  434. getDetail({ id: row.id }).then(res => {
  435. this.form = res.data.data;
  436. this.$refs.crud.rowEdit(row, index);
  437. });
  438. },
  439. rowSave(row, done, loading) {
  440. submit(row)
  441. .then(res => {
  442. this.onLoad(this.page, this.query);
  443. this.$message({
  444. type: "success",
  445. message: "操作成功!"
  446. });
  447. })
  448. .finally(() => {
  449. done();
  450. loading();
  451. });
  452. },
  453. rowUpdate(row, index, done, loading) {
  454. submit(row)
  455. .then(res => {
  456. this.onLoad(this.page, this.query);
  457. this.$message({
  458. type: "success",
  459. message: "操作成功!"
  460. });
  461. })
  462. .finally(() => {
  463. done();
  464. loading();
  465. });
  466. },
  467. rowDel(row) {
  468. this.$confirm("确定将选择数据删除?", {
  469. confirmButtonText: "确定",
  470. cancelButtonText: "取消",
  471. type: "warning"
  472. }).then(() => {
  473. remove({ ids: row.id }).then(res => {
  474. this.onLoad(this.page, this.query);
  475. this.$message.success("成功删除");
  476. });
  477. });
  478. },
  479. handleDelete() {
  480. if (this.selectionList.length === 0) {
  481. this.$message.warning("请选择至少一条数据");
  482. return;
  483. }
  484. for (const selection of this.selectionList) {
  485. if (selection.status == 0) {
  486. this.$message.warning("选中的数据中有启用数据,启用数据不可删除!");
  487. return;
  488. }
  489. }
  490. this.$confirm("确定将选择数据删除?", {
  491. confirmButtonText: "确定",
  492. cancelButtonText: "取消",
  493. type: "warning"
  494. }).then(() => {
  495. remove({ ids: this.ids }).then(() => {
  496. this.onLoad(this.page);
  497. this.$message({
  498. type: "success",
  499. message: "操作成功!"
  500. });
  501. this.$refs.crud.toggleSelection();
  502. });
  503. });
  504. },
  505. searchReset() {
  506. this.query = this.$options.data().query;
  507. this.onLoad(this.page, this.query);
  508. },
  509. searchChange(params, done) {
  510. this.page.currentPage = 1;
  511. this.onLoad(this.page, this.query);
  512. done();
  513. },
  514. selectionChange(list) {
  515. this.selectionList = list;
  516. },
  517. selectionClear() {
  518. this.selectionList = [];
  519. this.$refs.crud.toggleSelection();
  520. },
  521. currentChange(currentPage) {
  522. this.page.currentPage = currentPage;
  523. },
  524. sizeChange(pageSize) {
  525. this.page.pageSize = pageSize;
  526. },
  527. refreshChange() {
  528. this.onLoad(this.page, this.query);
  529. },
  530. onLoad(page, params = {}) {
  531. let obj = {};
  532. obj = {
  533. ...Object.assign(params, this.query)
  534. };
  535. this.loading = true;
  536. getList(page.currentPage, page.pageSize, obj)
  537. .then(res => {
  538. this.page.total = res.data.data.total;
  539. this.data = res.data.data.records;
  540. this.$nextTick(() => {
  541. this.$refs.crud.dicInit();
  542. });
  543. })
  544. .finally(() => {
  545. this.loading = false;
  546. });
  547. },
  548. //自定义列保存
  549. async saveColumn(ref, option, optionBack, code) {
  550. /**
  551. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  552. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  553. * 一定要执行异步操作,要等接口成功返回,才能执行下一行编码
  554. */
  555. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  556. if (inSave) {
  557. this.$message.success("保存成功");
  558. //关闭窗口
  559. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  560. }
  561. },
  562. //自定义列重置
  563. async resetColumn(ref, option, optionBack, code) {
  564. this[option] = this[optionBack];
  565. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  566. if (inSave) {
  567. this.$message.success("重置成功");
  568. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  569. }
  570. },
  571. // 更改表格颜色
  572. headerClassName(tab) {
  573. //颜色间隔
  574. let back = "";
  575. if (tab.columnIndex >= 0 && tab.column.level === 1) {
  576. if (tab.columnIndex % 2 === 0) {
  577. back = "back-one";
  578. } else if (tab.columnIndex % 2 === 1) {
  579. back = "back-two";
  580. }
  581. }
  582. return back;
  583. }
  584. }
  585. };
  586. </script>
  587. <style lang="scss" scoped>
  588. ::v-deep#out-table .back-one {
  589. background: #ecf5ff !important;
  590. }
  591. ::v-deep#out-table .back-two {
  592. background: #ecf5ff !important;
  593. }
  594. /deep/ .el-col-md-8 {
  595. width: 24.33333%;
  596. }
  597. </style>