var insTb; 
 | 
var admin; 
 | 
var areas; 
 | 
var matXmSelect; 
 | 
var printContent = []; 
 | 
layui.config({ 
 | 
    base: baseUrl + "/static/layui/lay/modules/" 
 | 
}).extend({ 
 | 
    dropdown: 'dropdown/dropdown', 
 | 
}).use(['form','treeTable', 'admin', 'xmSelect', 'dropdown', 'element','layer'], function() { 
 | 
    var $ = layui.jquery; 
 | 
    var layer = layui.layer; 
 | 
    var form = layui.form; 
 | 
    admin = layui.admin; 
 | 
    var treeTable = layui.treeTable; 
 | 
    var xmSelect = layui.xmSelect; 
 | 
    var tbDataList = []; 
 | 
  
 | 
    insTb = treeTable.render({ 
 | 
        elem: '#node', 
 | 
        url: baseUrl+'/node/list/tree/auth', 
 | 
        headers: {token: localStorage.getItem('token')}, 
 | 
        height: 'full-200', 
 | 
        toolbar: '#toolbar', 
 | 
        treeLinkage:false, 
 | 
        tree: { 
 | 
            iconIndex: 2,           // 折叠图标显示在第几列 
 | 
            isPidData: true,        // 是否是id、pid形式数据 
 | 
            idName: 'id',           // id字段名称 
 | 
            pidName: 'parentId'     // pid字段名称 
 | 
        }, 
 | 
        cols: [[ 
 | 
            {type: 'checkbox'}, 
 | 
            {type: 'numbers'} 
 | 
            ,{field: 'name', align: 'left',title: '编号/名称', minWidth: 150} 
 | 
            // ,{field: 'uuid', left: 'center',title: '编号/名称', minWidth: 150} 
 | 
            ,{field: 'type$', align: 'center',title: '类型', templet: '#typeTpl'} 
 | 
            // ,{field: 'leading', align: 'center',title: '负责人'} 
 | 
            // ,{field: 'img', align: 'center',title: '图片', hide: true} 
 | 
            // ,{field: 'brief', align: 'center',title: '简要描述'} 
 | 
            // ,{field: 'count', align: 'center',title: '数量'} 
 | 
            // ,{field: 'sort', align: 'center',title: '排序'} 
 | 
            ,{field: 'status$', align: 'center',title: '状态', hide: true} 
 | 
            ,{field: 'row1$', align: 'center',title: '排'} 
 | 
            ,{field: 'bay1$', align: 'center',title: '列'} 
 | 
            ,{field: 'lev1$', align: 'center',title: '层'} 
 | 
            ,{field: 'updateTime$', align: 'center',title: '修改时间'} 
 | 
            ,{field: 'updateBy$', align: 'center',title: '修改人员'} 
 | 
            ,{field: 'memo', align: 'center',title: '备注', hide: true} 
 | 
  
 | 
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:150} 
 | 
        ]], 
 | 
        done: function (data) { 
 | 
            console.log(data) 
 | 
            $('.ew-tree-table-box').css('height', '100%'); 
 | 
            insTb.expandAll(); 
 | 
            tbDataList = data; 
 | 
  
 | 
        } 
 | 
    }); 
 | 
  
 | 
    /* 表格头工具栏点击事件 */ 
 | 
    treeTable.on('toolbar(node)', function (obj) { 
 | 
        var checkRows = insTb.checkStatus(); 
 | 
        if (obj.event === 'add') { // 添加 
 | 
            showEditModel(); 
 | 
        } else if (obj.event === 'del') { // 删除 
 | 
            if (checkRows.length === 0) { 
 | 
                layer.msg('请选择要删除的数据', {icon: 2}); 
 | 
                return; 
 | 
            } 
 | 
            var ids = checkRows.map(function (d) { 
 | 
                if (!d.LAY_INDETERMINATE) { 
 | 
                    return d.id; 
 | 
                } else { 
 | 
                    return null; 
 | 
                } 
 | 
            }); 
 | 
            doDel({ids: ids}); 
 | 
        } else if (obj.event === 'printBatch') { 
 | 
            printContent = []; 
 | 
            if (checkRows.length === 0) { 
 | 
                layer.msg('请选择要打印的数据', {icon: 2}); 
 | 
                return; 
 | 
            } 
 | 
            printContent = checkRows.map(function (d) { 
 | 
                if (!d.LAY_INDETERMINATE && d.type === 3) { 
 | 
                    return d.name; 
 | 
                } else { 
 | 
                    return null; 
 | 
                } 
 | 
            }); 
 | 
            layer.open({ 
 | 
                type: 1, 
 | 
                title: '批量打印 [数量'+ printContent.length +']', 
 | 
                area: ['500px'], 
 | 
                shadeClose: true, 
 | 
                content: $('#printDataDiv'), 
 | 
                success: function(layero, index){ 
 | 
                }, 
 | 
                end: function () { 
 | 
                } 
 | 
            }); 
 | 
  
 | 
  
 | 
            //printBatch(printContent, 1); 
 | 
        }else if (obj.event === 'nodeInit'){ 
 | 
            nodeInit(); 
 | 
        } 
 | 
    }); 
 | 
  
 | 
    /* 表格操作列点击事件 */ 
 | 
    treeTable.on('tool(node)', function (obj) { 
 | 
        if (obj.event === 'edit') { // 修改 
 | 
            showEditModel(obj.data); 
 | 
        } else if (obj.event === 'del') { // 删除 
 | 
            doDel(obj); 
 | 
        } 
 | 
    }); 
 | 
  
 | 
    // 模板选择 
 | 
    form.on('radio(selectTemplateRadio)', function (data) { 
 | 
        $('.template-preview').hide(); 
 | 
        $('#template-preview-'+data.value).show(); 
 | 
    }); 
 | 
  
 | 
    /* 显示表单弹窗 */ 
 | 
    function showEditModel(mData) { 
 | 
        admin.open({ 
 | 
            type: 1, 
 | 
            area: '600px', 
 | 
            title: (mData ? '修改' : '添加') + '货位', 
 | 
            content: $('#editDialog').html(), 
 | 
            success: function (layero, dIndex) { 
 | 
                // 回显表单数据 
 | 
                form.val('detail', mData); 
 | 
                // 表单提交事件 
 | 
                form.on('submit(editSubmit)', function (data) { 
 | 
                    data.field.parentId = insXmSel.getValue('valueStr'); 
 | 
                    var loadIndex = layer.load(2); 
 | 
                    $.ajax({ 
 | 
                        url: baseUrl+"/node/"+(mData?'update':'add')+"/auth", 
 | 
                        headers: {'token': localStorage.getItem('token')}, 
 | 
                        data: data.field, 
 | 
                        method: 'POST', 
 | 
                        success: function (res) { 
 | 
                            layer.close(loadIndex); 
 | 
                            if (res.code === 200){ 
 | 
                                layer.close(dIndex); 
 | 
                                layer.msg(res.msg, {icon: 1}); 
 | 
                                insTb.refresh(); 
 | 
                            } else if (res.code === 403){ 
 | 
                                top.location.href = baseUrl+"/"; 
 | 
                            }else { 
 | 
                                layer.msg(res.msg, {icon: 2}); 
 | 
                            } 
 | 
                        } 
 | 
                    }) 
 | 
                    return false; 
 | 
                }); 
 | 
                // 渲染下拉树 
 | 
                var insXmSel = xmSelect.render({ 
 | 
                    el: '#nodeParentSel', 
 | 
                    height: '250px', 
 | 
                    data: insTb.options.data, 
 | 
                    initValue: mData ? [mData.parentId] : [], 
 | 
                    model: {label: {type: 'text'}}, 
 | 
                    prop: { 
 | 
                        name: 'name', 
 | 
                        value: 'id' 
 | 
                    }, 
 | 
                    radio: true, 
 | 
                    clickClose: true, 
 | 
                    tree: { 
 | 
                        show: true, 
 | 
                        indent: 15, 
 | 
                        strict: false, 
 | 
                        expandedKeys: true 
 | 
                    } 
 | 
                }); 
 | 
                // 弹窗不出现滚动条 
 | 
                $(layero).children('.layui-layer-content').css('overflow', 'visible'); 
 | 
                layui.form.render('select'); 
 | 
            } 
 | 
        }); 
 | 
    } 
 | 
  
 | 
    /* 删除 */ 
 | 
    function doDel(obj) { 
 | 
        layer.confirm('确定要删除选中数据吗?', { 
 | 
            skin: 'layui-layer-admin', 
 | 
            shade: .1 
 | 
        }, function (i) { 
 | 
            layer.close(i); 
 | 
            var loadIndex = layer.load(2); 
 | 
            var ids; 
 | 
            if (obj.data) { 
 | 
                ids = []; 
 | 
                ids[0] = obj.data.id; 
 | 
            } else { 
 | 
                ids = obj.ids; 
 | 
            } 
 | 
            $.ajax({ 
 | 
                url: baseUrl+"/node/delete0/auth", 
 | 
                headers: {'token': localStorage.getItem('token')}, 
 | 
                data: {ids: ids}, 
 | 
                method: 'POST', 
 | 
                success: function (res) { 
 | 
                    layer.close(loadIndex); 
 | 
                    if (res.code === 200){ 
 | 
                        layer.msg(res.msg, {icon: 1}); 
 | 
                        insTb.refresh(); 
 | 
                    } else if (res.code === 403){ 
 | 
                        top.location.href = baseUrl+"/"; 
 | 
                    } else { 
 | 
                        layer.msg(res.msg, {icon: 2}); 
 | 
                    } 
 | 
                } 
 | 
            }) 
 | 
        }); 
 | 
    } 
 | 
  
 | 
    // 批量打印 
 | 
    function printBatch(printMsgList, type) { 
 | 
  
 | 
        var data = []; 
 | 
        for (var i = 0; i<printMsgList.length; i ++) { 
 | 
            if (printMsgList[i] != null && printMsgList[i] !== '') { 
 | 
                var barcodeUrl; 
 | 
                if (type === 1) { 
 | 
                    barcodeUrl = baseUrl+"/mac/code/auth?type="+type+"¶m="+printMsgList[i]+"&width="+200+"&height="+70; 
 | 
                } else { 
 | 
                    barcodeUrl = baseUrl+"/mac/code/auth?type="+type+"¶m="+printMsgList[i]+"&width="+400+"&height="+180; 
 | 
                } 
 | 
                data.push({ 
 | 
                    item: printMsgList[i], 
 | 
                    barcodeUrl: barcodeUrl 
 | 
                }) 
 | 
            } 
 | 
        } 
 | 
        var tpl = $('#locPrintTpl').html(); 
 | 
        var template = Handlebars.compile(tpl); 
 | 
        var html = template({data: data}); 
 | 
        var box = $("#printBox"); 
 | 
        box.html(html); 
 | 
        box.show(); 
 | 
        box.print({mediaPrint:true}); 
 | 
        box.hide(); 
 | 
    } 
 | 
  
 | 
    // 开始打印 
 | 
    form.on('submit(doPrint)', function (data) { 
 | 
        var templateNo = data.field.selectTemplate; 
 | 
        var data = []; 
 | 
        var type = 1; 
 | 
        for (var i = 0; i<printContent.length; i ++) { 
 | 
            if (printContent[i] != null && printContent[i] !== '') { 
 | 
                var barcodeUrl; 
 | 
                if (type === 1) { 
 | 
                    barcodeUrl = baseUrl+"/mac/code/auth?type="+type+"¶m="+printContent[i]+"&width="+200+"&height="+70; 
 | 
                } else { 
 | 
                    barcodeUrl = baseUrl+"/mac/code/auth?type="+type+"¶m="+printContent[i]+"&width="+400+"&height="+180; 
 | 
                } 
 | 
                data.push({ 
 | 
                    item: printContent[i], 
 | 
                    barcodeUrl: barcodeUrl 
 | 
                }) 
 | 
            } 
 | 
        } 
 | 
        var templateDom = $("#templatePreview"+templateNo); 
 | 
        var tpl = templateDom.html(); 
 | 
        var template = Handlebars.compile(tpl); 
 | 
        var html = template({data: data}); 
 | 
        var box = $("#box"); 
 | 
        box.html(html); 
 | 
        box.show(); 
 | 
        box.print({mediaPrint:true}); 
 | 
        box.hide(); 
 | 
    }); 
 | 
  
 | 
  
 | 
    function nodeInit(){ 
 | 
        layer.prompt({title: '请输入口令,并重置库位', formType: 1,   shadeClose: true}, function(pass, idx){ 
 | 
            http.get(baseUrl+"/node/init/pwd", {pwd: pass}, function (res) { 
 | 
                if (res.data) { 
 | 
                    layer.open({ 
 | 
                        type: 1, 
 | 
                        title: '初始化库位', 
 | 
                        area: ["400px"], 
 | 
                        maxmin: true, 
 | 
                        shadeClose: true, 
 | 
                        content: $("#resetLocDiv"), 
 | 
                        success: function (layero, index) { 
 | 
  
 | 
  
 | 
                            // 渲染物料选择 
 | 
                            matXmSelect = xmSelect.render({ 
 | 
                                el: '#mat', 
 | 
                                style: { 
 | 
                                    width: '200px'                                    , 
 | 
                                    height: 'auto' 
 | 
                                }, 
 | 
                                autoRow: true, 
 | 
                                toolbar: { show: true }, 
 | 
                                filterable: true, 
 | 
                                remoteSearch: true, 
 | 
                                radio: true, 
 | 
                                clickClose: true, 
 | 
                                remoteMethod: function(val, cb, show){ 
 | 
                                    $.ajax({ 
 | 
                                        url: baseUrl+"/node/all/get/loc", 
 | 
                                        headers: {'token': localStorage.getItem('token')}, 
 | 
                                        method: 'POST', 
 | 
                                        success: function (res) { 
 | 
                                            if (res.code === 200){ 
 | 
                                                cb(res.data) 
 | 
                                            } else { 
 | 
                                                cb([]); 
 | 
                                                layer.msg(res.msg, {icon: 2}); 
 | 
                                            } 
 | 
                                        } 
 | 
                                    }); 
 | 
                                } 
 | 
                            }) 
 | 
                        } 
 | 
                    }) 
 | 
                } else { 
 | 
                    layer.msg("口令错误"); 
 | 
                } 
 | 
                layer.close(idx); 
 | 
            }) 
 | 
        }); 
 | 
    } 
 | 
  
 | 
    // 初始化保存 
 | 
    form.on('submit(initDo)', function (data) { 
 | 
        areas =  matXmSelect.getValue(); 
 | 
        data.field.value = areas[0].value; 
 | 
        data.field.name = areas[0].name; 
 | 
        console.log(data.field); 
 | 
        $.ajax({ 
 | 
            url: baseUrl+"/node/init/auth", 
 | 
            headers: {'token': localStorage.getItem('token')}, 
 | 
            data: data.field, 
 | 
            method: 'POST', 
 | 
            async: false, 
 | 
            success: function (res) { 
 | 
                if (res.code === 200){ 
 | 
                    layer.msg(res.msg); 
 | 
                    layer.closeAll(); 
 | 
                    // tableReload(false); 
 | 
                } else if (res.code === 403){ 
 | 
                    parent.location.href = "/"; 
 | 
                }else { 
 | 
                    layer.msg(res.msg) 
 | 
                } 
 | 
            } 
 | 
        }) 
 | 
    }); 
 | 
  
 | 
  
 | 
  
 | 
}); 
 | 
  
 | 
