leftMenoyView.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /*
  2. * @Author: dayan_hjm 库存金额
  3. * @Date: 2023-10-23 09:32:12
  4. * @Last Modified by: dayan_hjm
  5. * @Last Modified time: 2023-11-28 10:43:30
  6. */
  7. import React, { useState, useEffect, Component } from "react";
  8. import styles from "../style.less";
  9. import { useHistory, useLocation, withRouter } from "react-router-dom";
  10. import mod from '../mod';
  11. import { getArrMax } from "@utils/util";
  12. import { getThousandNum } from "@utils/util";
  13. import {
  14. momeyService,
  15. } from "../api";
  16. @withRouter
  17. class LeftMenoyView extends Component {
  18. // 构造函数,组件的实例创建时,最先执行
  19. constructor(props, context) {
  20. super(props, context);
  21. this.store = mod;
  22. this.state = {
  23. max1:[],
  24. year:["碳酸锂","氧化纳",'金属锂',"氢氧化锂"],
  25. missionsIntensity_arr:[
  26. {value:0,name:"碳酸锂"},
  27. {value:0,name:"氧化纳"},
  28. {value:0,name:'金属锂'},
  29. {value:0,name:"氢氧化锂"},
  30. ],
  31. };
  32. }
  33. componentDidMount() {
  34. this.getUrl()
  35. }
  36. async getUrl() {
  37. let data_style= [{
  38. value: 25, name: '', itemStyle: {
  39. normal: {
  40. // barBorderRadius: 15,
  41. // borderColor: "rgba(141, 147, 255, 1)",
  42. // borderWidth: 1,
  43. color: {
  44. // 完成的圆环的颜色
  45. colorStops: [
  46. {
  47. offset: 0,
  48. color: 'rgba(141, 147, 255, 0.3)', // 0% 处的颜色
  49. },
  50. {
  51. offset: 1,
  52. color: 'rgba(141, 147, 255, 1)', // 100% 处的颜色
  53. },
  54. ],
  55. },
  56. },
  57. },
  58. }, {
  59. value: 33, name: '', itemStyle: {
  60. normal: {
  61. // barBorderRadius: 15,
  62. // borderColor: "rgba(105, 255, 222, 1)",
  63. // borderWidth: 1,
  64. color: {
  65. // 完成的圆环的颜色
  66. colorStops: [
  67. {
  68. offset: 0,
  69. color: 'rgba(105, 255, 222, 0.3)', // 0% 处的颜色
  70. },
  71. {
  72. offset: 1,
  73. color: 'rgba(105, 255, 222, 1)', // 100% 处的颜色
  74. },
  75. ],
  76. },
  77. },
  78. },
  79. }, {
  80. value: 35, name: '', itemStyle: {
  81. normal: {
  82. // barBorderRadius: 15,
  83. // borderColor: "rgba(47, 210, 255, 1)",
  84. // borderWidth: 1,
  85. color: {
  86. // 完成的圆环的颜色
  87. colorStops: [
  88. {
  89. offset: 0,
  90. color: 'rgba(47, 210, 255, 0.3)', // 0% 处的颜色
  91. },
  92. {
  93. offset: 1,
  94. color: 'rgba(47, 210, 255, 1)', // 100% 处的颜色
  95. },
  96. ],
  97. },
  98. },
  99. },
  100. }, {
  101. value: 40, name: '', itemStyle: {
  102. normal: {
  103. // barBorderRadius: 15,
  104. // borderColor: "rgba(255, 206, 0, 1)",
  105. // borderWidth: 1,
  106. color: {
  107. // 完成的圆环的颜色
  108. colorStops: [
  109. {
  110. offset: 0,
  111. color: 'rgba(255, 206, 0, 0.3)', // 0% 处的颜色
  112. },
  113. {
  114. offset: 1,
  115. color: 'rgba(255, 206, 0, 1)', // 100% 处的颜色
  116. },
  117. ],
  118. },
  119. },
  120. },
  121. }]
  122. await momeyService().then(({ data = [], resultCode }) => {
  123. if (+resultCode === 0) {
  124. let year = [], missionsIntensity_arr = [],max1=[],num=[];
  125. data.map((x, i) => {
  126. num.push(x.indexValue)
  127. year.unshift(x.prodCatgory);
  128. data_style[i].value = x.indexValue;
  129. data_style[i].name = x.prodCatgory;
  130. missionsIntensity_arr.push(data_style[i])
  131. });
  132. const max_1 = getArrMax(num);
  133. for (let index = 0; index < data.length; index++) {
  134. max1.unshift(max_1/0.7)
  135. }
  136. console.log("year, missionsIntensity_arr,max1",year, missionsIntensity_arr,max1)
  137. this.setState({ year, missionsIntensity_arr,max1 });
  138. this.setData();
  139. this.setData2();
  140. }
  141. });
  142. }
  143. setData() {
  144. setTimeout(() => {
  145. // 基于准备好的dom,初始化echarts实例
  146. var myChart = echarts.init(document.getElementById('echarts4'));
  147. var option = {
  148. grid: {
  149. left: '0%',
  150. top: '4%',
  151. right: '5%',
  152. bottom: '0%',
  153. containLabel: true
  154. },
  155. xAxis: [{
  156. show: false,
  157. }],
  158. yAxis: [{
  159. axisTick: 'none',
  160. axisLine: 'none',
  161. offset: '7',
  162. axisLabel: {
  163. textStyle: {
  164. color: 'rgba(255,255,255,.9)',
  165. fontSize: '0',
  166. }
  167. },
  168. data: this.state.year
  169. },
  170. {
  171. name: '单位:件',
  172. nameGap: '50',
  173. nameTextStyle: {
  174. color: 'rgba(255,255,255,.6)',
  175. fontSize: '16',
  176. },
  177. axisLine: {
  178. lineStyle: {
  179. color: 'rgba(0,0,0,0)'
  180. }
  181. },
  182. data: [],
  183. }],
  184. series: [{
  185. name: '条',
  186. type: 'bar',
  187. yAxisIndex: 0,
  188. data: this.state.missionsIntensity_arr,
  189. label: {
  190. normal: {
  191. show: true,
  192. position: 'right',
  193. formatter: function (param) {
  194. return getThousandNum(param.value) + '万元';
  195. // return param.name+":"+param.value + '万元';
  196. },
  197. textStyle: {
  198. color: 'rgba(255,255,255,1)',
  199. fontSize: '10',
  200. }
  201. }
  202. },
  203. barWidth: 15,
  204. itemStyle: {
  205. normal: {
  206. color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [
  207. { offset: 0, color: 'rgba(255, 206, 0, 1)' },
  208. { offset: 0.7, color: '#ffd01d94' },
  209. { offset: 1, color: '#ffd01d94' },
  210. ]),
  211. barBorderRadius: 15,
  212. // borderColor: "rgba(255, 206, 0, 1)",
  213. // borderWidth: 1
  214. }
  215. },
  216. labelLine: {
  217. length: 10,
  218. length2: 50,
  219. },
  220. labelLayout: {
  221. x: "20%",
  222. y: "20%",
  223. verticalAlign: "bottom",
  224. dy: -10,
  225. },
  226. z: 2
  227. }, {
  228. name: '白框',
  229. type: 'bar',
  230. yAxisIndex: 1,
  231. barGap: '-100%',
  232. data: this.state.max1,
  233. barWidth: 15,
  234. itemStyle: {
  235. normal: {
  236. color: '#ffffff24',
  237. barBorderRadius: 15,
  238. }
  239. },
  240. z: 1
  241. }]
  242. };
  243. // 使用刚指定的配置项和数据显示图表。
  244. myChart.setOption(option);
  245. window.addEventListener("resize", function () {
  246. myChart.resize();
  247. });
  248. }, 3000)
  249. }
  250. setData2() {
  251. setTimeout(() => {
  252. // 基于准备好的dom,初始化echarts实例
  253. var myChart = echarts.init(document.getElementById('echarts6'));
  254. let index = 0;
  255. function fun() {
  256. var timer = setInterval(function () {
  257. myChart.dispatchAction({
  258. type: 'hideTip',
  259. seriesIndex: 0,
  260. dataIndex: index,
  261. });
  262. // 显示提示框
  263. myChart.dispatchAction({
  264. type: 'showTip',
  265. seriesIndex: 0,
  266. dataIndex: index,
  267. });
  268. // 取消高亮指定的数据图形
  269. myChart.dispatchAction({
  270. type: 'downplay',
  271. seriesIndex: 0,
  272. dataIndex: index == 0 ? 3 : index - 1,
  273. });
  274. myChart.dispatchAction({
  275. type: 'highlight',
  276. seriesIndex: 0,
  277. dataIndex: index,
  278. });
  279. index++;
  280. if (index >= 4) {
  281. index = 0;
  282. }
  283. }, 3000);
  284. }
  285. fun();
  286. setTimeout(function () {
  287. fun();
  288. }, 5000);
  289. var option = {
  290. // //标题
  291. // title: {
  292. // text: '16%',
  293. // subtext: '氢氧化锂',
  294. // x: 'center',
  295. // y: '40%',
  296. // textStyle: {
  297. // color: '#fff',
  298. // fontSize: 20,
  299. // lineHeight: 10,
  300. // },
  301. // subtextStyle: {
  302. // color: 'rgba(205, 241, 255, 1)',
  303. // fontSize: 14,
  304. // lineHeight: 10,
  305. // marginTop: 15,
  306. // },
  307. // },
  308. //图例组件
  309. tooltip: {
  310. trigger: 'item',
  311. position: ['50%', '50%'],
  312. formatter: function (params, ticket, callback) {
  313. // $.get('detail?name=' + params.name, function (content) {
  314. // callback(ticket, toHTML(content));
  315. // });
  316. return `<div class="testDiv"><p class="p1">
  317. ${params.percent ? params.percent.toFixed() : 0}<spanp class="p3">%</span>
  318. </p>
  319. <p class="p2">${params.name}</p>
  320. </div>`;
  321. },
  322. backgroundColor: 'rgba(0,0,0,0)',
  323. textStyle: {
  324. color: '#fff',
  325. fontSize: 20,
  326. lineHeight: 10,
  327. },
  328. },
  329. series: [
  330. {
  331. type: 'pie',
  332. radius: ['50%', '65%'],
  333. center: ['50%', '50%'],
  334. roseType: 'area',
  335. //标题与数字一行显示
  336. label: {
  337. show: false,
  338. },
  339. //标题与数字分二行显示
  340. // label: {
  341. // alignTo: 'edge',
  342. // formatter: '{name|{b}}\n{time|{d}%}',
  343. // minMargin: 5,
  344. // edgeDistance: 10,
  345. // lineHeight: 30,
  346. // rich: {
  347. // time: {
  348. // fontSize: 10,
  349. // color: 'auto'
  350. // }
  351. // }
  352. // },
  353. labelLine: {
  354. show: false
  355. },
  356. data: this.state.missionsIntensity_arr,
  357. },
  358. ],
  359. };
  360. // 使用刚指定的配置项和数据显示图表。
  361. myChart.setOption(option);
  362. window.addEventListener("resize", function () {
  363. myChart.resize();
  364. });
  365. }, 3000)
  366. }
  367. render() {
  368. return (
  369. <div className={["eacharView cbLeftMenoyView"]}>
  370. <div id="echarts6_box">
  371. <img
  372. src={require("@assets/imgs/dataVimg/guanghuan.png").default}
  373. alt=""
  374. class="guanghuan animate__animated animate__pulse animate__infinite animate__slower"
  375. />
  376. <div id="echarts6"></div>
  377. </div>
  378. <ul className={"name_ul"}>
  379. {
  380. this.state.year.map(x=>{
  381. return <li>{x}</li>
  382. })
  383. }
  384. </ul>
  385. <div id="echarts4"></div>
  386. </div>
  387. )
  388. }
  389. }
  390. export default LeftMenoyView;