home2.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. let $totalHeaderbox = $('.totalHeaderbox');
  2. var _orderStatusChart = document.getElementById('orderStatusChart');
  3. var _productionStatusChart = document.getElementById('productionStatusChart');
  4. var orderStatusChart = echarts.init(_orderStatusChart);
  5. var productionStatusChart = echarts.init(_productionStatusChart);
  6. $(function () {
  7. RenderHeaderAlert();
  8. initCharts();
  9. $(".order-info-box .box-tools input[type='radio']").on('click', function () {
  10. loadOrderStatusChart();
  11. });
  12. $(".production-info-box .box-tools input[type='radio']").on('click', function () {
  13. loadProductionStatusChart();
  14. });
  15. });
  16. function RenderHeaderAlert() {
  17. SaveAjax({
  18. url: window.appUrl + "Common/GetIndexAlertSum",
  19. dataType: "json",
  20. isAlert: false,
  21. isValidate: false,
  22. success: function (res) {
  23. $totalHeaderbox.empty();
  24. if (res && res.length > 0) {
  25. res.forEach(function (v, i) {
  26. let color = v.sumType == "1"
  27. ? "aqua"
  28. : v.sumType == "2"
  29. ? "red"
  30. : v.sumType == "3"
  31. ? "green"
  32. : "aqua";
  33. $totalHeaderbox.append(`
  34. <div class="col-md-4 col-sm-6 col-xs-12 totalHeaderItem" data-sumtype="${v.sumType}">
  35. <div class="info-box">
  36. <span class="info-box-icon bg-${color}"><img src="/Content/Images/index/${v
  37. .tipName}.png" /></span>
  38. <div class="info-box-content">
  39. <span class="info-box-text" >${v.sumName}</span>
  40. <span class="info-box-number">${v.quantity}</span>
  41. </div>
  42. </div>
  43. </div>`);
  44. });
  45. BindItemEvent();
  46. }
  47. }
  48. });
  49. }
  50. function BindItemEvent() {
  51. $('.totalHeaderItem').on('click',
  52. function (e) {
  53. let st = $(e.target).closest('.totalHeaderItem').data('sumtype');
  54. $('.alertContent > .row').css("display", "none");
  55. if (st == 1) {
  56. //GetOrderAlert();
  57. } else if (st == 2) {
  58. //GetProductionOrderAlert();
  59. } else if (st == 3) {
  60. //GetPackageApplyAlert();
  61. }
  62. });
  63. }
  64. var option1={},option2={};
  65. function initCharts() {
  66. var option = {
  67. tooltip: {
  68. trigger: 'axis',
  69. axisPointer: {
  70. type: 'cross',
  71. crossStyle: {
  72. color: '#999'
  73. }
  74. }
  75. },
  76. toolbox: {
  77. feature: {
  78. dataView: { show: false, readOnly: false },
  79. magicType: { show: true, type: ['line', 'bar'] },
  80. restore: { show: false },
  81. saveAsImage: { show: true }
  82. },
  83. iconStyle: {
  84. //color:'rgb(255,255,255)'
  85. borderColor: 'rgb(255,255,255)'
  86. }
  87. },
  88. legend: {
  89. //data: ['Evaporation', 'Precipitation'],
  90. backgroundColor: 'rgb(255,255,255)',
  91. textStyle: {
  92. color: '#0087ED',
  93. fontSize: '12px',
  94. fontWeight: 200
  95. }
  96. },
  97. xAxis: [
  98. {
  99. type: 'category',
  100. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  101. axisPointer: {
  102. type: 'shadow'
  103. },
  104. axisLine: {
  105. lineStyle: {
  106. color: '#0087ED',
  107. width:2
  108. }
  109. }
  110. }
  111. ],
  112. yAxis: [
  113. {
  114. type: 'value',
  115. name: '',
  116. min: 0,
  117. //max: 250,
  118. interval: 50,
  119. //axisLabel: {
  120. // formatter: '{value} ml'
  121. //}
  122. axisLine: {
  123. lineStyle: {
  124. color: '#0087ED',
  125. width: 1
  126. }
  127. }
  128. }
  129. ],
  130. series: [
  131. // {
  132. // name: 'Evaporation',
  133. // type: 'bar',
  134. // label: {
  135. // show: true
  136. // },
  137. // color:'rgba(220,20,60, 0.6)',
  138. // data: [
  139. // 2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6
  140. // ],
  141. // itemStyle: {
  142. // borderRadius: [0, 0, 0, 0],
  143. // color: 'rgba(220,20,60, 0.6)'
  144. // },
  145. // animation:true
  146. // },
  147. // {
  148. // name: 'Precipitation',
  149. // type: 'bar',
  150. // tooltip: {
  151. // valueFormatter: function (value) {
  152. // return value;
  153. // }
  154. // },
  155. // label: {
  156. // show: true
  157. // },
  158. // data: [
  159. // 2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6
  160. // ],
  161. // itemStyle: {
  162. // borderRadius: [8, 8, 0, 0]
  163. // },
  164. // animation: true
  165. // }
  166. ]
  167. };
  168. $.extend(true, option1, option);
  169. $.extend(true, option2, option);
  170. loadOrderStatusChart();
  171. loadProductionStatusChart();
  172. }
  173. function loadOrderStatusChart() {
  174. var qt = $('input[name="orderQt"]:checked').val();
  175. SaveAjax({
  176. url: window.appUrl + "Common/GetHomeStatusCharts?ct=1&qt="+qt,
  177. dataType: "json",
  178. isAlert: false,
  179. isValidate: false,
  180. success: function (res) {
  181. console.log(res);
  182. let yearArr = [], orderArr = [], notOrderArr = [];
  183. let q_orderArr = [[],[],[],[]];
  184. let q_notOrderArr = [[], [], [], []];
  185. let arrMap = new Map();
  186. res.forEach(function (v, i) {
  187. //默认年份
  188. //let ev = qt == "1" ? `${v.year.substr(2,2)}-Q${v.quarterly}` : v.year;
  189. let ev = v.year;
  190. if (!yearArr.some(ele => ele === ev)) {
  191. yearArr.push(ev);
  192. }
  193. if (qt == "1") {
  194. if (v.statusId == 2 || v.statusId == 15 || v.statusId == 9) {
  195. if (!arrMap.has(ev + "@" + v.quarterly+ "@0")) {
  196. arrMap.set(ev + "@" + v.quarterly + "@0", v.count ? v.count : Number(!!v.count));
  197. } else {
  198. let preV = arrMap.get(ev + "@" + v.quarterly + "@0");
  199. arrMap.set(ev + "@" + v.quarterly + "@0", Number(preV) + v.count ? v.count:Number(!!v.count));
  200. }
  201. } else {
  202. if (!arrMap.has(ev + "@" + v.quarterly + "@1")) {
  203. arrMap.set(ev + "@" + v.quarterly + "@1", v.count ? v.count : Number(!!v.count));
  204. } else {
  205. let preV = arrMap.get(ev + "@" + v.quarterly + "@1");
  206. arrMap.set(ev + "@" + v.quarterly + "@1", Number(preV) + v.count ? v.count : Number(!!v.count));
  207. }
  208. }
  209. } else {
  210. //非完成状态的
  211. if (v.statusId == 2 || v.statusId == 15 || v.statusId == 9) {
  212. if (!arrMap.has(ev + "@0")) {
  213. arrMap.set(ev + "@0", v.count);
  214. } else {
  215. let preV = arrMap.get(ev + "@0");
  216. arrMap.set(ev + "@0", preV + v.count);
  217. }
  218. } else {
  219. if (!arrMap.has(ev + "@1")) {
  220. arrMap.set(ev + "@1", v.count);
  221. } else {
  222. let preV = arrMap.get(ev + "@1");
  223. arrMap.set(ev + "@1", preV + v.count);
  224. }
  225. }
  226. }
  227. });
  228. let q_order_all = [], q_not_order_all = [];
  229. if (qt == "1") {
  230. yearArr.forEach(function (y, i) {
  231. let a0 = 0, a1 = 0; //4个季度的值汇总之和
  232. for (let j = 1; j <= 4; j++) {
  233. let tmp1 = arrMap.get(y + "@" + j + "@1");
  234. tmp1 = tmp1 ? tmp1 : Number(!!tmp1);
  235. let tmp0 = arrMap.get(y + "@" + j + "@0");
  236. tmp0 = tmp0 ? tmp0 : Number(!!tmp0);
  237. q_orderArr[j - 1].push(tmp1);
  238. q_notOrderArr[j - 1].push(tmp0);
  239. a0 += tmp0;
  240. a1 += tmp1;
  241. }
  242. q_order_all.push(a1);
  243. q_not_order_all.push(a0);
  244. });
  245. } else {
  246. yearArr.forEach(function (y, i) {
  247. orderArr.push(arrMap.get(y + "@1"));
  248. notOrderArr.push(arrMap.get(y + "@0"));
  249. });
  250. }
  251. // console.log('yearArr', yearArr)
  252. // console.log('orderArr', orderArr)
  253. // console.log('notOrderArr', notOrderArr)
  254. option1.xAxis[0].data = yearArr;
  255. option1.yAxis[0].interval = 1000;
  256. if (qt == "1") {
  257. console.log('yearArr', yearArr)
  258. console.log('q_orderArr', q_orderArr)
  259. console.log('q_notOrderArr', q_notOrderArr)
  260. console.log('q_order_all', q_order_all)
  261. console.log('q_not_order_all', q_not_order_all)
  262. option1.series = [];
  263. option1.legend.width = 600;
  264. option1.legend.padding = 10;
  265. option1.legend.data = [];
  266. option1.grid= {
  267. top:'15%'
  268. }
  269. q_orderArr.forEach((v, i) => {
  270. option1.legend.data.push(`Q${i + 1}完成订单`);
  271. option1.series.push(
  272. {
  273. type: 'bar',
  274. label: {
  275. show: true
  276. },
  277. data: v,
  278. name: `Q${i + 1}完成订单`,
  279. stack: 'one',
  280. itemStyle: {
  281. // borderRadius: [8, 8, 0, 0],
  282. // color: 'rgba(220,20,60, 0.6)'
  283. },
  284. animation: true
  285. }
  286. );
  287. });
  288. q_notOrderArr.forEach((v, i) => {
  289. option1.legend.data.push(`Q${i + 1}未完成订单`);
  290. option1.series.push(
  291. {
  292. type: 'bar',
  293. label: {
  294. show: true
  295. },
  296. data: v,
  297. name: `Q${i + 1}未完成订单`,
  298. stack: 'two',
  299. itemStyle: {
  300. // borderRadius: [8, 8, 0, 0],
  301. // color: 'rgba(220,20,60, 0.6)'
  302. },
  303. animation: true
  304. }
  305. );
  306. });
  307. option1.legend.data.push(`完成订单`);
  308. option1.legend.data.push(`未完成订单`);
  309. console.log("option1.legend.data", option1.legend.data)
  310. option1.series.push(
  311. {
  312. type: 'line',
  313. label: {
  314. show: true
  315. },
  316. data: q_order_all,
  317. name: `完成订单`,
  318. itemStyle: {
  319. // borderRadius: [8, 8, 0, 0],
  320. // color: 'rgba(220,20,60, 0.6)'
  321. },
  322. animation: true
  323. }
  324. );
  325. option1.series.push(
  326. {
  327. type: 'line',
  328. label: {
  329. show: true
  330. },
  331. data: q_not_order_all,
  332. name: `未完成订单`,
  333. itemStyle: {
  334. // borderRadius: [8, 8, 0, 0],
  335. // color: 'rgba(220,20,60, 0.6)'
  336. },
  337. animation: true
  338. }
  339. )
  340. } else {
  341. option1.legend.data = ["未完成订单明细", "完成订单明细"];
  342. option1.series = [];
  343. option1.series = [
  344. {
  345. type: 'bar',
  346. label: {
  347. show: true
  348. },
  349. data: notOrderArr,
  350. name: "未完成订单明细",
  351. stack: 'one',
  352. itemStyle: {
  353. // borderRadius: [8, 8, 0, 0],
  354. // color: 'rgba(220,20,60, 0.6)'
  355. },
  356. animation: true
  357. },
  358. {
  359. type: 'bar',
  360. label: {
  361. show: true
  362. },
  363. data: orderArr,
  364. name: "完成订单明细",
  365. stack: 'one',
  366. itemStyle: {
  367. // borderRadius: [8, 8, 0, 0],
  368. // color: 'rgba(220,20,60, 0.6)'
  369. },
  370. animation: true
  371. }
  372. ];
  373. }
  374. orderStatusChart.setOption(option1,true);
  375. }
  376. });
  377. }
  378. function loadProductionStatusChart() {
  379. var qt = $('input[name="productionQt"]:checked').val();
  380. SaveAjax({
  381. url: window.appUrl + "Common/GetHomeStatusCharts?ct=2&qt=" + qt,
  382. dataType: "json",
  383. isAlert: false,
  384. isValidate: false,
  385. success: function (res) {
  386. console.log(res);
  387. //1(新建),2(生产中),3(入库中),7(已经审核) 已入库/完成 4,5
  388. let yearArr = [], storeArr = [], notStoreArr = [];
  389. let arrMap = new Map();
  390. res.forEach(function (v, i) {
  391. //默认年份
  392. let ev = qt == "1" ? `${v.year.substr(2, 2)}-Q${v.quarterly}` : v.year;
  393. if (!yearArr.some(ele => ele === ev)) {
  394. yearArr.push(ev);
  395. }
  396. //非完成状态的
  397. if (v.statusId == 1 || v.statusId == 2 || v.statusId == 3 || v.statusId == 7) {
  398. if (!arrMap.has(ev + "@0")) {
  399. arrMap.set(ev + "@0", v.count);
  400. } else {
  401. let preV = arrMap.get(ev + "@0");
  402. arrMap.set(ev + "@0", preV + v.count);
  403. }
  404. } else if (v.statusId == 4 || v.statusId == 5) {//已入库 / 完成 4, 5
  405. if (!arrMap.has(ev + "@1")) {
  406. arrMap.set(ev + "@1", v.count);
  407. } else {
  408. let preV = arrMap.get(ev + "@1");
  409. arrMap.set(ev + "@1", preV + v.count);
  410. }
  411. }
  412. });
  413. yearArr.forEach(function (y, i) {
  414. storeArr.push(arrMap.get(y + "@1"));
  415. notStoreArr.push(arrMap.get(y + "@0"));
  416. });
  417. console.log('yearArr', yearArr)
  418. console.log('storeArr', storeArr)
  419. console.log('notStoreArr', notStoreArr)
  420. option2.xAxis[0].data = yearArr;
  421. option2.yAxis[0].interval = qt == "1"?500: 1000;
  422. option2.legend.data = ["未完成排产单", "已入库/已完成的排产单"];
  423. // option2.series[0].data = notStoreArr;
  424. // option2.series[0].stack = 'one';
  425. // option2.series[0].name = "未完成排产单";
  426. // option2.series[1].data = storeArr;
  427. // option2.series[1].stack = 'one';
  428. // option2.series[1].name = "已入库/已完成的排产单";
  429. option2.series = [
  430. {
  431. type: 'bar',
  432. label: {
  433. show: true
  434. },
  435. data: notStoreArr,
  436. name: "未完成排产单",
  437. stack: 'one',
  438. itemStyle: {
  439. //borderRadius: [8, 8, 0, 0],
  440. color: 'rgba(220,20,60, 0.6)'
  441. },
  442. animation: true
  443. },
  444. {
  445. type: 'bar',
  446. label: {
  447. show: true
  448. },
  449. data: storeArr,
  450. name: "已入库/已完成的排产单",
  451. stack: 'one',
  452. itemStyle: {
  453. borderRadius: [8, 8, 0, 0],
  454. },
  455. animation: true
  456. }
  457. ];
  458. productionStatusChart.setOption(option2);
  459. }
  460. });
  461. }