newRedrankvue.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // dependency : newCommon
  2. var RedRankTable = new Module("#table-rank", "fcBiWorkerDaily");
  3. RedRankTable.slides = 0;
  4. RedRankTable.parts = 3;
  5. RedRankTable.partLen = 4;
  6. RedRankTable.slideLen = RedRankTable.parts * RedRankTable.partLen;
  7. RedRankTable.curSlide = 0;
  8. RedRankTable.markerLen = 3;
  9. RedRankTable.drawData = function (data) {
  10. // showSlide
  11. this.showSlide(this.curSlide, data);
  12. };
  13. RedRankTable.showSlide = function (slide, data) {
  14. for(var part = 0; part < this.parts; part++){
  15. this.showPart(slide, part, data);
  16. }
  17. };
  18. RedRankTable.showPart = function(slide, part, data){
  19. var lpos = slide * this.slideLen + (part * this.partLen);
  20. var rpos = slide * this.slideLen + ((part+1) * this.partLen);
  21. var partList = [];
  22. for (var i = lpos; i < rpos; i++) {
  23. var one = data.getSorted(i);
  24. if(one == null || one === undefined) {
  25. partList[partList.length] = {passNum : 0, failNum: 0, failRate: 0, failRateStr:"", totalNum:0, workerId: 0, fcDay: new Date().toLocaleDateString()};
  26. } else {
  27. partList[partList.length] = one.jsonObj;
  28. partList[partList.length - 1].failRateStr = ""+(partList[partList.length - 1].failRate / 100.00).toFixed(2);
  29. partList[partList.length - 1].totalNum = partList[partList.length - 1].failNum + partList[partList.length - 1].passNum;
  30. }
  31. partList[partList.length - 1].workerName = getUserName(partList[partList.length - 1].workerId);
  32. if("[用户:"+0+"]" === partList[partList.length - 1].workerName){
  33. partList[partList.length - 1].workerName = "-";
  34. }
  35. partList[partList.length - 1].seq = i;
  36. partList[partList.length - 1].isRed = false;
  37. partList[partList.length - 1].isGreen = false;
  38. if(data.len() - partList[partList.length - 1].seq <= this.markerLen && partList[partList.length - 1].workerId > 0) {
  39. partList[partList.length - 1].isRed = true;
  40. }
  41. if(i <= this.markerLen - 1 && partList[partList.length - 1].workerId > 0) {
  42. partList[partList.length - 1].isRed = false;
  43. partList[partList.length - 1].isGreen = true;
  44. }
  45. }
  46. let k = newRedrankvue.parting[part].length;
  47. for(let i = 0; i < k; i++){
  48. newRedrankvue.parting[part].pop();
  49. }
  50. for(let i = 0; i < partList.length; i++){
  51. newRedrankvue.parting[part].push(partList[i]);
  52. }
  53. };
  54. RedRankTable.tickInterval = 6000;
  55. RedRankTable.tick = function(obj){
  56. var totalDataLen = obj.activeData != null ? obj.activeData.len() : 0;
  57. if(obj.slides !== Math.ceil(totalDataLen / obj.slideLen)){
  58. obj.slides = Math.ceil(totalDataLen / obj.slideLen);
  59. obj.curSlide = 0;
  60. } else {
  61. obj.curSlide = (obj.curSlide + 1) % obj.slides;
  62. }
  63. };
  64. RedRankTable.init();
  65. var newRedrankvue = new Vue({
  66. el: '#redrank',
  67. data: function () {
  68. var t = [];
  69. for(let i = 0; i < RedRankTable.parts; i++){
  70. var q = [];
  71. for(let j = 0; j < RedRankTable.partLen ; j++){
  72. q[j] = {};
  73. }
  74. t[i] = q;
  75. }
  76. return {
  77. parting : t,
  78. title: '本厂今日生产能手榜'
  79. }
  80. },
  81. methods: {
  82. clicktitle: function () {
  83. alert("Hello! This is Title");
  84. },
  85. useId: function () {
  86. this.useSort("Id");
  87. },
  88. usePass: function () {
  89. this.useSort("Pass");
  90. },
  91. useFail: function () {
  92. this.useSort("Fail");
  93. },
  94. useRate: function () {
  95. this.useSort("Rate");
  96. },
  97. useTotal: function () {
  98. this.useSort("Total");
  99. },
  100. useSort: function (column) {
  101. let sorter = function () {};
  102. let sortName = "";
  103. switch (column) {
  104. case "Pass": {
  105. sortName = "良品数量";
  106. sorter = RedRankTablePlugin.sortPass;
  107. break;
  108. }
  109. case "Fail": {
  110. sortName = "坏品数量";
  111. sorter = RedRankTablePlugin.sortFail;
  112. break;
  113. }
  114. case "Rate": {
  115. sortName = "不良率数量";
  116. sorter = RedRankTablePlugin.sortRate;
  117. break;
  118. }
  119. case "Total": {
  120. sortName = "总量数量";
  121. sorter = RedRankTablePlugin.sortTotal;
  122. break;
  123. }
  124. case "Id": {
  125. sortName = "人员ID";
  126. sorter = RedRankTablePlugin.sortId;
  127. break;
  128. }
  129. }
  130. send_alert("已经切换为按照 " + sortName + " 进行排序!");
  131. RedRankTablePlugin.workerDailyService.list.sortBy(sorter);
  132. console.warn(column);
  133. }
  134. }
  135. });
  136. var RedRankTablePlugin = new (function() {
  137. this.workerDailyService = new DataObjectService("fcBiWorkerDaily", ONDEMAND | AUTO | FAST, "?type=1");
  138. this.tick = function(obj){
  139. RedRankTable.setData(RedRankTablePlugin.workerDailyService.getList());
  140. };
  141. this.sortPass = function (l, r){
  142. var q = {};
  143. checkNull(l, r, q);
  144. if(q.out !== -2) return (-1) * q.out;
  145. var t = calcCompare(r.jsonObj.passNum, l.jsonObj.passNum, q);
  146. return t;
  147. };
  148. this.sortFail = function (l, r){
  149. var q = {};
  150. checkNull(l, r, q);
  151. if(q.out !== -2) return q.out;
  152. var t = calcCompare(l.jsonObj.failNum, r.jsonObj.failNum, q);
  153. return t;
  154. };
  155. this.sortTotal = function (l, r){
  156. var q = {};
  157. checkNull(l, r, q);
  158. if(q.out !== -2) return (-1) * q.out;
  159. var t = calcCompare(r.jsonObj.failNum + r.jsonObj.passNum, l.jsonObj.failNum + l.jsonObj.passNum, q);
  160. return t;
  161. };
  162. function checkNull(l, r, q) {
  163. if (l.jsonObj == null || l.jsonObj === undefined) {
  164. if (r.jsonObj == null || r.jsonObj === undefined) {
  165. q.out = 0;
  166. return;
  167. }
  168. q.out = -1;
  169. return;
  170. }
  171. if (r.jsonObj == null || r.jsonObj === undefined) {
  172. q.out = 1;
  173. return;
  174. }
  175. if(r.jsonObj == null || r.jsonObj === undefined){
  176. q = 1;
  177. return;
  178. }
  179. q.out = -2;
  180. }
  181. function calcCompare(l, r, q) {
  182. if (l > r) {
  183. q = 1;
  184. } else if (l === r) {
  185. q = 0;
  186. } else if (l < r) {
  187. q = -1;
  188. } else {
  189. console.error("login error");
  190. q = 0;
  191. }
  192. return q;
  193. }
  194. this.sortRate = function (l, r){
  195. var q = {};
  196. checkNull(l, r, q);
  197. if(q.out !== -2) return q.out;
  198. t = calcCompare(l.jsonObj.failRate, r.jsonObj.failRate, q);
  199. return t;
  200. };
  201. this.sortId = function (l, r){
  202. var q = {};
  203. checkNull(l, r, q);
  204. if(q.out !== -2) return q.out;
  205. var t = calcCompare(l.jsonObj.workerId, r.jsonObj.workerId, q);
  206. return t;
  207. };
  208. this.setup = function(obj){
  209. setInterval(obj.tick, 1000, obj);
  210. };
  211. this.setup(this);
  212. })();
  213. (function() {
  214. setInterval(RedRankTablePlugin.tick, 1000);
  215. })();