#
luxiaotao1123
2021-04-07 746bc3009489b5fe644666cbed138582726f498a
src/main/webapp/static/js/mat/mat.js
@@ -1,11 +1,48 @@
var pageCurr;
var printMatCodeNos = [];
layui.use(['table','laydate', 'form'], function(){
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'treeTable', 'admin', 'xmSelect'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
    var treeTable = layui.treeTable;
    var xmSelect = layui.xmSelect;
    // 商品分类数据
    var insTb = treeTable.render({
        elem: '#tag',
        url: baseUrl+'/tag/list/auth',
        headers: {token: localStorage.getItem('token')},
        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: 'type$', align: 'center',title: '类型'}
            ,{field: 'leading', align: 'center',title: '负责人'}
            ,{field: 'img', align: 'center',title: '图片', hide: true}
            ,{field: 'sort', align: 'center',title: '排序', hide: true}
            ,{field: 'status$', align: 'center',title: '状态'}
            ,{field: 'updateTime$', align: 'center',title: '修改时间'}
            ,{field: 'updateBy$', align: 'center',title: '修改人员', hide: true}
            ,{field: 'memo', align: 'center',title: '备注', hide: true}
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:150}
        ]],
        done: function (data) {
            $('.ew-tree-table-box').css('height', '100%');
            insTb.expandAll();
        }
    });
    // 数据渲染
    tableIns = table.render({
@@ -108,18 +145,7 @@
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event) {
            case 'addData':
                layer.open({
                    type: 2,
                    title: '新增',
                    maxmin: true,
                    area: [top.detailWidth, top.detailHeight],
                    content: 'mat_detail.html',
                    success: function(layero, index){
                        layer.getChildFrame('#data-detail-submit-edit', index).hide();
                       clearFormVal(layer.getChildFrame('#detail', index));
                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                    }
                });
                showEditModel()
                break;
            case 'deleteData':
                var data = checkStatus.data;
@@ -232,46 +258,77 @@
                    }
                });
                break;
            // 详情
            case 'detail':
                layer.open({
                    type: 2,
                    title: '详情',
                    maxmin: true,
                    area: [top.detailWidth, top.detailHeight],
                    shadeClose: true,
                    content: 'mat_detail.html',
                    success: function(layero, index){
                        setFormVal(layer.getChildFrame('#detail', index), 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');
                    }
                });
                break;
            // 编辑
            case 'edit':
                layer.open({
                    type: 2,
                    title: '修改',
                    maxmin: true,
                    area: [top.detailWidth, top.detailHeight],
                    content: 'mat_detail.html',
                    success: function(layero, index){
                        layer.getChildFrame('#data-detail-submit-save', index).hide();
                        setFormVal(layer.getChildFrame('#detail', index), data, false);
                        top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
                        top.convertDisabled(layer.getChildFrame('#id', index), true);
                        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');
                    }
                });
                showEditModel(data)
                break;
        }
    });
    /* 显示表单弹窗 */
    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.tagId = insXmSel.getValue('valueStr');
                    if (isEmpty(data.field.tagId)) {
                        layer.msg('分类不能为空', {icon: 2});
                        return false;
                    }
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/mat/"+(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});
                                $(".layui-laypage-btn")[0].click();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                // 渲染下拉树
                var insXmSel = xmSelect.render({
                    el: '#tagSel',
                    height: '250px',
                    data: insTb.options.data,
                    initValue: mData ? [mData.tagId] : [],
                    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');
            }
        });
    }
    // 模板选择
    form.on('radio(selectTemplateRadio)', function (data) {
@@ -315,74 +372,6 @@
            }
        })
    })
    // 数据保存动作
    form.on('submit(save)', function () {
        if (banMsg != null){
            layer.msg(banMsg);
            return;
        }
        method("add");
    });
    // 数据修改动作
    form.on('submit(edit)', function () {
        method("update")
    });
    function method(name){
        var index = layer.load(1, {
            shade: [0.5,'#000'] //0.1透明度的背景
        });
        var data = {
//            id: $('#id').val(),
            id: $('#id').val(),
            uuid: $('#uuid').val(),
            nodeId: $('#nodeId').val(),
            tagId: $('#tagId').val(),
            matnr: $('#matnr').val(),
            maktx: $('#maktx').val(),
            name: $('#name').val(),
            specs: $('#specs').val(),
            model: $('#model').val(),
            batch: $('#batch').val(),
            unit: $('#unit').val(),
            barcode: $('#barcode').val(),
            docId: $('#docId').val(),
            docNum: $('#docNum').val(),
            custName: $('#custName').val(),
            itemNum: $('#itemNum').val(),
            count: $('#count').val(),
            weight: $('#weight').val(),
            status: $('#status').val(),
            createBy: $('#createBy').val(),
            createTime: top.strToDate($('#createTime\\$').val()),
            updateBy: $('#updateBy').val(),
            updateTime: top.strToDate($('#updateTime\\$').val()),
            memo: $('#memo').val(),
        };
        $.ajax({
            url: baseUrl+"/mat/"+name+"/auth",
            headers: {'token': localStorage.getItem('token')},
            data: top.reObject(data),
            method: 'POST',
            success: function (res) {
                if (res.code === 200){
                    parent.layer.closeAll();
                    parent.$(".layui-laypage-btn")[0].click();
                    $("#data-detail :input").each(function () {
                        $(this).val("");
                    });
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                }else {
                    layer.msg(res.msg)
                }
                layer.close(index);
            }
        })
    }
    // 复选框事件
    form.on('checkbox(detailCheckbox)', function (data) {