report.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <!-- -->
  2. <template>
  3. <div class="chart-template chart-template-withperiod">
  4. <p>
  5. <span>安防设施建设达标率</span>
  6. </p>
  7. <div>
  8. <el-tabs v-model="activeName" @tab-click="handleClick">
  9. <el-tab-pane
  10. v-for="t in types"
  11. :key="t.value"
  12. :label="t.text"
  13. :name="t.value"
  14. ></el-tab-pane>
  15. </el-tabs>
  16. </div>
  17. <div ref="chart"></div>
  18. </div>
  19. </template>
  20. <script>
  21. import "./../../board.scss";
  22. import * as echarts from "echarts";
  23. import {
  24. findMaxIndex,
  25. getChartDOMSize,
  26. getNextPeriod,
  27. getPeriodText,
  28. } from "../../utils.js";
  29. import { orgGA38 } from "@/api/board/cockpit.js";
  30. const types = [
  31. {
  32. text: "今天",
  33. value: "1",
  34. },
  35. {
  36. text: "近7天",
  37. value: "2",
  38. },
  39. {
  40. text: "近30天",
  41. value: "3",
  42. },
  43. {
  44. text: "近90天",
  45. value: "4",
  46. },
  47. {
  48. text: "本年",
  49. value: "5",
  50. },
  51. ];
  52. export default {
  53. props: {
  54. orgId: {
  55. type: String,
  56. isRequired: true,
  57. },
  58. maxDiagram: {
  59. type: Number,
  60. isRequired: false,
  61. },
  62. orgName: {
  63. type: String,
  64. isRequired: false,
  65. },
  66. // title: {
  67. // type: String,
  68. // isRequired: true,
  69. // },
  70. },
  71. data() {
  72. return {
  73. data: {
  74. all: [],
  75. completed: [],
  76. name: [],
  77. },
  78. activeName: types[0].value,
  79. };
  80. },
  81. components: {},
  82. computed: {},
  83. watch: {
  84. orgId: {
  85. deep: true,
  86. handler(val) {
  87. this.resetTimer();
  88. this.getData();
  89. },
  90. },
  91. data: {
  92. deep: true,
  93. handler() {
  94. this.initMap();
  95. },
  96. },
  97. },
  98. created() {
  99. this.types = types;
  100. this.maxDisplay = 16;
  101. this.refreshTime = 1 * 10 * 1000;
  102. this.isMouseOver = false;
  103. },
  104. async mounted() {
  105. window.addEventListener("resize", this.windowResize);
  106. },
  107. beforeDestroy() {
  108. this.timer && clearInterval(this.timer);
  109. this.timer = null;
  110. window.removeEventListener("resize", this.windowResize);
  111. },
  112. methods: {
  113. handleClick() {
  114. this.resetTimer();
  115. this.getData();
  116. },
  117. handleMouseEnter() {
  118. this.isMouseOver = true;
  119. },
  120. handleMouseLeave() {
  121. this.isMouseOver = false;
  122. },
  123. async getData() {
  124. let r = (await orgGA38({ orgId: this.orgId, period: this.activeName }))
  125. .data;
  126. let data = {
  127. ga2021: [],
  128. ga2015: [],
  129. rate: [],
  130. name: [],
  131. };
  132. for (let p in r) {
  133. let item = r[p];
  134. if (this.maxDiagram && data.name.length >= this.maxDiagram) {
  135. break;
  136. }
  137. data.ga2021.push(item.ga382021);
  138. data.ga2015.push(item.ga382015);
  139. data.rate.push((item.reachRate * 100).toFixed(0));
  140. if (this.orgName && item.orgName.startsWith(this.orgName)) {
  141. data.name.push(item.orgName.substr(this.orgName.length));
  142. } else {
  143. data.name.push(item.orgName);
  144. }
  145. }
  146. this.data = data;
  147. // console.info(this.data);
  148. },
  149. windowResize() {
  150. this.myChart && this.myChart.resize();
  151. },
  152. initMap() {
  153. this.myChart && this.myChart.dispose();
  154. let c = this.$refs["chart"];
  155. // 基于准备好的dom,初始化echarts实例
  156. this.myChart = echarts.init(
  157. c
  158. // document.getElementById("commAlarmEvent_Chart")
  159. );
  160. let t = this;
  161. // 指定图表的配置项和数据
  162. var option = {
  163. // color: ["#82D5AE"],
  164. tooltip: {
  165. trigger: "axis",
  166. confine: true,
  167. axisPointer: {
  168. type: "shadow",
  169. },
  170. // formatter: "完成率:{c}%",
  171. },
  172. legend: {
  173. show: true,
  174. textStyle: {
  175. color: "rgb(245, 245, 245)",
  176. },
  177. },
  178. grid: {
  179. left: "3%",
  180. right: "4%",
  181. bottom: "2%",
  182. top: "20px",
  183. containLabel: true,
  184. },
  185. xAxis: [
  186. {
  187. type: "category",
  188. data: this.data.name,
  189. // data: this.mapdata.totalDataVo.xlist,
  190. axisTick: {
  191. alignWithLabel: true,
  192. },
  193. axisLine: {
  194. show: true,
  195. lineStyle: {
  196. type: "solid",
  197. color: "rgb(245, 245, 245)", //左边线的颜⾊
  198. },
  199. },
  200. axisLabel: {
  201. interval: 0,
  202. rotate: -45,
  203. fontSize: 12,
  204. color: "#fff",
  205. },
  206. },
  207. ],
  208. yAxis: [
  209. {
  210. type: "value",
  211. minInterval: 1,
  212. // max: function (value) {
  213. // let m = value.max == Math.ceil(value.max) ? Math.ceil(value.max * 1.0001) : Math.ceil(value.max);
  214. // return m
  215. // },
  216. },
  217. ],
  218. series: [
  219. {
  220. name: "GA38-2021",
  221. type: "bar",
  222. stack: "ga38",
  223. barWidth: "14",
  224. // label: {
  225. // show: true,
  226. // position: 'top',
  227. // },
  228. data: this.data.ga2021,
  229. // itemStyle: {
  230. // normal: {
  231. // label: {
  232. // formatter: function (param) {
  233. // // if (t.data.all[param.dataIndex]) {
  234. // // let rate = param.value / t.data.all[param.dataIndex];
  235. // // return (Math.floor(rate * 1000) / 10).toFixed(1) + "%";
  236. // // } else {
  237. // // return "";
  238. // // }
  239. // return parseFloat(param.value).toFixed(0) + "%";
  240. // },
  241. // show: true,
  242. // position: "top",
  243. // textStyle: {
  244. // fontWeight: "bolder",
  245. // fontSize: "10",
  246. // color: "rgb(245, 245, 245)",
  247. // },
  248. // },
  249. // },
  250. // },
  251. },
  252. {
  253. name: "GA38-2015",
  254. type: "bar",
  255. stack: "ga38",
  256. barWidth: "14",
  257. // label: {
  258. // show: true,
  259. // position: 'top',
  260. // },
  261. data: this.data.ga2015,
  262. },
  263. {
  264. name: "达标率",
  265. type: "bar",
  266. stack: "ga38",
  267. barWidth: "14",
  268. tooltip: {
  269. valueFormatter: (v) => `${v}%`,
  270. },
  271. // label: {
  272. // show: true,
  273. // formatter:'{c}%'
  274. // },
  275. data: this.data.rate,
  276. },
  277. ],
  278. };
  279. if (option && typeof option === "object") {
  280. this.myChart.setOption(option);
  281. }
  282. },
  283. resetTimer() {
  284. this.timer && clearInterval(this.timer);
  285. this.timer = setInterval(() => {
  286. if (this.isMouseOver) {
  287. return;
  288. }
  289. this.activeName = getNextPeriod(this.types, this.activeName);
  290. this.getData();
  291. }, this.refreshTime);
  292. },
  293. },
  294. };
  295. </script>
  296. <style lang="less" scoped></style>