leftMenoyView.jsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * @Author: dayan_hjm 库存金额
  3. * @Date: 2023-10-23 09:32:12
  4. * @Last Modified by: dayan_hjm
  5. * @Last Modified time: 2024-10-28 13:59:03
  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. total: 0,
  25. year: [
  26. {
  27. name: "氢氧化锂(电池级)",
  28. tips: '/ LHM(BG)',
  29. },
  30. {
  31. name: "氢氧化锂(工业级)",
  32. tips: '/ LHM(PG)',
  33. },
  34. {
  35. name: "氢氧化锂(待检验)",
  36. tips: '/ LHM(PENDING)',
  37. },],
  38. missionsIntensity_arr: [
  39. { value: 0, name: "氢氧化锂(电池级)/ LHM(BG)" },
  40. { value: 0, name: "氢氧化锂(工业级)/ LHM(PG)" },
  41. { value: 0, name: '氢氧化锂(待检验)/ LHM(PENDING)' },
  42. ],
  43. };
  44. }
  45. componentDidMount() {
  46. this.getUrl()
  47. }
  48. async getUrl() {
  49. let data_style = [
  50. {
  51. value: 0, name: '氢氧化锂(电池级)/ LHM(BG)', itemStyle: {
  52. borderRadius: 20,
  53. normal: {
  54. color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
  55. offset: 0,
  56. color: 'rgba(141, 147, 255, 0)'
  57. }, {
  58. offset: 1,
  59. color: 'rgba(141, 147, 255, 1)'
  60. }]),
  61. }
  62. }
  63. },
  64. {
  65. value: 0, name: '氢氧化锂(工业级)/ LHM(PG)', itemStyle: {
  66. borderRadius: 20,
  67. normal: {
  68. color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
  69. offset: 0,
  70. color: 'rgba(255, 206, 0, 0)'
  71. }, {
  72. offset: 1,
  73. color: 'rgba(255, 206, 0, 1)'
  74. }]),
  75. }
  76. }
  77. },
  78. {
  79. value: 0, name: '油氢氧化锂(待检验)/ LHM(PENDING)', itemStyle: {
  80. borderRadius: 20,
  81. normal: {
  82. color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
  83. offset: 0,
  84. color: 'rgba(105, 255, 222, 0)'
  85. }, {
  86. offset: 1,
  87. color: 'rgba(105, 255, 222, 1)'
  88. }]),
  89. }
  90. }
  91. },
  92. ]
  93. await momeyService().then(({ data = [], resultCode }) => {
  94. if (+resultCode === 0) {
  95. let total = 0, max1 = [], num = [];
  96. data.map((x, i) => {
  97. if (x.IndexCode == '11') {
  98. data_style[0].value = x.IndexValue;
  99. num.push(x.IndexValue)
  100. total += Number(x.IndexValue || 0)
  101. } else if (x.IndexCode == '12') {
  102. num.push(x.IndexValue)
  103. data_style[1].value = x.IndexValue;
  104. total += Number(x.IndexValue || 0)
  105. } else if (x.IndexCode == '13') {
  106. num.push(x.IndexValue)
  107. data_style[2].value = x.IndexValue;
  108. total += Number(x.IndexValue || 0)
  109. }
  110. });
  111. const max_1 = getArrMax(num);
  112. for (let index = 0; index < data_style.length; index++) {
  113. max1.unshift(max_1 / 0.8)
  114. }
  115. this.setState({ missionsIntensity_arr: data_style, total:total.toFixed(2), max1 });
  116. this.setData();
  117. this.setData2();
  118. }
  119. });
  120. }
  121. setData() {
  122. const new_arr = this.state.missionsIntensity_arr.reverse();
  123. setTimeout(() => {
  124. // 基于准备好的dom,初始化echarts实例
  125. var myChart = echarts.init(document.getElementById('echarts41'));
  126. var option = {
  127. grid: {
  128. left: '0%',
  129. top: '4%',
  130. right: '5%',
  131. bottom: '0%',
  132. containLabel: true
  133. },
  134. xAxis: [{
  135. show: false,
  136. }],
  137. yAxis: [{
  138. axisTick: 'none',
  139. axisLine: 'none',
  140. offset: '7',
  141. axisLabel: {
  142. textStyle: {
  143. color: 'rgba(255,255,255,.9)',
  144. fontSize: '0',
  145. }
  146. },
  147. data: this.state.year
  148. },
  149. {
  150. name: '单位:件',
  151. nameGap: '50',
  152. nameTextStyle: {
  153. color: 'rgba(255,255,255,.6)',
  154. fontSize: '16',
  155. },
  156. axisLine: {
  157. lineStyle: {
  158. color: 'rgba(0,0,0,0)'
  159. }
  160. },
  161. data: [],
  162. }],
  163. series: [{
  164. name: '条',
  165. type: 'bar',
  166. yAxisIndex: 0,
  167. data: new_arr,
  168. label: {
  169. normal: {
  170. show: true,
  171. position: 'right',
  172. formatter: function (param) {
  173. return getThousandNum(param.value) + 't';
  174. // return param.name+":"+param.value + '万元';
  175. },
  176. textStyle: {
  177. color: '#CDF1FF',
  178. fontSize: '10',
  179. }
  180. }
  181. },
  182. barWidth: 15,
  183. itemStyle: {
  184. normal: {
  185. color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [
  186. { offset: 0, color: 'rgba(255, 206, 0, 1)' },
  187. { offset: 0.7, color: '#ffd01d94' },
  188. { offset: 1, color: '#ffd01d94' },
  189. ]),
  190. barBorderRadius: 15,
  191. // borderColor: "rgba(255, 206, 0, 1)",
  192. // borderWidth: 1
  193. }
  194. },
  195. labelLine: {
  196. length: 10,
  197. length2: 50,
  198. },
  199. // labelLayout: {
  200. // x: "20%",
  201. // y: "20%",
  202. // verticalAlign: "bottom",
  203. // dy: -10,
  204. // },
  205. z: 2
  206. }, {
  207. name: '白框',
  208. type: 'bar',
  209. yAxisIndex: 1,
  210. barGap: '-100%',
  211. data: this.state.max1,
  212. barWidth: 15,
  213. itemStyle: {
  214. normal: {
  215. color: '#ffffff24',
  216. barBorderRadius: 15,
  217. }
  218. },
  219. z: 1
  220. }]
  221. };
  222. // 使用刚指定的配置项和数据显示图表。
  223. myChart.setOption(option);
  224. window.addEventListener("resize", function () {
  225. myChart.resize();
  226. });
  227. }, 3000)
  228. }
  229. setData2() {
  230. setTimeout(() => {
  231. // 基于准备好的dom,初始化echarts实例
  232. var myChart = echarts.init(document.getElementById('echarts61'));
  233. var option = {
  234. calculable: true,
  235. series: [
  236. {
  237. type: 'pie',
  238. radius: ['50%', '65%'],
  239. center: ['50%', '50%'],
  240. roseType: 'radius',
  241. data:this.state.missionsIntensity_arr,
  242. itemStyle: {
  243. borderRadius: 20,
  244. },
  245. labelLine: {
  246. show: false,
  247. }, label: {
  248. show: false,
  249. position: 'center',
  250. },
  251. },
  252. ],
  253. };
  254. // 使用刚指定的配置项和数据显示图表。
  255. myChart.setOption(option);
  256. window.addEventListener("resize", function () {
  257. myChart.resize();
  258. });
  259. }, 3000)
  260. }
  261. render() {
  262. const { total } = this.state;
  263. const { changNun } = this.props;
  264. return (
  265. <div className={["eacharView cbLeftMenoyView"]}>
  266. <div id="echarts6_box">
  267. <img
  268. src={require("@assets/imgs/dataVimg/guanghuan.png").default}
  269. alt=""
  270. class="guanghuan animate__animated animate__pulse animate__infinite animate__slower"
  271. />
  272. <div id="echarts61"></div>
  273. <div className="text_total">
  274. <p>
  275. {changNun && <span className="topMsg_number">{getThousandNum(Number(total))}</span>}
  276. {!changNun && <span className="topMsg_number" class="shu1">{Number(total)}</span>}
  277. <span className="topMsg_number_2">t</span>
  278. </p>
  279. <span className="topMsg_number_3">总库存</span>
  280. </div>
  281. </div>
  282. <ul className={"name_ul"}>
  283. {
  284. this.state.year.map(x => {
  285. return (<li>{x.name}<span style={{ fontSize: "0.7em" }}>{x.tips}</span></li>)
  286. })
  287. }
  288. </ul>
  289. <div id="echarts41"></div>
  290. </div>
  291. )
  292. }
  293. }
  294. export default LeftMenoyView;