Ebom.js 14.7 KB
var action = null,
    app = null;

layui.config({
    base: "/js/",
    version: 22
}).use(['system', 'tableSelect', "jqprint"], function () {
    var form = layui.form,
        $ = layui.jquery,
        system = layui.system,
        u = new system.u(), 
        table = layui.table,
        areaName = 'configure',
        sendDataDesc = null,
        tableName = 'BaseEbomHeader';

    action = {
        rowData: null,
        addOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${tableName}/Ins`,
                title: "  (产品和工艺的绑定[生产设置=>工艺路线=>按钮工艺产品])",
                submit: "submit(fromAdd)"
            }
            return options;
        },

        addOptionsDesc: function () {
            var options = {
                fromId: "#modifyFormDesc form",
                url: `/${areaName}/${tableName}/InsDesc`,
                content: $('#modifyFormDesc'),
                submit: "submit(fromAddDesc)"
            }

            return options;
        },

        editOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${tableName}/Upd`,
                title: "  (产品和工艺的绑定[生产设置=>工艺路线=>按钮工艺产品])",
                submit: "submit(fromUpdate)"
            }
            return options;
        },

        editOptionsDesc: function () {
            var options = {
                fromId: "#modifyFormDesc form",
                url: `/${areaName}/${tableName}/UpdDesc`,
                content: $('#modifyFormDesc'),
                submit: "submit(fromUpdateDesc)"
            }
            return options;
        },

        deleteOptions: function () {
            var options = {
                url: `/${areaName}/${tableName}/DelByIds`,
                keyId: "id",
                titleConfirmDelete: "尽量不要删除,可以选择禁用(对应明细数据也将被删除)?"
            }
            return options;
        },
        qcCodePrintOptions: () => {
            var options = {
                qrCodeValueKey: "productCode",
                //【qrcodeElem】 是要修改的内容其他的不要变 id 的变量值不需要变 
                customFn: (sysU, parameter, selectData) => {
                    for (var i = 0; i < selectData.length; i++) {
                        var qcCodeValue = selectData[i][parameter.qrCodeValueKey],
                            qrcodeId = "qrcode" + i,
                            qrcodeHeadId = "qrcodeHead" + i,
                            qrcodeElem = `<div  id="${qrcodeHeadId}"  class="qcCode" >
                                             <div id="${qrcodeId}" ></div>
                                             <div class="qcCode_lable">
                                                <label>产品编码:</label><label>${qcCodeValue}</label>
                                            </div>
                                             <div class="qcCode_lable">
                                                <label>产品名称:</label><label>${selectData[i].productName}</label>
                                             </div>
                                             <div class="qcCode_lable">
                                                <label>工艺路线编码:</label><label>${selectData[i].processCode}</label>
                                             </div>
                                          </div>`;
                        sysU.qRCodeWirtDom(parameter, qrcodeElem, qrcodeId, qcCodeValue);
                    }
                    return true;
                }
            }
            return options;
        },
        deleteOptionsDesc: function () {
            var options = {
                url: `/${areaName}/${tableName}/DelByIdsDesc`,
                keyId: "id",
                titleConfirmDelete: "尽量不要删除,可以选择禁用?"
            }
            return options;
        },

        exportOptions: function () {
            var options = {
                fromId: "listForm",
                url: `/${areaName}/${tableName}/Export`,
                isDefault: true,
                excelCols: {
                    head: app.data.cols,
                    body: app.data.colsDesc
                }
            }
            return options;
        },


        queryOptions: function () {
            var options = {
                resetFrom: "form[lay-filter=listForm]",
                fromId: "listForm",
                urlExport: `/${areaName}/${tableName}/Export`,
                urlQuery: `/${areaName}/${tableName}/Load`,
                mainTable: app.data.tableIns
            }
            return options;
        },

        uploadOptions: function () {
            var options = {
                url: `/${areaName}/${tableName}/Import`
            }
            return options;
        },

        rowClickOptions: function () {
            var options = {
                isDefault: true,
                targetTableId: app.data.tableElem,
                tabfilter: "tableTabBody",
                tabId: 2,
                customFn: app.methods.initTableDesc
            }
            return options;
        },

        addBefore: function (callBack) {
            u.initSelect(app.data.selectOption, callBack);
        },

        addBeforeDesc: function (callBack) {
            u.initSelect(app.data.selectOption, () => {
                callBack();
                $("input[name=bomHeaderId]").val(sendDataDesc.id);
            });
        },

        addSaveBefore: function (data, callBack) {
            if (callBack != null) callBack();
        },

        addSaveBeforeDesc: function (data, callBack) {
            if (callBack != null) callBack();
        },

        editBefore: function (data, callBack) {
            //先执行下拉框加载后,回调执行公共方法
            u.initSelect(app.data.selectOption, () => {
                callBack();
                form.val("modifyForm", data);
            });
        },

        editBeforeDesc: function (data, callBack) {
            u.initSelect(app.data.selectOption, () => {
                callBack();
                form.val("modifyFormDesc", data);
                $("input[name=bomHeaderId]").val(sendDataDesc.id);
            });
        },

        editSaveBefore: function (data, callBack) {
            if (callBack != null) callBack();
        },

        editSaveBeforeDesc: function (data, callBack) {
            if (callBack != null) callBack();
        },
        checkboxMethod: function (obj) {
            let pageFlag = "".GetUrlParam("page"),
                processHeadKeys = "".GetUrlParam("processHeadKeys"),
                lineCode = "".GetUrlParam("lineCode"),
                processCode = "".GetUrlParam("processCode"),
                processName = "".GetUrlParam("processName");
            if (pageFlag == "ProcessRoute") {
                var checkBoxData = {
                    processCode: processCode,
                    processName: processName,

                    processHeadKeys: processHeadKeys,
                    lineCode: lineCode,
                    productCode: null,
                    checkeds: obj.checked,
                };
                if (obj.type == "all") {
                    checkBoxData.productCode = u.getTableAllData(app.data.tableElem).GetArrValue("productCode");
                } else {
                    checkBoxData.productCode = obj.data.productCode;
                }
                if (checkBoxData.productCode == null || checkBoxData.productCode == "") {
                    layer.alert("checkboxMethod:产品【productCode】为空,请重新关闭后再操作,反复出现请联系管理员", { icon: 2, shadeClose: true, title: "提示" });
                    return false;
                }
                var ajaxConfig = {
                    data: checkBoxData,
                    url: `/${areaName}/${tableName}/OperateProduct`,
                    success: function (result) {
                        u.refreshTable(app, u, sendDataDesc, app.data.tableElem);
                        if (u.successBefore(result)) return false;
                        layer.msg(result.Message);
                    }
                };
                u.ajax(ajaxConfig);
            }

        },
        btnAddBom: function (sU, toolbarId, obj) {
            var data = action.rowData;
            if (data == null) {
                layer.msg("请选择一行数据新增或者编辑产品物料信息");
                return false;
            }
            var proHeadKeys = data.keys

            var materialCode = '';
            var data = sU.getTableAllData(app.data.tableElemDesc);  
            if (data.length > 0) materialCode = data.map(x => { return x.materialCode }).join()

            var height = 600;
            sU.openPage({
                area: ["1100px", height +"px"],
                type: 2,
                endCallBackFn: function () {
                    console.log("endCallBackFn");
                    action.actionSuccess(app.data.tableElemDesc);
                },
                content: `/material/Material/NewIndex?menuFlag=-2&selectColKeyCustom=materialCode&page=ProductDesc&proHeadKeys=${proHeadKeys}&materialCode=${materialCode}&height=${height}` ,
            })
        },


        //所有动作成功之后
        actionSuccess: (falg, curr = 1) => {
            debugger;
            u.refreshTable(app, u, sendDataDesc, falg);
        },
    }

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: 'id', width: 150, hide: true, title: 'Id' },
                { field: 'itemCode', width: 120, title: '产品编码' },
                { field: 'children', width: 120, title: '子料编码' },

                { field: 'createTime', width: 150, title: '建立时间' },
                { field: 'createBy', width: 150, title: '建立者' },
                { field: 'updateTime', width: 150, title: '更新时间' },
                { field: 'updateBy', width: 150, title: '更新者' }
            ]],
            colsDesc: [[
                { checkbox: true, fixed: true },
                { field: 'id', width: 150, hide: true, title: 'Id' }, 
                { field: 'bomHeaderId', width: 150, hide: true, title: '主表id' }, 
                
                { field: "materialCode", width: 120, title: "物料编号" },
                { field: "materialName", width: 150, title: "物料名称" },
                
                { field: "materialSpec", width: 150, title: "品名规格" },
                { field: "unit", width: 100, title: "单位" },
                { field: "qty", width: 150, title: "数量" },

                { field: 'createTime', width: 150, title: '建立时间' }, 
                { field: 'createBy', width: 150, title: '建立者' }

            ]],
            urlTable: `/${areaName}/${tableName}/Load`,
            tableIns: null,
            tableInsDesc: null,
            tableElem: "mainList",
            tableElemDesc: "mainListDesc",
         
            selectOption: {
                processCode: {
                    SelType: "FromUrl",
                    SelFrom: "/HomeRedis/GetBaseInfoByKey?key=base_process_route_head",
                    SelLabel: "processName",
                    SelValue: "processCode",
                    Dom: [$("[name='processCode']")]
                },
                line: {
                    SelType: "FromUrl",
                    SelFrom: "/HomeRedis/GetBaseInfoByKey?key=base_line",
                    SelLabel: "LineName",
                    SelValue: "LineCode",
                    Dom: [$("[name='lineCode']")]
                },
                //返回的数据 用于后续操作
                selectData: {

                }
            }
        },
        methods: {
            initTable: function () {
                var pageFlag = "".GetUrlParam("page");
                let options = {
                    elem: "#" + app.data.tableElem,
                    url: `/${areaName}/${tableName}/Load`,
                    cols: u.columnRecord(app.data.tableElem, app.data.cols),
                    toolbar: pageFlag != "ProductionOrder" ? '#toolbarTable' : "",
                    //toolbar: '#toolbarTable',
                    height: "full-56",
                    where: { keyword: pageFlag == "ProcessRoute" || pageFlag == "ProductionOrder" ? "no_process_product_rel" : pageFlag },
                    doneExtend: function (res, obj) {
                        //工艺产品的实时刷新选中
                        var processCode = "".GetUrlParam("processCode");
                        if (pageFlag == "ProcessRoute") {
                            var ajaxConfig = {
                                data: { processCode: processCode },
                                url: `/${areaName}/${tableName}/GetProductByProcessCode`,
                                success: function (result) {
                                    if (u.successBefore(result)) return false;
                                    var targetArrValue = result.Result.map(function (e) { return e.productCode; });
                                    var selectColKey = "".GetUrlParam("selectColKeyCustom");
                                    u.SetTableCheck(targetArrValue, res, selectColKey, app.data.tableElem);
                                }
                            };
                            u.ajax(ajaxConfig);
                        } else if (pageFlag == "ProductionOrder") {
                            u.SetTableCheck("".GetUrlParam("productCode"), res, "".GetUrlParam("selectColKeyCustom"), app.data.tableElem);
                        }
                    }
                }
                app.data.tableIns = u.initTable(options);
            },

            initTableDesc: function (obj) {
                var pageFlag = "".GetUrlParam("page");
                sendDataDesc = { id: obj.data.id }
                let opt = {
                    cols: u.columnRecord(app.data.tableElemDesc, app.data.colsDesc),
                    elem: "#" + app.data.tableElemDesc,
                    url: `/${areaName}/${tableName}/LoadDesc`,
                    toolbar: pageFlag != "ProductionOrder" ? '#toolbarTableDesc' : "",
                    //toolbar: '#toolbarTableDesc',
                    height: "full-56",
                    where: sendDataDesc
                }
                app.data.tableInsDesc = u.initTable(opt);
            },

            initFrom: function () {
 
            }
        },


        registerEvent: function () {

        },
        init: function () {
            app.methods.initTable();
            app.registerEvent();
            app.methods.initFrom();
        }
    };
    app.init();

});