report.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 id="question_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 { question } 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. },
  59. data() {
  60. return {
  61. data: {
  62. all: [],
  63. completed: [],
  64. name: [],
  65. },
  66. types,
  67. activeName: types[0].value,
  68. };
  69. },
  70. components: {},
  71. computed: {},
  72. watch: {
  73. orgId: {
  74. deep: true,
  75. handler(val) {
  76. this.resetTimer();
  77. this.getData();
  78. },
  79. },
  80. data: {
  81. deep: true,
  82. handler() {
  83. this.initMap();
  84. },
  85. },
  86. },
  87. created() {
  88. // this.types = types;
  89. this.maxDisplay = 16;
  90. this.refreshTime = 1 * 10 * 1000;
  91. this.isMouseOver = false;
  92. },
  93. async mounted() {
  94. window.addEventListener("resize", this.windowResize);
  95. },
  96. beforeDestroy() {
  97. this.timer && clearInterval(this.timer);
  98. this.timer = null;
  99. window.removeEventListener("resize", this.windowResize);
  100. },
  101. methods: {
  102. handleClick() {
  103. this.resetTimer();
  104. this.getData();
  105. },
  106. handleMouseEnter() {
  107. this.isMouseOver = true;
  108. },
  109. handleMouseLeave() {
  110. this.isMouseOver = false;
  111. },
  112. async getData() {
  113. // let bs = parseInt(this.activeName) + 1;
  114. // this.data = {
  115. // all: 500*bs,
  116. // unconfirm: 112*bs, //未确认
  117. // auditing: 20*bs, //异议审批中
  118. // unreform: 50*bs, //待整改
  119. // notQuestion: 4*bs,
  120. // reformed: (500 - 112 - 20 - 50 - 4)*bs,
  121. // };
  122. let r = (await question({ orgId: this.orgId, period: this.activeName }))
  123. .data;
  124. this.data = r;
  125. if (r.total == 0) {
  126. this.data.reformRate = 100;
  127. } else {
  128. this.data.reformRate = ((r.reformed / r.total) * 100).toFixed(0);
  129. }
  130. },
  131. windowResize() {
  132. this.myChart && this.myChart.resize();
  133. },
  134. initMap() {
  135. this.myChart && this.myChart.dispose();
  136. // 基于准备好的dom,初始化echarts实例
  137. this.myChart = echarts.init(document.getElementById("question_Chart"));
  138. let chartData = [
  139. {
  140. name: "待确认",
  141. value: this.data.unconfirm,
  142. },
  143. {
  144. name: "有异议",
  145. value: this.data.dissent,
  146. },
  147. {
  148. name: "已关闭",
  149. value: this.data.closed,
  150. },
  151. {
  152. name: "待整改",
  153. value: this.data.unreform,
  154. },
  155. {
  156. name: "已整改",
  157. value: this.data.reformed,
  158. },
  159. {
  160. name: "已逾期",
  161. value: this.data.overdue,
  162. },
  163. {
  164. value: this.sum(
  165. this.data.unconfirm,
  166. this.data.dissent,
  167. this.data.closed,
  168. this.data.unreform,
  169. this.data.reformed,
  170. this.data.overdue
  171. ),
  172. itemStyle: {
  173. color: "none",
  174. decal: {
  175. symbol: "none",
  176. },
  177. label: {
  178. show: false,
  179. },
  180. },
  181. },
  182. ];
  183. let t = this;
  184. // 指定图表的配置项和数据
  185. var option = {
  186. // title: {
  187. // left: "center",
  188. // },
  189. tooltip: {
  190. trigger: "item",
  191. show: false,
  192. // formatter: "{a} <br/>{b} : {c} ({d}%)",
  193. },
  194. title: {
  195. text: `总数: ${this.data.total}`,
  196. subtext: `整改率: ${Math.round(this.data.reformed * 100)}%`,
  197. left: "center",
  198. top: "50%",
  199. textStyle: {
  200. fontSize: 16,
  201. color: "#fff",
  202. fontWeight: 200,
  203. // fontFamily:'SYNormal, Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif',
  204. align: "center",
  205. },
  206. subtextStyle: {
  207. fontSize: 16,
  208. color: "#fff",
  209. fontWeight: 200,
  210. // fontFamily:'SYNormal, Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif',
  211. align: "center",
  212. },
  213. },
  214. legend: {
  215. show: false,
  216. selectedMode: false,
  217. // type: "scroll",
  218. // orient: "vertical",
  219. // right: 10,
  220. // top: 20,
  221. // bottom: 20,
  222. // data: chartData.map((d) => d.name),
  223. // formatter: function (name) {
  224. // let d = chartData.find((c) => c.name === name);
  225. // return (
  226. // d.name + ":" + (d.value ? (d.value * 100).toFixed(2) + "%" : "-")
  227. // );
  228. // },
  229. // textStyle: {
  230. // color: "white",
  231. // },
  232. },
  233. series: [
  234. {
  235. name: "问题整改",
  236. type: "pie",
  237. radius: ["70%", "110%"],
  238. center: ["50%", "75%"],
  239. startAngle: 180,
  240. data: chartData,
  241. label: {
  242. show: true,
  243. // position: "center",
  244. color: "#8e949c",
  245. fontSize: 12,
  246. formatter: function (param) {
  247. if (param.name) {
  248. return `${param.name}(${Math.round(param.value * 100)}%)`;
  249. } else {
  250. return "";
  251. }
  252. },
  253. },
  254. // emphasis: {
  255. // itemStyle: {
  256. // shadowBlur: 10,
  257. // shadowOffsetX: 0,
  258. // shadowColor: "rgba(0, 0, 0, 0.5)",
  259. // },
  260. // },
  261. },
  262. ],
  263. };
  264. if (option && typeof option === "object") {
  265. this.myChart.setOption(option);
  266. }
  267. },
  268. resetTimer() {
  269. this.timer && clearInterval(this.timer);
  270. this.timer = setInterval(() => {
  271. if (this.isMouseOver) {
  272. return;
  273. }
  274. this.activeName = getNextPeriod(this.types, this.activeName);
  275. this.getData();
  276. }, this.refreshTime);
  277. },
  278. sum(...values) {
  279. let t = 0;
  280. values.forEach((v) => {
  281. if (v) {
  282. t = t + parseFloat(v);
  283. }
  284. });
  285. return t;
  286. },
  287. },
  288. };
  289. </script>
  290. <style lang="less" scoped></style>