#
luxiaotao1123
2021-04-03 918cf69e763d30a1315fa1c83a964dae4dd88f12
src/main/webapp/static/js/mat/mat.js
@@ -1,4 +1,5 @@
var pageCurr;
var printMatCodeNos = [];
layui.use(['table','laydate', 'form'], function(){
    var table = layui.table;
    var $ = layui.jquery;
@@ -20,30 +21,30 @@
        cols: [[
            {type: 'checkbox'}
//            ,{field: 'id', title: 'ID', sort: true,align: 'center', fixed: 'left', width: 80}
            ,{field: 'id', align: 'center',title: 'ID'}
            ,{field: 'uuid', align: 'center',title: '编号'}
            ,{field: 'nodeId$', align: 'center',title: '所属区域',event: 'nodeId', style: 'cursor:pointer'}
            ,{field: 'tagId$', align: 'center',title: '所属归类',event: 'tagId', style: 'cursor:pointer'}
//             ,{field: 'id', align: 'center',title: 'ID'}
//             ,{field: 'uuid', align: 'center',title: '编号'}
//             ,{field: 'nodeId$', align: 'center',title: '所属区域',event: 'nodeId', style: 'cursor:pointer'}
            ,{field: 'tagId$', align: 'center',title: '归类', templet: '#tagTpl'}
            ,{field: 'matnr', align: 'center',title: '商品编号'}
            ,{field: 'maktx', align: 'center',title: '商品名称'}
            ,{field: 'name', align: 'center',title: '名称'}
            ,{field: 'maktx', align: 'center',title: '商品名称', minWidth: 300}
            // ,{field: 'name', align: 'center',title: '名称'}
            ,{field: 'specs', align: 'center',title: '规格'}
            ,{field: 'model', align: 'center',title: '型号'}
            ,{field: 'batch', align: 'center',title: '批号'}
            ,{field: 'model', align: 'center',title: '型号', hide: true}
            ,{field: 'batch', align: 'center',title: '批号', hide: true}
            ,{field: 'unit', align: 'center',title: '单位'}
            ,{field: 'barcode', align: 'center',title: '条码'}
            ,{field: 'docId', align: 'center',title: '单据类型'}
            ,{field: 'docNum', align: 'center',title: '单据编号'}
            ,{field: 'custName', align: 'center',title: '客户名称'}
            ,{field: 'itemNum', align: 'center',title: '品项数'}
            ,{field: 'count', align: 'center',title: '库存余量'}
            ,{field: 'weight', align: 'center',title: '重量'}
            ,{field: 'status', align: 'center',title: ''}
            ,{field: 'createBy$', align: 'center',title: '添加人员',event: 'createBy', style: 'cursor:pointer'}
            ,{field: 'createTime$', align: 'center',title: '添加时间'}
            ,{field: 'updateBy$', align: 'center',title: '修改人员',event: 'updateBy', style: 'cursor:pointer'}
            ,{field: 'updateTime$', align: 'center',title: '修改时间'}
            ,{field: 'memo', align: 'center',title: '备注'}
            ,{field: 'barcode', align: 'center',title: '条码', hide: true}
            // ,{field: 'docId', align: 'center',title: '单据类型'}
            // ,{field: 'docNum', align: 'center',title: '单据编号'}
            // ,{field: 'custName', align: 'center',title: '客户名称'}
            ,{field: 'itemNum', align: 'center',title: '品项数', hide: true}
            ,{field: 'count', align: 'center',title: '库存余量', hide: true}
            ,{field: 'weight', align: 'center',title: '重量', hide: true}
            // ,{field: 'status', align: 'center',title: '状态'}
            // ,{field: 'createBy$', align: 'center',title: '添加人员'}
            // ,{field: 'createTime$', align: 'center',title: '添加时间'}
            // ,{field: 'updateBy$', align: 'center',title: '修改人员'}
            // ,{field: 'updateTime$', align: 'center',title: '修改时间'}
            ,{field: 'memo', align: 'center',title: '备注', hide: true}
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:150}
        ]],
@@ -184,6 +185,29 @@
                    });
                });
                break;
            // 批量打印
            case "btnPrintBatch":
                printMatCodeNos = [];
                var data = checkStatus.data;
                if (data.length === 0){
                    layer.msg('请选择打印数据');
                } else {
                    layer.open({
                        type: 1,
                        title: '批量打印 [数量'+ data.length +']',
                        area: ['500px'],
                        shadeClose: true,
                        content: $('#printDataDiv'),
                        success: function(layero, index){
                            for (var i = 0; i<data.length;i++) {
                                printMatCodeNos.push(data[i].matnr);
                            }
                        },
                        end: function () {
                        }
                    });
                }
                break;
        }
    });
