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

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

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