machiningGantt.js 5.7 KB
Newer Older
1 2 3 4 5 6 7 8 9

layui.config({
    base: basePath,
    version: skyeyeVersion
}).extend({
    window: 'js/winui.window'
}).define(['window', 'jquery', 'winui', 'form', 'laydate'], function (exports) {
    winui.renderColor();
    var $ = layui.$,
L
LAPTOP-NDCM9L6Q\王丽雅 已提交
10 11
        form = layui.form;
    var id = GetUrlParam("id");
12 13


L
LAPTOP-NDCM9L6Q\王丽雅 已提交
14 15 16
    // 根据id查询加工单信息
    AjaxPostUtil.request({url: sysMainMation.erpBasePath + "queryMachinForGanttById", params: {id: id}, type: 'json', method: 'GET', callback: function (json) {
            console.log(json)
17 18 19
            matchingLanguage();
            form.render();
            renderPanel();
L
LAPTOP-NDCM9L6Q\王丽雅 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
            // render();

            gantt.clearAll();  //清空缓存
            let nodeList = json.bean.node;
            if (isNull(nodeList) || nodeList.length == 0) {
                return;
            }
            $.each(nodeList, function (i, item) {
                item.start_date = new Date(item.start_date);
                item.end_date = new Date(item.end_date);
            });
            let linkList = json.bean.link;
            if (isNull(linkList) || linkList.length == 0) {
                linkList = [];
            }
            // 解析
            gantt.parse({
                data: nodeList,
                links: linkList
            });

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
        }});

    function renderPanel() {
        document.getElementById('device_load').style.cssText = 'height:' + ($(window).height() - 140) + 'px';
    }
    $(window).resize(function () {
        renderPanel();
    });

    // 时间格式
    gantt.config.date_format = "%Y-%m-%d";
    gantt.config.scales = [
        {unit: "year", step: 1, format: "%Y"},
        {unit: "day", step: 1, date: "%m-%d"}
    ];
    gantt.config.reorder_grid_columns = true;
    gantt.config.columns = [{
        name: "text",
        label: "产品",
        width: 200,
        align: "center",
        tree: true,
        resize: true
    }, {
        name: "start_date",
        label: "开始日期",
        width: 100,
        align: "center",
        resize: true
    }, {
        name: "duration",
        label: "持续时间",
        width: 100,
        align: "center",
        resize: true
    }];
    gantt.config.readonly = true;
    gantt.config.row_height = 40;
    gantt.config.scale_height = 50;
    gantt.config.drag_move = false;
    gantt.config.drag_resize = false;
    gantt.config.sort = true;
    gantt.config.show_quick_info = false;
    //  关闭点击事件
    gantt.attachEvent("onTaskDblClick", function (id, e) {
        return false;
    });
    gantt.config.show_tasks_outside_timescale = true;
    gantt.plugins({
        auto_scheduling: true,  //自动排程
        tooltip: true     //提示信息
    });
    // 样式
    gantt.config.layout = {
        css: "gantt_container",
        cols: [{
            width: 400,
            min_width: 300,
            rows: [
                {
                    view: "grid",
                    scrollX: "gridScroll",
                    scrollable: true,
                    scrollY: "scrollVer"
                },
                {view: "scrollbar", id: "gridScroll", group: "horizontal"}
            ]
        },
            {resizer: true, width: 1},
            {
                rows: [
                    {
                        view: "timeline",
                        scrollX: "scrollHor",
                        scrollY: "scrollVer"
                    },
                    {
                        view: "scrollbar",
                        id: "scrollHor",
                        group: "horizontal"
                    }
                ]
            },
            {view: "scrollbar", id: "scrollVer"}]
    };

    gantt.init("device_load");

    gantt.i18n.setLocale("cn");  //使用中文
L
LAPTOP-NDCM9L6Q\王丽雅 已提交
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
    // function render() {
    //     let milestoneId = $("#milestoneId").val();
    //     if (isNull(milestoneId)) {
    //         winui.window.msg("请选择产品", {icon: 2, time: 2000});
    //         return false;
    //     }
    //     let params = {
    //         id: objectId,
    //         // objectKey: objectKey,
    //         // holderId: milestoneId,
    //         // type: $("#type .plan-select").attr("data-type")
    //     };
    //     var tem = getInPoingArr(milestoneList, "id", milestoneId, null);
    //     gantt.config.start_date = new Date(tem.startTime);
    //     gantt.config.end_date = new Date(tem.endTime);
    //     console.log(999)
    //     AjaxPostUtil.request({url: sysMainMation.erpBasePath + "queryMachinForGanttById", params: params, type: 'json', method: 'GET', callback: function (json) {
    //             gantt.clearAll();  //清空缓存
    //             let nodeList = json.bean.node;
    //             if (isNull(nodeList) || nodeList.length == 0) {
    //                 return;
    //             }
    //             $.each(nodeList, function (i, item) {
    //                 item.start_date = new Date(item.start_date);
    //                 item.end_date = new Date(item.end_date);
    //             });
    //             let linkList = json.bean.link;
    //             if (isNull(linkList) || linkList.length == 0) {
    //                 linkList = [];
    //             }
    //             // 解析
    //             gantt.parse({
    //                 data: nodeList,
    //                 links: linkList
    //             });
    //         }});
    // }
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

    $("body").on("click", ".type-btn", function (e) {
        $(this).parent().find('.type-btn').removeClass("plan-select");
        $(this).addClass("plan-select");
        render();
    });

    form.on('submit(formSearch)', function (data) {
        if (winui.verifyForm(data.elem)) {
            render();
        }
        return false;
    });

    exports('machiningGantt', {});
});