czt
9 天以前 db67639449287bcec461916a7dca6003ee5dd03c
fzzy-igdss-web/src/main/resources/static/inout/inout-weight2.js
@@ -5,10 +5,9 @@
var page = 1;
var limit = 15;
var recordData = null;
var selectData = null;  //单选的信息
var snapData;//系统抓拍对象信息
var timerWeight;
var img1, img2, img3;// 页面中的图片上传名称
var curProgress = null;
$(function () {
    layui.use(['layer', 'laydate', 'form', 'table'], function () {
@@ -43,28 +42,14 @@
            }
        });
        // 监听仓库选择,选择后自动调用仓库的粮品种和产地信息
        form.on('select(select_depotId)', function (obj) {
            updateFoodVarietyByDepot(obj.value);
        });
        // 初始化表单数据
        renderTable();
    });
    //显示称重弹窗流程
    showProgress();
    // 监听比例值填写
    $(".per").blur(function () {
        deAutoByPer();
    });
    // 监听比例值填写
    // 监听重量变化
    $(".weight").blur(function () {
        deAutoByWeight();
        deAuto(this.name);
    });
    //初始化WebSocket
    // initWS(deptId, bizType, progress, userId);
});
window.onload = function () {
@@ -75,7 +60,7 @@
    }, 2500);
    // 加载视频
    initVideo(lprDto, snapDto1, snapDto2);
    initVideo(snapDto1, snapDto2, snapDto3);
    //设置地磅
    $("#scaleName").val(weightDto.sort);
