machiningGantt.js 5.1 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
    var state = GetUrlParam("state");
13

doc_wei's avatar
doc_wei 已提交
14
    let noteList = [];
doc_wei's avatar
doc_wei 已提交
15 16 17 18 19 20 21
    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\王丽雅 已提交
22

doc_wei's avatar
doc_wei 已提交
23 24 25 26 27 28 29 30 31 32 33
            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
            });
        }});
    }
34 35

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