machiningGantt.js 6.9 KB
Newer Older
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
var objectKey = "";
var objectId = "";

layui.config({
    base: basePath,
    version: skyeyeVersion
}).extend({
    window: 'js/winui.window'
}).define(['window', 'jquery', 'winui', 'form', 'laydate'], function (exports) {
    winui.renderColor();
    var $ = layui.$,
        form = layui.form,
        layer = layui.layer,
        laydate = layui.laydate;
    objectKey = GetUrlParam("objectKey");
    objectId = GetUrlParam("objectId");
    if (isNull(objectKey) || isNull(objectId)) {
        winui.window.msg("请传入适用对象信息", {icon: 2, time: 2000});
        return false;
    }

    // 根据供应商id获取所有审批通过之后的里程碑列表
    let milestoneList = [];
    AjaxPostUtil.request({url: sysMainMation.erpBasePath + "queryMachinById", params: {id: objectId}, type: 'json', method: 'GET', callback: function (json) {
            $("#milestoneId").html(getDataUseHandlebars(getFileContent('tpl/template/select-option-must.tpl'), json));
            milestoneList = json.bean.machinChildList;
            console.log(1,json)
            console.log(2,milestoneList)

            // var authPermission = teamObjectPermissionUtil.checkTeamBusinessAuthPermission(objectId, 'taskAuthEnum');
            // var btnStr = `<div style="" class="type-group" id="type">`;
            // var firstBtn = true;
            // if (authPermission['list']) {
            //     var defaultClassName = firstBtn ? 'plan-select' : '';
            //     firstBtn = false;
            //     btnStr += `<button type="button" class="layui-btn layui-btn-primary type-btn ${defaultClassName}" data-type="list" table-id="messageTable"><i class="layui-icon"></i>所有任务</button>`
            // }
            // if (authPermission['myExecute']) {
            //     var defaultClassName = firstBtn ? 'plan-select' : '';
            //     firstBtn = false;
            //     btnStr += `<button type="button" class="layui-btn layui-btn-primary type-btn ${defaultClassName}" data-type="myExecute" table-id="messageTable"><i class="layui-icon"></i>我执行的任务</button>`
            // }
            // if (authPermission['myCreate']) {
            //     var defaultClassName = firstBtn ? 'plan-select' : '';
            //     btnStr += `<button type="button" class="layui-btn layui-btn-primary type-btn ${defaultClassName}" data-type="myCreate" table-id="messageTable"><i class="layui-icon"></i>我创建的任务</button>`
            // }
            // btnStr += `</div>`;
            // $(".txtcenter").before(btnStr);

            matchingLanguage();
            form.render();
            renderPanel();
            render();
        }});

    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");  //使用中文
    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) {
                console.log(88,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
                });
            }});
    }

    $("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', {});
});