zhangjq
2026-01-27 6f51f667ae7b13dca029045c221d0b1722cf98df
public/pages/property/assetImportLogDetail/assetImportLogDetail.js
@@ -39,43 +39,68 @@
            pageType: 'detail' // 'detail' 表示单个日志详情页,'list' 表示日志列表页
        },
        _initMethod: function() {
            $that.assetImportLogDetailInfo.logId = vc.getParam('logId');
            $that.assetImportLogDetailInfo.logType = vc.getParam('logType');
            console.log('日志详情页初始化,logId:', $that.assetImportLogDetailInfo.logId, 'logType:', $that.assetImportLogDetailInfo.logType);
            // 先调用日志详情查询,再调用日志类型查询,确保即使没有日志类型也能显示日志详情
            $that._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            // 只有非广告合同汇总表导入日志才查询日志类型,因为该类型日志类型查询API返回404
            if ($that.assetImportLogDetailInfo.logType !== 'importContractV2') {
                $that.queryAssetImportLogType();
            } else {
                console.log('跳过日志类型查询,logType为importContractV2');
            }
            // 对于广告合同汇总表导入日志,如果没有详细日志,尝试查询合同列表,显示导入结果
            if ($that.assetImportLogDetailInfo.logType === 'importContractV2') {
                setTimeout(function() {
                    if (!$that.assetImportLogDetailInfo.logs || $that.assetImportLogDetailInfo.logs.length === 0) {
                        console.log('没有详细日志,尝试查询合同列表,显示导入结果');
                        $that._queryContractListForImportResult();
                    }
                }, 1000);
            // 标记组件未销毁
            if (vc.component) {
                vc.component._isDestroyed = false;
                vc.component.assetImportLogDetailInfo.logId = vc.getParam('logId');
                vc.component.assetImportLogDetailInfo.logType = vc.getParam('logType');
                console.log('日志详情页初始化,logId:', vc.component.assetImportLogDetailInfo.logId, 'logType:', vc.component.assetImportLogDetailInfo.logType);
                // 先调用日志详情查询,再调用日志类型查询,确保即使没有日志类型也能显示日志详情
                vc.component._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
                // 只有非广告合同汇总表导入日志才查询日志类型,因为该类型日志类型查询API返回404
                if (vc.component.assetImportLogDetailInfo.logType !== 'importContractV2') {
                    vc.component.queryAssetImportLogType();
                } else {
                    console.log('跳过日志类型查询,logType为importContractV2');
                }
                // 对于广告合同汇总表导入日志,如果没有详细日志,尝试查询合同列表,显示导入结果
                if (vc.component.assetImportLogDetailInfo.logType === 'importContractV2') {
                    setTimeout(function() {
                        // 检查组件是否已销毁
                        if (!vc.component || vc.component._isDestroyed) {
                            console.log('组件已销毁,跳过定时器处理');
                            return;
                        }
                        if (!vc.component.assetImportLogDetailInfo.logs || vc.component.assetImportLogDetailInfo.logs.length === 0) {
                            console.log('没有详细日志,尝试查询合同列表,显示导入结果');
                            vc.component._queryContractListForImportResult();
                        }
                    }, 1000);
                }
            }
        },
        _initEvent: function() {
            vc.on('assetImportLogDetail', 'listAssetImportLogDetail', function(_param) {
                $that._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
                // 检查组件是否存在且未销毁
                if (!vc.component || vc.component._isDestroyed) {
                    console.log('组件不存在或已销毁,跳过事件处理');
                    return;
                }
                vc.component._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function(_currentPage) {
                $that._listAssetImportLogDetails(_currentPage, DEFAULT_ROWS);
                // 检查组件是否存在且未销毁
                if (!vc.component || vc.component._isDestroyed) {
                    console.log('组件不存在或已销毁,跳过分页事件处理');
                    return;
                }
                vc.component._listAssetImportLogDetails(_currentPage, DEFAULT_ROWS);
            });
        },
        _destroyedMethod: function() {
            console.log('导入日志详情页面已销毁,清理资源');
            // 重置状态,避免组件销毁后仍有代码访问组件数据
            $that = null;
            // 标记组件已销毁,用于异步回调中检查
            if (vc.component) {
                vc.component._isDestroyed = true;
            }
            // 移除事件监听,避免内存泄漏
            vc.off('assetImportLogDetail');
            vc.off('pagination');
        },
        methods: {
            _openDelRoomModel: function(content) {
@@ -123,9 +148,9 @@
                    vc.http.apiGet('/assetImportLogDetail/queryAssetImportLogDetail',
                        params,
                        function(json, res) {
                            // 检查组件是否已销毁
                            if (!$that) {
                                console.log('组件已销毁,跳过日志详情处理');
                            // 检查组件是否存在且未销毁
                            if (!vc.component || vc.component._isDestroyed) {
                                console.log('组件不存在或已销毁,跳过日志详情处理');
                                return;
                            }
                            
@@ -144,56 +169,104 @@
                                    throw new Error('解析结果为空');
                                }
                                
                                // 检查是否获取到数据
                                if (_assetImportLogDetailInfo.code == 0) {
                                    // 正常显示数据,即使数据为空
                                    $that.assetImportLogDetailInfo.total = _assetImportLogDetailInfo.total || 0;
                                    $that.assetImportLogDetailInfo.records = _assetImportLogDetailInfo.records || 0;
                                    $that.assetImportLogDetailInfo.logs = _assetImportLogDetailInfo.data || [];
                                    console.log('查询到日志详情,共', $that.assetImportLogDetailInfo.logs.length, '条记录');
                                    // 如果日志详情为空,且是广告合同汇总表导入日志,创建模拟日志记录
                                    if ($that.assetImportLogDetailInfo.logs.length === 0 && $that.assetImportLogDetailInfo.logType === 'importContractV2') {
                                        console.log('日志详情为空,创建模拟日志记录');
                                        $that._queryContractListForImportResult();
                                // 检查是否获取到数据,处理两种情况:
                                // 1. 正常对象格式,带有code、total、records、data字段
                                // 2. 直接返回数组格式(API返回code:8时)
                                let logsData = [];
                                let isSuccess = false;
                                // 情况1:直接返回数组
                                if (Array.isArray(_assetImportLogDetailInfo)) {
                                    logsData = _assetImportLogDetailInfo;
                                    isSuccess = true;
                                }
                                // 情况2:对象格式,带有code字段
                                else if (_assetImportLogDetailInfo.code == 0 || _assetImportLogDetailInfo.code == 8) {
                                    let rawData = _assetImportLogDetailInfo.data || [];
                                    // 检查rawData是否为字符串格式的数组,如果是则解析
                                    if (typeof rawData === 'string' && (rawData.startsWith('[') || rawData.startsWith('{'))) {
                                        try {
                                            logsData = JSON.parse(rawData);
                                            // 如果解析后是对象,可能需要提取数组字段
                                            if (typeof logsData === 'object' && logsData.data) {
                                                logsData = logsData.data;
                                            }
                                        } catch (e) {
                                            console.error('解析data字符串失败:', e);
                                            logsData = [];
                                        }
                                    } else if (Array.isArray(rawData)) {
                                        // 已经是数组,直接使用
                                        logsData = rawData;
                                    } else {
                                        // 其他情况,使用空数组
                                        logsData = [];
                                    }
                                    // 更新分页
                                    vc.emit('pagination', 'init', {
                                        total: $that.assetImportLogDetailInfo.records,
                                        dataCount: $that.assetImportLogDetailInfo.total,
                                        currentPage: _page
                                    });
                                    isSuccess = true;
                                }
                                if (isSuccess) {
                                    // 正常显示数据,即使数据为空
                                    // 更严格的检查,确保vc.component和assetImportLogDetailInfo都存在
                                    if (vc.component && !vc.component._isDestroyed && vc.component.assetImportLogDetailInfo) {
                                        // 当API直接返回数组或没有返回total和records字段时,使用data数组的长度作为默认值
                                        vc.component.assetImportLogDetailInfo.total = Array.isArray(_assetImportLogDetailInfo) ? logsData.length : (_assetImportLogDetailInfo.total || logsData.length);
                                        vc.component.assetImportLogDetailInfo.records = Array.isArray(_assetImportLogDetailInfo) ? logsData.length : (_assetImportLogDetailInfo.records || logsData.length);
                                        vc.component.assetImportLogDetailInfo.logs = logsData;
                                        console.log('查询到日志详情,共', vc.component.assetImportLogDetailInfo.logs.length, '条记录');
                                        // 如果日志详情为空,且是广告合同汇总表导入日志,创建模拟日志记录
                                        if (vc.component.assetImportLogDetailInfo.logs.length === 0 && vc.component.assetImportLogDetailInfo.logType === 'importContractV2') {
                                            console.log('日志详情为空,创建模拟日志记录');
                                            // 再次检查组件是否存在
                                            if (vc.component && !vc.component._isDestroyed && vc.component.assetImportLogDetailInfo) {
                                                vc.component._queryContractListForImportResult();
                                            }
                                        }
                                        // 更新分页
                                        vc.emit('pagination', 'init', {
                                            total: vc.component.assetImportLogDetailInfo.records,
                                            dataCount: vc.component.assetImportLogDetailInfo.total,
                                            currentPage: _page
                                        });
                                    }
                                } else {
                                    // 显示错误信息
                                    vc.toast('查询导入日志详情失败: ' + (_assetImportLogDetailInfo.msg || '未知错误'));
                                    $that.assetImportLogDetailInfo.total = 0;
                                    $that.assetImportLogDetailInfo.records = 0;
                                    $that.assetImportLogDetailInfo.logs = [];
                                    // 如果是广告合同汇总表导入日志,创建模拟日志记录
                                    if ($that.assetImportLogDetailInfo.logType === 'importContractV2') {
                                        console.log('查询失败,创建模拟日志记录');
                                        $that._queryContractListForImportResult();
                                    // 更严格的检查,确保vc.component和assetImportLogDetailInfo都存在
                                    if (vc.component && !vc.component._isDestroyed && vc.component.assetImportLogDetailInfo) {
                                        vc.component.assetImportLogDetailInfo.total = 0;
                                        vc.component.assetImportLogDetailInfo.records = 0;
                                        vc.component.assetImportLogDetailInfo.logs = [];
                                        // 如果是广告合同汇总表导入日志,创建模拟日志记录
                                        if (vc.component.assetImportLogDetailInfo.logType === 'importContractV2') {
                                            console.log('查询失败,创建模拟日志记录');
                                            // 再次检查组件是否存在
                                            if (vc.component && !vc.component._isDestroyed && vc.component.assetImportLogDetailInfo) {
                                                vc.component._queryContractListForImportResult();
                                            }
                                        }
                                        // 更新分页
                                        vc.emit('pagination', 'init', {
                                            total: vc.component.assetImportLogDetailInfo.records,
                                            dataCount: vc.component.assetImportLogDetailInfo.total,
                                            currentPage: _page
                                        });
                                    }
                                    // 更新分页
                                    vc.emit('pagination', 'init', {
                                        total: $that.assetImportLogDetailInfo.records,
                                        dataCount: $that.assetImportLogDetailInfo.total,
                                        currentPage: _page
                                    });
                                }
                            } catch (e) {
                                console.error('解析日志详情失败:', e, json);
                                vc.toast('解析导入日志详情失败: ' + e.message);
                                
                                // 确保对象存在,避免设置属性时出错
                                if ($that && $that.assetImportLogDetailInfo) {
                                    $that.assetImportLogDetailInfo.total = 0;
                                    $that.assetImportLogDetailInfo.records = 0;
                                    $that.assetImportLogDetailInfo.logs = [];
                                // 确保组件存在且未销毁,避免设置属性时出错
                                if (vc.component && !vc.component._isDestroyed && vc.component.assetImportLogDetailInfo) {
                                    vc.component.assetImportLogDetailInfo.total = 0;
                                    vc.component.assetImportLogDetailInfo.records = 0;
                                    vc.component.assetImportLogDetailInfo.logs = [];
                                    
                                    // 更新分页
                                    vc.emit('pagination', 'init', {
@@ -205,9 +278,9 @@
                            }
                        },
                        function(errInfo, error) {
                            // 检查组件是否已销毁
                            if (!$that) {
                                console.log('组件已销毁,跳过日志详情错误处理');
                            // 检查组件是否存在且未销毁
                            if (!vc.component || vc.component._isDestroyed) {
                                console.log('组件不存在或已销毁,跳过日志详情错误处理');
                                return;
                            }
                            
@@ -218,6 +291,11 @@
                                console.log('网络错误或超时,准备重试,重试次数:', retryCount + 1);
                                // 延迟重试,避免立即重试
                                setTimeout(function() {
                                    // 检查组件是否存在且未销毁
                                    if (!vc.component || vc.component._isDestroyed) {
                                        console.log('组件不存在或已销毁,跳过重试');
                                        return;
                                    }
                                    queryLogDetails(params, isContractV2, retryCount + 1);
                                }, 1000);
                            } else {
@@ -232,58 +310,74 @@
                                }
                                
                                vc.toast(errorMsg);
                                $that.assetImportLogDetailInfo.total = 0;
                                $that.assetImportLogDetailInfo.records = 0;
                                $that.assetImportLogDetailInfo.logs = [];
                                // 更新分页
                                vc.emit('pagination', 'init', {
                                    total: 0,
                                    dataCount: 0,
                                    currentPage: _page
                                });
                                if (vc.component && !vc.component._isDestroyed && vc.component.assetImportLogDetailInfo) {
                                    vc.component.assetImportLogDetailInfo.total = 0;
                                    vc.component.assetImportLogDetailInfo.records = 0;
                                    vc.component.assetImportLogDetailInfo.logs = [];
                                    // 更新分页
                                    vc.emit('pagination', 'init', {
                                        total: 0,
                                        dataCount: 0,
                                        currentPage: _page
                                    });
                                }
                            }
                        }
                    );
                }
                
                // 确保组件存在且未销毁
                if (!vc.component || vc.component._isDestroyed) {
                    console.log('组件不存在或已销毁,跳过日志详情查询');
                    return;
                }
                // 对于广告合同汇总表导入日志,使用专门的查询逻辑
                if ($that.assetImportLogDetailInfo.logType === 'importContractV2') {
                    // 广告合同汇总表导入日志查询
                    var param = {
                        params: {
                            page: _page,
                            row: _rows,
                            logId: $that.assetImportLogDetailInfo.logId,
                            communityId: vc.getCurrentCommunity().communityId,
                            state: $that.assetImportLogDetailInfo.state,
                            importAdapt: 'importContractV2' // 使用importAdapt参数,与导入时保持一致
                        }
                    };
                    // 调用查询函数
                    queryLogDetails(param, true);
                } else {
                    // 其他类型日志的查询逻辑
                    var param = {
                        params: {
                            page: _page,
                            row: _rows,
                            logId: $that.assetImportLogDetailInfo.logId,
                            communityId: vc.getCurrentCommunity().communityId,
                            state: $that.assetImportLogDetailInfo.state,
                            logType: $that.assetImportLogDetailInfo.logType
                        }
                    };
                    // 调用查询函数
                    queryLogDetails(param, false);
                if (vc.component && !vc.component._isDestroyed) {
                    if (vc.component.assetImportLogDetailInfo.logType === 'importContractV2') {
                        // 广告合同汇总表导入日志查询
                        var param = {
                            params: {
                                page: _page,
                                row: _rows,
                                logId: vc.component.assetImportLogDetailInfo.logId,
                                communityId: vc.getCurrentCommunity().communityId,
                                state: vc.component.assetImportLogDetailInfo.state,
                                importAdapt: 'importContractV2' // 使用importAdapt参数,与导入时保持一致
                            }
                        };
                        // 调用查询函数
                        queryLogDetails(param, true);
                    } else {
                        // 其他类型日志的查询逻辑
                        var param = {
                            params: {
                                page: _page,
                                row: _rows,
                                logId: vc.component.assetImportLogDetailInfo.logId,
                                communityId: vc.getCurrentCommunity().communityId,
                                state: vc.component.assetImportLogDetailInfo.state,
                                logType: vc.component.assetImportLogDetailInfo.logType
                            }
                        };
                        // 调用查询函数
                        queryLogDetails(param, false);
                    }
                }
            },
            queryAssetImportLogType: function(_page, _rows) {
                // 确保组件存在且未销毁
                if (!vc.component || vc.component._isDestroyed) {
                    console.log('组件不存在或已销毁,跳过日志类型查询');
                    return;
                }
                let param = {
                    params: {
                        logType: $that.assetImportLogDetailInfo.logType,
                        logType: vc.component.assetImportLogDetailInfo.logType,
                    }
                };
                console.log('查询日志类型参数:', param);
@@ -291,6 +385,12 @@
                vc.http.apiGet('/assetImportLogType/queryAssetImportLogType',
                    param,
                    function(json, res) {
                        // 检查组件是否存在且未销毁
                        if (!vc.component || vc.component._isDestroyed) {
                            console.log('组件不存在或已销毁,跳过日志类型处理');
                            return;
                        }
                        console.log('查询日志类型响应:', json);
                        try {
                            let _json = JSON.parse(json);
@@ -299,26 +399,38 @@
                            // 检查是否为鉴权失败或404
                            if (_json.code == 404 || (_json.code && _json.code !== 0)) {
                                // 日志类型获取失败,使用默认空数组
                                $that.assetImportLogDetailInfo.logTypes = [];
                                vc.component.assetImportLogDetailInfo.logTypes = [];
                                console.warn('获取日志类型失败,使用默认空数组');
                            } else {
                                // 正常设置日志类型
                                $that.assetImportLogDetailInfo.logTypes = _json.data || [];
                                vc.component.assetImportLogDetailInfo.logTypes = _json.data || [];
                            }
                        } catch (e) {
                            // 解析失败,使用默认空数组
                            console.error('解析日志类型失败:', e);
                            $that.assetImportLogDetailInfo.logTypes = [];
                            if (vc.component && !vc.component._isDestroyed) {
                                vc.component.assetImportLogDetailInfo.logTypes = [];
                            }
                        }
                        
                        // 无论日志类型获取成功与否,都尝试获取日志详情
                        $that._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
                        if (vc.component && !vc.component._isDestroyed) {
                            vc.component._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
                        }
                    },
                    function(errInfo, error) {
                        // 检查组件是否存在且未销毁
                        if (!vc.component || vc.component._isDestroyed) {
                            console.log('组件不存在或已销毁,跳过日志类型错误处理');
                            return;
                        }
                        console.log('请求失败处理', errInfo, error);
                        // 即使获取日志类型失败,也要尝试获取日志详情
                        $that.assetImportLogDetailInfo.logTypes = [];
                        $that._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
                        if (vc.component && !vc.component._isDestroyed) {
                            vc.component.assetImportLogDetailInfo.logTypes = [];
                            vc.component._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
                        }
                    }
                );
            },
@@ -328,14 +440,24 @@
                vc.goBack();
            },
            queryAssetImportLogDetail: function() {
                $that._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
                // 检查组件是否存在且未销毁
                if (!vc.component || vc.component._isDestroyed) {
                    console.log('组件不存在或已销毁,跳过查询处理');
                    return;
                }
                vc.component._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            swatchDetailState: function(_item) {
                // 检查组件是否存在且未销毁
                if (!vc.component || vc.component._isDestroyed) {
                    console.log('组件不存在或已销毁,跳过状态筛选处理');
                    return;
                }
                // 注意:当前页面是单个导入日志的详情页面(URL包含logId参数)
                // 状态筛选只对当前日志的详情记录生效,而不是对导入日志列表生效
                console.log('状态筛选,state:', _item.value, 'logId:', $that.assetImportLogDetailInfo.logId);
                $that.assetImportLogDetailInfo.state = _item.value;
                $that._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
                console.log('状态筛选,state:', _item.value, 'logId:', vc.component.assetImportLogDetailInfo.logId);
                vc.component.assetImportLogDetailInfo.state = _item.value;
                vc.component._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            
            // 返回日志列表页面
@@ -347,8 +469,13 @@
            
            // 查询合同列表,用于显示导入结果
            _queryContractListForImportResult: function() {
                // 检查组件是否存在且未销毁,以及assetImportLogDetailInfo是否存在
                if (!vc.component || vc.component._isDestroyed || !vc.component.assetImportLogDetailInfo) {
                    console.log('组件不存在或已销毁,跳过合同列表查询');
                    return;
                }
                // 只有在没有真实日志记录时,才创建模拟日志记录
                if ($that.assetImportLogDetailInfo.logs && $that.assetImportLogDetailInfo.logs.length > 0) {
                if (vc.component.assetImportLogDetailInfo.logs && vc.component.assetImportLogDetailInfo.logs.length > 0) {
                    console.log('已有真实日志记录,跳过创建模拟日志记录');
                    return;
                }
@@ -358,9 +485,9 @@
                console.log('日志详情为空,不创建模拟日志记录,确保状态筛选能够正确生效');
                
                // 清空日志数据,确保状态筛选能够正确生效
                $that.assetImportLogDetailInfo.total = 0;
                $that.assetImportLogDetailInfo.records = 0;
                $that.assetImportLogDetailInfo.logs = [];
                vc.component.assetImportLogDetailInfo.total = 0;
                vc.component.assetImportLogDetailInfo.records = 0;
                vc.component.assetImportLogDetailInfo.logs = [];
                
                // 更新分页
                vc.emit('pagination', 'init', {