home.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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: 300
  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. tooltip: {
  135. valueFormatter: function (value) {
  136. return value;
  137. }
  138. },
  139. label: {
  140. show: true
  141. },
  142. color:'rgba(220,20,60, 0.6)',
  143. data: [
  144. 2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6
  145. ],
  146. itemStyle: {
  147. borderRadius:[0,0,0,0]
  148. },
  149. animation:true
  150. },
  151. {
  152. name: 'Precipitation',
  153. type: 'bar',
  154. tooltip: {
  155. valueFormatter: function (value) {
  156. return value;
  157. }
  158. },
  159. label: {
  160. show: true
  161. },
  162. data: [
  163. 2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6
  164. ],
  165. itemStyle: {
  166. borderRadius: [8, 8, 0, 0]
  167. },
  168. animation: true
  169. }
  170. ]
  171. };
  172. $.extend(true, option1, option);
  173. $.extend(true, option2, option);
  174. loadOrderStatusChart();
  175. loadProductionStatusChart();
  176. }
  177. function loadOrderStatusChart() {
  178. var qt = $('input[name="orderQt"]:checked').val();
  179. SaveAjax({
  180. url: window.appUrl + "Common/GetHomeStatusCharts?ct=1&qt="+qt,
  181. dataType: "json",
  182. isAlert: false,
  183. isValidate: false,
  184. success: function (res) {
  185. console.log(res);
  186. let yearArr = [], orderArr = [], notOrderArr = [];
  187. let arrMap = new Map();
  188. res.forEach(function (v, i) {
  189. //默认年份
  190. let ev = qt == "1" ? `${v.year.substr(2,2)}-Q${v.quarterly}` : v.year;
  191. if (!yearArr.some(ele => ele === ev)) {
  192. yearArr.push(ev);
  193. }
  194. //非完成状态的
  195. if (v.statusId == 2 || v.statusId == 15 || v.statusId == 9) {
  196. if (!arrMap.has(ev + "@0")) {
  197. arrMap.set(ev + "@0", v.count);
  198. } else {
  199. let preV = arrMap.get(ev + "@0");
  200. arrMap.set(ev + "@0", preV + v.count);
  201. }
  202. } else {
  203. if (!arrMap.has(ev + "@1")) {
  204. arrMap.set(ev + "@1", v.count);
  205. } else {
  206. let preV = arrMap.get(ev + "@1");
  207. arrMap.set(ev + "@1", preV + v.count);
  208. }
  209. }
  210. });
  211. yearArr.forEach(function (y, i) {
  212. orderArr.push(arrMap.get(y + "@1"));
  213. notOrderArr.push(arrMap.get(y + "@0"));
  214. });
  215. console.log('yearArr', yearArr)
  216. console.log('orderArr', orderArr)
  217. console.log('notOrderArr', notOrderArr)
  218. option1.xAxis[0].data = yearArr;
  219. option1.yAxis[0].interval = 1000;
  220. option1.legend.data = ["未完成订单明细", "完成订单明细"];
  221. option1.series[0].data = notOrderArr;
  222. option1.series[0].name = "未完成订单明细";
  223. option1.series[0].stack = 'one';
  224. option1.series[1].data = orderArr;
  225. option1.series[1].name = "完成订单明细";
  226. option1.series[1].stack = 'one';
  227. orderStatusChart.setOption(option1);
  228. }
  229. });
  230. }
  231. function loadProductionStatusChart() {
  232. var qt = $('input[name="productionQt"]:checked').val();
  233. SaveAjax({
  234. url: window.appUrl + "Common/GetHomeStatusCharts?ct=2&qt=" + qt,
  235. dataType: "json",
  236. isAlert: false,
  237. isValidate: false,
  238. success: function (res) {
  239. console.log(res);
  240. //1(新建),2(生产中),3(入库中),7(已经审核) 已入库/完成 4,5
  241. let yearArr = [], storeArr = [], notStoreArr = [];
  242. let arrMap = new Map();
  243. res.forEach(function (v, i) {
  244. //默认年份
  245. let ev = qt == "1" ? `${v.year.substr(2, 2)}-Q${v.quarterly}` : v.year;
  246. if (!yearArr.some(ele => ele === ev)) {
  247. yearArr.push(ev);
  248. }
  249. //非完成状态的
  250. if (v.statusId == 1 || v.statusId == 2 || v.statusId == 3 || v.statusId == 7) {
  251. if (!arrMap.has(ev + "@0")) {
  252. arrMap.set(ev + "@0", v.count);
  253. } else {
  254. let preV = arrMap.get(ev + "@0");
  255. arrMap.set(ev + "@0", preV + v.count);
  256. }
  257. } else if (v.statusId == 4 || v.statusId == 5) {//已入库 / 完成 4, 5
  258. if (!arrMap.has(ev + "@1")) {
  259. arrMap.set(ev + "@1", v.count);
  260. } else {
  261. let preV = arrMap.get(ev + "@1");
  262. arrMap.set(ev + "@1", preV + v.count);
  263. }
  264. }
  265. });
  266. yearArr.forEach(function (y, i) {
  267. storeArr.push(arrMap.get(y + "@1"));
  268. notStoreArr.push(arrMap.get(y + "@0"));
  269. });
  270. console.log('yearArr', yearArr)
  271. console.log('storeArr', storeArr)
  272. console.log('notStoreArr', notStoreArr)
  273. option2.xAxis[0].data = yearArr;
  274. option2.yAxis[0].interval = qt == "1"?500: 1000;
  275. option2.legend.data = ["未完成排产单", "已入库/已完成的排产单"];
  276. option2.series[0].data = notStoreArr;
  277. option2.series[0].stack = 'one';
  278. option2.series[0].name = "未完成排产单";
  279. option2.series[1].data = storeArr;
  280. option2.series[1].stack = 'one';
  281. option2.series[1].name = "已入库/已完成的排产单";
  282. productionStatusChart.setOption(option2);
  283. }
  284. });
  285. }