@@ -94,6 +79,7 @@
function flushData() {
    var index = layer.load();
    var param = form.val("form-param");
    param.weightTag = "WEIGHT";
    table.reload('tableData', {
        url: "/basic/inout/page-inout-data",
        where: param
@@ -108,6 +94,7 @@
// 渲染表单数据
function renderTable() {
    var param = form.val("form-param");
    param.weightTag = "WEIGHT";
    // 清空数据
    $("#tableData").empty();
    table.render({
@@ -162,8 +149,8 @@
            templet: function (item) {
                var result = item.foodVariety;
                $.each(listFoodVariety, function (index, data) {
                    if (item.foodVariety == data.code) {
                        result = data.name;
                    if (item.foodVariety == data.dictValue) {
                        result = data.dictLabel;
                        return true;
                    }
                });
@@ -206,17 +193,19 @@
    });
}
/*-----------------------弹窗显示渲染-开始------------------------------*/
//操作前,重新流水数据当前信息
/**
 * 称重弹窗重新查询数据
 * @param obj
 */
function afreshGetData(obj) {
    var index = layer.load();
    recordData = null;
    var data = obj.data;
    var param = {
        userId: data.userId,
        plateNum: data.plateNum,
        id: data.id
        type: data.type,
        progress: data.progress,
        id: data.id,
        plateNum: data.plateNum
    };
    $.ajax({
        type: "POST",
@@ -229,7 +218,8 @@
                layer.alert("请刷新页面后,重新操作!!");
            } else {
                recordData = result.data;
                showWindows(recordData.progress);
                curProgress = recordData.progress;
                showWindows();
            }
            layer.close(index);
        },
@@ -240,13 +230,18 @@
    });
}
//显示流程操作弹窗
/**
 * 登记弹窗
 */
function quickRegister() {
    $("#form-data")[0].reset();
    form.render();
    //登记按钮放开
    $("#btn_register").css("display", "block");
    $("#text-info").removeClass("text-info");
    //称重操作弹窗
    var pro = '登记';
    var pro = '登记称重';
    recordData = null;
    updateEditAndProgress();
    flushPage();
    layer.open({
@@ -263,15 +258,19 @@
    });
}
//显示流程操作弹窗
function showWindows(progress) {
    //登记按钮放开
/**
 * 称重弹窗
 * @param progress
 */
function showWindows() {
    $("#form-data")[0].reset();
    form.render();
    //登记按钮隐藏
    $("#btn_register").css("display", "none");
    $("#text-info").addClass("text-info");
    //称重操作弹窗
    var pro = '空车称重';
    if (progress == 'WEIGHT_FULL') {
    if (curProgress == 'WEIGHT_FULL') {
        pro = '满车称重';
    }
    updateEditAndProgress();
@@ -290,61 +289,117 @@
    });
}
//称重弹窗中流程环节显示
function showProgress() {
    if (!inoutProgress) {
        return;
    }
    if (inoutProgress.indexOf("REGISTER") == -1) {
        $("#progress-register").css("display", "none");
    }
    if (inoutProgress.indexOf("WEIGHT_FULL") == -1) {
        $("#progress-fullWeight").css("display", "none");
    }
    if (inoutProgress.indexOf("HANDLE") == -1) {
        $("#progress-hand").css("display", "none");
    }
    if (inoutProgress.indexOf("WEIGHT_EMPTY") == -1) {
        $("#progress-emptyWeight").css("display", "none");
    }
    if (inoutProgress.indexOf("CARD_BACK") == -1) {
        $("#progress-cardBack").css("display", "none");
    }
}
//称重弹窗中更新流程节点
/**
 * 根据业务数据更新页面中的状态
 */
function updateEditAndProgress() {
    if (recordData) {
        if (InoutProgress.WEIGHT_EMPTY == recordData.progress) {
            $("#emptyWeight").removeClass("rkbk-search-input");
            $("#emptyWeight").attr("disabled", false);
            $("#progress-hand").removeClass("active");
            $("#progress-fullWeight").removeClass("active");
            $("#fullWeight").addClass("rkbk-search-input");
            $("#fullWeight").attr("disabled", true);
    //当前流程节点
    if (curProgress == null) {
        if (type === "IN") {
            curProgress = "WEIGHT_FULL";
        }
        if (type === "OUT") {
            curProgress = "WEIGHT_EMPTY";
        }
    }
    //显示当前流程
    if (type === "IN") {
        $("#rk-progress-register").addClass("active");
        if (curProgress === InoutProgress.WEIGHT_FULL) {
            $("#rk-progress-fullWeight").addClass("active");
            $("#rk-progress-hand").removeClass("active");
            $("#rk-progress-emptyWeight").removeClass("active");
        if (InoutProgress.WEIGHT_FULL == recordData.progress) {
            //满车重量可编辑
            $("#fullWeight").removeClass("rkbk-search-input");
            $("#fullWeight").attr("disabled", false);
            $("#progress-hand").addClass("active");
            $("#progress-fullWeight").addClass("active");
            //空车重量不能编辑
            $("#emptyWeight").addClass("rkbk-search-input");
            $("#emptyWeight").attr("disabled", true);
        }
    } else {
        if (curProgress === InoutProgress.WEIGHT_EMPTY) {
            $("#rk-progress-fullWeight").addClass("active");
            $("#rk-progress-hand").addClass("active");
            $("#rk-progress-emptyWeight").addClass("active");
            //满车重量不能编辑
            $("#fullWeight").addClass("rkbk-search-input");
            $("#fullWeight").attr("disabled", true);
            //空车重量可编辑
            $("#emptyWeight").removeClass("rkbk-search-input");
            $("#emptyWeight").attr("disabled", false);
        }
    }
    if (type === "OUT") {
        $("#ck-progress-register").addClass("active");
        if (curProgress === InoutProgress.WEIGHT_EMPTY) {
            $("#ck-progress-emptyWeight").addClass("active");
            $("#ck-progress-hand").removeClass("active");
            $("#ck-progress-fullWeight").removeClass("active");
            //满车重量不能编辑
            $("#fullWeight").addClass("rkbk-search-input");
            $("#fullWeight").attr("disabled", true);
            //空车重量可编辑
            $("#emptyWeight").removeClass("rkbk-search-input");
            $("#emptyWeight").attr("disabled", false);
        }
        if (curProgress === InoutProgress.WEIGHT_FULL) {
            $("#ck-progress-emptyWeight").addClass("active");
            $("#ck-progress-hand").addClass("active");
            $("#ck-progress-fullWeight").addClass("active");
            //满车重量可编辑
            $("#fullWeight").removeClass("rkbk-search-input");
            $("#fullWeight").attr("disabled", false);
            //空车重量不能编辑
            $("#emptyWeight").addClass("rkbk-search-input");
            $("#emptyWeight").attr("disabled", true);
        }
    }
    //流程显示
    if (inoutProgress) {
        if (inoutProgress.indexOf("REGISTER") === -1) {
            $("#rk-progress-register").css("display", "none");
            $("#ck-progress-register").css("display", "none");
        }
        if (inoutProgress.indexOf("WEIGHT_FULL") === -1) {
            $("#rk-progress-fullWeight").css("display", "none");
            $("#ck-progress-fullWeight").css("display", "none");
        }
        if (inoutProgress.indexOf("HANDLE") === -1) {
            $("#rk-progress-hand").css("display", "none");
            $("#ck-progress-hand").css("display", "none");
        }
        if (inoutProgress.indexOf("WEIGHT_EMPTY") === -1) {
            $("#rk-progress-emptyWeight").css("display", "none");
            $("#ck-progress-emptyWeight").css("display", "none");
        }
        if (inoutProgress.indexOf("CARD_BACK") === -1) {
            $("#rk-progress-cardBack").css("display", "none");
            $("#ck-progress-cardBack").css("display", "none");
        }
        if (type === "IN") {
            $("#rk_progress").css("display", "block");
            $("#ck_progress").css("display", "none");
        }
        if (type === "OUT") {
            $("#ck_progress").css("display", "block");
            $("#rk_progress").css("display", "none");
        }
    }
    //根据配置信息设置地磅是否可编辑
    if (weightEditTag && weightEditTag == 'N') {
        $("#fullWeight").addClass("rkbk-search-input");
        $("#fullWeight").attr("disabled", true);
        $("#emptyWeight").addClass("rkbk-search-input");
        $("#emptyWeight").attr("disabled", true);
        $("#progress-hand").removeClass("active");
        $("#progress-fullWeight").removeClass("active");
    }
}
@@ -399,308 +454,135 @@
//点击称重
function weight() {
    // 没有业务数据不可执行
    if (!recordData) {
        layer.alert("没有查询到业务数据,执行被拒绝!!");
        return;
    }
    // 如果是空车称重
    if (InoutProgress.WEIGHT_EMPTY == recordData.progress) {
        form.val("form-weight", {
    if (InoutProgress.WEIGHT_EMPTY === curProgress) {
        form.val("form-data", {
            emptyWeight: weightDto.weight
        });
        form.render();
    }
    // 如果是满车称重
    if (InoutProgress.WEIGHT_FULL == recordData.progress) {
        form.val("form-weight", {
    if (InoutProgress.WEIGHT_FULL === curProgress) {
        form.val("form-data", {
            fullWeight: weightDto.weight
        });
        form.render();
    }
    form.render();
    snapData == null;
    //点击称重时候自动抓拍数据
    layer.msg("系统自动抓拍保留记录……");
    var data = form.val("form-data");
    if (!data.plateNum) {
        alertError("提示:填写登记车牌信息");
        return;
    }
    // 点击称重自动调用抓拍
    snapData = {
        companyId: companyId,
        deptId: deptId,
        bizTag: recordData.progress,
        bizType: bizType,
        plateNum: recordData.plateNum + "-" + recordData.carNum,
        id1: (null != lprDto) ? lprDto.id : null,
        id2: (null != snapDto1) ? snapDto1.id : null,
        id3: (null != snapDto2) ? snapDto2.id : null
        progress: curProgress,
        bizType: type,
        id1: snapDto1.id,
        id2: snapDto2.id,
        id3: snapDto3.id,
        sort: $("#scaleName").val()
    };
    console.log(snapData);
    //当前AJAX服务为同步服务,返回数据包装照片信息
    var index = layer.load();
    $.ajax({
        sync: false,
        type: "POST",
        url: "../../basic/inout/snap-img",
        url: "/inout/api/snap-img",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(snapData),
        success: function (result) {
            layer.close(index);
            if (result.code != "0000") {
                layer.alert(result.msg);
                alertError(result.msg);
            } else {
                layer.msg("抓拍成功");
                snapData = result.data;
            }
        },
        error: function () {
            layer.close(index);
            layer.msg("后台调用截图失败,请重新尝试!!");
            alertError("后台调用截图失败,请重新尝试");
        }
    });
    //二次称重后,自动调用下自动计算
    if (InoutProgress.WEIGHT_EMPTY == recordData.progress) {
        deAutoByPer();
    }
    flushBtn("btn-weight");
}
// 自动计算,注意:出库水分是 +,入库水分需要 -
function deAutoByPer() {
    var curData = form.val("form-weight");
    var netWeight = 0, deImpurity = 0, deWet = 0, deSum = 0, settleWeight = 0;
    if (curData.fullWeight == 0 || curData.emptyWeight == 0) {
        return;
    }
    // 计算净重
    netWeight = curData.fullWeight - curData.emptyWeight;
    if (netWeight <= 0) {
        layer.msg("净重小于等于0,当前计算不正确!");
        return;
    }
    // 杂质扣重
    if (curData.impurity > 0) {
        deImpurity = (netWeight * curData.impurity / 100.00).toFixed(0);
    }
    // 水分增重
    if (curData.wet > 0) {
        deWet = (netWeight * curData.wet / 100.00).toFixed(0);
    }
    // 总扣重
    deSum = Number(deImpurity) + Number(curData.deOther)
        + Number(curData.deHandle);
    deSum = deSum.toFixed(0);
    // 结算净重,把水分添加近来
    settleWeight = Number(netWeight) - Number(deSum) + Number(deWet);
    settleWeight = settleWeight.toFixed(0);
    form.val("form-weight", {
        netWeight: netWeight,
        deImpurity: deImpurity,
        deWet: deWet,
        deSum: deSum,
        settleWeight: settleWeight
    });
    form.render();
}
// 自动计算
function deAutoByWeight() {
    var curData = form.val("form-weight");
    var netWeight = 0, impurity = 0, wet = 0, deSum = 0, settleWeight = 0;
    if (curData.fullWeight == 0 || curData.emptyWeight == 0) {
        return;
    }
    // 净重
    netWeight = curData.fullWeight - curData.emptyWeight;
    if (netWeight <= 0) {
        layer.msg("净重小于等于0,当前计算不正确!");
        return;
    }
    // 杂质-百分比
    if (curData.deImpurity > 0) {
        impurity = (curData.deImpurity / netWeight * 100).toFixed(2);
    }
    // 水分 -百分比
    if (curData.deWet > 0) {
        wet = (curData.deWet / netWeight * 100).toFixed(2);
    }
    // 总扣重= 杂质扣重 + 不完善扣重 + 气体扣重 + 值仓扣重 + 包装扣重
    deSum = Number(curData.deImpurity)
        + Number(curData.deOther) + Number(curData.deHandle);
    deSum = deSum.toFixed(0);
    // 结算净重,把水分添加近来
    settleWeight = Number(netWeight) - Number(deSum) + Number(curData.deWet);
    settleWeight = settleWeight.toFixed(0);
    form.val("form-weight", {
        netWeight: netWeight,
        impurity: impurity,
        wet: wet,
        deSum: deSum,
        settleWeight: settleWeight
    });
    form.render();
}
//根据当前操作的按钮ID更新其他按钮状态
function flushBtn(btnId) {
    if ("btn-weight" == btnId) {// 称重后可以点击完成称重
        $("#btn-submit").removeClass("layui-btn-disabled");
        $("#btn-submit").attr("disabled", false);
    }
    if ("btn-submit" == btnId) {
        $("#btn-submit").addClass("layui-btn-disabled");
        $("#btn-submit").attr("disabled", true);
        flushData();
        if (InoutProgress.WEIGHT_EMPTY == recordData.progress) {// 出库,如果是空车称重,完成收直接刷新页面
            layer.closeAll();
        } else {
            // 完成称重后控制按钮
            $("#btn-weight").addClass("layui-btn-disabled");
            $("#btn-weight").attr("disabled", true);
            $("#btn-printBill").removeClass("layui-btn-disabled");
            $("#btn-printBill").attr("disabled", false);
            addDisabled();
        }
    }
    if ("btn-printBill" == btnId) {// 打印过磅单,说明业务完成
        $("#btn-weight").removeClass("layui-btn-disabled");
        $("#btn-weight").attr("disabled", false);
        $("#btn-submit").addClass("layui-btn-disabled");
        $("#btn-submit").attr("disabled", true);
        $("#btn-printBill").addClass("layui-btn-disabled");
        $("#btn-printBill").attr("disabled", true);
        layer.closeAll();
        flushData();
    }
}
//更改扣重信息框不可编辑
function addDisabled() {
    //杂质
    $("#impurity").attr("disabled", true);
    $("#deImpurity").attr("disabled", true);
    //水分
    $("#wet").attr("disabled", true);
    $("#deWet").attr("disabled", true);
    //值仓
    $("#deHandle").attr("disabled", true);
    //其他
    $("#deOther").attr("disabled", true);
}
//恢复扣重信息框编辑状态
function delDisabled() {
    //杂质
    $("#impurity").attr("disabled", false);
    $("#deImpurity").attr("disabled", false);
    //水分
    $("#wet").attr("disabled", false);
    $("#deWet").attr("disabled", false);
    //值仓
    $("#deHandle").attr("disabled", false);
    //其他
    $("#deOther").attr("disabled", false);
}
// 点击打印,系统判断是否已经执行完成,如果已经完成,直接打印,如果未完成则先执行完成
/**
 * 点击打印,系统判断是否已经执行完成,如果已经完成,直接打印,如果未完成则先执行完成
 */
function printBill() {
    if (!recordData) {
        layer.alert("没有获取到业务数据,不支持打印!");
        alertError("没有获取到业务数据,打印被拒绝!");
        return;
    }
    // 从后台获取模版并打印
    var data = form.val("form-weight");
    // 合并更新當前编辑数据
    Object.assign(recordData, data);
    printBillStep2();
};
// 点击打印,先执行系统默认执行完成卡回收
function printBillStep2() {
    var index = layer.load();
    $.ajax({
        type: "POST",
        url: "../../basic/inout-report/inout-bill-weight",
        url: "/basic/print/bill-weight",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(recordData),
        success: function (result) {
            layer.close(index);
            if (result.code != "0000") {
                layer.msg(result.msg);
                alertError(result.msg);
            } else {
                layer.msg("开始渲染打印单……");
                printWeight(result.data);
                // 刷新按钮
                flushBtn("btn-printBill");
            }
        },
        error: function () {
            layer.close(index);
            layer.msg("获取打印模版失败,请联系管理员查看原因!!");
            alertError("获取打印模版失败,请联系管理员查看原因");
        }
    });
};
}
/**
 * 称重提交
 */
function submit() {
//完成称重
function submitWeight() {
    if (null == recordData) {
        notify("没有数据可以提交", null);
        return;
    }
    var data = form.val("form-weight");
    var data = form.val("form-data");
    if (!data.depotId) {
        notify("装卸仓库必须填写", null);
        alertError("提示:装卸仓库必填");
        return;
    }
    // 校验-出库空车
    if (InoutProgress.WEIGHT_EMPTY == recordData.progress) {
        if (data.emptyWeight <= 0.0) {
            notify("空车称重信息必填", null);
            return;
        }
        if (!data.customerName) {
            notify("往来单位信息必填", null);
            return;
        }
    } else {
    if (!data.customerName) {
        alertError("提示:通知单信息必填");
        return;
    }
    if (!data.foodVariety) {
        alertError("提示:粮食品种必填");
        return;
    }
    // 校验-入库满车称重
    if (InoutProgress.WEIGHT_FULL === curProgress) {
        if (data.fullWeight <= 0.0) {
            notify("满车称重信息必填", null);
            return;
        }
        if (!data.foodVariety) {
            notify("粮食品种必填", null);
            return;
        }
        if (!data.foodLocation) {
            notify("粮食产地必填", null);
            return;
        }
        if (!data.settleWeight || data.settleWeight <= 0.0) {
            notify("扣重后净信息不正确,请核实计算", null);
            alertError("提示:满车称重信息必填");
            return;
        }
    }
    // 合并更新當前编辑数据
    Object.assign(recordData, data);
    if (InoutProgress.WEIGHT_EMPTY === curProgress) {
        if (data.emptyWeight <= 0.0) {
            alertError("提示:空车称重信息必填");
            return;
        }
    }
    if(recordData){
        //合并数据
        Object.assign(recordData, data);
    }else {
        recordData = data;
    }
    recordData.progress = curProgress;
    // 获取照片
    var files = [{
@@ -711,69 +593,106 @@
        fileName: snapData.fileName3
    }];
    recordData.files = files;
    var index = layer.load();
    $.ajax({
        type: "POST",
        url: "../../basic/inout/inout-next-step",
        url: "/basic/inout/submit-weight",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(recordData),
        success: function (result) {
            if (result.code != "0000") {
                layer.alert("数据提交失败,请重试!!");
                alertError(result.msg);
            } else {
                curProgress = null;
                clearInterval(timerWeight);
                layer.alert("数据提交成功!!");
                // 更新按钮显示
                flushBtn("btn-submit");
                notify("数据提交成功", result.data);
                //第一次称重后,刷新页面
                if (recordData.recordWeight <= 0.0) {
                    $("#form-data")[0].reset();
                    form.render();
                }
            }
            layer.close(index);
        },
        error: function () {
            layer.close(index);
            layer.alert("提交失败,请重新尝试!!");
            alertError("提交失败,请重新尝试");
        }
    });
}
//重新称重时,表单不清空,按钮重置
function flushPage() {
    weightDto.weight = 0.0;
    $("#weightValue").text("0.0");
    $("#img_scale_statule").attr("src", "/img/web/inout/icon-red.png");
    timerGetWeight();
    //扣重信息框恢复为可编辑
    delDisabled();
    //表单数据重置
    form.val("form-weight", recordData);
    form.val("form-data", recordData);
    form.render();
}
//根据选择的仓库信息,更新粮食品种
function updateFoodVarietyByDepot(selectId) {
    var selectDepot;
    $.each(listDepot, function (index, data) {
        if (data.id === selectId) {
            selectDepot = data;
            return false;
/**
 * 读取身份证
 */
function flushIdCard() {
    var index = layer.load();
    $.ajax({
        type: "GET",
        async: true,
        url: "http://127.0.0.1:9111/IDCARD",
        data: {},
        dataType: "json",
        success: function (json) {
            layer.close(index);
            var data = json;
            if (data.code === "200" || data.code == 200) {
                // 临时赋值
                $("#userName").val(data.cnName);
                $("#userAddress").val(data.address);
                $("#userId").val(data.idNum);
            } else {
                alertError("没有获取到身份证信息!");
                return;
            }
        },
        error: function () {
            layer.alert("身份证读取失败!", {
                offset: ['300px', '300px']
            });
            layer.close(index);
        }
    });
    if (selectDepot) {
        form.val("form-weight", {
            foodVariety: selectDepot.foodVariety,
            foodLocation: selectDepot.foodLocation,
            foodLevel: selectDepot.foodLevel,
            noticeId: selectDepot.noticeId
        });
        form.render();
    }
}
/*-----------------------称重操作-结束------------------------------*/
/**
 * 读取车牌号
 */
function flushPlateNum() {
    var param = JSON.stringify(snapDto1);
    var index = layer.load();
    $.ajax({
        type: "POST",
        url: "/inout/api/get-plateNum",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: param,
        success: function (result) {
            if (result.code != "0000") {
                alertError(result.msg);
            } else {
                $("#plateNum").val(result.data.plateNum);
            }
            layer.close(index);
        },
        error: function () {
            layer.close(index);
            alertError("车牌识别失败!");
        }
    });
}
/**
 * 弹出提醒框
@@ -793,7 +712,7 @@
        }
        $("#resultIntelCard").text(data.intelCard);
        layer.open({
        var indexNotify = layer.open({
            type: 1,
            offset: ['150px', '200px'],
            area: '450px;',
@@ -802,7 +721,7 @@
            btn: ['确定'],
            content: $('#dialog-from-notify'),
            yes: function (index) {
                layer.closeAll();
                layer.close(indexNotify);
            }
        });
    } else {