自动化立体仓库 - WMS系统
lty
5 天以前 8e943b7104561c3b14cf223016698709c5ade4b5
src/main/webapp/static/js/mat/mat.js
@@ -1,14 +1,28 @@
var pageCurr;
var printMatCodeNos = [];
var admin;
// Local translation helper
function t(key, params) {
    if (typeof I18n !== 'undefined' && typeof I18n.t === 'function') {
        return I18n.t(key, params);
    }
    return key;
}
function getCol() {
    var cols = [
        {type: 'checkbox'}
        ,{field: 'tagId$', align: 'center',title: '归类', templet: '#tagTpl'}
        ,{field: 'tagId$', align: 'center',title: t('classification'), templet: '#tagTpl'}
        // ,{field: 'store_max', align: 'center',title: t('stock_upper_limit')}
        // ,{field: 'store_min', align: 'center',title: t('stock_lower_limit')}
        // ,{field: 'store_max_date', align: 'center',title: t('stock_age_upper_limit_days')}
        ,{field: 'areaId$', align: 'center',title: t('area'), templet: '#areaTpl'}
    ];
    cols.push.apply(cols, matCols);
    cols.push.apply(cols, getMatCols());
    cols.push(
        {fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:150}
        {fixed: 'right', title: t('operation'), align: 'center', toolbar: '#operate', width:150}
    )
    return cols;
}
@@ -26,6 +40,31 @@
    admin = layui.admin;
    var treeTable = layui.treeTable;
    var xmSelect = layui.xmSelect;
    // 区域数据
    var areaData = [];
    // 加载区域数据
    $.ajax({
        url: baseUrl+'/area/list/auth',
        headers: {token: localStorage.getItem('token')},
        method: 'GET',
        async: false,
        success: function (res) {
            if (res.code === 200 && res.data && res.data.records) {
                // 过滤掉空值
                areaData = res.data.records.filter(function(item) {
                    return item != null && item.areaId != null;
                });
                console.log('区域数据加载成功:', areaData);
            } else {
                console.error('区域数据加载失败:', res);
            }
        },
        error: function(err) {
            console.error('区域数据请求失败:', err);
        }
    });
    // 商品分类数据
    var insTb = treeTable.render({
@@ -46,6 +85,26 @@
    });
    // 数据渲染
    var tableDone = function(res, curr, count) {
        if (res.code === 403) {
            top.location.href = baseUrl+"/";
        }
        pageCurr=curr;
        limit();
        form.on('checkbox(tableCheckbox)', function (data) {
            var _index = $(data.elem).attr('table-index')||0;
            if(data.elem.checked){
                res.data[_index][data.value] = 'Y';
            }else{
                res.data[_index][data.value] = 'N';
            }
        });
        if (typeof I18n !== 'undefined') {
            I18n.updatePage();
            I18n.updateLayuiPagination();
        }
    };
    tableIns = table.render({
        elem: '#mat',
        headers: {token: localStorage.getItem('token')},
@@ -72,21 +131,7 @@
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
            form.on('checkbox(tableCheckbox)', function (data) {
                var _index = $(data.elem).attr('table-index')||0;
                if(data.elem.checked){
                    res.data[_index][data.value] = 'Y';
                }else{
                    res.data[_index][data.value] = 'N';
                }
            });
        }
        done: tableDone
    });
    // 监听排序事件
@@ -102,13 +147,15 @@
            page: {
                curr: 1
            },
            done: function (res, curr, count) {
                if (res.code === 403) {
                    top.location.href = baseUrl+"/";
                }
                pageCurr=curr;
                limit();
            }
            done: tableDone
        });
    });
    // 监听语言切换
    $(document).on('i18n:languageChanged i18n:ready', function() {
        tableIns.reload({
            cols: [getCol()],
            done: tableDone
        });
    });
@@ -122,9 +169,9 @@
            case 'deleteData':
                var data = checkStatus.data;
                if (data.length === 0){
                    layer.msg('请选择数据');
                    layer.msg(I18n.t('please_select_data'));
                } else {
                    layer.confirm('确定删除'+(data.length===1?'此':data.length)+'条数据吗', function(){
                    layer.confirm(I18n.t('confirm_delete_prefix') + (data.length===1?I18n.t('this'):data.length) + I18n.t('confirm_delete_suffix'), function(){
                        $.ajax({
                            url: baseUrl+"/mat/delete/auth",
                            headers: {'token': localStorage.getItem('token')},
@@ -138,7 +185,7 @@
                                } else if (res.code === 403){
                                    top.location.href = baseUrl+"/";
                                } else {
                                    layer.msg(res.msg)
                                    layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2})
                                }
                            }
                        })
@@ -146,7 +193,7 @@
                }
                break;
            case 'exportData':
                layer.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                layer.confirm(I18n.t('confirm_export_excel'), {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
@@ -177,7 +224,7 @@
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg)
                                layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2})
                            }
                        }
                    });
