index.vue 10 KB

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