tableItem.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. <template>
  2. <div>
  3. <table v-show="false">
  4. <tr>
  5. <td colspan="18">达州钢铁每日船舶动态明细表</td>
  6. <td colspan="4">{{deadline}}</td>
  7. </tr>
  8. </table>
  9. <el-table
  10. :show-summary="isShowSum"
  11. :data="tableData"
  12. :height="height"
  13. style="width: 100%"
  14. :span-method="objectSpanMethod"
  15. :border="true"
  16. :header-cell-style="headerCellStyle"
  17. >
  18. <el-table-column
  19. v-if="isShowBox"
  20. type="selection"
  21. width="50"
  22. align="center"
  23. >
  24. </el-table-column>
  25. <template>
  26. <column-item
  27. v-for="item in col"
  28. :key="item.label"
  29. :col="item"
  30. ></column-item>
  31. </template>
  32. <template #empty>
  33. <div class="empty" style="height:12.5rem;">
  34. <span class="empty-desc">暂无数据</span>
  35. </div>
  36. </template>
  37. <div slot="append" style="width: 100%;">
  38. <!-- 下游港口库存 -->
  39. <div class="appendSlot" style="margin-top:20px">
  40. <span class="normalFirst"
  41. >下游港口库存<span style="color:blue">{{
  42. this.downStockMap.downStockTonnage
  43. }}</span
  44. ><span>吨:</span></span
  45. >
  46. <span
  47. v-for="item in downStockStringArr"
  48. :class="item.class"
  49. :key="item.value"
  50. >{{ item.value }}</span
  51. >
  52. </div>
  53. <el-divider></el-divider>
  54. <!-- 万港库存 -->
  55. <div class="appendSlot">
  56. <span class="normalFirst"
  57. >万港库存<span style="color:blue">{{
  58. this.stockMap.stockTonnage
  59. }}</span
  60. ><span>吨:</span></span
  61. >
  62. <span
  63. v-for="item in stockStringArr"
  64. :class="item.class"
  65. :key="item.value"
  66. >{{ item.value }}</span
  67. >
  68. </div>
  69. <el-divider></el-divider>
  70. <!-- 在途库存 -->
  71. <div class="appendSlot">
  72. <span class="normalFirst"
  73. >在途货物<span style="color:blue">{{
  74. this.runStockMap.runStockTonnage
  75. }}</span
  76. ><span>吨(含万港/待卸船舶):</span></span
  77. >
  78. <span
  79. v-for="item in runStockStringArr"
  80. :class="item.class"
  81. :key="item.value"
  82. >{{ item.value }}</span
  83. >
  84. </div>
  85. <el-divider></el-divider>
  86. <!-- 库存表 -->
  87. <table v-show="false">
  88. <tr>
  89. <td colspan="22">{{ downStockString }}</td>
  90. </tr>
  91. <tr>
  92. <td colspan="22">{{ stockString }}</td>
  93. </tr>
  94. <tr>
  95. <td colspan="22">{{ runStockString }}</td>
  96. </tr>
  97. <tr>
  98. <td colspan="22"></td>
  99. </tr>
  100. </table>
  101. <!-- 万州港装车数据 -->
  102. <div class="appendSlot">
  103. <el-table
  104. ref="loadTable"
  105. highlight-current-row
  106. border
  107. show-summary
  108. :data="loadTable"
  109. :span-method="objectSpanMethod1"
  110. :row-style="{ height: '40px' }"
  111. style="font-size: 18px"
  112. >
  113. <el-table-column label="万州港发货信息">
  114. <el-table-column
  115. align="center"
  116. prop="materialName"
  117. width="200px"
  118. label="物资名"
  119. >
  120. </el-table-column>
  121. <el-table-column
  122. align="center"
  123. prop="resultForeignShipName"
  124. width="200px"
  125. label="船号"
  126. >
  127. </el-table-column>
  128. <el-table-column
  129. align="center"
  130. prop="num"
  131. width="200px"
  132. label="装车量"
  133. >
  134. </el-table-column>
  135. <el-table-column
  136. align="center"
  137. prop="time"
  138. width="200px"
  139. label="时间"
  140. >
  141. </el-table-column>
  142. <el-table-column width="200px" label="备注"> </el-table-column>
  143. </el-table-column>
  144. </el-table>
  145. </div>
  146. <el-divider></el-divider>
  147. <!-- 等闸线 -->
  148. <div class="appendSlot">
  149. <el-table
  150. highlight-current-row
  151. border
  152. :data="controlLinesTable"
  153. :row-style="{ height: '40px' }"
  154. style="font-size: 12px"
  155. >
  156. <el-table-column label="控制线等闸船舶动态">
  157. <!-- 4 -->
  158. <el-table-column
  159. align="center"
  160. prop="lineDate4"
  161. width="100px"
  162. label="日期"
  163. >
  164. </el-table-column>
  165. <el-table-column
  166. align="center"
  167. prop="up4"
  168. width="80px"
  169. label="上行等闸数"
  170. >
  171. </el-table-column>
  172. <el-table-column
  173. align="center"
  174. prop="down4"
  175. width="80px"
  176. label="下行等闸数"
  177. >
  178. </el-table-column>
  179. <el-table-column
  180. align="center"
  181. prop="count4"
  182. width="80px"
  183. label="总计"
  184. >
  185. </el-table-column>
  186. <!-- 3 -->
  187. <el-table-column
  188. align="center"
  189. prop="lineDate3"
  190. width="100px"
  191. label="日期"
  192. >
  193. </el-table-column>
  194. <el-table-column
  195. align="center"
  196. prop="up3"
  197. width="80px"
  198. label="上行等闸数"
  199. >
  200. </el-table-column>
  201. <el-table-column
  202. align="center"
  203. prop="down3"
  204. width="80px"
  205. label="下行等闸数"
  206. >
  207. </el-table-column>
  208. <el-table-column
  209. align="center"
  210. prop="count3"
  211. width="80px"
  212. label="总计"
  213. >
  214. </el-table-column>
  215. <!-- 2 -->
  216. <el-table-column
  217. align="center"
  218. prop="lineDate2"
  219. width="100px"
  220. label="日期"
  221. >
  222. </el-table-column>
  223. <el-table-column
  224. align="center"
  225. prop="up2"
  226. width="80px"
  227. label="上行等闸数"
  228. >
  229. </el-table-column>
  230. <el-table-column
  231. align="center"
  232. prop="down2"
  233. width="80px"
  234. label="下行等闸数"
  235. >
  236. </el-table-column>
  237. <el-table-column
  238. align="center"
  239. prop="count2"
  240. width="80px"
  241. label="总计"
  242. >
  243. </el-table-column>
  244. <!-- 1 -->
  245. <el-table-column
  246. align="center"
  247. prop="lineDate1"
  248. width="100px"
  249. label="日期"
  250. >
  251. </el-table-column>
  252. <el-table-column
  253. align="center"
  254. prop="up1"
  255. width="80px"
  256. label="上行等闸数"
  257. >
  258. </el-table-column>
  259. <el-table-column
  260. align="center"
  261. prop="down1"
  262. width="80px"
  263. label="下行等闸数"
  264. >
  265. </el-table-column>
  266. <el-table-column
  267. align="center"
  268. prop="count1"
  269. width="80px"
  270. label="总计"
  271. >
  272. </el-table-column>
  273. </el-table-column>
  274. </el-table>
  275. </div>
  276. </div>
  277. </el-table>
  278. </div>
  279. </template>
  280. <script>
  281. import ColumnItem from './columnItem'
  282. export default {
  283. name: 'TableItem',
  284. components: {
  285. ColumnItem
  286. },
  287. props: {
  288. // 表格数据
  289. tableData: {
  290. type: Array,
  291. default: () => []
  292. },
  293. // 树型结构表头数据
  294. col: {
  295. type: Array,
  296. default: () => []
  297. },
  298. // 是否在表格下方显示合计
  299. isShowSum: {
  300. type: Boolean,
  301. default: false
  302. },
  303. // 判断单元格文字是居中还是左对齐显示,默认居中
  304. alignType: {
  305. type: String,
  306. default: 'center'
  307. },
  308. // 设置表格高度,固定表头
  309. height: {
  310. type: String,
  311. default: null // 默认不固定表头
  312. },
  313. // 判断是否显示多选框
  314. isShowBox: {
  315. type: Boolean,
  316. default: false // 默认不展示
  317. }
  318. },
  319. data() {
  320. return {
  321. stockString: null,
  322. downStockString: null,
  323. runStockString: null,
  324. stockStringArr: [],
  325. downStockStringArr: [],
  326. downStockMap: {},
  327. stockMap: {},
  328. runStockMap: {},
  329. runStockStringArr: [],
  330. spanArr: [],
  331. loadTable: [],
  332. controlLinesTable: [],
  333. deadline:null
  334. }
  335. },
  336. mounted() {
  337. this.getStockString()
  338. this.getDownStockString()
  339. this.getRunStockList()
  340. this.searchLoadData()
  341. this.getControlLines()
  342. this.initialDate()
  343. },
  344. methods: {
  345. initialDate(){
  346. let now=new Date();
  347. this.deadline=now.getFullYear()+'年'+(now.getMonth()+1)+'月'+now.getDate()+'日';
  348. if(now.getHours()>=8&&now.getHours()<18){
  349. this.deadline+='(数据截止于8:00)';
  350. }else{
  351. this.deadline+='(数据截止于18:00)';
  352. }
  353. console.log("deadline:",this.deadline);
  354. },
  355. getStockString() {
  356. let that = this
  357. this.axios
  358. .post(
  359. '/api/v1/wmsh/getLoadPortStockList?apiId=158&pageSize=1000&pageNum=1'
  360. )
  361. .then(res => {
  362. console.log(res)
  363. if (res.status == '200') {
  364. let resultActualInstallations = 0
  365. res.data.data.list.forEach(e => {
  366. resultActualInstallations =
  367. resultActualInstallations + e.gmTonnage
  368. })
  369. console.log(res.data.data, '万港')
  370. this.stockMap.stockTonnage = `${resultActualInstallations.toFixed(
  371. 2
  372. )}`
  373. let arr1 = []
  374. console.log(res.data.data.list, '万港')
  375. res.data.data.list.forEach(e => {
  376. let arr = []
  377. arr = res.data.data.list
  378. .map(e1 => {
  379. if (e.type == e1.type && !arr.includes(e)) {
  380. return e1
  381. }
  382. })
  383. .filter(e2 => {
  384. return typeof e2 !== 'undefined'
  385. })
  386. if (arr1.length == 0) {
  387. arr1.push(arr)
  388. } else {
  389. if (arr1[arr1.length - 1][0]['type'] != arr[0]['type']) {
  390. arr1.push(arr)
  391. }
  392. }
  393. })
  394. console.log(arr1, 'arr1')
  395. let index = 2.1
  396. arr1.forEach(e => {
  397. this.stockStringArr.push({
  398. class: 'type',
  399. value: `${index.toFixed(1)}${e[0]['type']}${
  400. e[0]['typeTotalTonnage']
  401. }吨:`
  402. })
  403. index = index + 0.1
  404. e.forEach(e1 => {
  405. this.stockStringArr.push({
  406. class: 'normal',
  407. value: `${e1['materialName']}/“${e1['resultForeignShipName']}”/${e1['gmTonnage']}吨;`
  408. })
  409. })
  410. })
  411. //处理打印字符串
  412. this.stockString='万港库存:'+this.stockMap.stockTonnage+"吨:";
  413. this.stockStringArr.forEach((item)=>{
  414. this.stockString+=item.value;
  415. });
  416. }
  417. })
  418. },
  419. getDownStockString() {
  420. let that = this
  421. this.axios.post('/api/v1/wmsh/getDownPortStockList').then(res => {
  422. console.log('下游港口吨位')
  423. console.log(res.data.data)
  424. if (res.status == '200') {
  425. console.log(res.data.data)
  426. let resultActualInstallations = 0
  427. res.data.data.forEach(e => {
  428. resultActualInstallations = resultActualInstallations + e.gmTonnage
  429. })
  430. this.downStockMap.downStockTonnage = `${resultActualInstallations.toFixed(
  431. 2
  432. )}`
  433. let arr1 = []
  434. res.data.data.forEach(e => {
  435. let arr = []
  436. arr = res.data.data
  437. .map(e1 => {
  438. if (e1.type == e.type && !arr.includes(e)) {
  439. return e1
  440. }
  441. })
  442. .filter(e2 => {
  443. return typeof e2 !== 'undefined'
  444. })
  445. if (arr1.length == 0) {
  446. arr1.push(arr)
  447. } else {
  448. if (arr1[arr1.length - 1][0]['type'] != arr[0]['type']) {
  449. arr1.push(arr)
  450. }
  451. }
  452. })
  453. console.log(arr1, 'arr1')
  454. let index = 1.1
  455. arr1.forEach(e => {
  456. this.downStockStringArr.push({
  457. class: 'type',
  458. value: `${index.toFixed(1)}${e[0]['type']}${
  459. e[0]['typeTotalTonnage']
  460. }吨:`
  461. })
  462. index = index + 0.1
  463. e.forEach(e1 => {
  464. this.downStockStringArr.push({
  465. class: 'normal',
  466. value: `${e1['portName']}/${e1['materialName']}/“${e1['resultForeignShipName']}”/${e1['gmTonnage']}吨;`
  467. })
  468. })
  469. })
  470. //处理打印字符串
  471. this.downStockString='下游港口库存:'+this.downStockMap.downStockTonnage+"吨:";
  472. this.downStockStringArr.forEach((item)=>{
  473. this.downStockString+=item.value;
  474. });
  475. }
  476. })
  477. },
  478. getRunStockList() {
  479. let that = this
  480. this.axios.post('/api/v1/wmsh/getRunStockList').then(res => {
  481. console.log(res)
  482. if (res.status == '200') {
  483. let resultActualInstallations = 0
  484. res.data.data.forEach(e => {
  485. resultActualInstallations = resultActualInstallations + e.gmTonnage
  486. })
  487. this.runStockMap.runStockTonnage = `${resultActualInstallations.toFixed(
  488. 2
  489. )}`
  490. let arr1 = []
  491. res.data.data.forEach(e => {
  492. let arr = []
  493. arr = res.data.data
  494. .map(e1 => {
  495. if (e1.type == e.type && !arr.includes(e)) {
  496. return e1
  497. }
  498. })
  499. .filter(e2 => {
  500. return typeof e2 !== 'undefined'
  501. })
  502. if (arr1.length == 0) {
  503. arr1.push(arr)
  504. } else {
  505. if (arr1[arr1.length - 1][0]['type'] != arr[0]['type']) {
  506. arr1.push(arr)
  507. }
  508. }
  509. })
  510. console.log(arr1, 'arr1')
  511. let index = 1.1
  512. arr1.forEach(e => {
  513. this.runStockStringArr.push({
  514. class: 'type',
  515. value: `${index.toFixed(1)}${e[0]['type']}${
  516. e[0]['typeTotalTonnage']
  517. }吨:`
  518. })
  519. index = index + 0.1
  520. //按物资分
  521. let temp = [];
  522. e.forEach(e1 => {
  523. this.runStockStringArr.push({
  524. class: 'normal',
  525. value: `${e1['materialName']}:/“${e1['resultForeignShipName']}”/${e1['gmTonnage']}吨;`
  526. })
  527. })
  528. })
  529. //处理打印字符串
  530. this.runStockString='在途货物:'+this.runStockMap.runStockTonnage+"吨:";
  531. this.runStockStringArr.forEach((item)=>{
  532. this.runStockString+=item.value;
  533. });
  534. }
  535. })
  536. },
  537. headerCellStyle({ row, column, rowIndex, columnIndex }) {
  538. let columnIndexList1 = [5]
  539. let columnIndexList2 = [6]
  540. let columnIndexList3 = [7]
  541. let columnIndexList4 = [8]
  542. if (columnIndexList1.includes(columnIndex) && rowIndex == 0) {
  543. //如果有多个css样式,使用;隔开
  544. return 'color:#fff;cursor: pointer;background-color:red !important'
  545. }
  546. if (columnIndexList2.includes(columnIndex) && rowIndex == 0) {
  547. //如果有多个css样式,使用;隔开
  548. return 'color:#fff;cursor: pointer;background-color:green !important'
  549. }
  550. if (columnIndexList3.includes(columnIndex) && rowIndex == 0) {
  551. //如果有多个css样式,使用;隔开
  552. return 'color:#fff;cursor: pointer;background-color:blue !important'
  553. }
  554. if (columnIndexList4.includes(columnIndex) && rowIndex == 0) {
  555. //如果有多个css样式,使用;隔开
  556. return 'color:#000;cursor: pointer;background-color:yellow !important '
  557. }
  558. },
  559. flitterData(arr) {
  560. var spanOneArr = []
  561. let concatOne = 0
  562. arr.forEach((item, index) => {
  563. if (index === 0) {
  564. spanOneArr.push(1)
  565. } else {
  566. // name 修改
  567. if (item.batchInfacoryId === arr[index - 1].batchInfacoryId) {
  568. // 第一列需合并相同内容的判断条件
  569. spanOneArr[concatOne] += 1
  570. spanOneArr.push(0)
  571. } else {
  572. spanOneArr.push(1)
  573. concatOne = index
  574. }
  575. }
  576. })
  577. return {
  578. one: spanOneArr
  579. }
  580. },
  581. flitterData1(arr) {
  582. var spanOneArr = []
  583. let concatOne = 0
  584. arr.forEach((item, index) => {
  585. if (index === 0) {
  586. spanOneArr.push(1)
  587. } else {
  588. // name 修改
  589. if (item.materialType === arr[index - 1].materialType) {
  590. // 第一列需合并相同内容的判断条件
  591. spanOneArr[concatOne] += 1
  592. spanOneArr.push(0)
  593. } else {
  594. spanOneArr.push(1)
  595. concatOne = index
  596. }
  597. }
  598. })
  599. return {
  600. one: spanOneArr
  601. }
  602. },
  603. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  604. if (columnIndex === 0) {
  605. const _row = this.flitterData1(this.tableData).one[rowIndex]
  606. const _col = _row > 0 ? 1 : 0
  607. return {
  608. rowspan: _row,
  609. colspan: _col
  610. }
  611. }
  612. if (columnIndex === 1) {
  613. // this.tableData 修改
  614. const _row = this.flitterData(this.tableData).one[rowIndex]
  615. const _col = _row > 0 ? 1 : 0
  616. return {
  617. rowspan: _row,
  618. colspan: _col
  619. }
  620. }
  621. if (columnIndex === 4) {
  622. // this.tableData 修改
  623. const _row = this.flitterData(this.tableData).one[rowIndex]
  624. const _col = _row > 0 ? 1 : 0
  625. return {
  626. rowspan: _row,
  627. colspan: _col
  628. }
  629. }
  630. if (columnIndex === 2) {
  631. // this.tableData 修改
  632. const _row = this.flitterData(this.tableData).one[rowIndex]
  633. const _col = _row > 0 ? 1 : 0
  634. return {
  635. rowspan: _row,
  636. colspan: _col
  637. }
  638. }
  639. if (columnIndex === 3) {
  640. // this.tableData 修改
  641. const _row = this.flitterData(this.tableData).one[rowIndex]
  642. const _col = _row > 0 ? 1 : 0
  643. return {
  644. rowspan: _row,
  645. colspan: _col
  646. }
  647. }
  648. if (row.type === 1) {
  649. return {
  650. rowspan: 1,
  651. colspan: 17
  652. }
  653. }
  654. },
  655. //查询装车数据
  656. searchLoadData() {
  657. let map = {}
  658. this.axios.post('/api/v1/tms/getLoadData', map).then(res => {
  659. if (res.data.code == '200') {
  660. this.getSpanArr(res.data.data)
  661. this.loadTable = res.data.data
  662. this.count = 0
  663. this.loadTable.forEach(item => {
  664. this.count += item.num
  665. })
  666. } else {
  667. this.$message({
  668. type: 'error',
  669. message: res.data.data
  670. })
  671. }
  672. })
  673. },
  674. //处理数据,得到合并数组
  675. getSpanArr(data) {
  676. this.spanArr = []
  677. for (let i = 0; i < data.length; i++) {
  678. if (i == 0) {
  679. this.spanArr.push(1)
  680. this.spanIndex = 0
  681. } else {
  682. // 判断当前行与前一行内容是否相同
  683. if (data[i].materialName == data[i - 1].materialName) {
  684. this.spanArr[this.spanIndex] += 1 // 相同的话,当前下标所代表的值加一,例如:第一列的前三行可合并
  685. this.spanArr.push(0) // 记录完毕后,再往数组里添加一个元素0,作为下一次合并的初始值
  686. } else {
  687. this.spanArr.push(1) // 否则,依旧是一行
  688. this.spanIndex = i
  689. }
  690. }
  691. }
  692. },
  693. objectSpanMethod1({ row, column, rowIndex, columnIndex }) {
  694. if (columnIndex === 0) {
  695. const _row = this.spanArr[rowIndex] // 行数
  696. const _col = _row > 0 ? 1 : 0 // 列数
  697. return {
  698. rowspan: _row,
  699. colspan: _col
  700. }
  701. } else if (rowIndex === 0 && columnIndex === 3) {
  702. return {
  703. rowspan: this.loadTable.length,
  704. colspan: 1
  705. }
  706. }
  707. },
  708. //查询控制线数据
  709. getControlLines() {
  710. let map = {
  711. year: new Date().getFullYear(),
  712. month: new Date().getMonth() + 1
  713. }
  714. this.axios.post('/api/v1/tms/getControlLinesTable', map).then(res => {
  715. if (res.data.code == '200') {
  716. this.controlLinesTable = res.data.data
  717. } else {
  718. this.$message({
  719. type: 'error',
  720. message: res.data.data
  721. })
  722. }
  723. })
  724. }
  725. }
  726. }
  727. </script>
  728. <style>
  729. /* 处理表格表头和内容错位问题 */
  730. .el-table th.gutter {
  731. display: table-cell !important;
  732. }
  733. .el-table th,
  734. .el-table td {
  735. padding: 0.4375rem 0 !important;
  736. }
  737. </style>
  738. <style lang="scss" scoped>
  739. .el-table {
  740. .appendSlot {
  741. margin-left: 1%;
  742. font-size: 18px;
  743. line-height: 20px;
  744. // .normalFirst {
  745. // margin-left: 42px;
  746. // }
  747. .normal {
  748. margin-left: 20px;
  749. font-weight: 500;
  750. }
  751. .type {
  752. margin-left: 20px;
  753. color: red;
  754. font-weight: 600;
  755. margin-right: 10px;
  756. }
  757. // display: flex;
  758. // // align-items: center;
  759. // // justify-content: center;
  760. .black {
  761. font-weight: 700;
  762. }
  763. }
  764. }
  765. </style>