dowmShipDynamicTable.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <!-- 万州港作业报表 -->
  3. <div class="dowmShipDynamicTable">
  4. <div style="height:100%;width:100%">
  5. <div class="search" style="display:flex;margin: 10px;">
  6. <el-input
  7. placeholder="请输入"
  8. v-model="map.input"
  9. style="margin: 10px; width:10%"
  10. clearable
  11. ></el-input>
  12. <el-date-picker style="margin: 10px;" v-model="map.startTime" type="datetime" placeholder="起始日期"></el-date-picker>
  13. <el-date-picker style="margin: 10px;" v-model="map.endTime" type="datetime" placeholder="结束日期"></el-date-picker>
  14. <el-button
  15. type="primary"
  16. class="btn"
  17. @click="getTableData()"
  18. style="margin: 10px;"
  19. >
  20. <i class="el-icon-search"></i>查询
  21. </el-button>
  22. </div>
  23. <!-- 下游港口船舶动态表 -->
  24. <div class="loadData" style="height:500px;margin-left:5px">
  25. <!-- <div style="font-size:16px;color:red">港口装车数据:共{{count}}车</div> -->
  26. <div class="loadTable" style="height:500px;overflow:scroll;">
  27. <el-table
  28. ref="loadTable"
  29. highlight-current-row
  30. empty-text="请查询数据"
  31. border
  32. show-summary
  33. :summary-method="getSummaries"
  34. :span-method="objectSpanMethod"
  35. :data="tableData"
  36. :row-style="{height:'40px'}"
  37. style="width: 100%;font-size: 18px">
  38. <el-table-column
  39. align="center"
  40. prop="portName"
  41. label="放货港口"
  42. width="100px">
  43. </el-table-column>
  44. <el-table-column
  45. align="center"
  46. prop="productName"
  47. label="品种/数量/放货日期"
  48. width="380px">
  49. </el-table-column>
  50. <el-table-column
  51. align="center"
  52. prop="gmTonnage"
  53. label="港口库存"
  54. width="100px">
  55. </el-table-column>
  56. <el-table-column
  57. align="center"
  58. prop="capacityNumber"
  59. label="船名"
  60. width="100px">
  61. </el-table-column>
  62. <el-table-column
  63. align="center"
  64. prop="instructPlannedLoading"
  65. label="计划吨位"
  66. width="100px">
  67. </el-table-column>
  68. <el-table-column
  69. align="center"
  70. prop="shipDynamic"
  71. label="船舶动态"
  72. width="250px">
  73. <template slot-scope="scope">
  74. <el-input v-model="scope.row.shipDynamic"></el-input>
  75. </template>
  76. </el-table-column>
  77. <el-table-column
  78. align="center"
  79. label="装船(吨)"
  80. prop="loadDetails"
  81. width="250px">
  82. <template slot-scope="scope">
  83. <el-input v-model="scope.row.loadDetails"></el-input>
  84. </template>
  85. </el-table-column>
  86. <el-table-column fixed="right" label="操作" align="center" width="50">
  87. <template slot-scope="scope">
  88. <el-button @click="updateDynamic(scope.row)" type="text" size="small">保存</el-button>
  89. </template>
  90. </el-table-column>
  91. </el-table>
  92. </div >
  93. </div>
  94. </div>
  95. </div>
  96. </template>
  97. <script>
  98. import PageTitle from "@/components/Page/Title";
  99. import { sjTime } from "@/utils/sharedJsFile";
  100. import {getCookie} from "@/utils/util.js";
  101. import BigNumber from "bignumber.js";
  102. export default {
  103. components: { PageTitle },
  104. data() {
  105. return {
  106. tableData:[],
  107. mergeTable:[{
  108. rowIndex:1,
  109. columnIndex:1,
  110. rowspan:1,
  111. }],
  112. spanArr: [], // 用于存放需要合并的行的个数
  113. spanIndex: 0, // 记录spanArr数组的下标
  114. map:{
  115. input:"",
  116. startTime:null,
  117. endTime:null
  118. },
  119. };
  120. },
  121. mounted(){
  122. //this.getTableData();
  123. },
  124. methods: {
  125. //查询表格数据
  126. getTableData(){
  127. console.log("map",this.map);
  128. //时间校验
  129. if(this.map.startTime && this.map.endTime){
  130. if(this.map.startTime>=this.map.endTime){
  131. this.$message({
  132. message:"结束日期必须大于起始日期!",
  133. type:"warning",
  134. duration:2000
  135. });
  136. return;
  137. }
  138. this.map.startTime=sjTime(this.map.startTime);
  139. this.map.endTime=sjTime(this.map.endTime);
  140. }else if((this.map.startTime && !this.map.endTime) || (!this.map.startTime && this.map.endTime)){
  141. this.$message({
  142. message:"起止日期错误!",
  143. type:"warning",
  144. duration:2000
  145. });
  146. return;
  147. }
  148. //发送请求
  149. this.axios.post('/api/v1/tms/getDownShipDynamaics',this.map).then((res)=>{
  150. if(res.data.code == "200"){
  151. this.getSpanArr(res.data.data);//先得到合并数组
  152. return Promise.resolve(res);
  153. }else {
  154. this.$message({
  155. type: "error",
  156. message: res.data.data,
  157. });
  158. }
  159. }).then((res)=>{
  160. //再给表格赋值
  161. this.tableData=res.data.data;
  162. });
  163. },
  164. updateDynamic(row){
  165. console.log("row:",row);
  166. if(!row.instructionsCapacityId){
  167. this.$message.warning("无法保存,请先操作装船指令!");
  168. return;
  169. }
  170. this.axios.post('/api/v1/tms/updateInstructionsCapacity',row).then((res)=>{
  171. if(res.data.code == "200"){
  172. this.$message.success("保存成功!");
  173. this.getTableData();
  174. }else {
  175. this.$message({
  176. type: "error",
  177. message: res.data.data,
  178. });
  179. }
  180. });
  181. },
  182. getSummaries(param) {
  183. console.log("param",param);
  184. const { columns, data } = param;
  185. const sums = [];
  186. columns.forEach((column, index) => {
  187. if (index === 0) {
  188. sums[index] = '合计';
  189. return;
  190. }
  191. if (index === 3 || index===5) {
  192. sums[index] = '';
  193. return;
  194. }
  195. const values = data.map(item => Number(item[column.property]));
  196. if (!values.every(value => isNaN(value))) {
  197. sums[index] = values.reduce((prev, curr) => {
  198. const value = Number(curr);
  199. if (!isNaN(value)) {
  200. return new BigNumber(prev).plus(curr).toNumber();
  201. } else {
  202. return prev;
  203. }
  204. }, 0);
  205. } else {
  206. sums[index] = '';
  207. }
  208. });
  209. return sums;
  210. },
  211. //处理数据,得到合并数组
  212. getSpanArr(data) {
  213. this.spanArr=[];
  214. for (let i = 0; i < data.length; i++) {
  215. if (i == 0) {
  216. this.spanArr.push(1);
  217. this.spanIndex = 0;
  218. } else {
  219. // 判断当前行与前一行内容是否相同
  220. if (data[i].portName == data[i - 1].portName) {
  221. this.spanArr[this.spanIndex] += 1; // 相同的话,当前下标所代表的值加一,例如:第一列的前三行可合并
  222. this.spanArr.push(0);// 记录完毕后,再往数组里添加一个元素0,作为下一次合并的初始值
  223. } else {
  224. this.spanArr.push(1); // 否则,依旧是一行
  225. this.spanIndex = i;
  226. }
  227. }
  228. }
  229. console.log("spanArr",this.spanArr);
  230. },
  231. //合并
  232. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  233. if (columnIndex === 0) {
  234. const _row = this.spanArr[rowIndex]; // 行数
  235. const _col = _row > 0 ? 1 : 0; // 列数
  236. return {
  237. rowspan: _row,
  238. colspan: _col
  239. };
  240. }
  241. },
  242. },
  243. };
  244. </script>
  245. <style lang='scss'>
  246. </style>