tableItem.vue 21 KB

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