zhangjq
2026-01-26 da84a8d3418433c7de77068c933349c874ec70bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/**
    入驻小区
**/
(function(vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            assetImportLogDetailInfo: {
                logs: [],
                logTypes: [],
                states: [{
                        name: '全部',
                        value: ''
                    },
                    {
                        name: '待导入',
                        value: 'W'
                    },
                    {
                        name: '导入成功',
                        value: 'C'
                    },
                    {
                        name: '导入失败',
                        value: 'F'
                    }
                ],
                total: 0,
                records: 1,
                moreCondition: false,
                logId: '',
                logType: '',
                state: '',
            },
            logDetails: '',
            // 当前页面是单个导入日志的详情页面(URL包含logId参数)
            // 状态筛选只对当前日志的详情记录生效,而不是对导入日志列表生效
            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);
            }
        },
        _initEvent: function() {
 
            vc.on('assetImportLogDetail', 'listAssetImportLogDetail', function(_param) {
                $that._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function(_currentPage) {
                $that._listAssetImportLogDetails(_currentPage, DEFAULT_ROWS);
            });
        },
        _destroyedMethod: function() {
            console.log('导入日志详情页面已销毁,清理资源');
            // 重置状态,避免组件销毁后仍有代码访问组件数据
            $that = null;
        },
        methods: {
            _openDelRoomModel: function(content) {
                // 解析 JSON 字符串
                try {
                    if (!content) {
                        this.logDetails = '内容为空';
                    } else if (typeof content === 'object') {
                        // 如果已经是对象,直接转换为格式化的JSON字符串
                        this.logDetails = JSON.stringify(content, null, 2);
                    } else if (typeof content === 'string') {
                        if (content.trim() === '') {
                            this.logDetails = '无内容';
                        } else {
                            try {
                                // 尝试解析字符串为JSON
                                const parsedContent = JSON.parse(content);
                                // 将解析后的对象转换为格式化的JSON字符串
                                this.logDetails = JSON.stringify(parsedContent, null, 2);
                            } catch (e) {
                                // 如果解析失败,显示原始字符串
                                this.logDetails = content;
                            }
                        }
                    } else {
                        // 其他类型直接显示
                        this.logDetails = content.toString();
                    }
                } catch (e) {
                    console.error('无法解析内容: ', e);
                    // 显示原始内容,而不是简单的错误信息
                    this.logDetails = content || '内容无法解析';
                }
                
                // 打开模态框
                $('#detailModal').modal('show');
            },
            
            _listAssetImportLogDetails: function(_page, _rows) {
                // 查询日志详情,增加重试机制
                function queryLogDetails(params, isContractV2, retryCount = 0) {
                    const maxRetries = 2;
                    console.log('查询日志详情参数:', params, '重试次数:', retryCount);
                    
                    vc.http.apiGet('/assetImportLogDetail/queryAssetImportLogDetail',
                        params,
                        function(json, res) {
                            // 检查组件是否已销毁
                            if (!$that) {
                                console.log('组件已销毁,跳过日志详情处理');
                                return;
                            }
                            
                            console.log('查询日志详情响应:', json);
                            try {
                                // 检查响应是否为空
                                if (!json || json.trim() === '') {
                                    throw new Error('响应数据为空');
                                }
                                
                                var _assetImportLogDetailInfo = JSON.parse(json);
                                console.log('解析后日志详情:', _assetImportLogDetailInfo);
                                
                                // 检查解析结果是否有效
                                if (!_assetImportLogDetailInfo) {
                                    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();
                                    }
                                    
                                    // 更新分页
                                    vc.emit('pagination', 'init', {
                                        total: $that.assetImportLogDetailInfo.records,
                                        dataCount: $that.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.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 = [];
                                    
                                    // 更新分页
                                    vc.emit('pagination', 'init', {
                                        total: 0,
                                        dataCount: 0,
                                        currentPage: _page
                                    });
                                }
                            }
                        },
                        function(errInfo, error) {
                            // 检查组件是否已销毁
                            if (!$that) {
                                console.log('组件已销毁,跳过日志详情错误处理');
                                return;
                            }
                            
                            console.log('请求日志详情失败:', errInfo, error);
                            
                            // 如果是网络错误或超时,且重试次数未达上限,则重试
                            if ((errInfo && (errInfo.includes('I/O error') || errInfo.includes('Read timed out') || errInfo.includes('timeout'))) && retryCount < maxRetries) {
                                console.log('网络错误或超时,准备重试,重试次数:', retryCount + 1);
                                // 延迟重试,避免立即重试
                                setTimeout(function() {
                                    queryLogDetails(params, isContractV2, retryCount + 1);
                                }, 1000);
                            } else {
                                // 显示友好的错误信息
                                let errorMsg = '查询导入日志详情失败: ';
                                if (errInfo && errInfo.includes('Read timed out')) {
                                    errorMsg += '请求超时,请稍后重试';
                                } else if (errInfo && errInfo.includes('I/O error')) {
                                    errorMsg += '网络异常,请检查网络连接';
                                } else {
                                    errorMsg += (errInfo || '未知错误');
                                }
                                
                                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 ($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);
                }
            },
            queryAssetImportLogType: function(_page, _rows) {
                let param = {
                    params: {
                        logType: $that.assetImportLogDetailInfo.logType,
                    }
                };
                console.log('查询日志类型参数:', param);
                //发送get请求
                vc.http.apiGet('/assetImportLogType/queryAssetImportLogType',
                    param,
                    function(json, res) {
                        console.log('查询日志类型响应:', json);
                        try {
                            let _json = JSON.parse(json);
                            console.log('解析后日志类型:', _json);
                            
                            // 检查是否为鉴权失败或404
                            if (_json.code == 404 || (_json.code && _json.code !== 0)) {
                                // 日志类型获取失败,使用默认空数组
                                $that.assetImportLogDetailInfo.logTypes = [];
                                console.warn('获取日志类型失败,使用默认空数组');
                            } else {
                                // 正常设置日志类型
                                $that.assetImportLogDetailInfo.logTypes = _json.data || [];
                            }
                        } catch (e) {
                            // 解析失败,使用默认空数组
                            console.error('解析日志类型失败:', e);
                            $that.assetImportLogDetailInfo.logTypes = [];
                        }
                        
                        // 无论日志类型获取成功与否,都尝试获取日志详情
                        $that._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理', errInfo, error);
                        // 即使获取日志类型失败,也要尝试获取日志详情
                        $that.assetImportLogDetailInfo.logTypes = [];
                        $that._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
                    }
                );
            },
 
 
            _goBack: function() {
                vc.goBack();
            },
            queryAssetImportLogDetail: function() {
                $that._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            swatchDetailState: function(_item) {
                // 注意:当前页面是单个导入日志的详情页面(URL包含logId参数)
                // 状态筛选只对当前日志的详情记录生效,而不是对导入日志列表生效
                console.log('状态筛选,state:', _item.value, 'logId:', $that.assetImportLogDetailInfo.logId);
                $that.assetImportLogDetailInfo.state = _item.value;
                $that._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            
            // 返回日志列表页面
            _goToImportLogList: function() {
                console.log('返回日志列表页面');
                // 跳转到导入日志列表页面
                vc.jumpToPage('/#/pages/property/assetImportLog');
            },
            
            // 查询合同列表,用于显示导入结果
            _queryContractListForImportResult: function() {
                // 只有在没有真实日志记录时,才创建模拟日志记录
                if ($that.assetImportLogDetailInfo.logs && $that.assetImportLogDetailInfo.logs.length > 0) {
                    console.log('已有真实日志记录,跳过创建模拟日志记录');
                    return;
                }
                
                // 不创建模拟日志记录,确保状态筛选能够正确生效
                // 当用户筛选特定状态时,如果没有对应记录,应该显示空结果,而不是模拟的成功记录
                console.log('日志详情为空,不创建模拟日志记录,确保状态筛选能够正确生效');
                
                // 清空日志数据,确保状态筛选能够正确生效
                $that.assetImportLogDetailInfo.total = 0;
                $that.assetImportLogDetailInfo.records = 0;
                $that.assetImportLogDetailInfo.logs = [];
                
                // 更新分页
                vc.emit('pagination', 'init', {
                    total: 0,
                    dataCount: 0,
                    currentPage: 1
                });
            }
        }
    });
})(window.vc);