/**
|
入驻小区
|
**/
|
(function (vc) {
|
var DEFAULT_PAGE = vc.paginationConfig ? vc.paginationConfig.defaultPage : 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() {
|
// 标记组件未销毁
|
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) {
|
// 检查组件是否存在且未销毁
|
if (!vc.component || vc.component._isDestroyed) {
|
console.log('组件不存在或已销毁,跳过事件处理');
|
return;
|
}
|
vc.component._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
|
});
|
vc.on('pagination', 'page_event', function(_currentPage) {
|
// 检查组件是否存在且未销毁
|
if (!vc.component || vc.component._isDestroyed) {
|
console.log('组件不存在或已销毁,跳过分页事件处理');
|
return;
|
}
|
vc.component._listAssetImportLogDetails(_currentPage, DEFAULT_ROWS);
|
});
|
},
|
_destroyedMethod: function() {
|
console.log('导入日志详情页面已销毁,清理资源');
|
// 标记组件已销毁,用于异步回调中检查
|
if (vc.component) {
|
vc.component._isDestroyed = true;
|
}
|
// 移除事件监听,避免内存泄漏
|
vc.off('assetImportLogDetail');
|
vc.off('pagination');
|
},
|
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 (!vc.component || vc.component._isDestroyed) {
|
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('解析结果为空');
|
}
|
|
// 检查是否获取到数据,处理两种情况:
|
// 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 = [];
|
}
|
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();
|
}
|
}
|
|
// 更新分页
|
var totalPages = Math.ceil(vc.component.assetImportLogDetailInfo.total / _rows) || 1;
|
vc.emit('pagination', 'init', {
|
total: totalPages,
|
dataCount: vc.component.assetImportLogDetailInfo.total,
|
currentPage: _page
|
});
|
}
|
} else {
|
// 显示错误信息
|
vc.toast('查询导入日志详情失败: ' + (_assetImportLogDetailInfo.msg || '未知错误'));
|
// 更严格的检查,确保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();
|
}
|
}
|
|
// 更新分页
|
var totalPages = Math.ceil(vc.component.assetImportLogDetailInfo.total / _rows) || 1;
|
vc.emit('pagination', 'init', {
|
total: totalPages,
|
dataCount: vc.component.assetImportLogDetailInfo.total,
|
currentPage: _page
|
});
|
}
|
}
|
} catch (e) {
|
console.error('解析日志详情失败:', e, json);
|
vc.toast('解析导入日志详情失败: ' + e.message);
|
|
// 确保组件存在且未销毁,避免设置属性时出错
|
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
|
});
|
}
|
}
|
},
|
function(errInfo, error) {
|
// 检查组件是否存在且未销毁
|
if (!vc.component || vc.component._isDestroyed) {
|
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() {
|
// 检查组件是否存在且未销毁
|
if (!vc.component || vc.component._isDestroyed) {
|
console.log('组件不存在或已销毁,跳过重试');
|
return;
|
}
|
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);
|
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 (vc.component && !vc.component._isDestroyed) {
|
// 检查用户账号是否为合同管理员账号
|
var contractAdminAccounts = ['18916013413'];
|
var userAccount = '';
|
|
// 尝试从多个来源获取用户账号
|
var data = vc.getData();
|
console.log('获取到的vc.getData():', data);
|
|
if (data && typeof data === 'object') {
|
if (data.username || data.phone) {
|
userAccount = data.username || data.phone;
|
console.log('从vc.getData()直接获取到用户账号:', userAccount);
|
} else if (data.userId) {
|
userAccount = data.userId.toString();
|
console.log('从vc.getData().userId获取到用户账号:', userAccount);
|
} else if (data.userInfo && typeof data.userInfo === 'object') {
|
if (data.userInfo.username || data.userInfo.phone) {
|
userAccount = data.userInfo.username || data.userInfo.phone;
|
console.log('从vc.getData().userInfo获取到用户账号:', userAccount);
|
} else if (data.userInfo.userId) {
|
userAccount = data.userInfo.userId.toString();
|
console.log('从vc.getData().userInfo.userId获取到用户账号:', userAccount);
|
}
|
}
|
// 尝试从nav.getNavUserInfo获取
|
else if (data.nav && data.nav.userInfo) {
|
if (data.nav.userInfo.username || data.nav.userInfo.phone) {
|
userAccount = data.nav.userInfo.username || data.nav.userInfo.phone;
|
console.log('从vc.getData().nav.userInfo获取到用户账号:', userAccount);
|
} else if (data.nav.userInfo.userId) {
|
userAccount = data.nav.userInfo.userId.toString();
|
console.log('从vc.getData().nav.userInfo.userId获取到用户账号:', userAccount);
|
}
|
}
|
}
|
|
// 尝试从localStorage获取
|
if (!userAccount) {
|
try {
|
let localUserInfo = JSON.parse(window.localStorage.getItem('userInfo'));
|
if (localUserInfo) {
|
console.log('localStorage中的用户信息:', localUserInfo);
|
if (localUserInfo.username || localUserInfo.phone) {
|
userAccount = localUserInfo.username || localUserInfo.phone;
|
console.log('从localStorage获取到用户账号:', userAccount);
|
} else if (localUserInfo.userId) {
|
userAccount = localUserInfo.userId.toString();
|
console.log('从localStorage.userId获取到用户账号:', userAccount);
|
}
|
}
|
} catch (e) {
|
console.error('解析localStorage中的userInfo失败:', e);
|
}
|
}
|
|
// 尝试从sessionStorage获取
|
if (!userAccount) {
|
try {
|
let sessionUserInfo = JSON.parse(window.sessionStorage.getItem('userInfo'));
|
if (sessionUserInfo) {
|
console.log('sessionStorage中的用户信息:', sessionUserInfo);
|
if (sessionUserInfo.username || sessionUserInfo.phone) {
|
userAccount = sessionUserInfo.username || sessionUserInfo.phone;
|
console.log('从sessionStorage获取到用户账号:', userAccount);
|
} else if (sessionUserInfo.userId) {
|
userAccount = sessionUserInfo.userId.toString();
|
console.log('从sessionStorage.userId获取到用户账号:', userAccount);
|
}
|
}
|
} catch (e) {
|
console.error('解析sessionStorage中的userInfo失败:', e);
|
}
|
}
|
|
console.log('最终获取到的用户账号:', userAccount);
|
var isContractAdminAccount = contractAdminAccounts.includes(userAccount);
|
console.log('是否为合同管理员账号:', isContractAdminAccount);
|
|
if (vc.component.assetImportLogDetailInfo.logType === 'importContractV2') {
|
// 广告合同汇总表导入日志查询
|
var param = {
|
params: {
|
page: _page,
|
row: _rows,
|
logId: vc.component.assetImportLogDetailInfo.logId,
|
state: vc.component.assetImportLogDetailInfo.state,
|
importAdapt: 'importContractV2' // 使用importAdapt参数,与导入时保持一致
|
}
|
};
|
|
// 只有非合同管理员才需要传入communityId
|
if (!isContractAdminAccount) {
|
var currentCommunity = vc.getCurrentCommunity();
|
if (currentCommunity && currentCommunity.communityId) {
|
param.params.communityId = currentCommunity.communityId;
|
}
|
}
|
|
// 调用查询函数
|
queryLogDetails(param, true);
|
} else {
|
// 其他类型日志的查询逻辑
|
var param = {
|
params: {
|
page: _page,
|
row: _rows,
|
logId: vc.component.assetImportLogDetailInfo.logId,
|
state: vc.component.assetImportLogDetailInfo.state,
|
logType: vc.component.assetImportLogDetailInfo.logType
|
}
|
};
|
|
// 只有非合同管理员才需要传入communityId
|
if (!isContractAdminAccount) {
|
var currentCommunity = vc.getCurrentCommunity();
|
if (currentCommunity && currentCommunity.communityId) {
|
param.params.communityId = currentCommunity.communityId;
|
}
|
}
|
|
// 调用查询函数
|
queryLogDetails(param, false);
|
}
|
}
|
},
|
queryAssetImportLogType: function(_page, _rows) {
|
// 确保组件存在且未销毁
|
if (!vc.component || vc.component._isDestroyed) {
|
console.log('组件不存在或已销毁,跳过日志类型查询');
|
return;
|
}
|
|
let param = {
|
params: {
|
logType: vc.component.assetImportLogDetailInfo.logType,
|
}
|
};
|
console.log('查询日志类型参数:', param);
|
//发送get请求
|
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);
|
console.log('解析后日志类型:', _json);
|
|
// 检查是否为鉴权失败或404
|
if (_json.code == 404 || (_json.code && _json.code !== 0)) {
|
// 日志类型获取失败,使用默认空数组
|
vc.component.assetImportLogDetailInfo.logTypes = [];
|
console.warn('获取日志类型失败,使用默认空数组');
|
} else {
|
// 正常设置日志类型
|
vc.component.assetImportLogDetailInfo.logTypes = _json.data || [];
|
}
|
} catch (e) {
|
// 解析失败,使用默认空数组
|
console.error('解析日志类型失败:', e);
|
if (vc.component && !vc.component._isDestroyed) {
|
vc.component.assetImportLogDetailInfo.logTypes = [];
|
}
|
}
|
|
// 无论日志类型获取成功与否,都尝试获取日志详情
|
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);
|
// 即使获取日志类型失败,也要尝试获取日志详情
|
if (vc.component && !vc.component._isDestroyed) {
|
vc.component.assetImportLogDetailInfo.logTypes = [];
|
vc.component._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
|
}
|
}
|
);
|
},
|
|
|
_goBack: function() {
|
vc.goBack();
|
},
|
queryAssetImportLogDetail: function() {
|
// 检查组件是否存在且未销毁
|
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:', vc.component.assetImportLogDetailInfo.logId);
|
vc.component.assetImportLogDetailInfo.state = _item.value;
|
vc.component._listAssetImportLogDetails(DEFAULT_PAGE, DEFAULT_ROWS);
|
},
|
|
// 返回日志列表页面
|
_goToImportLogList: function() {
|
console.log('返回日志列表页面');
|
// 跳转到导入日志列表页面
|
vc.jumpToPage('/#/pages/property/assetImportLog');
|
},
|
|
// 查询合同列表,用于显示导入结果
|
_queryContractListForImportResult: function() {
|
// 检查组件是否存在且未销毁,以及assetImportLogDetailInfo是否存在
|
if (!vc.component || vc.component._isDestroyed || !vc.component.assetImportLogDetailInfo) {
|
console.log('组件不存在或已销毁,跳过合同列表查询');
|
return;
|
}
|
// 只有在没有真实日志记录时,才创建模拟日志记录
|
if (vc.component.assetImportLogDetailInfo.logs && vc.component.assetImportLogDetailInfo.logs.length > 0) {
|
console.log('已有真实日志记录,跳过创建模拟日志记录');
|
return;
|
}
|
|
// 不创建模拟日志记录,确保状态筛选能够正确生效
|
// 当用户筛选特定状态时,如果没有对应记录,应该显示空结果,而不是模拟的成功记录
|
console.log('日志详情为空,不创建模拟日志记录,确保状态筛选能够正确生效');
|
|
// 清空日志数据,确保状态筛选能够正确生效
|
vc.component.assetImportLogDetailInfo.total = 0;
|
vc.component.assetImportLogDetailInfo.records = 0;
|
vc.component.assetImportLogDetailInfo.logs = [];
|
|
// 更新分页
|
vc.emit('pagination', 'init', {
|
total: 0,
|
dataCount: 0,
|
currentPage: 1
|
});
|
}
|
}
|
});
|
})(window.vc);
|