123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- // dependency : newCommon
- var RedRankTable = new Module("#table-rank", "fcBiWorkerDaily");
- RedRankTable.slides = 0;
- RedRankTable.parts = 3;
- RedRankTable.partLen = 4;
- RedRankTable.slideLen = RedRankTable.parts * RedRankTable.partLen;
- RedRankTable.curSlide = 0;
- RedRankTable.markerLen = 3;
- RedRankTable.drawData = function (data) {
- // showSlide
- this.showSlide(this.curSlide, data);
- };
- RedRankTable.showSlide = function (slide, data) {
- for(var part = 0; part < this.parts; part++){
- this.showPart(slide, part, data);
- }
- };
- RedRankTable.showPart = function(slide, part, data){
- var lpos = slide * this.slideLen + (part * this.partLen);
- var rpos = slide * this.slideLen + ((part+1) * this.partLen);
- var partList = [];
- for (var i = lpos; i < rpos; i++) {
- var one = data.getSorted(i);
- if(one == null || one === undefined) {
- partList[partList.length] = {passNum : 0, failNum: 0, failRate: 0, failRateStr:"", totalNum:0, workerId: 0, fcDay: new Date().toLocaleDateString()};
- } else {
- partList[partList.length] = one.jsonObj;
- partList[partList.length - 1].failRateStr = ""+(partList[partList.length - 1].failRate / 100.00).toFixed(2);
- partList[partList.length - 1].totalNum = partList[partList.length - 1].failNum + partList[partList.length - 1].passNum;
- }
- partList[partList.length - 1].workerName = getUserName(partList[partList.length - 1].workerId);
- if("[用户:"+0+"]" === partList[partList.length - 1].workerName){
- partList[partList.length - 1].workerName = "-";
- }
- partList[partList.length - 1].seq = i;
- partList[partList.length - 1].isRed = false;
- partList[partList.length - 1].isGreen = false;
- if(data.len() - partList[partList.length - 1].seq <= this.markerLen && partList[partList.length - 1].workerId > 0) {
- partList[partList.length - 1].isRed = true;
- }
- if(i <= this.markerLen - 1 && partList[partList.length - 1].workerId > 0) {
- partList[partList.length - 1].isRed = false;
- partList[partList.length - 1].isGreen = true;
- }
- }
- let k = newRedrankvue.parting[part].length;
- for(let i = 0; i < k; i++){
- newRedrankvue.parting[part].pop();
- }
- for(let i = 0; i < partList.length; i++){
- newRedrankvue.parting[part].push(partList[i]);
- }
- };
- RedRankTable.tickInterval = 6000;
- RedRankTable.tick = function(obj){
- var totalDataLen = obj.activeData != null ? obj.activeData.len() : 0;
- if(obj.slides !== Math.ceil(totalDataLen / obj.slideLen)){
- obj.slides = Math.ceil(totalDataLen / obj.slideLen);
- obj.curSlide = 0;
- } else {
- obj.curSlide = (obj.curSlide + 1) % obj.slides;
- }
- };
- RedRankTable.init();
- var newRedrankvue = new Vue({
- el: '#redrank',
- data: function () {
- var t = [];
- for(let i = 0; i < RedRankTable.parts; i++){
- var q = [];
- for(let j = 0; j < RedRankTable.partLen ; j++){
- q[j] = {};
- }
- t[i] = q;
- }
- return {
- parting : t,
- title: '本厂今日生产能手榜'
- }
- },
- methods: {
- clicktitle: function () {
- alert("Hello! This is Title");
- },
- useId: function () {
- this.useSort("Id");
- },
- usePass: function () {
- this.useSort("Pass");
- },
- useFail: function () {
- this.useSort("Fail");
- },
- useRate: function () {
- this.useSort("Rate");
- },
- useTotal: function () {
- this.useSort("Total");
- },
- useSort: function (column) {
- let sorter = function () {};
- let sortName = "";
- switch (column) {
- case "Pass": {
- sortName = "良品数量";
- sorter = RedRankTablePlugin.sortPass;
- break;
- }
- case "Fail": {
- sortName = "坏品数量";
- sorter = RedRankTablePlugin.sortFail;
- break;
- }
- case "Rate": {
- sortName = "不良率数量";
- sorter = RedRankTablePlugin.sortRate;
- break;
- }
- case "Total": {
- sortName = "总量数量";
- sorter = RedRankTablePlugin.sortTotal;
- break;
- }
- case "Id": {
- sortName = "人员ID";
- sorter = RedRankTablePlugin.sortId;
- break;
- }
- }
- send_alert("已经切换为按照 " + sortName + " 进行排序!");
- RedRankTablePlugin.workerDailyService.list.sortBy(sorter);
- console.warn(column);
- }
- }
- });
- var RedRankTablePlugin = new (function() {
- this.workerDailyService = new DataObjectService("fcBiWorkerDaily", ONDEMAND | AUTO | FAST, "?type=1");
- this.tick = function(obj){
- RedRankTable.setData(RedRankTablePlugin.workerDailyService.getList());
- };
- this.sortPass = function (l, r){
- var q = {};
- checkNull(l, r, q);
- if(q.out !== -2) return (-1) * q.out;
- var t = calcCompare(r.jsonObj.passNum, l.jsonObj.passNum, q);
- return t;
- };
- this.sortFail = function (l, r){
- var q = {};
- checkNull(l, r, q);
- if(q.out !== -2) return q.out;
- var t = calcCompare(l.jsonObj.failNum, r.jsonObj.failNum, q);
- return t;
- };
- this.sortTotal = function (l, r){
- var q = {};
- checkNull(l, r, q);
- if(q.out !== -2) return (-1) * q.out;
- var t = calcCompare(r.jsonObj.failNum + r.jsonObj.passNum, l.jsonObj.failNum + l.jsonObj.passNum, q);
- return t;
- };
- function checkNull(l, r, q) {
- if (l.jsonObj == null || l.jsonObj === undefined) {
- if (r.jsonObj == null || r.jsonObj === undefined) {
- q.out = 0;
- return;
- }
- q.out = -1;
- return;
- }
- if (r.jsonObj == null || r.jsonObj === undefined) {
- q.out = 1;
- return;
- }
- if(r.jsonObj == null || r.jsonObj === undefined){
- q = 1;
- return;
- }
- q.out = -2;
- }
- function calcCompare(l, r, q) {
- if (l > r) {
- q = 1;
- } else if (l === r) {
- q = 0;
- } else if (l < r) {
- q = -1;
- } else {
- console.error("login error");
- q = 0;
- }
- return q;
- }
- this.sortRate = function (l, r){
- var q = {};
- checkNull(l, r, q);
- if(q.out !== -2) return q.out;
- t = calcCompare(l.jsonObj.failRate, r.jsonObj.failRate, q);
- return t;
- };
- this.sortId = function (l, r){
- var q = {};
- checkNull(l, r, q);
- if(q.out !== -2) return q.out;
- var t = calcCompare(l.jsonObj.workerId, r.jsonObj.workerId, q);
- return t;
- };
- this.setup = function(obj){
- setInterval(obj.tick, 1000, obj);
- };
- this.setup(this);
- })();
- (function() {
- setInterval(RedRankTablePlugin.tick, 1000);
- })();
|