Nesting.js 11.3 KB
let customImportFileName = ["form", "element", "jquery", "treeTable", "laypage"],
    action = null,
    app = null;
layui.config({
    base: "/js/",
    version: 1222
}).use(['ztree', 'system'], function () {
    var form = layui.form,
        $ = layui.jquery,
        element = layui.element,
        table = layui.table,
        system = layui.system,
        sendData = {},
        u = new system.u(),
        areaName = "Material",
        tableName = "Nesting",
        app = null;

    action = {
        //套料计算
        BtnNestingCalculation: function (sysU, toolbarId, obj) {
            var Ids = [];
            $("input:checked").each(function () {
                var id = $(this).val();
                if (id != undefined && id.length > 0&&id!="on")
                    Ids.push(id);
            })
            sendData.cutDetailIds = Ids.join(",");
            var ajaxConfig = {
                data: sendData,
                url: `/${areaName}/${tableName}/NestingCalculation`,
                success: function (result) {
                    if (sysU.successBefore(result)) return;
                    app.methods.initTableMiddle(result.Result.cutplanList);
                    app.methods.initTableRightDown(result.Result.notWorkOrderList);
                    app.methods.initTableRightUp(result.Result.notInventoryList);
                    layer.msg(result.Message, { icon: sysU.config.iconoOk, shade: 0.4, time: 1000 });
                }
            };
            sysU.ajax(ajaxConfig);
        },

        //保存套料方案
        BtnSaveCutPlan: function (sysU, toolbarId, obj) {
            var Ids = [];
            $("input:checked").each(function () {
                var id = $(this).val();
                if (id != undefined && id.length > 0 && id != "on")
                    Ids.push(id);
            })
            sendData.cutDetailIds = Ids.join(",");
            var ajaxConfig = {
                data: sendData,
                url: `/${areaName}/${tableName}/SaveNestingProgramme`,
                success: function (result) {
                    if (sysU.successBefore(result)) return;
                    app.methods.initTableLeftDown();
                    app.methods.initTableLeftUp();
                    layer.msg(result.Message, { icon: sysU.config.iconoOk, shade: 0.4, time: 1000 });
                }
            };
            sysU.ajax(ajaxConfig);
        },

        BtnRefresh: function () {
            app.methods.initTableLeftDown();
            app.methods.initTableLeftUp();
            app.methods.initTableMiddle([]);
            app.methods.initTableRightDown([]);
            app.methods.initTableRightUp([]);
        },

        //所有动作成功之后
        actionSuccess: (falg) => {
   
        }
    }

    app = {
        data: {
            colsLeftUp: [[
                { field: "id", width: 130, title: "ID" },
                { field: "pipeSN", width: 140, title: "管材SN" },
                { field: "materialCode", width: 130, title: "物料编码" },
                { field: "pipeLength", width: 130, title: "管材长度(mm)" }
            ]],
            tableObjLeftUp: null,
            tableElemLeftUp: "leftUpList",
            //工单
            colsLeftDown: [[
                { type: "checkbox", isShow: function (obj) { return obj.cuttingLength > 0 ? false : true }, value: function (obj) { return obj.id } },
                { field: "workOrderCode", width: 150, title: "工单号" },
                { field: "keys", width: 100, title: "keys", hide: true}, 

                { field: "parentTypeId", width: 100, title: "父Key", hide: true, },
                { field: "nowWorkCenterName", width: 80, title: "工作中心" },
                { field: "cutMaterCode", width: 100, title: "物料编码" },
                { field: "cuttingLength", width: 120, title: "切割长度(mm)", templet: function (obj) { return obj.cuttingLength > 0 ? obj.cuttingLength : "" } }
            ]],
            tableObjLeftDown: null,
            tableElemLeftDown: "leftDownList",

            //套料数据
            colsMiddle: [[
                { field: "nowWorkCenterName", width: 150, title: "工作中心" },
                { field: "materialCode", width: 150, title: "物料编码" },
                { field: "pipeLength", width: 110, title: "管材长度(mm)", templet: function (obj) { return obj.pipeLength > 0 ? obj.pipeLength : "" } },
                { field: "lossCount", width: 80, title: "利用率%", templet: function (obj) { return obj.lossCount > 0 ? (obj.lossCount*100).toFixed(2)+"%" : "" } },
                { field: "oddmentsLength", width: 110, title: "余料长度(mm)" },
                { field: "keys", width: 100, title: "keys", hide: true, noExel: true },

                { field: "parentTypeId", width: 100, title: "父Key", hide: true, },
                { field: "id", width: 80, title: "ID", templet: function (obj) { return obj.id > 0 ? obj.id : "" } },
                { field: "iwpNo", width: 150, title: "工单号" },
                { field: "barCode", width: 80, title: "追踪码" },
                { field: "cuttingLength", width: 120, title: "切割长度(mm)", templet: function (obj) { return obj.cuttingLength > 0 ? obj.cuttingLength : "" } }

            ]],
            tableObjMiddle: null,
            tableElemMiddle: "middleList",

            //未套料工单
            colsRightDown: [[
                { field: "workOrderCode", width: 150, title: "工单号" },
                { field: "keys", width: 100, title: "keys", hide: true },

                { field: "parentTypeId", width: 100, title: "父Key", hide: true, },
                { field: "nowWorkCenterName", width: 80, title: "工作中心" },
                { field: "cutMaterCode", width: 100, title: "物料编码" },
                { field: "cuttingLength", width: 120, title: "切割长度(mm)", templet: function (obj) { return obj.cuttingLength > 0 ? obj.cuttingLength : "" } }
            ]],
            tableObjRightDown: null,
            tableElemRightDown: "rightDownList",

            colsRightUp: [[
                { field: "id", width: 100, title: "ID" },
                { field: "pipeSN", width: 110, title: "管材SN" },
                { field: "materialCode", width: 110, title: "物料编码" },
                { field: "pipeLength", width: 120, title: "管材长度(mm)" }
            ]],
            tableObjRightUp: null,
            tableElemRightUp: "rightUpList",
            selectOption: {
                //返回的数据 用于后续操作
                selectData: {

                }
            }
        },
        methods: {
            //库存管材
            initTableLeftUp: function (options) {
                var planTime = $("#planTime").val();
                var where = { planTime: planTime };
                if (options != undefined) $.extend(where, options);
                let opt = {
                    cols: u.columnRecord(app.data.tableElemLeftUp, app.data.colsLeftUp),
                    elem: "#" + app.data.tableElemLeftUp,
                    url: `/${areaName}/${tableName}/GetMaterialInfo`,
                    height: "full-445",
                    page: false,
                    where: where,
                };
                app.data.tableObjLeftUp = u.initTable(opt);
            },
            //工单
            initTableLeftDown: function (options) {
                var planTime = $("#planTime").val();
                var where = { planTime: planTime };
                //if (options != undefined) $.extend(where, options);
                let opt = {
                    cols: u.columnRecord(app.data.tableElemLeftDown, app.data.colsLeftDown),
                    elem: "#" + app.data.tableElemLeftDown,
                    url: `/${areaName}/${tableName}/GetCutterInfo`,
                    page: false,
                    where: where,
                    tree: {
                        iconIndex: 1,//需要从0开始 ,1是第二列
                        isPidData: true, //点击是否可以收缩
                        idName: "keys",//父ID 该值不能为空也不能相同, 无法出现树结构
                        pidName: "parentTypeId",//子ID
                        openName: "open"
                    },
                    doneExtend: function () {
                        //节点是否全部展开
                        // app.data.tableObjLeftDown.expandAll();
                        setTimeout(() => {
                            layer.closeAll()
                        }, 800)
                    }
                }
                app.data.tableObjLeftDown = u.initTable(opt);
            },
            //套料方案
            initTableMiddle: function (data) {
                let opt = {
                    cols: u.columnRecord(app.data.tableElemMiddle, app.data.colsMiddle),
                    elem: "#" + app.data.tableElemMiddle,
                    data: data,
                    page: false,
                    tree: {
                        iconIndex:0,
                        isPidData: true,
                        idName: "keys",//父ID
                        pidName: "parentTypeId",//子ID
                        openName: "open"
                    },
                    doneExtend: function () { 
                        setTimeout(() => {
                            layer.closeAll()
                            //if (app.data.tableObjMiddle != null) app.data.tableObjMiddle.expandAll()
                        }, 800)
                    }
                };
                app.data.tableObjMiddle = u.initTable(opt) ;
               
            },
            //未套料工单
            initTableRightDown: function (data) {
                let opt = {
                    cols: u.columnRecord(app.data.tableElemRightDown, app.data.colsRightDown),
                    elem: "#" + app.data.tableElemRightDown,
                    data: data,
                    page: false,
                    tree: {
                        iconIndex: 0,
                        isPidData: true,
                        idName: "keys",//父ID
                        pidName: "parentTypeId",//子ID
                        openName: "open"
                    },
                    doneExtend: function () {
                        setTimeout(() => {
                            layer.closeAll()
                            //if (app.data.tableObjRightDown != null) app.data.tableObjRightDown.expandAll()
                        }, 800)
                    }
                }
                app.data.tableObjRightDown = u.initTable(opt);
            },
            //余料
            initTableRightUp: function (data) {
                let opt = {
                    cols: u.columnRecord(app.data.tableElemRightUp, app.data.colsRightUp),
                    elem: "#" + app.data.tableElemRightUp,
                    even: true,
                    height: "full-445",
                    data: data,
                    limit: Number.MAX_VALUE
                }
                app.data.tableObjRightUp = table.render(opt);
            },

            initFrom: function () {
            }
        },
        registerEvent: function () {
            system.queryExtend();
        },
        init: function () {
            app.methods.initFrom();
            app.methods.initTableLeftDown();
            app.methods.initTableLeftUp();
            app.registerEvent();
        }
    };
    app.init();
});