@@ -191,6 +215,23 @@
    table.on('tool(mat)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            // 打印
            case "btnPrint":
                printMatCodeNos = [];
                layer.open({
                    type: 1,
                    title: data.matnr + ' [数量:1]',
                    area: ['500px'],
                    shadeClose: true,
                    content: $('#printDataDiv'),
                    success: function(layero, index){
                        layer.iframeAuto(index);
                        printMatCodeNos.push(data.matnr);
                    },
                    end: function () {
                    }
                });
                break;
            // 详情
            case 'detail':
                layer.open({
@@ -229,154 +270,52 @@
                    }
                });
                break;
            case 'nodeId':
                var param = top.reObject(data).nodeId;
                if (param === undefined) {
                    layer.msg("无数据");
                } else {
                   layer.open({
                       type: 2,
                       title: '所属区域详情',
                       maxmin: true,
                       area: [top.detailWidth, top.detailHeight],
                       shadeClose: true,
                       content: '../node/node_detail.html',
                       success: function(layero, index){
                           $.ajax({
                               url: "baseUrl+/node/"+ param +"/auth",
                               headers: {'token': localStorage.getItem('token')},
                               method: 'GET',
                               success: function (res) {
                                   if (res.code === 200){
                                       setFormVal(layer.getChildFrame('#detail', index), res.data, true);
                                       top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
                                       layer.getChildFrame('#data-detail-submit-save,#data-detail-submit-edit,#prompt', index).hide();
                                       layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                                       layero.find('iframe')[0].contentWindow.layui.form.render('select');
                                       layero.find('iframe')[0].contentWindow.layui.form.render('checkbox');
                                   } else if (res.code === 403){
                                       top.location.href = baseUrl+"/";
                                   }else {
                                       layer.msg(res.msg)
                                   }
                               }
                           })
                       }
                   });
                }
                break;
            case 'tagId':
                var param = top.reObject(data).tagId;
                if (param === undefined) {
                    layer.msg("无数据");
                } else {
                   layer.open({
                       type: 2,
                       title: '所属归类详情',
                       maxmin: true,
                       area: [top.detailWidth, top.detailHeight],
                       shadeClose: true,
                       content: '../tag/tag_detail.html',
                       success: function(layero, index){
                           $.ajax({
                               url: "baseUrl+/tag/"+ param +"/auth",
                               headers: {'token': localStorage.getItem('token')},
                               method: 'GET',
                               success: function (res) {
                                   if (res.code === 200){
                                       setFormVal(layer.getChildFrame('#detail', index), res.data, true);
                                       top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
                                       layer.getChildFrame('#data-detail-submit-save,#data-detail-submit-edit,#prompt', index).hide();
                                       layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                                       layero.find('iframe')[0].contentWindow.layui.form.render('select');
                                       layero.find('iframe')[0].contentWindow.layui.form.render('checkbox');
                                   } else if (res.code === 403){
                                       top.location.href = baseUrl+"/";
                                   }else {
                                       layer.msg(res.msg)
                                   }
                               }
                           })
                       }
                   });
                }
                break;
            case 'createBy':
                var param = top.reObject(data).createBy;
                if (param === undefined) {
                    layer.msg("无数据");
                } else {
                   layer.open({
                       type: 2,
                       title: '添加人员详情',
                       maxmin: true,
                       area: [top.detailWidth, top.detailHeight],
                       shadeClose: true,
                       content: '../user/user_detail.html',
                       success: function(layero, index){
                           $.ajax({
                               url: "baseUrl+/user/"+ param +"/auth",
                               headers: {'token': localStorage.getItem('token')},
                               method: 'GET',
                               success: function (res) {
                                   if (res.code === 200){
                                       setFormVal(layer.getChildFrame('#detail', index), res.data, true);
                                       top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
                                       layer.getChildFrame('#data-detail-submit-save,#data-detail-submit-edit,#prompt', index).hide();
                                       layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                                       layero.find('iframe')[0].contentWindow.layui.form.render('select');
                                       layero.find('iframe')[0].contentWindow.layui.form.render('checkbox');
                                   } else if (res.code === 403){
                                       top.location.href = baseUrl+"/";
                                   }else {
                                       layer.msg(res.msg)
                                   }
                               }
                           })
                       }
                   });
                }
                break;
            case 'updateBy':
                var param = top.reObject(data).updateBy;
                if (param === undefined) {
                    layer.msg("无数据");
                } else {
                   layer.open({
                       type: 2,
                       title: '修改人员详情',
                       maxmin: true,
                       area: [top.detailWidth, top.detailHeight],
                       shadeClose: true,
                       content: '../user/user_detail.html',
                       success: function(layero, index){
                           $.ajax({
                               url: "baseUrl+/user/"+ param +"/auth",
                               headers: {'token': localStorage.getItem('token')},
                               method: 'GET',
                               success: function (res) {
                                   if (res.code === 200){
                                       setFormVal(layer.getChildFrame('#detail', index), res.data, true);
                                       top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
                                       layer.getChildFrame('#data-detail-submit-save,#data-detail-submit-edit,#prompt', index).hide();
                                       layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                                       layero.find('iframe')[0].contentWindow.layui.form.render('select');
                                       layero.find('iframe')[0].contentWindow.layui.form.render('checkbox');
                                   } else if (res.code === 403){
                                       top.location.href = baseUrl+"/";
                                   }else {
                                       layer.msg(res.msg)
                                   }
                               }
                           })
                       }
                   });
                }
                break;
        }
    });
    // 模板选择
    form.on('radio(selectTemplateRadio)', function (data) {
        $('.template-preview').hide();
        $('#template-preview-'+data.value).show();
    });
    // 开始打印
    form.on('submit(doPrint)', function (data) {
        var templateNo = data.field.selectTemplate;
        $.ajax({
            url: baseUrl+"/mat/print/auth",
            headers: {'token': localStorage.getItem('token')},
            data: {param: printMatCodeNos},
            method: 'POST',
            async: false,
            success: function (res) {
                if (res.code === 200){
                    layer.closeAll();
                    for (let i=0;i<res.data.length;i++){
                        var templateDom = $("#templatePreview"+templateNo);
                        var className = templateDom.attr("class");
                        if (className === 'template-barcode') {
                            res.data[i]["barcodeUrl"]=baseUrl+"/mac/code/auth?type=1&param="+res.data[i].matnr;
                        } else {
                            res.data[i]["barcodeUrl"]=baseUrl+"/mac/code/auth?type=2&param="+res.data[i].matnr;
                        }
                    }
                    var tpl = templateDom.html();
                    var template = Handlebars.compile(tpl);
                    var html = template(res);
                    let box = $("#box");
                    box.html(html);box.show();
                    box.print({mediaPrint:true});
                    box.hide();
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                }else {
                    layer.msg(res.msg)
                }
            }
        })
    })
    // 数据保存动作
    form.on('submit(save)', function () {
        if (banMsg != null){