sgj
2026-02-25 23ba8d87f56be44209687ee03c8bda3e351412d1
fzzy-igdss-web/src/main/resources/static/security/snap/snapRecord.js
@@ -1,6 +1,40 @@
var layer;
var laypage;
// 监听收储公司 Select2 变化
$(document).ready(function() {
    // 监听收储公司下拉框变化
    $('select[name="key"]').on('change', function() {
        var selectedParentId = $(this).val();
        if(selectedParentId) {
            getSelectData(selectedParentId);
        } else {
            // 如果清空了收储公司选择,也清空库区选项
            var $deptSelect = $('select[name="deptId"]');
            $deptSelect.empty()
                .append('<option value="">所有</option>')
                .select2({
                    placeholder: "请选择库区",
                    allowClear: true,
                    width: 'resolve'
                });
        }
    });
    // 在点击库区下拉框时,仅验证而不发起新请求
    $('select[name="deptId"]').on('select2:opening', function(e) {
        var selectedParentId = $('select[name="key"]').val();
        if(!selectedParentId) {
            e.preventDefault();
            layer.msg('请先选择收储公司');
            return false;
        }
        // 不在此处发起请求,依赖 change 事件时的预加载
        return true;
    });
});
$(function () {
    // 初始化分页
    layui.use(['laypage', 'layer'], function () {
@@ -15,6 +49,67 @@
    initImagePreview();
});
// 修改 getSelectData 函数,支持 Select2 的数据格式
function getSelectData(parentId) {
    if(!parentId) {
        return layer.msg('请选择收储公司');
    }
    $.ajax({
        url: "../../system/dept-new/getDeptByUserType",
        type: 'POST',
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: parentId,
        success: function (response) {
            if (response) {
                deptList = response;
                // 重新初始化 Select2 或更新选项
                updateDeptSelect2Options(deptList);
            } else {
                layer.msg(response.msg || '数据加载失败');
            }
        },
        error: function (xhr, status, error) {
            layer.msg('数据加载失败');
        }
    });
}
// 更新 Select2 下拉框选项
function updateDeptSelect2Options(deptList) {
    var $deptSelect = $('select[name="deptId"]');
    // 保存当前选中的值
    var currentVal = $deptSelect.val();
    // 清空现有选项
    $deptSelect.empty();
    // 添加"所有"选项
    $deptSelect.append('<option value="">所有</option>');
    // 添加动态数据选项
    if(deptList && deptList.length > 0) {
        deptList.forEach(function(dept) {
            $deptSelect.append('<option value="' + dept.id + '">' + dept.kqmc + '</option>');
        });
    }
    // 重新初始化 Select2
    $deptSelect.select2({
        placeholder: "请选择库区",
        allowClear: true,
        width: 'resolve'
    });
    // 恢复之前的选择
    if(currentVal) {
        $deptSelect.val(currentVal).trigger('change');
    }
}
/**
 * 初始化分页组件
 */
@@ -24,9 +119,9 @@
        count: typeof totalItems !== 'undefined' ? totalItems : 0,
        limit: typeof pageSize !== 'undefined' ? pageSize : 6,
        curr: typeof currentPage !== 'undefined' ? currentPage : 1,
        layout: [ 'prev',  'next', ],
        prev: '<i class="layui-icon layui-icon-left"></i>',
        next: '<i class="layui-icon layui-icon-right"></i>',
        layout: ['prev', 'page', 'next', ],
        // prev: '<i class="layui-icon layui-icon-left"></i>',
        // next: '<i class="layui-icon layui-icon-right"></i>',
        jump: function (obj, first) {
            if (!first) {
                searchRecord(obj.curr, obj.limit)
@@ -47,9 +142,9 @@
        count: totalCount,
        limit: pageSize,
        curr: currentPage,
        layout: ['prev',  'next', ],
        prev: '<i class="layui-icon layui-icon-left"></i>',
        next: '<i class="layui-icon layui-icon-right"></i>',
        layout: ['prev', 'page', 'next', ],
        // prev: '<i class="layui-icon layui-icon-left"></i>',
        // next: '<i class="layui-icon layui-icon-right"></i>',
        jump: function (obj, first) {
            if (!first) {
                searchRecord(obj.curr, obj.limit)
@@ -177,12 +272,11 @@
                        <span>${formatDate(record.snapTime)}</span>
                    </div>
                 </div>
<!--
  <div class="meta-item">
                 <div class="meta-item">
                    <i class="layui-icon layui-icon-home"></i>
                    <span>${record.deptId || ''}</span>
                    <span>${getDeptName(record.deptId) || record.deptId || ''}</span>
                 </div>  
 -->
                                   
            </div>        
        </div>
@@ -209,6 +303,24 @@
        });
        // 返回摄像头名称,如果找不到则返回null
        return camera ? camera.name : null;
    }
    return null;
}
/**
 * 根据库区ID获取库区名称
 * @param {string} deptId - 摄像头ID
 * @returns {string|null} 摄像头名称或null
 */
function getDeptName(deptId) {
    // 确保deptList存在且为数组
    if (typeof deptList !== 'undefined' && Array.isArray(deptList) && deptId) {
        // 查找匹配的摄像头对象
        var dept = deptList.find(function(item) {
            return item.id === deptId;
        });
        // 返回摄像头名称,如果找不到则返回null
        return dept ? dept.kqmc : null;
    }
    return null;
}
@@ -319,14 +431,6 @@
    });
}
function openConf() {
    var url = ctx + "com.fzzy.igds.SnapConf.d";
    var options = {
        title: "抓拍配置",
        url: url,
        btn: 0,
        yes: function (index, layero) {
            $.modal.close(index);
        }
    };
    $.modal.openOptions(options);
    var url = ctx + "com.fzzy.igds.ConfByDept.d";
    $.modal.openTab("库区配置", url);
}