report.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 { drill } from "@/api/board/cockpit.js";
  24. import {
  25. findMaxIndex,
  26. getChartDOMSize,
  27. getNextPeriod,
  28. getPeriodText,
  29. } from "../../utils.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. },
  59. data() {
  60. return {
  61. data: {
  62. all: [],
  63. completed: [],
  64. name: [],
  65. },
  66. activeName: types[0].value,
  67. };
  68. },
  69. components: {},
  70. computed: {},
  71. watch: {
  72. orgId: {
  73. deep: true,
  74. handler(val) {
  75. this.resetTimer();
  76. this.getData();
  77. },
  78. },
  79. data: {
  80. deep: true,
  81. handler() {
  82. this.initMap();
  83. },
  84. },
  85. },
  86. created() {
  87. this.types = types;
  88. this.maxDisplay = 16;
  89. this.refreshTime = 1 * 10 * 1000;
  90. this.isMouseOver = false;
  91. },
  92. async mounted() {
  93. window.addEventListener("resize", this.windowResize);
  94. },
  95. beforeDestroy() {
  96. this.timer && clearInterval(this.timer);
  97. this.timer = null;
  98. window.removeEventListener("resize", this.windowResize);
  99. },
  100. methods: {
  101. handleClick() {
  102. this.resetTimer();
  103. this.getData();
  104. },
  105. handleMouseEnter() {
  106. this.isMouseOver = true;
  107. },
  108. handleMouseLeave() {
  109. this.isMouseOver = false;
  110. },
  111. async getData() {
  112. let r = (await drill({ orgId: this.orgId, period: this.activeName }))
  113. .data;
  114. let data = {
  115. all: [],
  116. completed: [],
  117. rate: [],
  118. name: [],
  119. };
  120. for (let item of r) {
  121. if (data.all.length >= 16) {
  122. break;
  123. }
  124. data.all.push(item.total);
  125. data.completed.push(item.completed);
  126. data.rate.push((item.completedRate * 100).toFixed(0));
  127. data.name.push(item.orgName);
  128. }
  129. this.data = data;
  130. // console.info(this.data);
  131. },
  132. windowResize() {
  133. this.myChart && this.myChart.resize();
  134. },
  135. initMap() {
  136. this.myChart && this.myChart.dispose();
  137. let c = this.$refs["chart"];
  138. // 基于准备好的dom,初始化echarts实例
  139. this.myChart = echarts.init(
  140. c
  141. // document.getElementById("commAlarmEvent_Chart")
  142. );
  143. let t = this;
  144. // 指定图表的配置项和数据
  145. var option = {
  146. // color: ["#82D5AE"],
  147. tooltip: {
  148. trigger: "axis",
  149. confine: true,
  150. axisPointer: {
  151. type: "shadow",
  152. },
  153. // formatter: "完成率:{c}%",
  154. },
  155. legend: {
  156. show: true,
  157. textStyle: {
  158. color: "rgb(245, 245, 245)",
  159. },
  160. },
  161. grid: {
  162. left: "3%",
  163. right: "4%",
  164. bottom: "2%",
  165. top: "20px",
  166. containLabel: true,
  167. },
  168. xAxis: [
  169. {
  170. type: "category",
  171. data: this.data.name,
  172. // data: this.mapdata.totalDataVo.xlist,
  173. axisTick: {
  174. alignWithLabel: true,
  175. },
  176. axisLine: {
  177. show: true,
  178. lineStyle: {
  179. type: "solid",
  180. color: "rgb(245, 245, 245)", //左边线的颜⾊
  181. },
  182. },
  183. axisLabel: {
  184. interval: 0,
  185. rotate: -45,
  186. fontSize: 12,
  187. color: "#fff",
  188. },
  189. },
  190. ],
  191. yAxis: [
  192. {
  193. type: "value",
  194. minInterval: 1,
  195. // max: function (value) {
  196. // let m = value.max == Math.ceil(value.max) ? Math.ceil(value.max * 1.0001) : Math.ceil(value.max);
  197. // return m
  198. // },
  199. },
  200. ],
  201. series: [
  202. // {
  203. // name: "总数",
  204. // type: "bar",
  205. // barWidth: "14",
  206. // // label: {
  207. // // show: true,
  208. // // position: 'top',
  209. // // },
  210. // data: this.data.all,
  211. // },
  212. {
  213. name: "应完成",
  214. type: "bar",
  215. barWidth: "14",
  216. // label: {
  217. // show: true,
  218. // position: 'top',
  219. // },
  220. data: this.data.all,
  221. // itemStyle: {
  222. // normal: {
  223. // label: {
  224. // formatter: function (param) {
  225. // if (t.data.all[param.dataIndex]) {
  226. // let rate = param.value / t.data.all[param.dataIndex];
  227. // return (Math.floor(rate * 1000) / 10).toFixed(1) + "%";
  228. // } else {
  229. // return "";
  230. // }
  231. // return param.value + "%";
  232. // },
  233. // show: false,
  234. // position: "top",
  235. // textStyle: {
  236. // fontWeight: "bolder",
  237. // fontSize: "10",
  238. // color: "rgb(245, 245, 245)",
  239. // },
  240. // },
  241. // },
  242. // },
  243. },
  244. {
  245. name: "已完成",
  246. type: "line",
  247. data: this.data.completed,
  248. },
  249. ],
  250. };
  251. if (option && typeof option === "object") {
  252. this.myChart.setOption(option);
  253. }
  254. },
  255. resetTimer() {
  256. this.timer && clearInterval(this.timer);
  257. this.timer = setInterval(() => {
  258. if (this.isMouseOver) {
  259. return;
  260. }
  261. this.activeName = getNextPeriod(this.types, this.activeName);
  262. this.getData();
  263. }, this.refreshTime);
  264. },
  265. },
  266. };
  267. </script>
  268. <style lang="less" scoped></style>