main.js 25.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
layui.config({
    base: "/js/"
}).use(['form', 'vue', 'ztree', 'layer', 'jquery', 'table', 'droptree', 'hhweb', 'utils'], function () {
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery;
    var table = layui.table;
    var hhweb = layui.hhweb;
    var toplayer = (top == undefined || top.layer === undefined) ? layer : top.layer;  //顶层的LAYER
    //给按钮添加快捷键
    //Ctrl+I键添加,Ctrl+R键刷新,Ctrl+D键删除,Ctrl+E键编辑,Ctrl+F查询,Ctrl+S保存,Ctrl+A全选,Ctrl+Shift+A取消全选,左 上一页 右 下一页
    $(document).bind("keydown", function (e) {
        //禁用页面F5刷新
        if (e.which == 116) {
            e.preventDefault(); //Skip default behavior of the enter key
        }
    });

    $(document).ready(function () {
        
        function GetDateStr(AddDayCount) {
            var dd = new Date();
            dd.setDate(dd.getDate() + AddDayCount);//获取AddDayCount天后的日期
            var y = dd.getFullYear();
            var m = 0;//获取当前月份的日期
            var d = 0;
            m = dd.getMonth() + 1;
            d = dd.getDate();
            if (m >= 10) {
                m = m;
            }
            else {
                m = "0" + m;
            }
            if (d >= 10) {
                d = d;
            }
            else {
                d = "0" + d;
            }
            return y + "-" + m + "-" + d;
        }

        var timeTicket = setInterval(function () {
            window.location.reload();
        }, 90000)
        clearInterval(timeTicket);

        //图一:最近7天每日收发货量
        $.ajax({
            url: "/base/EchartsData/GetWeekTaskInfo",
            data: {},
            type: "POST",
            dataType: "json",
            async: true,
            success: function (data) {
                //没有数据时提示
                //if (data.hasOwnProperty("type")) {
                //    dialogMsg(data.message, 0);
                //    return;
                //}
                var chart1 = echarts.init(document.getElementById('chart1'));
                //chart1.showLoading({
                //    text: '正在加载中......',
                //    effect: 'whirling'
                //});
                var indata = new Array();
                var outdata = new Array();
                var ydate = new Array();
                var movedata = new Array();
                var m = 0;
                for (var i = 0; i < 7; i++) {
                    for (var k = 0; k > -7; k--) {

                        if (typeof data.data[i] !== 'undefined') {
                            if (data.data[i].type == "receipt") {
                                if (data.data[i].name == GetDateStr(k)) {
                                    indata[6 + k] = data.data[i].count;
                                }

                            } else if (data.data[i].type == "shipment") {
                                if (data.data[i].name == GetDateStr(k)) {
                                    outdata[6 + k] = data.data[i].count;
                                }
                            }
                            else if (data.data[i].type == "Cyclecount"){
                                if (data.data[i].name == GetDateStr(k)) {
                                    movedata[6 + k] = data.data[i].count;
                                }
                                m++;
                            }
                        }
                        else {
                            if (typeof indata[i] == 'undefined') {
                                indata[i] = 0;
                            } else if (typeof outdata[i] == 'undefined') {
                                outdata[i] = 0;
                            }
                        }
                    }
                };

                if (movedata.length == 0) {
                    movedata = [0, 0, 0, 0, 0, 0, 0];
                };
                for (var i = 0; i < 7; i++) {
                    if (typeof indata[i] == 'undefined' && typeof outdata[i] == 'undefined') {
                        if (indata[i] = 'undefined') {
                            indata[i] = 0;
                        };
                        if (outdata[i] = 'undefined') {
                            outdata[i] = 0;
                        }
                    }
                }

                //数组去重
                function uniq(array) {
                    var temp = []; //一个新的临时数组
                    for (var i = 0; i < array.length; i++) {
                        if (temp.indexOf(array[i]) == -1) {
                            temp.push(array[i]);
                        }
                    }
                    return temp;
                }

                ydate = uniq(ydate);

                var option = {
                    title: {
                        text: '业务量统计',
                        subtext: '单位:个',
                        left: 'left'
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {            // 坐标轴指示器,坐标轴触发有效
                            type: 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
                        }
                    },
                    legend: {
                        data: ['入库', '出库', '移库']
                    },
                    toolbox: {
                        show: true,
                        // orient: 'vertical',
                        x: 'right',
                        // y: 'center',
                        feature: {
                            mark: { show: true },
                            dataView: { show: true, readOnly: false },
                            magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },
                            restore: { show: true },
                            saveAsImage: { show: true }
                        }
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [
                        {
                            type: 'category',
                            data: [GetDateStr(-6), GetDateStr(-5), GetDateStr(-4), GetDateStr(-3), GetDateStr(-2), GetDateStr(-1), GetDateStr(0)]
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value'
                        }
                    ],
                    series: [
                        {
                            name: '入库',
                            type: 'bar',
                            data: [indata[0], indata[1], indata[2], indata[3], indata[4], indata[5], indata[6]],
                            markLine: {
                                data: [
                                    { type: 'average', name: '平均值' }
                                ]
                            },
                            markLine: {
                                lineStyle: {
                                    normal: {
                                        type: 'dashed'
                                    }
                                },
                                data: [
                                    [{ type: 'min' }, { type: 'max' }]
                                ]
                            }
                        },
                        {
                            name: '出库',
                            type: 'bar',
                            stack: '广告',
                            data: [outdata[0], outdata[1], outdata[2], outdata[3], outdata[4], outdata[5], outdata[6]],
                            //data: [77, 823,522, 123, 452, 66, 98],
                            markLine: {
                                data: [
                                    { type: 'average', name: '平均值' }
                                ]
                            },
                            markLine: {
                                lineStyle: {
                                    normal: {
                                        type: 'dashed'
                                    }
                                },
                                data: [
                                    [{ type: 'min' }, { type: 'max' }]
                                ]
                            }
                        },
                        {
                            name: '移库',
                            type: 'bar',
                            data: [movedata[0], movedata[1], movedata[2], movedata[3], movedata[4], movedata[5], movedata[6]],
                            //data: [33, 22, 12, 53, 62, 32, 31],
                            markLine: {
                                lineStyle: {
                                    normal: {
                                        type: 'dashed'
                                    }
                                },
                                data: [
                                    [{ type: 'min' }, { type: 'max' }]
                                ]
                            }
                        }
                    ]
                };
                chart1.setOption(option);
                //chart1.hideLoading();

                //计算今日总单量
                var hsum = document.getElementById("s1");
                var hin = document.getElementById("s2");
                var hout = document.getElementById("s3");
                var hmove = document.getElementById("s4");
                hsum.innerHTML = parseInt(indata[6] + outdata[6] + movedata[6]);
                hin.innerHTML = parseInt(indata[6]);
                hout.innerHTML = parseInt(outdata[6]);
                hmove.innerHTML = parseInt(movedata[6]);
            },
            //error: function (XMLHttpRequest, textStatus, errorThrown) {
            //    layer.alert(errorThrown, { icon: 2, title: '提示' });
            //}
        });

        //图二:库位利用率
        $.ajax({
            url: "/base/EchartsData/GetWareCellOption",
            data: {},
            type: "POST",
            dataType: "json",
            async: true,
            success: function (data) {
                //没有数据时提示
                //if (data.hasOwnProperty("type")) {
                //    dialogMsg(data.message, 0);
                //    return;
                //}
                var lock = 0, empty = 0, disable = 0, occupy = 0,some=0;
                for (var i = 0; i <= data.data.length; i++) {
                    if (typeof data.data[i] !== 'undefined') {
                        if (data.data[i].name == "lock") {
                            lock = data.data[i].count;
                        } else if (data.data[i].name == "empty") {
                            empty = data.data[i].count;
                        } else if (data.data[i].name == "some") {
                            some = data.data[i].count;
                        }else if (data.data[i].name == "disable") {
                            disable = data.data[i].count;
                        } else if (data.data[i].name == "emptycontainer") {
                            occupy = data.data[i].count;
                        }
                    }
                }

                var myChart = echarts.init(document.getElementById('chart2'));
                //myChart.showLoading({
                //    text: '正在加载中......',
                //    effect: 'whirling'
                //});
                var warecelloption = {
                    title: {
                        text: '仓位统计',
                        subtext: '单位:个',
                        left: '5'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        // orient: 'vertical',
                        // top: 'middle',
                        bottom: 5,
                        left: 'center',
                        data: ['空容器','有货', '锁定', '禁用', '空仓位']
                    },
                    toolbox: {
                        show: true,
                        feature: {
                            mark: { show: true },
                            dataView: { show: true, readOnly: false },
                            magicType: { show: true, type: ['pie', 'funnel'] },
                            restore: { show: true },
                            saveAsImage: { show: true }
                        }
                    },
                    series: [
                        {
                            name: '库位使用率',
                            type: 'pie',
                            radius: '50%',
                            center: ['50%', '50%'],
                            selectedMode: 'single',
                            data: [
                                { value: occupy, name: '空容器' },
                                { value: some, name: '有货' },
                                { value: lock, name: '锁定' },
                                { value: disable, name: '禁用' },
                                { value: empty, name: '空仓位' },

                            ],
                            label: {
                                normal: {
                                    position: 'outer',
                                    formatter: "{b}:{c}\n({d}%)",
                                    textStyle: {
                                        fontWeight: 'normal',
                                        fontSize: 14
                                    }
                                }
                            },
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };

                myChart.setOption(warecelloption);
                //myChart.hideLoading();
            },
            //error: function (XMLHttpRequest, textStatus, errorThrown) {
            //    layer.alert(errorThrown, { icon: 2, title: '提示' });
            //}
        });

        var receipt = 0;
        var shipment = 0;
        //图三:待执行出入库任务
        $.ajax({
            url: "/base/EchartsData/GetExceTaskInfo",
            data: {},
            type: "POST",
            dataType: "json",
            async: true,
            success: function (data) {
                //没有数据时提示
                //if (data.hasOwnProperty("type")) {
                //    dialogMsg(data.message, 0);
                //    return;
                //}
                for (var i = 0; i <= data.data.length; i++) {
                    if (typeof data.data[i] !== 'undefined') {
                        if (data.data[i].name == "100" || data.data[i].name == "200") {
                            receipt = receipt+1;
                        } else if (data.data[i].name == "300" || data.data[i].name == "400") {
                            shipment = shipment + 1;
                        } 
                        else {
                            receipt = receipt;
                            shipment = shipment;
                        }
                    }
                }

                var myChart = echarts.init(document.getElementById('chart3'));
                //myChart.showLoading({
                //    text: '正在加载中......',
                //    effect: 'whirling'
                //});
                var taskoption = {
                    title: {
                        text: '任务数量统计',
                        subtext: '单位:个',
                        x: 'center'
                    },
                    tooltip: {
                        formatter: "{a} <br/>{c} {b}"
                    },
                    toolbox: {
                        show: true,
                        feature: {
                            mark: { show: true },
                            restore: { show: true },
                            saveAsImage: { show: true }
                        }
                    },
                    series: [
                        {
                            name: '出库任务数:',
                            type: 'gauge',
                            center: ['70%', '55%'],    // 默认全局居中
                            z: 3,
                            min: 0,
                            max: 200,
                            splitNumber: 10,
                            radius: '95%',
                            axisLine: {            // 坐标轴线
                                lineStyle: {       // 属性lineStyle控制线条样式
                                    width: 10
                                }
                            },
                            axisTick: {            // 坐标轴小标记
                                length: 15,        // 属性length控制线长
                                lineStyle: {       // 属性lineStyle控制线条样式
                                    color: 'auto'
                                }
                            },
                            splitLine: {           // 分隔线
                                length: 20,         // 属性length控制线长
                                lineStyle: {       // 属性lineStyle(详见lineStyle)控制线条样式
                                    color: 'auto'
                                }
                            },
                            axisLabel: {
                                backgroundColor: 'auto',
                                borderRadius: 2,
                                color: '#eee',
                                padding: 3,
                                textShadowBlur: 2,
                                textShadowOffsetX: 1,
                                textShadowOffsetY: 1,
                                textShadowColor: '#222'
                            },
                            title: {
                                textStyle: {       // 其余属性默认使用全局文本样式,详见TEXTSTYLE
                                    fontWeight: 'bolder',
                                    fontSize: 15,
                                    fontStyle: 'italic'
                                }
                            },
                            detail: {
                                // 其余属性默认使用全局文本样式,详见TEXTSTYLE
                                //formatter: function (value) {
                                //    value = (value + '').split('.');
                                //    value.length < 2 && (value.push('00'));
                                //    return ('00' + value[0]).slice(-2)
                                //        + '.' + (value[1] + '00').slice(0, 2);
                                //},
                                fontWeight: 'bolder',
                                borderRadius: 3,
                                backgroundColor: '#444',
                                borderColor: '#aaa',
                                shadowBlur: 5,
                                shadowColor: '#333',
                                shadowOffsetX: 0,
                                shadowOffsetY: 3,
                                borderWidth: 2,
                                textBorderColor: '#000',
                                textBorderWidth: 2,
                                textShadowBlur: 2,
                                textShadowColor: '#fff',
                                textShadowOffsetX: 0,
                                textShadowOffsetY: 0,
                                fontFamily: 'Arial',
                                width: 80,
                                color: '#eee',
                                rich: {}
                            },
                            data: [{ value: shipment, name: '出库任务数' }]
                        },
                        {
                            name: '入库任务数:',
                            type: 'gauge',
                            center: ['28%', '55%'],    // 默认全局居中
                            radius: '95%',
                            min: 0,
                            max: 200,
                            //endAngle: 1,
                            splitNumber: 10,
                            axisLine: {            // 坐标轴线
                                lineStyle: {       // 属性lineStyle控制线条样式
                                    width: 10
                                }
                            },
                            axisTick: {            // 坐标轴小标记
                                length: 15,        // 属性length控制线长
                                lineStyle: {       // 属性lineStyle控制线条样式
                                    color: 'auto'
                                }
                            },
                            splitLine: {           // 分隔线
                                length: 20,         // 属性length控制线长
                                lineStyle: {       // 属性lineStyle(详见lineStyle)控制线条样式
                                    color: 'auto'
                                }
                            },
                            pointer: {
                                width: 5
                            },
                            title: {
                                offsetCenter: [0, '-30%'],       // x, y,单位px
                            },
                            detail: {
                                textStyle: {       // 其余属性默认使用全局文本样式,详见TEXTSTYLE
                                    fontWeight: 'bolder'
                                }
                            },
                            data: [{ value: receipt, name: '入库任务数' }]
                        }
                    ]
                };

                myChart.setOption(taskoption);
                //myChart.hideLoading();
                //计算待执行的任务数量
                var htask = document.getElementById("s6");
                htask.innerHTML = parseInt(receipt + shipment);
            },
            //error: function (XMLHttpRequest, textStatus, errorThrown) {
            //    layer.alert(errorThrown, { icon: 2, title: '提示' });
            //}
        });

        //图四:库存概况
        $.ajax({
            url: "/base/EchartsData/GetMaterielInfo",
            data: {},
            type: "POST",
            dataType: "json",
            async: true,
            success: function (data) {
                var selected = {};
                var legendData = [];
                var seriesData = [];
                for (var i = 0; i <= data.data.length && i < 10; i++) {
                    if (typeof data.data[i] !== 'undefined') {
                        legendData.push(data.data[i].name);
                        seriesData.push({
                            name: data.data[i].name,
                            value: data.data[i].value
                        });
                        selected[data.data[i].name] = i < 15;
                    }
                };

                //没有数据时提示
                //if (data.hasOwnProperty("type")) {
                //    dialogMsg(data.message, 0);
                //    return;
                //}
                var myChart = echarts.init(document.getElementById('chart4'));
                //myChart.showLoading({
                //    text: '正在加载中......',
                //    effect: 'whirling'
                //});
                var option = {
                    title: {
                        text: '库内物料库存数量',
                        subtext: '按物料分类',
                        x: 'left'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        type: 'scroll',
                        orient: 'vertical',
                        right: 10,
                        top: 20,
                        bottom: 20,
                        data: legendData,

                        selected: selected
                    },
                    series: [
                        {
                            name: '物料',
                            type: 'pie',
                            radius: '65%',
                            center: ['40%', '55%'],
                            selectedMode: 'single',
                            data: seriesData,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                myChart.setOption(option);
                //myChart.hideLoading();
                //计算库内物料品种数量
                var hm = document.getElementById("s5");
                hm.innerHTML = parseInt(data.data.length);
            },
            //error: function (XMLHttpRequest, textStatus, errorThrown) {
            //    layer.alert(errorThrown, { icon: 2, title: '提示' });
            //}
        });
    })
});