/** * 费用明细导入适配器 V2 * 处理商铺物业费和住宅物业费导入模板 */ (function (vc) { vc.extends({ data: { importReportMainV2Info: { residentialData: [], // 住宅物业费数据 commercialData: [], // 商铺物业费数据 importProgress: 0, // 导入进度 isImporting: false, // 是否正在导入 importResult: { success: 0, fail: 0, total: 0 } } }, _initMethod: function () { // 初始化导入适配器 console.log('费用明细导入适配器 V2 已初始化'); }, _initEvent: function () { // 监听导入事件 vc.on('importReportMainV2', 'startImport', function (_param) { vc.component._startImport(_param); }); }, methods: { /** * 开始导入数据 * @param {Object} _param 导入参数,包含file对象 */ _startImport: function (_param) { if (!_param || !_param.file) { vc.toast('请选择导入文件'); return; } vc.component.importReportMainV2Info.isImporting = true; vc.component.importReportMainV2Info.importProgress = 0; // 构建FormData,使用与Excel导入相同的参数格式 var param = new FormData(); param.append('uploadFile', _param.file); // 后端要求的文件名参数 param.append('communityId', _param.communityId || vc.getCurrentCommunity().communityId); // 小区编号 param.append('importAdapt', 'importReportMainV2'); // 后端提供的导入适配器 let userInfo = vc.getData('/nav/getUserInfo'); param.append('userId', userInfo ? userInfo.userId : ''); // 操作员工编号 param.append('userName', userInfo ? userInfo.name : ''); // 操作员工姓名 // 使用正确的模块名和方法名格式 vc.http.upload( 'assetImport', 'importData', param, { emulateJSON: true, headers: { "Content-Type": "multipart/form-data" } }, function (json, res) { try { var _json = JSON.parse(json); if (_json.code === 0) { vc.component.importReportMainV2Info.isImporting = false; vc.component.importReportMainV2Info.importProgress = 100; vc.toast('导入成功,共导入 ' + _json.data + ' 条数据'); // 通知父组件导入完成 vc.emit('importReportMainV2', 'importComplete', { success: _json.data, fail: 0, total: _json.data }); // 刷新费用明细列表 vc.emit('costDetail', 'listCostDetail', {}); return; } vc.toast(_json.msg || '导入失败', 10000); vc.component.importReportMainV2Info.isImporting = false; } catch (e) { vc.toast('导入失败:数据解析错误', 10000); vc.component.importReportMainV2Info.isImporting = false; } }, function (errInfo, error) { vc.toast('导入失败:' + (errInfo || '网络错误'), 10000); vc.component.importReportMainV2Info.isImporting = false; } ); }, /** * 格式化导入数据,转换为系统需要的格式 * @param {Array} _data 原始CSV数据 * @returns {Array} 格式化后的数据 */ _formatImportData: function (_data) { var formattedData = []; _data.forEach(item => { // 处理日期格式,支持多种日期格式 var dateValue = item['日期'] || item['date'] || ''; if (dateValue) { // 如果是时间戳格式,转换为日期字符串 if (/^\d+$/.test(dateValue) && dateValue.length === 13) { var dateObj = new Date(parseInt(dateValue)); dateValue = vc.dateFormat(dateObj, 'yyyy-MM-dd'); } else if (typeof dateValue === 'object' && dateValue instanceof Date) { dateValue = vc.dateFormat(dateValue, 'yyyy-MM-dd'); } } // 格式化单个数据项 var formattedItem = { communityId: vc.getCurrentCommunity().communityId, flowNumber: item['流转编码'] || item['flowNumber'] || '', projectCode: item['小区编码'] || item['projectCode'] || '', projectName: item['小区名称'] || item['projectName'] || '', date: dateValue, projectContent: item['工程内容'] || item['projectContent'] || '', managementOfficeAmount: parseFloat(item['管理处金额'] || item['managementAmount'] || 0), managementOfficeSeal: item['是否盖章'] === '是' || item['managementStamped'] === '是' || item['managementStamped'] === '1' ? '是' : '否', ownersCommitteeAmount: parseFloat(item['业委会金额'] || item['committeeAmount'] || 0), auditAmount: parseFloat(item['审价金额'] || item['appraisalAmount'] || 0), ownersCommitteeSeal: item['业委会是否盖章'] === '是' || item['committeeStamped'] === '是' || item['committeeStamped'] === '1' ? '是' : '否', reportDepartment: item['签报部门'] || item['approvalDepartment'] || '', fundTypeLevel1: item['基金类型-一级分类'] || item['fundTypeLevel1'] || '', fundTypeLevel2: item['基金类型-二级分类'] || item['fundTypeLevel2'] || '', buildingOrAll: item['幢/全体'] || item['buildingType'] || '', maintenanceType: item['维修类型'] || item['maintenanceType'] || '', createTime: vc.dateFormat(new Date(), 'yyyy-MM-dd HH:mm:ss') }; formattedData.push(formattedItem); }); return formattedData; }, /** * 取消导入 */ _cancelImport: function () { vc.component.importReportMainV2Info.isImporting = false; vc.toast('导入已取消'); } } }); })(window.vc);