sgj
2026-02-26 6c955bced91e431cb6dbd255257d3dafd1dc6cf2
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)
@@ -168,11 +263,11 @@
            </div>
            <div class="gallery-meta">
                 <div style="display: flex; align-items: center; gap: 15px;width: 100%">
                     <div class="meta-item" style="width: 50%">
                     <div class="meta-item" style="min-width: 60%">
                        <i class="layui-icon layui-icon-video"></i>
                        <span>${getCameraName(record.cameraId) || record.cameraId || ''}</span>
                    </div>
                    <div class="meta-item" style="width: 50%">
                    <div class="meta-item" style="min-width: 40%">
                        <i class="layui-icon layui-icon-date"></i>
                        <span>${formatDate(record.snapTime)}</span>
                    </div>
@@ -336,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);
}