@@ -188,11 +235,11 @@
                printMatCodeNos = [];
                var data = checkStatus.data;
                if (data.length === 0){
                    layer.msg('请选择打印数据');
                    layer.msg(I18n.t('please_select_print_data'));
                } else {
                    layer.open({
                        type: 1,
                        title: '批量打印 [数量'+ data.length +']',
                        title: I18n.t('batch_print_count', {count: data.length}),
                        area: ['500px'],
                        shadeClose: true,
                        content: $('#printDataDiv'),
@@ -218,13 +265,17 @@
                printMatCodeNos = [];
                layer.open({
                    type: 1,
                    title: data.matnr + ' [数量:1]',
                    title: data.matnr + ' [' + I18n.t('count') + ':1]',
                    area: ['500px'],
                    shadeClose: true,
                    content: $('#printDataDiv'),
                    success: function(layero, index){
                        layer.iframeAuto(index);
                        printMatCodeNos.push(data.matnr);
                        if (typeof I18n !== 'undefined' && I18n.updatePage) {
                            I18n.updatePage($(layero));
                            form.render();
                        }
                    },
                    end: function () {
                    }
@@ -242,7 +293,7 @@
        admin.open({
            type: 1,
            area: '600px',
            title: (mData ? '修改' : '添加') + '商品',
            title: (mData ? I18n.t('edit') : I18n.t('add')) + I18n.t('material'),
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                // 回显表单数据
@@ -250,14 +301,23 @@
                // 新增自动生成商品编号
                if (!mData) {
                    http.get(baseUrl + "/mat/auto/matnr/auth", null, function (res) {
                        $('#matnr').val(res.data);
                        $(layero).find('#matnr').val(res.data);
                    })
                }
                if (typeof I18n !== 'undefined') {
                    setTimeout(function() {
                        I18n.updatePage($(layero));
                    }, 50);
                }
                // 表单提交事件
                form.on('submit(editSubmit)', function (data) {
                    console.log(data)
                    data.field.tagId = insXmSel.getValue('valueStr');
                    data.field.areaId = areaXmSel.getValue('valueStr');
                    if (isEmpty(data.field.tagId)) {
                        layer.msg('分类不能为空', {icon: 2});
                        layer.msg(I18n.t('category_cannot_be_empty'), {icon: 2});
                        return false;
                    }
                    var loadIndex = layer.load(2);
@@ -270,7 +330,7 @@
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                layer.msg(t('response.operation_success'), {icon: 1});
                                $(".layui-laypage-btn")[0].click();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
@@ -283,7 +343,7 @@
                });
                // 渲染下拉树
                var insXmSel = xmSelect.render({
                    el: '#tagSel',
                    el: $(layero).find('#tagSel')[0],
                    height: '250px',
                    data: insTb.options.data,
                    initValue: mData ? [mData.tagId] : [],
@@ -299,6 +359,22 @@
                        indent: 15,
                        strict: false,
                        expandedKeys: true
                    }
                });
                // 渲染区域下拉选择
                var areaXmSel = xmSelect.render({
                    el: $(layero).find('#areaSel')[0],
                    height: '250px',
                    data: areaData.length > 0 ? areaData : [],
                    initValue: mData && mData.areaId ? [mData.areaId] : [],
                    model: {label: {type: 'text'}},
                    prop: {
                        name: 'areaName',
                        value: 'areaId'
                    },
                    radio: true,
                    clickClose: true,
                    on: function(data) {
                    }
                });
                // 弹窗不出现滚动条
@@ -340,12 +416,15 @@
                    var html = template(res);
                    var box = $("#box");
                    box.html(html);box.show();
                    if (typeof I18n !== 'undefined' && I18n.updatePage) {
                        I18n.updatePage(box[0]);
                    }
                    box.print({mediaPrint:true});
                    box.hide();
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                }else {
                    layer.msg(res.msg)
                    layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2})
                }
            }
        })
@@ -393,7 +472,7 @@
        return;
    }
    var file = obj.files[0];
    admin.confirm('确认同步 [' + file.name +'] 文件吗?', function (index) {
    admin.confirm(I18n.t('confirm_sync_file', {filename: file.name}), function (index) {
        layer.load(1, {shade: [0.1,'#fff']});
        var url = baseUrl + "/mat/excel/import/auth";
        var form = new FormData();
@@ -462,6 +541,10 @@
                pageCurr -= 1;
            }
            limit(child);
            if (typeof I18n !== 'undefined') {
                I18n.updatePage();
                I18n.updateLayuiPagination();
            }
        }
    });
}