operateEcharts.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <div>
  3. <div class="eachartTop">
  4. <SearchHeader
  5. title="时间筛选: "
  6. :isShowQuert="true"
  7. :dates="mdate"
  8. @changeValue="changeValue"
  9. />
  10. </div>
  11. <statistic :col="4" class="statistic" :cols="12">
  12. <statistic-item>
  13. <span>
  14. 现金总收入: (元)
  15. </span>
  16. <span>
  17. <count-to :endVal="totalAmount" :duration="300" :decimals="2" class="blod" />
  18. </span>
  19. </statistic-item>
  20. <statistic-item>
  21. <span>
  22. 管乐迷现金收入: (元)
  23. </span>
  24. <span>
  25. <count-to :endVal="gymTotal" :duration="300" :decimals="2" :class="'des'" />
  26. </span>
  27. </statistic-item>
  28. <statistic-item>
  29. <span>
  30. 酷乐秀现金收入: (元)
  31. </span>
  32. <span>
  33. <count-to :endVal="colexiuTotal" :duration="300" :decimals="2" :class="'des'" />
  34. </span>
  35. </statistic-item>
  36. <statistic-item>
  37. <span>
  38. 管乐团现金收入: (元)
  39. </span>
  40. <span>
  41. <count-to :endVal="gytTotal" :duration="300" :decimals="2" :class="'des'" />
  42. </span>
  43. </statistic-item>
  44. </statistic>
  45. <div></div>
  46. <div class="operateEcharts">
  47. <div class="eachartTitle">
  48. <div>
  49. 管乐迷现金收入:
  50. <count-to :endVal="gymTotal" :duration="300" :decimals="2" class="des" /> 元
  51. </div>
  52. <el-select
  53. clearable
  54. filterable
  55. placeholder="请选择分部"
  56. v-model="organId"
  57. @change="
  58. () => {
  59. this.getData();
  60. }
  61. "
  62. >
  63. <el-option
  64. v-for="(item, index) in selects.branchs"
  65. :key="index"
  66. :label="item.name"
  67. :value="item.id"
  68. ></el-option>
  69. </el-select>
  70. </div>
  71. <div class="gym-echarts"></div>
  72. <div class="eachartTitle">
  73. <div>
  74. 酷乐秀现金收入:
  75. <count-to :endVal="colexiuTotal" :duration="300" :decimals="2" class="des" /> 元
  76. </div>
  77. </div>
  78. <div class="colexiu-echarts"></div>
  79. <div class="eachartTitle">
  80. <div>
  81. 管乐团现金收入:
  82. <count-to :endVal="gytTotal" :duration="300" :decimals="2" class="des" /> 元
  83. </div>
  84. </div>
  85. <div class="gyt-echarts"></div>
  86. </div>
  87. </div>
  88. </template>
  89. <script>
  90. import echarts from "echarts";
  91. import CountTo from "vue-count-to";
  92. import { multiDataSourceHomeStatsSummerIncome } from "../../api";
  93. import SearchHeader from "./searchDayHeader";
  94. import { getTimes } from "@/utils";
  95. export default {
  96. components: {
  97. CountTo,
  98. SearchHeader
  99. },
  100. data() {
  101. return {
  102. organId: "",
  103. mdate: [],
  104. gymECharts: null,
  105. gymData: [],
  106. gymTotal: 0,
  107. gytEcharts: null,
  108. gytData: [],
  109. gytTotal: 0,
  110. colexiuEcharts: null,
  111. colexiuData: [],
  112. colexiuTotal: 0
  113. };
  114. },
  115. mounted() {
  116. this.mdate = this.getInitDate();
  117. this.getData();
  118. window.addEventListener("resize", this.resize);
  119. },
  120. beforeDestroy() {
  121. window.removeEventListener("resize", this.resize);
  122. },
  123. methods: {
  124. getInitDate() {
  125. const end = this.$helpers.dayjs(new Date()).format("YYYY-MM-DD");
  126. const start = this.$helpers
  127. .dayjs(new Date())
  128. // .set("month", 1)
  129. .subtract(1, "month")
  130. .format("YYYY-MM-DD");
  131. return [start, end];
  132. },
  133. getData() {
  134. multiDataSourceHomeStatsSummerIncome({
  135. ...getTimes(this.mdate, ["startTime", "endTime"]),
  136. organIds: this.organId
  137. }).then(res => {
  138. if (Array.isArray(res.data)) {
  139. const gym = res.data.find(item => item.platform == "gym");
  140. if (gym) {
  141. this.gymTotal = gym.totalAmount;
  142. this.gymData = gym.incomeByDates;
  143. }
  144. const gyt = res.data.find(item => item.platform == "gyt");
  145. if (gyt) {
  146. this.gytTotal = gyt.totalAmount;
  147. this.gytData = gyt.incomeByDates;
  148. }
  149. const clx = res.data.find(item => item.platform == "cls");
  150. if (clx) {
  151. this.colexiuTotal = clx.totalAmount;
  152. this.colexiuData = clx.incomeByDates;
  153. }
  154. this.init();
  155. }
  156. });
  157. },
  158. changeValue(date) {
  159. // 请求更改数据
  160. this.mdate = date;
  161. this.getData();
  162. },
  163. resize() {
  164. this.gymECharts.resize();
  165. this.gytEcharts.resize();
  166. this.colexiuEcharts.resize();
  167. },
  168. init() {
  169. this.createGym();
  170. this.createGyt();
  171. this.createColexiu();
  172. },
  173. createGym() {
  174. if (this.gymECharts) {
  175. this.gymECharts.dispose();
  176. }
  177. this.gymECharts = echarts.init(document.querySelector(".gym-echarts"));
  178. const option = {
  179. title: {
  180. top: "0%",
  181. text: "",
  182. textStyle: {
  183. color: "#333",
  184. fontSize: 14
  185. }
  186. },
  187. tooltip: {
  188. trigger: "axis"
  189. },
  190. grid: {
  191. left: 5,
  192. top: 30,
  193. right: 5,
  194. bottom: 5,
  195. containLabel: true
  196. },
  197. xAxis: {
  198. type: "category",
  199. data: this.gymData.map(item => item.date),
  200. axisLabel: {
  201. color: "#333",
  202. fontSize: 10
  203. }
  204. },
  205. yAxis: {
  206. type: "value",
  207. axisLabel: { formatter: "{value}元" }
  208. },
  209. series: [
  210. {
  211. data: this.gymData.map(item => item.totalAmount),
  212. type: "bar",
  213. color: "#00a79d",
  214. barWidth: 40
  215. }
  216. ]
  217. };
  218. option && this.gymECharts.setOption(option);
  219. },
  220. createGyt() {
  221. if (this.gytEcharts) {
  222. this.gytEcharts.dispose();
  223. }
  224. this.gytEcharts = echarts.init(document.querySelector(".gyt-echarts"));
  225. const option = {
  226. grid: {
  227. left: 5,
  228. top: 30,
  229. right: 5,
  230. bottom: 5,
  231. containLabel: true
  232. },
  233. tooltip: {
  234. trigger: "axis"
  235. },
  236. xAxis: {
  237. type: "category",
  238. data: this.gytData.map(item => item.date),
  239. axisLabel: {
  240. color: "#333",
  241. fontSize: 10
  242. }
  243. },
  244. yAxis: {
  245. type: "value",
  246. axisLabel: { formatter: "{value}元" }
  247. },
  248. series: [
  249. {
  250. data: this.gytData.map(item => item.totalAmount),
  251. type: "bar",
  252. color: "#00a79d",
  253. barWidth: 40
  254. }
  255. ]
  256. };
  257. option && this.gytEcharts.setOption(option);
  258. },
  259. createColexiu() {
  260. if (this.colexiuEcharts) {
  261. this.colexiuEcharts.dispose();
  262. }
  263. this.colexiuEcharts = echarts.init(
  264. document.querySelector(".colexiu-echarts")
  265. );
  266. const option = {
  267. grid: {
  268. left: 5,
  269. top: 30,
  270. right: 5,
  271. bottom: 5,
  272. containLabel: true
  273. },
  274. tooltip: {
  275. trigger: "axis"
  276. },
  277. xAxis: {
  278. type: "category",
  279. data: this.colexiuData.map(item => item.date),
  280. axisLabel: {
  281. color: "#333",
  282. fontSize: 10
  283. }
  284. },
  285. yAxis: {
  286. type: "value",
  287. axisLabel: { formatter: "{value}元" }
  288. },
  289. series: [
  290. {
  291. data: this.colexiuData.map(item => item.totalAmount),
  292. type: "bar",
  293. color: "#00a79d",
  294. barWidth: 40
  295. }
  296. ]
  297. };
  298. option && this.colexiuEcharts.setOption(option);
  299. }
  300. },
  301. computed: {
  302. totalAmount() {
  303. return this.gymTotal + this.gytTotal + this.colexiuTotal;
  304. }
  305. }
  306. };
  307. </script>
  308. <style lang="less" scoped>
  309. .eachartTop {
  310. margin-bottom: 20px;
  311. // display: flex;
  312. // align-items: center;
  313. // justify-content: space-between;
  314. // flex-wrap: wrap;
  315. // ::v-deep .box {
  316. // margin-right: 5px;
  317. // }
  318. // ::v-deep .shape {
  319. // display: none;
  320. // }
  321. }
  322. .eachartTitle {
  323. display: flex;
  324. align-items: center;
  325. justify-content: space-between;
  326. }
  327. .operateEcharts {
  328. // display: flex;
  329. .gym-echarts,
  330. .gyt-echarts,
  331. .colexiu-echarts {
  332. width: 100%;
  333. height: 350px;
  334. margin-bottom: 24px;
  335. }
  336. }
  337. .statistic .statistic-content > span {
  338. &:first-child {
  339. font-size: 14px !important;
  340. }
  341. font-size: 18px !important;
  342. }
  343. .blod {
  344. font-weight: bold !important;
  345. color: var(--color-primary) !important;
  346. font-size: 22px !important;
  347. }
  348. .des {
  349. font-size: 18px !important;
  350. color: var(--color-primary);
  351. }
  352. </style>