machiningGantt.js 4.9 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

doc_wei's avatar
doc_wei 已提交
13
    let noteList = [];
L
LAPTOP-NDCM9L6Q\王丽雅 已提交
14 15
    // 根据id查询加工单信息
    AjaxPostUtil.request({url: sysMainMation.erpBasePath + "queryMachinForGanttById", params: {id: id}, type: 'json', method: 'GET', callback: function (json) {
16 17 18
        matchingLanguage();
        form.render();
        renderPanel();
L
LAPTOP-NDCM9L6Q\王丽雅 已提交
19

doc_wei's avatar
doc_wei 已提交
20 21
        gantt.config.start_date = new Date(json.bean.mathinTime.start_time);
        gantt.config.end_date = new Date(json.bean.mathinTime.end_time);
22 23
        gantt.clearAll();  //清空缓存
        // 解析
doc_wei's avatar
doc_wei 已提交
24
        noteList = json.bean.node;
25 26 27 28 29
        gantt.parse({
            data: json.bean.node,
            links: json.bean.link
        });
    }});
30 31

    function renderPanel() {
doc_wei's avatar
doc_wei 已提交
32
        document.getElementById('device_load').style.cssText = 'height:' + $(window).height() + 'px';
33 34 35 36 37 38 39 40 41 42 43 44
    }
    $(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;
doc_wei's avatar
doc_wei 已提交
45 46 47
    gantt.config.columns = [
    {name: "wbs", label: "序号", width: 50, template: gantt.getWBSCode},
    {
48 49 50
        name: "text",
        label: "产品",
        width: 200,
doc_wei's avatar
doc_wei 已提交
51
        align: "left",
52 53
        tree: true,
        resize: true
doc_wei's avatar
doc_wei 已提交
54 55 56 57 58 59 60 61 62 63 64 65
    }, {
        name: "types",
        label: "类型",
        width: 60,
        align: "center",
        resize: true,
        template: function (item) {
            if (item.types == "project") {
                return "<span style='color: #009688; font-weight: bold;'>产品</span>";
            }
            return "<span style='color: #FFB800;'>工序</span>";
        }
66 67 68 69 70 71
    }, {
        name: "start_date",
        label: "开始日期",
        width: 100,
        align: "center",
        resize: true
doc_wei's avatar
doc_wei 已提交
72 73 74 75 76 77
    }, {
        name: "end_date",
        label: "结束日期",
        width: 100,
        align: "center",
        resize: true
78 79 80 81 82 83 84
    }, {
        name: "duration",
        label: "持续时间",
        width: 100,
        align: "center",
        resize: true
    }];
doc_wei's avatar
doc_wei 已提交
85
    // 是否可以编辑
86 87 88 89 90 91 92 93 94 95 96
    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;
    });
doc_wei's avatar
doc_wei 已提交
97 98 99 100 101 102 103
    gantt.attachEvent("onTaskClick", function(id, e){
        // 这里的代码会在节点被点击时执行
        // id 参数是被点击的任务的ID
        // e 参数是点击事件的事件对象
        let item = getInPoingArr(noteList, "id", id, null);
        if (item.types != "project") {
            console.log(item)
104
            _openNewWindows({
105
                url: "../../tpl/departmentMachining/arrange.html?id=" + id,
106 107 108 109
                title: "车间任务安排",
                pageId: "workshopTaskArrangement",
                area: ['90vw', '90vh'],
                callBack: function (refreshCode) {
110 111
                    winui.window.msg(systemLanguage["com.skyeye.successfulOperation"][languageType], {icon: 1, time: 2000});
                    loadTable();
112
                }});
doc_wei's avatar
doc_wei 已提交
113 114 115 116
        }
        // 返回true以允许默认行为继续,返回false可以阻止默认行为
        return true;
    });
117 118 119 120 121 122 123 124 125
    gantt.config.show_tasks_outside_timescale = true;
    gantt.plugins({
        auto_scheduling: true,  //自动排程
        tooltip: true     //提示信息
    });
    // 样式
    gantt.config.layout = {
        css: "gantt_container",
        cols: [{
doc_wei's avatar
doc_wei 已提交
126
            width: 500,
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
            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");  //使用中文

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