fault.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. $(".form-control").datepicker({
  2. format: 'yyyy-mm-dd',
  3. language: 'zh-CN',
  4. autoclose: true,
  5. todayBtn: 'linked'
  6. }).on('changeDate', function () {
  7. zTreeOnClick();
  8. }).on('keydown', function (e) {
  9. return false;
  10. });
  11. $("input[name='optionsRadios']").change(function (obj) {
  12. var str = $("input[name='optionsRadios']:checked").val();
  13. if (str === "0") {
  14. $("#day").attr("class", "tab-pane active")
  15. $("#days").attr("class", "tab-pane")
  16. }
  17. if (str === "1") {
  18. $("#day").attr("class", "tab-pane")
  19. $("#days").attr("class", "tab-pane active")
  20. }
  21. zTreeOnClick();
  22. });
  23. //$("input:radio:first").attr("checked", "checked");
  24. //$("input:radio:first").change();
  25. function shortcut(key) {
  26. if (key === -2) {
  27. var date = new Date();
  28. var d = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + (date.getDate() - 2);
  29. $("#date").val(d).datepicker('setDate', d);
  30. }
  31. if (key === -1) {
  32. var date = new Date();
  33. var d = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + (date.getDate() - 1);
  34. $("#date").val(d).datepicker('setDate', d);
  35. }
  36. if (key === 0) {
  37. var date = new Date();
  38. var d = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
  39. $("#date").val(d).datepicker('setDate', d);
  40. }
  41. }
  42. function getTOP10Faults(id, startTime, endTime) {
  43. $.ajax({
  44. url: '/Fault/GetTOP10Faults',
  45. type: 'GET',
  46. async: true,
  47. data: {
  48. "id": id,
  49. "startTime": startTime,
  50. "endTime": endTime,
  51. "filterString": "安全门,门禁,提示上料,提示卸料"
  52. },
  53. success: function (rev) {
  54. option.series = [];
  55. var x = [];
  56. var y1 = [];
  57. var y2 = [];
  58. for (var i = 0; i < rev.length; i++) {
  59. x.push(rev[i].faultInfo);
  60. y1.push(rev[i].shiftCount);
  61. y2.push(rev[i].nightShiftCount);
  62. }
  63. option.xAxis.data = x;
  64. var serie = {
  65. name: '白班',
  66. type: 'bar',
  67. stack: 'total',
  68. label: {
  69. show: true,
  70. formatter: (params) => '白班: ' + params.value + '次'
  71. },
  72. data: y1
  73. }
  74. option.series.push(serie);
  75. var serie1 = {
  76. name: '夜班',
  77. type: 'bar',
  78. stack: 'total',
  79. label: {
  80. show: true,
  81. formatter: (params) => '夜班: ' + params.value + '次'
  82. },
  83. data: y2
  84. }
  85. option.series.push(serie1);
  86. myChart.setOption(option, true);
  87. }
  88. });
  89. option2.series = [];
  90. myChart2.setOption(option2, true);
  91. }
  92. var dom = document.getElementById('container1');
  93. var myChart = echarts.init(dom, 'dark');
  94. var app = {};
  95. var option;
  96. option = {
  97. backgroundColor: '#001529',
  98. tooltip: {
  99. trigger: 'axis',
  100. axisPointer: {
  101. type: 'cross',
  102. crossStyle: {
  103. color: '#999'
  104. }
  105. }
  106. },
  107. toolbox: {
  108. feature: {
  109. dataZoom: { yAxisIndex: 'none' },
  110. restore: {},
  111. saveAsImage: {}
  112. }
  113. },
  114. xAxis: {
  115. type: 'category',
  116. axisPointer: {
  117. type: 'shadow'
  118. },
  119. axisLabel: {
  120. interval: 0,
  121. rotate: 30,
  122. formatter: function (value) {
  123. if (value.length > 5) {
  124. return value.substring(5, 15) + "..";
  125. }
  126. return value;
  127. }
  128. }
  129. },
  130. yAxis: [
  131. {
  132. type: 'value',
  133. name: '次数'
  134. }
  135. ],
  136. series: [],
  137. code:[]
  138. };
  139. if (option && typeof option === 'object') {
  140. myChart.setOption(option);
  141. }
  142. window.addEventListener('resize', myChart.resize);
  143. var emphasisStyle = {
  144. itemStyle: {
  145. shadowBlur: 10,
  146. shadowColor: 'rgba(0,0,0,0.3)'
  147. }
  148. };
  149. function addSerie(name, type, data, yIndex, company) {
  150. var serie = {
  151. name: name,
  152. type: type,
  153. label: {
  154. show: true
  155. },
  156. yAxisIndex: yIndex,
  157. tooltip: {
  158. valueFormatter: function (value) {
  159. return value + company;
  160. }
  161. },
  162. data: data
  163. }
  164. option.series.push(serie);
  165. }
  166. function getFaultTrend(id, code, startTime, endTime) {
  167. $.ajax({
  168. url: '/Fault/GetFaultTrend',
  169. type: 'GET',
  170. async: true,
  171. data: {
  172. "id": id,
  173. "faultInfo": code,
  174. "startTime": startTime,
  175. "endTime": endTime
  176. },
  177. success: function (rev) {
  178. option2.series = [];
  179. for (var i = 0; i < rev.series.length; i++) {
  180. addSerie2(rev.series[i].name, "line", rev.series[i].data, 0, " 次");
  181. addSerie3("", "line", startTime, endTime);
  182. }
  183. myChart2.setOption(option2, true);
  184. }
  185. });
  186. }
  187. var dom2 = document.getElementById('container2');
  188. var myChart2 = echarts.init(dom2, 'dark');
  189. var app2 = {};
  190. var option2;
  191. option2 = {
  192. backgroundColor: '#001529',
  193. tooltip: {
  194. trigger: 'axis',
  195. axisPointer: {
  196. type: 'cross',
  197. crossStyle: {
  198. color: '#999'
  199. }
  200. }
  201. },
  202. legend: {},
  203. toolbox: {
  204. feature: {
  205. dataZoom: { yAxisIndex: 'none' },
  206. restore: {},
  207. saveAsImage: {}
  208. }
  209. },
  210. xAxis: {
  211. type: 'category',
  212. axisPointer: {
  213. type: 'shadow'
  214. },
  215. axisLabel: {
  216. interval: 0,
  217. formatter: function (value) {
  218. return value.substring(0, 13)
  219. }
  220. }
  221. },
  222. yAxis: [
  223. {
  224. type: 'value',
  225. name: '次数'
  226. }
  227. ],
  228. series: []
  229. };
  230. if (option2 && typeof option === 'object') {
  231. myChart2.setOption(option2);
  232. }
  233. window.addEventListener('resize', myChart2.resize);
  234. function addSerie2(name, type, data, yIndex, company) {
  235. var serie = {
  236. name: name,
  237. type: type,
  238. label: {
  239. show: true
  240. },
  241. yAxisIndex: yIndex,
  242. tooltip: {
  243. valueFormatter: function (value) {
  244. return value + company;
  245. }
  246. },
  247. data: data
  248. }
  249. option2.series.push(serie);
  250. }
  251. function addSerie3(name, type, start, end) {
  252. var serie = {
  253. name: name,
  254. type: type,
  255. areaStyle: {},
  256. lineStyle: {
  257. width: 1
  258. },
  259. emphasis: {
  260. focus: 'series'
  261. },
  262. markArea: {
  263. silent: true,
  264. itemStyle: {
  265. opacity: 0.3
  266. },
  267. data: [
  268. [
  269. {
  270. xAxis: start
  271. },
  272. {
  273. //xAxis: '2009/9/22\n7:00'
  274. xAxis: end
  275. }
  276. ]
  277. ]
  278. }
  279. }
  280. option2.series.push(serie);
  281. }
  282. var zTreeObj;
  283. var setting = {
  284. callback: {
  285. onClick: zTreeOnClick
  286. },
  287. view: {
  288. showIcon: false
  289. }
  290. };
  291. $.ajax({
  292. url: "/ProductionLine/GetProductionLineMachineTree",
  293. type: "GET",
  294. async: true,
  295. success: function (zNodes) {
  296. zTreeObj = $.fn.zTree.init($("#productionLineTree"), setting, zNodes);
  297. }
  298. });
  299. function zTreeOnClick() {
  300. var treeNode = zTreeObj.getSelectedNodes()[0];
  301. if (treeNode.level === 1) {
  302. var str = $("input[name='optionsRadios']:checked").val();
  303. if (str === "0") {
  304. var startTime = $("#date").val();
  305. var endTime = $("#date").val();
  306. getTOP10Faults(treeNode.id, startTime, endTime);
  307. }
  308. if (str === "1") {
  309. var startTime = $("#date1").val();
  310. var endTime = $("#date2").val();
  311. getTOP10Faults(treeNode.id, startTime, endTime);
  312. }
  313. }
  314. }
  315. myChart.on('click', function (params) {
  316. //console.log(params);
  317. var treeNode = zTreeObj.getSelectedNodes()[0];
  318. if (treeNode.level === 1) {
  319. var str = $("input[name='optionsRadios']:checked").val();
  320. if (str === "0") {
  321. var startTime = $("#date").val();
  322. var endTime = $("#date").val();
  323. getFaultTrend(treeNode.id, params.name, startTime, endTime);
  324. }
  325. if (str === "1") {
  326. var startTime = $("#date1").val();
  327. var endTime = $("#date2").val();
  328. getFaultTrend(treeNode.id, params.name, startTime, endTime);
  329. }
  330. }
  331. });
  332. function getFaultTrendV1(id, code, day) {
  333. $.ajax({
  334. url: '/Fault/GetFaultTrendV1',
  335. type: 'GET',
  336. async: true,
  337. data: {
  338. "id": id,
  339. "faultInfo": code,
  340. "day": day
  341. },
  342. success: function (rev) {
  343. option2.series = [];
  344. for (var i = 0; i < rev.series.length; i++) {
  345. addSerie2(rev.series[i].name, "line", rev.series[i].data, 0, " 次");
  346. }
  347. myChart2.setOption(option2, true);
  348. }
  349. });
  350. }