自动化立体仓库 - WMS系统
#
mrzhssss
2022-12-01 e19b4d3b6a68314887f78786c36ad97339d5faaf
src/main/webapp/static/js/order/out.js
@@ -1,12 +1,10 @@
var pageCurr;
var tableData;
var insTb2;
const sensorType = 5;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).extend({
    notice: 'notice/notice',
}).use(['table','laydate', 'form', 'util', 'admin', 'notice', 'treeTable', 'xmSelect'], function(){
}).use(['table','laydate', 'form', 'util', 'admin', 'notice', 'treeTable', 'xmSelect', 'tableMerge', 'tableX' , 'laytpl'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
@@ -17,97 +15,46 @@
    var notice = layui.notice;
    var treeTable = layui.treeTable;
    var xmSelect = layui.xmSelect;
    // 设备类型数据
    var modelTb = treeTable.render({
        elem: '#nothing',
        url: baseUrl+'/sensorModel/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}
        ]],
        done: function (data) {
            modelTb.expandAll();
        }
    });
    var tableMerge = layui.tableMerge;
    var tableX = layui.tableX;
    var laytpl = layui.laytpl;
    insTb2 = table.render({
        elem: '#sensorTable',
        elem: '#orderDetlTable',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/sensor/list/auth?sensor_type='+sensorType,
        url: baseUrl+'/orderDetl/pakout/list/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#sensorToolbar',
        height: 'full-100',
        toolbar: '#orderDetToolbar',
        height: 'full-120',
        where: {order_id: 9999999999},
        cols: [[
            {type: 'checkbox'}
            // ,{field: 'id', align: 'center',title: 'ID'}
            ,{field: 'hostId$', align: 'center',title: '所属项目', templet: '#hostTpl', width: 130}
            // ,{field: 'sensorType$', align: 'center',title: '设备类型'}
            ,{field: 'uuid', align: 'center',title: '设备编码', width: 160}
            ,{field: 'location', align: 'center',title: '地理位置', width: 180, style: 'font-size: 13px', hide: false}
            ,{field: 'sensorModel$', align: 'center',title: '设备型号', width: 130, hide: false}
            // ,{field: 'ccid', align: 'center',title: 'CCID'}
            ,{field: 'sim', align: 'center',title: 'sim卡号',hide: true}
            // ,{field: 'name', align: 'center',title: '设备名'}
            // ,{field: 'topic', align: 'center',title: '主题'}
            // ,{field: 'ip', align: 'center',title: 'ip'}
            // ,{field: 'port', align: 'center',title: '端口'}
            // ,{field: 'data', align: 'center',title: '报文'}
            // ,{field: 'lon', align: 'center',title: '经度'}
            // ,{field: 'lat', align: 'center',title: '纬度'}
            ,{field: 'signal', align: 'center',title: '信号值'}
            ,{field: 'battery', align: 'center',title: '电量',hide: true}
            // ,{field: 'charge$', align: 'center',title: '充电状态'}
            // ,{field: 'tiltX', align: 'center',title: 'x轴倾斜'}
            // ,{field: 'tiltY', align: 'center',title: 'y轴倾斜'}
            // ,{field: 'tiltZ', align: 'center',title: 'z轴倾斜'}
            // ,{field: 'tilt$', align: 'center',title: '倾斜状态'}
            ,{field: 'tempe', align: 'center',title: '温度', hide: true}
            ,{
                field: 'online', title: '网络', templet: function (d) {
                    var strs = [
                        '<span class="text-success">在线</span>',
                        '<span class="text-danger">离线</span>'
                    ];
                    return strs[d.online?0:1];
                }, align: 'center', sort: true
            }
            ,{
                field: 'error', title: '状态', templet: function (d) {
                    var strs = [
                        '<span class="layui-badge layui-badge-red">异常</span>',
                        '<span class="layui-badge layui-badge-green">正常</span>'
                    ];
                    return strs[d.error?0:1];
                }, align: 'center', sort: false, minWidth: 70, hide: false
            }
            // ,{field: 'worn$', align: 'center',title: '破损状态'}
            // ,{field: 'overflow$', align: 'center',title: '定点水位'}
            // ,{field: 'nsAngle', align: 'center',title: '南北角度'}
            // ,{field: 'waterGage', align: 'center',title: '管道水压'}
            // ,{field: 'harmGas', align: 'center',title: '有害气体'}
            // ,{field: 'lnGas', align: 'center',title: '可燃气体'}
            // ,{field: 'hsGas', align: 'center',title: '硫化氢气体'}
            // ,{field: 'reserve0', align: 'center',title: '预留0'}
            // ,{field: 'reserve1', align: 'center',title: '预留1'}
            // ,{field: 'status$', align: 'center',title: '状态', templet: '#statusTpl', width: 120, unresize: true}
            // ,{field: 'createTime$', align: 'center',title: '添加时间'}
            ,{type: 'numbers', title: '#'}
            ,{field: 'orderNo', align: 'center',title: '单据编号', templet: '#orderNoTpl', width: 160}
            ,{field: 'matnr', align: 'center',title: '商品编码', width: 160}
            ,{field: 'maktx', align: 'center',title: '商品名称', width: 200}
            ,{field: 'batch', align: 'center',title: '序列码'}
            ,{field: 'specs', align: 'center',title: '规格'}
            // ,{field: 'anfme', align: 'center',title: '数量'}
            // ,{field: 'qty', align: 'center',title: '作业数量', style: 'font-weight: bold'}
            ,{field: 'enableQty', align: 'center',title: '总数量', style: 'font-weight: bold'}
            // ,{field: 'name', align: 'center',title: '名称'}
            // ,{field: 'model', align: 'center',title: '型号'}
            ,{field: 'unit', align: 'center',title: '单位', hide: true}
            ,{field: 'barcode', align: 'center',title: '商品条码', hide: true}
            // ,{field: 'supplier', align: 'center',title: '供应商'}
            // ,{field: 'unitPrice', 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: '添加人员'}
            ,{field: 'updateTime$', align: 'center',title: '更新时间', minWidth: 170}
            // ,{field: 'createTime$', align: 'center',title: '添加时间'}
            // ,{field: 'updateBy$', align: 'center',title: '修改人员'}
            ,{field: 'addr', align: 'center',title: '详细地址', hide: true}
            ,{field: 'memo', align: 'center',title: '备注', hide: true}
            // ,{field: 'updateTime$', align: 'center',title: '修改时间'}
            // ,{field: 'memo', align: 'center',title: '备注'}
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width: 160}
        ]],
        request: {
@@ -129,11 +76,11 @@
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            tableData = table.cache.sensorTable;
            pageCurr=curr;
            limit();
        }
    });
    /* 表格2搜索 */
    form.on('submit(sensorTbSearch)', function (data) {
        insTb2.reload({where: data.field, page: {curr: 1}});
@@ -141,9 +88,17 @@
    });
    /* 表格2头工具栏点击事件 */
    table.on('toolbar(sensorTable)', function (obj) {
        if (obj.event === 'add') { // 添加
            showEditModel()
    table.on('toolbar(orderDetlTable)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        if (obj.event === 'pakoutPreview') { // 添加
            if (checkStatus.length === 0) {
                layer.msg('请选择至少一条出库明细', {icon: 2});
                return;
            }
            pakoutPreview(checkStatus.map(function (d) {
                return d.id;
            }));
        } else if (obj.event === 'del') { // 删除
            var checkRows = table.checkStatus('sensorTable');
            if (checkRows.data.length === 0) {
@@ -158,140 +113,199 @@
    });
    /* 表格2工具条点击事件 */
    table.on('tool(sensorTable)', function (obj) {
    table.on('tool(orderDetlTable)', function (obj) {
        console.log(obj);
        var data = obj.data;
        switch (obj.event) {
            case 'detl':
                top.sensorByDetl = data.id;
            // 出库
            case 'pakoutPreview':
                pakoutPreview([data.id])
                break;
            // 编辑
            case 'edit':
                showEditModel(data);
                break;
            // 删除
            case 'del':
                var ids = [data.id];
                doDelSensor({ids: ids});
                break;
            // 基点定位
            case 'lbs':
                notice.msg('请求中...', {icon: 4, position: "topCenter"});
                var param = {
                    uuid: data.uuid,
                    event: obj.event
                };
                $.ajax({
                    url: baseUrl+"/main/command/v1/auth",
                    headers: {'token': localStorage.getItem('token')},
                    data: JSON.stringify(param),
                    contentType:'application/json;charset=UTF-8',
                    method: 'POST',
                    success: function (res) {
                        notice.destroy();
                        if (res.code === 200){
                            admin.open({
                                title: '终端响应',
                                url: 'callback.html',
                                area: '360px',
                                data: {
                                    request: param,
                                    response: res.data
                                },
                                tpl: true
                            });
                        } else if (res.code === 403){
                            top.location.href = baseUrl+"/";
                        }else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }
                })
                break
        }
    });
    // 设备明细展开回调
    window.onSensorDetlDialog = function () {
    };
    /* 显示表单弹窗 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: '900px',
            title: (mData ? '修改' : '添加') + '设备',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                // 回显表单数据
                form.val('detail', mData);
                // 地图定位回显
                if (mData) {
                    setTimeout(function () {
                        $("#mapIframe")[0].contentWindow.position(mData.lon, mData.lat);
                    }, 500)
                }
                // 表单提交事件
                form.on('submit(editSubmit)', function (data) {
                    data.field.sensorModel = insXmSel.getValue('valueStr');
                    if (isEmpty(data.field.hostId)) {
                        layer.msg('请选择所属项目', {icon: 2});
                        return false;
                    }
                    data.field.lon = $("#mapIframe").contents().find("#lon").val();
                    data.field.lat = $("#mapIframe").contents().find("#lat").val();
                    data.field.city = $("#mapIframe").contents().find("#city").val();
                    if (isEmpty(data.field.lon) || isEmpty(data.field.lat)) {
                        layer.msg('设备不在定位', {icon: 2});
                        return false;
                    }
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/sensor/"+(mData?'update':'add')+"/auth?sensorType="+sensorType,
                        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});
    function pakoutPreview(ids) {
        let loadIndex = layer.load(2);
        $.ajax({
            url: baseUrl + "/out/pakout/preview/auth",
            headers: {'token': localStorage.getItem('token')},
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify(ids),
            method: 'POST',
            success: function (res) {
                layer.close(loadIndex);
                var tableCache;
                if (res.code === 200){
                    layer.open({
                        type: 1
                        ,title: false
                        ,closeBtn: false
                        ,offset: '50px'
                        ,area: ['1200px', '700px']
                        ,shade: 0.5
                        ,shadeClose: false
                        ,btn: ['立即出库', '稍后处理']
                        ,btnAlign: 'c'
                        ,moveType: 1 //拖拽模式,0或者1
                        ,content: $('#pakoutPreviewBox').html()
                        ,success: function(layero, index){
                            console.log(res.data);
                            stoPreTabIdx = table.render({
                                elem: '#stoPreTab',
                                data: res.data,
                                height: 520,
                                page: false,
                                limit: Number.MAX_VALUE,
                                cellMinWidth: 100,
                                cols: [[
                                    // {type: 'checkbox', merge: ['orderNo']},
                                    {field: 'orderNo', title: '单据编号', merge: true, align: 'center'},
                                    {field: 'title', title: '商品', merge: true, align: 'center', width: 350},
                                    {field: 'batch', title: '序列码', align: 'center'},
                                    // { title: '剩余需求量', align: 'center' , width: 120, toolbar: '#checkNeedQty'},
                                    // {field: 'anfme', title: '实际数量', align: 'center', width: 90, style: 'font-weight: bold'},
                                    { title: '出库数量', align: 'center',field: 'anfme', width: 90, style: 'font-weight: bold; color: red'},
                                    {field: 'locNo', title: '货位', align: 'center', width: 100, templet: '#locNoTpl'},
                                    {field: 'staNos', align: 'center', title: '出库站', merge: ['locNo'], templet: '#tbBasicTbStaNos'},
                                    {type: 'checkbox', merge: ['locNo']},
                                ]],
                                done: function (res) {
                                    tableMerge.render(this);
                                    $('.layui-table-body.layui-table-main').css("overflow", "auto");
                                    tableCache = tableData = table.cache.stoPreTab;
                                }
                            });
                            // 修改出库站
                            form.on('select(tbBasicTbStaNos)', function (obj) {
                                let index  = obj.othis.parents('tr').attr("data-index");
                                let data = tableCache[index];
                                for (let i = 0; i<tableCache.length; i++) {
                                    if (tableCache[i].locNo === data.locNo) {
                                        tableCache[i]['staNo'] = Number(obj.elem.value);
                                    }
                                }
                                obj.othis.children().find("input").css("color", "blue");
                                return false;
                            });
                            // 批量修改出库站
                            form.on('submit(batchModifySta)', function () {
                                let stoPreTabData = layui.table.checkStatus('stoPreTab').data;
                                if (stoPreTabData.length < 1) {
                                    layer.msg("请至少选择一条以上合并数据", {icon: 7});
                                    return false;
                                }
                                modifySta(stoPreTabData);
                            });
                            // 批量修改出库站 - 站点选择
                            function modifySta(stoPreTabData) {
                                // 出库站取交集
                                let staBatchSelectVal = [];
                                for(let i = 0; i<stoPreTabData.length; i++) {
                                    let staNos = stoPreTabData[i].staNos;
                                    if (staNos !== null) {
                                        if (staBatchSelectVal.length === 0) {
                                            staBatchSelectVal = staNos;
                                        } else {
                                            staBatchSelectVal = staBatchSelectVal.filter(val =>
                                                {
                                                    return new Set(staNos).has(val)
                                                }
                                            )
                                        }
                                    }
                                }
                                if (staBatchSelectVal.length === 0) {
                                    layer.msg("出库站没有交集,无法批量修改", {icon: 2});
                                    return;
                                }
                                admin.open({
                                    type: 1,
                                    area: '300px',
                                    offset: 'auto',
                                    title: '请选择站点',
                                    content: $('#staBatchSelectDialog').html(),
                                    success: function (layero, ddIndex) {
                                        // 渲染下拉框
                                        let template = Handlebars.compile($('#batchStaSelectTpl').html());
                                        $('#batchSelectStaBox').html(template({list: staBatchSelectVal}));
                                        // 确认
                                        form.on('submit(staBatchSelectConfirm)', function (obj) {
                                            let loadIdx = layer.load(2);
                                            let batchSta = Number(obj.field.batchSta);
                                            let arr = [];
                                            for (let j = 0; j<stoPreTabData.length; j++) {
                                                for (let i = 0; i<tableCache.length; i++) {
                                                    if (tableCache[i].orderNo === stoPreTabData[j].orderNo
                                                        && tableCache[i].matnr === stoPreTabData[j].matnr
                                                        && tableCache[i].locNo === stoPreTabData[j].locNo) {
                                                        tableCache[i]['staNo'] = batchSta;
                                                        arr.push(i);
                                                    }
                                                }
                                            }
                                            stoPreTabIdx.reload({data: tableCache});
                                            arr.forEach(item => {
                                                $('div[lay-id=stoPreTab] tr[data-index="' + item + '"] .order-sta-select').val(batchSta);
                                            });
                                            layui.form.render('select');
                                            arr.forEach(item => {
                                                $('div[lay-id=stoPreTab] tr[data-index="' + item + '"] .layui-select-title').find("input").css("color", "blue");
                                            });
                                            layer.close(loadIdx); layer.close(ddIndex);
                                            return false;
                                        });
                                        // 弹窗不出现滚动条
                                        $(layero).children('.layui-layer-content').css('overflow', 'visible');
                                        layui.form.render('select');
                                    },
                                })
                            }
                        }
                    })
                    return false;
                });
                // 渲染下拉树
                var insXmSel = xmSelect.render({
                    el: '#modelSel',
                    height: '250px',
                    data: modelTb.options.data,
                    initValue: mData&&mData.sensorModel ? [mData.sensorModel] : [],
                    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');
                        ,yes: function(index, layero){
                            //按钮【立即出库】的回调
                            pakout(tableCache, index);
                        }
                        ,btn2: function(index, layero){
                            //按钮【稍后处理】的回调
                            layer.close(index)
                            //return false 开启该代码可禁止点击该按钮关闭
                        }
                    });
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                } else {
                    layer.msg(res.msg, {icon: 2})
                }
            }
        })
    }
    function pakout(tableCache, layerIndex) {
        // let loadIndex = layer.load(2);
        notice.msg('正在生成出库任务......', {icon: 4});
        $.ajax({
            url: baseUrl + "/out/pakout/auth",
            headers: {'token': localStorage.getItem('token')},
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify(tableCache),
            method: 'POST',
            success: function (res) {
                notice.destroy();
                if (res.code === 200) {
                    layer.close(layerIndex);
                    layer.msg(res.msg, {icon: 1});
                    insTb.reload({where: null});
                    insTb2.reload({where: null, page: {curr: 1}});
                } else if (res.code === 403) {
                    top.location.href = baseUrl + "/";
                } else {
                    layer.msg(res.msg, {icon: 2})
                }
            }
        });
    }
    /* 删除订单 */
@@ -333,6 +347,8 @@
        })
    })
    window.pakoutPreview = pakoutPreview;
});
function tableReload(child) {
@@ -348,3 +364,25 @@
    });
}
/**
 * 一键出库
 */
function autoOut(orderId) {
    let loadIndex = layer.msg('请求中...', {icon: 16, shade: 0.01, time: false});
    $.ajax({
        url: baseUrl + "/out/pakout/orderDetlIds/auth",
        headers: {'token': localStorage.getItem('token')},
        data: { orderId : orderId },
        method: 'POST',
        success: function (res) {
            layer.close(loadIndex);
            if (res.code === 200){
                pakoutPreview(res.data);
            } else if (res.code === 403){
                top.location.href = baseUrl+"/";
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }
    })
}