entrustMine.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <!-- 万州港-达州计量委托界面 -->
  3. <div class="trainTransport">
  4. <div class="top">
  5. <el-input
  6. class="el-input"
  7. placeholder="请输入内容"
  8. v-model="input"
  9. clearable
  10. >
  11. </el-input>
  12. <el-date-picker
  13. v-model="startTime"
  14. type="datetime"
  15. placeholder="选择日期"
  16. >
  17. </el-date-picker>
  18. <span>至</span>
  19. <el-date-picker v-model="endTime" type="datetime" placeholder="选择日期">
  20. </el-date-picker>
  21. <el-button type="primary" class="btn" @click="onclick">
  22. <i class="el-icon-search"></i>查询
  23. </el-button>
  24. <!-- <el-button type="primary" @click="exportData()">
  25. <i class="el-icon-download"></i>导出(Excel)
  26. </el-button> -->
  27. <el-button type="primary" @click="exportExcel">
  28. <i class="el-icon-download"></i>导出(Excel)
  29. </el-button>
  30. <el-button type="primary" @click="refresh()">
  31. <i class="el-icon-refresh"></i>刷新
  32. </el-button>
  33. </div>
  34. <el-tabs v-model="activeName" @tab-click="handleClick">
  35. <el-tab-pane label="待计量" name="first">
  36. <dilTable
  37. v-bind.sync="option"
  38. @selection-change="selectionChange"
  39. >
  40. </dilTable>
  41. </el-tab-pane>
  42. <el-tab-pane label="已计量" name="second">
  43. <dilTable
  44. ref="weighted"
  45. v-bind.sync="option2"
  46. @selection-change="selectionChange2"
  47. >
  48. </dilTable>
  49. </el-tab-pane>
  50. </el-tabs>
  51. <div class="count" v-show="sum1>0 && activeName == 'second'" style="margin-right:50px;font-size:18px;">
  52. <div style="display:flex;flex-direction:row-reverse">标重总吨位:{{sum1}}</div>
  53. <div style="display:flex;flex-direction:row-reverse">净重总吨位:{{sum2}}</div>
  54. </div>
  55. </div>
  56. </template>
  57. <script>
  58. import { sjTime } from "@/utils/sharedJsFile";
  59. import bignumber,{BigNumber} from 'bignumber.js';
  60. import { XLSX$Utils } from 'xlsx';
  61. export default {
  62. data() {
  63. return {
  64. activeName: "first",
  65. time: [],
  66. input: "",
  67. option: {
  68. // 表格请求数据的地址
  69. requestUrl: "/api/v1/tms/getLoadResultToSendMC?apiId=491&resultType=3",
  70. // 控制显示多选列
  71. selectionType: "select",
  72. },
  73. option2: {
  74. // 表格请求数据的地址
  75. requestUrl: "/api/v1/tms/getWeightResult?apiId=491&resultType=3",
  76. // 控制显示多选列
  77. selectionType: "select",
  78. },
  79. selectionListMap: [],
  80. selectionListMap2: [],
  81. resultIdList: [],
  82. startTime: null,
  83. endTime: null,
  84. tableTitle: "国产矿计量表",
  85. sum1:0.0,
  86. sum2:0.0,
  87. };
  88. },
  89. methods: {
  90. handleClick(tag, event) {
  91. console.log(tag, event);
  92. },
  93. onclick() {
  94. let startTime = null;
  95. let endTime = null;
  96. if (this.startTime) {
  97. startTime = sjTime(this.startTime);
  98. }
  99. if (this.endTime) {
  100. endTime = sjTime(this.endTime);
  101. }
  102. if (startTime && endTime) {
  103. if (startTime < endTime) {
  104. //判断是否是承运商
  105. if (this.activeName == "first") {
  106. this.option.requestUrl =
  107. "/api/v1/tms/getLoadResultToSendMC?apiId=491&resultType=3" +
  108. "&con=" +
  109. this.input +
  110. "&startTime=" +
  111. startTime +
  112. "&endTime=" +
  113. endTime +
  114. "&i=" +
  115. new Date();
  116. } else {
  117. this.option2.requestUrl =
  118. "/api/v1/tms/getWeightResult?apiId=491&resultType=3" +
  119. "&con=" +
  120. this.input +
  121. "&startTime=" +
  122. startTime +
  123. "&endTime=" +
  124. endTime +
  125. "&i=" +
  126. new Date();
  127. }
  128. }
  129. } else {
  130. if (this.activeName == "first") {
  131. this.option.requestUrl =
  132. "/api/v1/tms/getLoadResultToSendMC?apiId=491&resultType=3" +
  133. "&con=" +
  134. this.input +
  135. "&i=" +
  136. new Date();
  137. } else {
  138. this.option2.requestUrl =
  139. "/api/v1/tms/getWeightResult?apiId=491&resultType=3" +
  140. "&con=" +
  141. this.input +
  142. "&i=" +
  143. new Date();
  144. }
  145. }
  146. },
  147. selectionChange(selection) {
  148. this.selectionListMap = [];
  149. console.log(selection);
  150. this.selectionListMap = selection;
  151. },
  152. selectionChange2(selection) {
  153. let that=this;
  154. this.selectionListMap2 = [];
  155. console.log(selection);
  156. this.selectionListMap2 = selection;
  157. let sum1 = 0;
  158. let sum2 = new BigNumber(0);
  159. selection.forEach(element => {
  160. sum1+=element.resultBillableTonnage;
  161. sum2=sum2.plus(element.resultNetWeight);
  162. });
  163. this.sum1=sum1;
  164. this.sum2=sum2.toNumber();
  165. },
  166. refresh(){
  167. this.$router.go(0);
  168. },
  169. exportExcel(){
  170. let excel=this.$refs.excelDom;
  171. console.log(XLSX);
  172. console.log(XLSX.version);
  173. if(this.selectionListMap2.length<=0){
  174. this.$message({
  175. message: "请先勾选数据!",
  176. type: "warning"
  177. });
  178. return;
  179. };
  180. //创建工作簿对象
  181. let wb = XLSX.utils.book_new();
  182. //数据
  183. let sheetData = [
  184. ['卸车明细表'],
  185. ['序号','发站','到站','发货日期','到货日期','卸货地点','品名','矿种','计费吨位','车号','计量吨位','计费吨位合计']
  186. ];
  187. let totalRealWeight=new bignumber(0);
  188. let totalWeight=0;
  189. this.selectionListMap2.forEach((selection)=>{
  190. totalRealWeight=totalRealWeight.plus(selection.resultNetWeight);
  191. totalWeight+=selection.resultBillableTonnage;
  192. let arr=[
  193. selection.ROW_ID,
  194. selection.sendStationName,
  195. selection.arrivalStationName,
  196. selection.sendDate,
  197. selection.arrivalDate,
  198. selection.resultForeignShipName,
  199. selection.supplierName+selection.materialName,
  200. null,
  201. selection.resultBillableTonnage,
  202. selection.resultWagonNo,
  203. ]
  204. sheetData.push(arr);
  205. });
  206. console.log("totalReal:",totalRealWeight.toNumber());
  207. console.log("total:",totalWeight);
  208. sheetData[2].push(totalRealWeight.toNumber());
  209. sheetData[2].push(totalWeight);
  210. console.log("sheetData",sheetData);
  211. //把数据转化成excel的页
  212. let sheet = XLSX.utils.aoa_to_sheet(sheetData);
  213. //合并单元格
  214. sheet['!merges'] = [
  215. {
  216. s: { c: 0, r: 0 },// 合并开始位置 c:列位置 r:表示行位置
  217. e: { c: 11, r: 0 } // 合并结束位置
  218. },
  219. {
  220. s: { c: 10, r: 2 },// 合并开始位置 c:列位置 r:表示行位置
  221. e: { c: 10, r: sheetData.length-1 } // 合并结束位置
  222. },
  223. {
  224. s: { c: 11, r: 2 },// 合并开始位置 c:列位置 r:表示行位置
  225. e: { c: 11, r: sheetData.length-1 } // 合并结束位置
  226. }
  227. ]
  228. //把这一页加入excel
  229. XLSX.utils.book_append_sheet(wb, sheet, "第一页");
  230. XLSX.writeFile(wb, '计量作业.xlsx');
  231. }
  232. },
  233. };
  234. </script>
  235. <style lang='scss'>
  236. .trainTransport {
  237. .top {
  238. padding: 1.25rem 0.375rem;
  239. .el-input {
  240. width: 20%;
  241. margin-right: 1.25rem;
  242. }
  243. }
  244. }
  245. </style>