// excel导入模板下载 
 | 
function excelMouldDownload(){ 
 | 
    layer.load(1, {shade: [0.1,'#fff']}); 
 | 
    location.href = baseUrl + "/node/excel/import/mould"; 
 | 
    layer.closeAll('loading'); 
 | 
} 
 | 
  
 | 
// excel导入 
 | 
function importExcel() { 
 | 
    $("#importExcel").trigger("click"); 
 | 
} 
 | 
function upload(obj){ 
 | 
    if(!obj.files) { 
 | 
        return; 
 | 
    } 
 | 
    var file = obj.files[0]; 
 | 
    admin.confirm('确认同步 [' + file.name +'] 文件吗?', function (index) { 
 | 
        layer.load(1, {shade: [0.1,'#fff']}); 
 | 
        var url = baseUrl + "/node/excel/import/auth"; 
 | 
        var form = new FormData(); 
 | 
        form.append("file", file); 
 | 
        xhr = new XMLHttpRequest(); 
 | 
        xhr.open("post", url, true); //post方式,url为服务器请求地址,true 该参数规定请求是否异步处理。 
 | 
        xhr.setRequestHeader('token', localStorage.getItem('token')); 
 | 
        xhr.onload = uploadComplete; //请求完成 
 | 
        xhr.onerror =  uploadFailed; //请求失败 
 | 
        xhr.onloadend = function () { // // 上传完成重置文件流 
 | 
            layer.closeAll('loading'); 
 | 
            $("#importExcel").val(""); 
 | 
        }; 
 | 
        // xhr.upload.onprogress = progressFunction;//【上传进度调用方法实现】 
 | 
        xhr.upload.onloadstart = function(){//上传开始执行方法 
 | 
            ot = new Date().getTime();   //设置上传开始时间 
 | 
            oloaded = 0;//设置上传开始时,以上传的文件大小为0 
 | 
        }; 
 | 
        xhr.send(form); 
 | 
    }, function(index){ 
 | 
        $("#importExcel").val(""); 
 | 
    }); 
 | 
} 
 | 
function uploadComplete(evt) { 
 | 
    var res = JSON.parse(evt.target.responseText); 
 | 
    if(res.code === 200) { 
 | 
        layer.msg(res.msg, {icon: 1}); 
 | 
        insTb.refresh(); 
 | 
    } else { 
 | 
        layer.msg(res.msg, {icon: 2}); 
 | 
    } 
 | 
} 
 | 
function uploadFailed(evt) { 
 | 
    var res = JSON.parse(evt.target.responseText); 
 | 
    layer.msg(res.msg, {icon: 2}); 
 | 
} 
 | 
  
 | 
// excel导出 
 | 
function exportExcel() { 
 | 
  
 | 
} 
 |