Nesting.js 8.88 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,
                type: "post",
                url: `/${areaName}/${tableName}/NestingCalculation`,
                success: function (result) {
                    if (sysU.successBefore(result)) return;
                    app.methods.initTableMiddle(result.Result.cutplanList);
                    app.methods.initTableRightDown(result.Result.notWorkOrderList);
                    $('table').attr({ "lay-size": "sm" });

                    layer.msg(result.Message, { icon: 6, 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,
                type: "post",
                url: `/${areaName}/${tableName}/SaveNestingProgramme`,
                success: function (result) {
                    if (sysU.successBefore(result)) return;
                    app.methods.initTableLeftDown();
                    $('table').attr({ "lay-size": "sm" });

                    layer.msg(result.Message, { icon: 6, shade: 0.4, time: 1000 });
                }
            };
            sysU.ajax(ajaxConfig);
        },

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

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

            $('table').attr({ "lay-size": "sm" });
        }
    }

    app = {
        data: {
            //工单
            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: "id", width: 80, title: "ID", templet: function (obj) { return obj.cuttingLength > 0 ? obj.id : "" } },
                { 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: "materialCode", width: 90, 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.toFixed(2)+"%" : "" } },
                { field: "oddmentsLength", width: 110, title: "余料长度(mm)", templet: function (obj) { return obj.oddmentsLength > 0 ? obj.oddmentsLength : "" } },
                { 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: "id", width: 80, title: "ID", templet: function (obj) { return obj.cuttingLength > 0 ? obj.id : "" } },
                { field: "cutMaterCode", width: 100, title: "物料编码" },
                { field: "cuttingLength", width: 120, title: "切割长度(mm)", templet: function (obj) { return obj.cuttingLength > 0 ? obj.cuttingLength : "" } }
            ]],
            tableObjRightDown: null,
            tableElemRightDown: "rightDownList",

            contentLeft: $(".content-left"),
            contentRight: $(".content-right"),
            selectOption: {
                //返回的数据 用于后续操作
                selectData: {

                }
            }
        },
        methods: {
            //工单
            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`,
                    height: "full-431",
                    page: false,
                    where: where,
                    tree: {
                        iconIndex:1,
                        isPidData: true,
                        idName: "keys",//父ID
                        pidName: "parentTypeId",//子ID
                        openName: "open"
                    },
                }
                app.data.tableObjLeftDown = u.initTable(opt);
            },
            //套料方案
            initTableMiddle: function (data) {

                let opt = {
                    cols: u.columnRecord(app.data.tableElemMiddle, app.data.colsMiddle),
                    elem: "#" + app.data.tableElemMiddle,
                    even: true,
                    //height: "full-96",
                    data: data,
                    limit: Number.MAX_VALUE,
                    tree: {
                        iconIndex:1,
                        isPidData: true,
                        idName: "keys",//父ID
                        pidName: "parentTypeId",//子ID
                        openName: "open"
                    },
                };
                app.data.tableObjMiddle = table.render(opt);
               
            },
            //未套料工单
            initTableRightDown: function (data) {

                let opt = {
                    cols: u.columnRecord(app.data.tableElemRightDown, app.data.colsRightDown),
                    elem: "#" + app.data.tableElemRightDown,
                    even: true,
                    height: "full-431",
                    data: data,
                    limit: Number.MAX_VALUE,
                    tree: {
                        iconIndex: 1,
                        isPidData: true,
                        idName: "keys",//父ID
                        pidName: "parentTypeId",//子ID
                        openName: "open"
                    },
                }
                app.data.tableObjRightDown = table.render(opt);
            },

            initFrom: function () {
                var height = u.getFrameHeight() - 60;
                app.data.contentLeft.height(height);
                app.data.contentRight.height(height);
            }
        },
        registerEvent: function () {
            system.queryExtend();
        },
        init: function () {
            app.methods.initFrom();
            app.methods.initTableLeftDown();
            app.registerEvent();
        }
    };
    app.init();
});