index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <div class="airportInfo">
  3. <div class="variable">
  4. <StatisticsHeader
  5. :title="titleTop"
  6. :items="formItems"
  7. :data="formData"
  8. :eledata="eledata"
  9. with-setting
  10. :withSetting="false"
  11. :withExport="true"
  12. :set="set"
  13. :action="action"
  14. :asShow="asShow"
  15. @getFormData="getFormData"
  16. @export="tableToExcel"
  17. @upset="upset"
  18. />
  19. </div>
  20. <div class="echart">
  21. <Echarts
  22. :id="dataid"
  23. :option="tableData"
  24. v-if="picShow == true ? true : false"
  25. />
  26. <Tableformbrs
  27. :tableList="tableList"
  28. :action="action"
  29. v-if="!picShow"
  30. :set="set"
  31. :total-num="totalNum"
  32. />
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import Echarts from "../components/echart/index.vue";
  38. import Tableformbrs from "../components/echart/tableforms.vue";
  39. import StatisticsHeader from "../components/echart/statisticsHeader.vue";
  40. import { export_json_to_excel } from "@/utils/Export2Excel";
  41. import { Query } from "@/api/webApi";
  42. export default {
  43. name: "ChartsBar",
  44. data() {
  45. return {
  46. asShow: true,
  47. optiondata: [],
  48. picShow: true, //图片表格切换
  49. action: 4,
  50. dataid: "collection_ecahrt4",
  51. listqueryTemplateID: DATACONTENT_ID.modePullgoods,
  52. eledata: 4,
  53. set: "",
  54. isShow: Echarts,
  55. tableList: [],
  56. tableListcop: [],
  57. listname: "",
  58. listHeader: [],
  59. tableData: {
  60. time: [],
  61. data1: [],
  62. data2: [],
  63. kg: "",
  64. tyol: "",
  65. },
  66. formData: {
  67. airport: "",
  68. dateTime: "",
  69. },
  70. titleTop: "拉货统计",
  71. formItems: [
  72. {
  73. prop: "fttp",
  74. inputType: "select",
  75. placeholder: "国内国际",
  76. requiredWarning: "请先选择国内国际",
  77. clearable: true,
  78. options: [
  79. {
  80. value: "国内离港",
  81. label: "国内出港",
  82. },
  83. {
  84. value: "国际离港",
  85. label: "国际出港",
  86. },
  87. ],
  88. },
  89. {
  90. prop: "kht",
  91. inputType: "select",
  92. placeholder: "客货类型",
  93. requiredWarning: "请先选择客货类型",
  94. clearable: true,
  95. options: [
  96. {
  97. value: "客机",
  98. label: "客机",
  99. },
  100. {
  101. value: "货机",
  102. label: "货机",
  103. },
  104. {
  105. value: "其它",
  106. label: "其它",
  107. },
  108. {
  109. value: "全部",
  110. label: "全部",
  111. },
  112. ],
  113. },
  114. {
  115. prop: "td",
  116. inputType: "select",
  117. placeholder: "统计维度",
  118. requiredWarning: "请先选择统计时间维度",
  119. clearable: true,
  120. options: [
  121. {
  122. value: "月",
  123. label: "月",
  124. },
  125. {
  126. value: "年",
  127. label: "年",
  128. },
  129. ],
  130. },
  131. {
  132. prop: "set",
  133. inputType: "select",
  134. placeholder: "统计航班",
  135. requiredWarning: "",
  136. clearable: true,
  137. options: [
  138. {
  139. value: 1,
  140. label: "统计航班",
  141. },
  142. {
  143. value: 2,
  144. label: "统计重量",
  145. },
  146. ],
  147. },
  148. {
  149. prop: "dateTime",
  150. inputType: "datePicker",
  151. clearable: true,
  152. width: "240px",
  153. options: [],
  154. },
  155. ],
  156. totalNum: 0
  157. };
  158. },
  159. mounted() {
  160. // this.getQuery([]);
  161. },
  162. watch: {
  163. // 监听数据变化,重绘折线图
  164. option: {
  165. deep: true,
  166. handler(newVal) {},
  167. },
  168. },
  169. destroyed() {},
  170. methods: {
  171. getFormData(data) {
  172. this.tableData.time = [];
  173. this.tableData.data1 = [];
  174. this.tableData.data2 = [];
  175. this.set = data.set;
  176. let option = [
  177. {
  178. fttp: data.fttp,
  179. kht: data.kht,
  180. td: data.td,
  181. fd1: data.dateTime[0],
  182. fd2: data.dateTime[1],
  183. spe: data.spe,
  184. },
  185. ];
  186. this.optiondata = [
  187. {
  188. fttp: data.fttp,
  189. kht: data.kht,
  190. td: data.td,
  191. fd1: data.dateTime[0],
  192. fd2: data.dateTime[1],
  193. spe: data.spe,
  194. },
  195. ];
  196. this.getQuery(option, data.set);
  197. this.listname =
  198. "拉货统计" +
  199. data.fttp +
  200. data.kht +
  201. data.td +
  202. data.dateTime[0] +
  203. "--" +
  204. data.dateTime[1];
  205. this.listHeader = [
  206. "序号",
  207. "时间",
  208. "航班量(班)",
  209. "环比(%)",
  210. "重量(吨)",
  211. "环比(%)",
  212. ];
  213. },
  214. //获取表格数据
  215. async getQuery(data, dat) {
  216. try {
  217. const { code, returnData } = await Query({
  218. id: this.listqueryTemplateID,
  219. dataContent: data,
  220. });
  221. if (code == 0) {
  222. this.tableData.time = [];
  223. this.tableData.data1 = [];
  224. this.tableData.data2 = [];
  225. this.totalNum = returnData.listValues.length
  226. this.tableList = JSON.parse(JSON.stringify(returnData.listValues));
  227. this.tableListcop = JSON.parse(JSON.stringify(returnData.listValues));
  228. this.tableList.forEach((item, index) => {
  229. item.indexs = index + 1;
  230. });
  231. for (let i = 0; i < 10; i++) {
  232. if (!this.tableList[i]) {
  233. this.tableList.push({});
  234. }
  235. }
  236. this.tableListcop.forEach((item, index) => {
  237. item.indexs = index + 1;
  238. });
  239. if (this.picShow == true) {
  240. let objar = {
  241. indexs: "合计",
  242. pullFlightNum: returnData.listValues[0].totalPullFlightNum,
  243. pullWeight: returnData.listValues[0].totalPullWeight,
  244. };
  245. this.tableListcop.push(objar);
  246. } else {
  247. let objar = {
  248. indexs: "合计",
  249. totalWeight: returnData.listValues[0].hejiTotalWeight,
  250. pullWeight: returnData.listValues[0].hejiPullWeight,
  251. };
  252. this.tableListcop.push(objar);
  253. }
  254. returnData.listValues.forEach((element) => {
  255. this.tableData.time.push(element.dat);
  256. this.tableData.kg = "单位:吨";
  257. if (dat == 1) {
  258. this.tableData.data2.push(
  259. element.pullFlightNum ? element.pullFlightNum : 0
  260. );
  261. this.tableData.kg = "单位:班";
  262. } else if (dat == 2) {
  263. this.tableData.kg = "单位:吨";
  264. this.tableData.data2.push(
  265. element.pullWeight ? element.pullWeight : 0
  266. );
  267. }
  268. this.tableData.data1 = [];
  269. });
  270. this.tableData.data1.push(0);
  271. for (let index = 0; index < this.tableData.data2.length; index++) {
  272. if (index > 0) {
  273. const element =
  274. (this.tableData.data2[index] -
  275. this.tableData.data2[index - 1]) /
  276. this.tableData.data2[index - 1];
  277. this.tableData.data1.push(
  278. element.toFixed(2) ? element.toFixed(2) : 0
  279. );
  280. this.tableData.data1.forEach((element) => {
  281. element = Number(element);
  282. if (typeof element !== "number") {
  283. element = 0;
  284. }
  285. });
  286. }
  287. }
  288. }
  289. } catch (error) {
  290. this.page--;
  291. }
  292. },
  293. //导出
  294. tableToExcel() {
  295. import("../../../utils/Export2Excel").then((excel) => {
  296. // 设置导出表格的头部
  297. const tHeader = this.listHeader;
  298. // 将要导出的数据进行一个过滤
  299. /**
  300. * 源数据导入到excel的数据每一条重新拼成一个数组,数组里的每个元素就是filterVal里的每个字段
  301. */
  302. const data = this.tableListcop.map((item, index) => {
  303. if (this.picShow == true) {
  304. return [
  305. item.indexs,
  306. item.dat,
  307. item.pullFlightNum,
  308. item.flightChain,
  309. item.pullWeight,
  310. item.weightChain,
  311. ];
  312. } else {
  313. return [
  314. item.indexs,
  315. item.flightdate,
  316. item.flightNo,
  317. item.line,
  318. item.stand,
  319. item.totalWeight,
  320. item.pullWeight,
  321. ];
  322. }
  323. });
  324. data[data.length - 1].indexs = "总计";
  325. // 调用我们封装好的方法进行导出Excel
  326. excel.export_json_to_excel({
  327. // 导出的头部
  328. header: tHeader,
  329. // 导出的内容
  330. data,
  331. // 导出的文件名称
  332. filename: this.listname,
  333. // 导出的表格宽度是否自动
  334. autoWidth: true,
  335. // 导出文件的后缀类型
  336. bookType: "xlsx",
  337. });
  338. });
  339. },
  340. upset(data) {
  341. this.picShow = data;
  342. if (this.picShow == false) {
  343. this.tableData.time = [];
  344. this.tableData.data1 = [];
  345. this.tableData.data2 = [];
  346. this.listHeader = [
  347. "序号",
  348. "日期",
  349. "航班号",
  350. "航线",
  351. "机位",
  352. "货物总重 (KG)",
  353. "拉货 (KG)",
  354. ];
  355. this.listqueryTemplateID = DATACONTENT_ID.modePulltable;
  356. this.getQuery(this.optiondata, this.set);
  357. // console.log(this.tableListcop);
  358. } else if (this.picShow == true) {
  359. this.tableData.time = [];
  360. this.tableData.data1 = [];
  361. this.tableData.data2 = [];
  362. this.listHeader = [
  363. "序号",
  364. "时间",
  365. "航班量(班)",
  366. "环比(%)",
  367. "重量(吨)",
  368. "环比(%)",
  369. ];
  370. this.listqueryTemplateID = DATACONTENT_ID.modePullgoods;
  371. this.getQuery(this.optiondata, this.set);
  372. }
  373. },
  374. },
  375. components: {
  376. Echarts,
  377. StatisticsHeader,
  378. Tableformbrs,
  379. },
  380. };
  381. </script>
  382. <style lang="scss" scoped>
  383. .airportInfo {
  384. position: relative;
  385. .header {
  386. width: 103%;
  387. height: 36px;
  388. display: flex;
  389. align-items: center;
  390. justify-content: center;
  391. background: #f7f7f7;
  392. position: relative;
  393. left: -23px;
  394. > .nav {
  395. padding: 0 30px 0 30px;
  396. cursor: pointer;
  397. font-size: 16px;
  398. font-family: Microsoft YaHei;
  399. font-weight: 400;
  400. color: #101116;
  401. }
  402. > .navs {
  403. height: 100%;
  404. padding: 0 30px 0 30px;
  405. cursor: pointer;
  406. display: flex;
  407. align-items: center;
  408. font-size: 16px;
  409. font-family: Microsoft YaHei;
  410. font-weight: bold;
  411. color: #ac014d;
  412. border-bottom: 2px solid #ac014d;
  413. }
  414. }
  415. .variable {
  416. width: 100%;
  417. height: 52px;
  418. }
  419. .echart {
  420. width: 100%;
  421. height: 746px;
  422. position: absolute;
  423. background: #ffffff;
  424. box-shadow: 0px 3px 3px 0px rgba(0, 0, 0, 0.1);
  425. border-radius: 4px;
  426. }
  427. }
  428. </style>