now-year.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <div class="now-year-container">
  3. <div class="now-year-title">
  4. <img src="@/assets/images/qst.png" class="title-icon" />
  5. 实施服务(今年数据)
  6. </div>
  7. <div id="nowYearChart" class="chart"></div>
  8. </div>
  9. </template>
  10. <script>
  11. import { mapState } from "vuex"
  12. import * as echarts from "echarts"
  13. export default {
  14. name: "NowYearServices",
  15. props: {
  16. data: {
  17. type: Object,
  18. default: () => ({}),
  19. },
  20. },
  21. data() {
  22. return {
  23. chartInstance: null,
  24. chartData: {
  25. categories: [
  26. "签约户数",
  27. "合同份数",
  28. "服务小区",
  29. "服务企业",
  30. "履约城市",
  31. ],
  32. },
  33. }
  34. },
  35. computed: {
  36. ...mapState(["entCode", "communityId"]),
  37. },
  38. watch: {
  39. data: {
  40. handler(newVal, oldVal) {
  41. if (newVal) {
  42. this.initChart()
  43. }
  44. },
  45. deep: true,
  46. },
  47. },
  48. mounted() {
  49. this.init()
  50. window.addEventListener("resize", this.handleResize)
  51. },
  52. beforeDestroy() {
  53. if (this.chartInstance) {
  54. this.chartInstance.dispose()
  55. }
  56. window.removeEventListener("resize", this.handleResize)
  57. },
  58. methods: {
  59. // 初始化组件
  60. init() {
  61. this.initChart()
  62. },
  63. // 初始化图表
  64. initChart() {
  65. this.chartInstance = echarts.init(
  66. document.getElementById("nowYearChart")
  67. )
  68. const option = {
  69. tooltip: {
  70. trigger: "axis",
  71. axisPointer: {
  72. type: "shadow",
  73. },
  74. backgroundColor: "rgba(17, 28, 49, 0.9)",
  75. borderColor: "rgba(64, 158, 255, 0.2)",
  76. textStyle: {
  77. color: "#ffffff",
  78. },
  79. },
  80. legend: {
  81. data: ["进行中", "上月完成", "今年累计"],
  82. textStyle: {
  83. color: "#a0b3d6",
  84. },
  85. itemWidth: 16,
  86. itemHeight: 8,
  87. top: 10,
  88. },
  89. grid: {
  90. left: "3%",
  91. right: "4%",
  92. bottom: "3%",
  93. top: 50,
  94. containLabel: true,
  95. },
  96. xAxis: {
  97. type: "log",
  98. show: false, // 隐藏x轴
  99. axisLine: {
  100. show: false,
  101. },
  102. axisTick: {
  103. show: false,
  104. },
  105. axisLabel: {
  106. show: false,
  107. },
  108. splitLine: {
  109. show: false,
  110. },
  111. },
  112. yAxis: {
  113. type: "category",
  114. data: this.chartData.categories,
  115. show: true, // 隐藏y轴
  116. axisLine: {
  117. show: false,
  118. },
  119. axisTick: {
  120. show: false,
  121. },
  122. axisLabel: {
  123. show: true,
  124. color: "#a1a1a1",
  125. fontSize: 14,
  126. },
  127. },
  128. series: [
  129. {
  130. name: "进行中",
  131. type: "bar",
  132. stack: "total",
  133. // barMinHeight: 10,
  134. itemStyle: {
  135. color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
  136. { offset: 0, color: "#1620D4" },
  137. { offset: 0.8, color: "#3AB3E3" },
  138. ]),
  139. borderRadius: [20, 0, 0, 20],
  140. },
  141. label: {
  142. show: true,
  143. color: "#fff",
  144. },
  145. barGap: "0%",
  146. barCategoryGap: "20%",
  147. data: this.data.service_ing,
  148. },
  149. {
  150. name: "上月完成",
  151. type: "bar",
  152. stack: "total",
  153. // barMinHeight: 10,
  154. itemStyle: {
  155. color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
  156. { offset: 0, color: "#192FC9" },
  157. { offset: 0.8, color: "#6D44BC" },
  158. ]),
  159. borderRadius: [0, 0, 0, 0],
  160. },
  161. label: {
  162. show: true,
  163. color: "#fff",
  164. },
  165. barGap: "0%",
  166. data: this.data.service_last_month,
  167. },
  168. {
  169. name: "今年累计",
  170. type: "bar",
  171. stack: "total",
  172. // barMinHeight: 10,
  173. label: {
  174. show: true,
  175. color: "#fff",
  176. },
  177. itemStyle: {
  178. color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
  179. { offset: 0, color: "#F7897D" },
  180. { offset: 0.8, color: "#F66C89" },
  181. ]),
  182. borderRadius: [0, 20, 20, 0],
  183. },
  184. barGap: "0%",
  185. data: this.data.year_summary,
  186. },
  187. ],
  188. }
  189. this.chartInstance.setOption(option)
  190. this.chartInstance.resize()
  191. },
  192. // 处理窗口大小变化
  193. handleResize() {
  194. if (this.chartInstance) {
  195. this.chartInstance.resize()
  196. }
  197. },
  198. },
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. @import "@/assets/css/theme.scss";
  203. .now-year-container {
  204. background: var(--content-bg);
  205. border-radius: halfW(4);
  206. display: flex;
  207. flex-direction: column;
  208. }
  209. .now-year-title {
  210. font-size: halfW(16);
  211. border-radius: halfW(4);
  212. color: var(--title-primary);
  213. background: var(--title-bg);
  214. padding: halfH(4) halfW(10);
  215. display: flex;
  216. align-items: center;
  217. }
  218. .chart {
  219. width: 100%;
  220. height: 100%;
  221. }
  222. </style>