| | |
| | | } |
| | | }, |
| | | _initMethod: function () { |
| | | // 获取费用类型字典 |
| | | vc.getDict('pay_fee_config', "fee_type_cd", function (_data) { |
| | | $that.importMeterWaterFeeInfo.feeTypeCds = _data; |
| | | vc.component.importMeterWaterFeeInfo.feeTypeCds = _data; |
| | | }); |
| | | |
| | | // 初始化社区ID |
| | | vc.component._refreshCommunityId(); |
| | | }, |
| | | _initEvent: function () { |
| | | vc.on('importMeterWaterFee', 'openImportMeterWaterFeeModal', |
| | | function (_room) { |
| | | $that._listImportMeterTypes(); |
| | | // 打开模态框时刷新社区ID |
| | | vc.component._refreshCommunityId(); |
| | | vc.component._listImportMeterTypes(); |
| | | $('#importMeterWaterFeeModel').modal('show'); |
| | | } |
| | | ); |
| | |
| | | methods: { |
| | | importMeterWaterFeeValidate() { |
| | | return vc.validate.validate({ |
| | | importMeterWaterFeeInfo: $that.importMeterWaterFeeInfo |
| | | importMeterWaterFeeInfo: vc.component.importMeterWaterFeeInfo |
| | | }, { |
| | | 'importMeterWaterFeeInfo.communityId': [ |
| | | { |
| | | limit: "required", |
| | | param: "", |
| | | errInfo: "数据异常还没有入驻小区" |
| | | } |
| | | ], |
| | | 'importMeterWaterFeeInfo.configId': [ |
| | | { |
| | | limit: "required", |
| | | param: "", |
| | | errInfo: "费用类型不能为空" |
| | | } |
| | | ], |
| | | 'importMeterWaterFeeInfo.excelTemplate': [ |
| | |
| | | }); |
| | | }, |
| | | _importMeterWaterData: function () { |
| | | if (!$that.importMeterWaterFeeValidate()) { |
| | | if (!vc.component.importMeterWaterFeeValidate()) { |
| | | vc.toast(vc.validate.errInfo); |
| | | return; |
| | | } |
| | | // 导入数据 |
| | | if (!$that.checkFileType($that.importMeterWaterFeeInfo.excelTemplate.name.split('.')[1])) { |
| | | if (!vc.component.checkFileType(vc.component.importMeterWaterFeeInfo.excelTemplate.name.split('.')[1])) { |
| | | vc.toast('不是有效的Excel格式'); |
| | | return; |
| | | } |
| | | if (!$that.checkFileSize($that.importMeterWaterFeeInfo.excelTemplate.size)) { |
| | | vc.toast('Excel文件大小不能超过20M'); |
| | | return; |
| | | } |
| | | // 移除文件大小限制检查 |
| | | // if (!vc.component.checkFileSize(vc.component.importMeterWaterFeeInfo.excelTemplate.size)) { |
| | | // vc.toast('Excel文件大小不能超过20M'); |
| | | // return; |
| | | // } |
| | | let param = new FormData(); |
| | | param.append("uploadFile", $that.importMeterWaterFeeInfo.excelTemplate); |
| | | param.append('communityId', $that.importMeterWaterFeeInfo.communityId); |
| | | param.append('feeTypeCd', $that.importMeterWaterFeeInfo.feeTypeCd); |
| | | param.append('configId', $that.importMeterWaterFeeInfo.configId); |
| | | param.append('meterType', $that.importMeterWaterFeeInfo.meterType); |
| | | param.append('importAdapt', "importMeterWaterFee"); |
| | | param.append("uploadFile", vc.component.importMeterWaterFeeInfo.excelTemplate); |
| | | param.append('communityId', vc.component.importMeterWaterFeeInfo.communityId); |
| | | param.append('feeTypeCd', vc.component.importMeterWaterFeeInfo.feeTypeCd); |
| | | param.append('configId', vc.component.importMeterWaterFeeInfo.configId); |
| | | param.append('meterType', vc.component.importMeterWaterFeeInfo.meterType); |
| | | param.append('userId', '-1'); // 添加userId参数 |
| | | param.append('USER-ID', '-1'); // 添加USER-ID参数(大写形式) |
| | | // 根据费用类型选择对应的适配器 |
| | | if (vc.component.importMeterWaterFeeInfo.feeTypeCd === '630000017') { |
| | | // 水费使用 importMeterWaterFeeV2 |
| | | param.append('importAdapt', "importMeterWaterFeeV2"); |
| | | } else if (vc.component.importMeterWaterFeeInfo.feeTypeCd === '630000007') { |
| | | // 电费使用 importElectricityFeeV2 |
| | | param.append('importAdapt', "importElectricityFeeV2"); |
| | | } else { |
| | | // 其他费用使用原有适配器 |
| | | param.append('importAdapt', "importMeterWaterFee"); |
| | | } |
| | | |
| | | // 添加详细错误信息参数,让后端返回完整的提示词 |
| | | param.append('showDetailError', 'true'); |
| | | |
| | | // 打印调试信息 |
| | | console.log('导入请求参数详情:', { |
| | | communityId: vc.component.importMeterWaterFeeInfo.communityId, |
| | | feeTypeCd: vc.component.importMeterWaterFeeInfo.feeTypeCd, |
| | | importAdapt: vc.component.importMeterWaterFeeInfo.feeTypeCd === '630000017' ? 'importMeterWaterFeeV2' : |
| | | vc.component.importMeterWaterFeeInfo.feeTypeCd === '630000007' ? 'importElectricityFeeV2' : 'importMeterWaterFee', |
| | | showDetailError: 'true' |
| | | }); |
| | | |
| | | vc.http.upload( |
| | | 'assetImport', |
| | | 'importData', |
| | | param, { |
| | | emulateJSON: true, |
| | | //添加请求头 |
| | | // 移除emulateJSON,避免与Content-Type冲突 |
| | | headers: { |
| | | "Content-Type": "multipart/form-data" |
| | | } |
| | |
| | | }); |
| | | }, |
| | | _exportMeterWaterFeeTemplate: function () { |
| | | let _meterType = $that.importMeterWaterFeeInfo.meterType; |
| | | if (!vc.notNull(_meterType)) { |
| | | vc.toast('请选择抄表类型'); |
| | | let _feeTypeCd = vc.component.importMeterWaterFeeInfo.feeTypeCd; |
| | | |
| | | if (!vc.notNull(_feeTypeCd)) { |
| | | vc.toast('请选择费用类型'); |
| | | return; |
| | | } |
| | | // vc.jumpToPage('/callComponent/importMeterWaterFee/exportData?communityId=' + + '&meterType=' + _meterType); |
| | | $('#importMeterWaterFeeModel').modal('hide'); |
| | | let param = { |
| | | params: { |
| | | communityId:vc.getCurrentCommunity().communityId, |
| | | meterType:_meterType, |
| | | pagePath:'exportMeterWater' |
| | | } |
| | | }; |
| | | //发送get请求 |
| | | vc.http.apiGet('/export.exportData', param, |
| | | function(json, res) { |
| | | let _json = JSON.parse(json); |
| | | vc.toast(_json.msg); |
| | | if (_json.code == 0) { |
| | | vc.jumpToPage('/#/pages/property/downloadTempFile?tab=下载中心') |
| | | } |
| | | }, |
| | | function(errInfo, error) { |
| | | console.log('请求失败处理'); |
| | | }); |
| | | |
| | | // 根据费用类型选择对应的模板 |
| | | let templateUrl = ''; |
| | | if (_feeTypeCd === '630000017') { |
| | | // 水费模板(对应 sheet:水费流水模板) |
| | | templateUrl = '/import/Z4水费流水模版.xlsx'; |
| | | } else if (_feeTypeCd === '630000007') { |
| | | // 电费模板(对应 sheet:电费流水模版) |
| | | templateUrl = '/import/Z4电费流水模版.xlsx'; // 使用正确的文件名,与实际文件名匹配 |
| | | } else { |
| | | // 其他费用使用默认模板 |
| | | templateUrl = '/import/抄表导入模板.xlsx'; |
| | | } |
| | | |
| | | // 直接下载模板文件 |
| | | window.open(templateUrl, '_blank'); |
| | | }, |
| | | _listImportMeterTypes: function (_page, _rows) { |
| | | var param = { |
| | |
| | | param, |
| | | function (json, res) { |
| | | var _meterTypeManageInfo = JSON.parse(json); |
| | | $that.importMeterWaterFeeInfo.meterTypes = _meterTypeManageInfo.data; |
| | | vc.component.importMeterWaterFeeInfo.meterTypes = _meterTypeManageInfo.data; |
| | | }, |
| | | function (errInfo, error) { |
| | | console.log('请求失败处理'); |
| | |
| | | ); |
| | | }, |
| | | clearAddFeeConfigInfo: function () { |
| | | $that.importMeterWaterFeeInfo = { |
| | | vc.component.importMeterWaterFeeInfo = { |
| | | communityId: vc.getCurrentCommunity().communityId, |
| | | excelTemplate: '', |
| | | secondaryFeeTypeCd: '', |
| | |
| | | }; |
| | | }, |
| | | getExcelTemplate: function (e) { |
| | | //console.log("getExcelTemplate 开始调用") |
| | | $that.importMeterWaterFeeInfo.excelTemplate = e.target.files[0]; |
| | | // 清除旧的文件对象,确保获取最新的文件 |
| | | vc.component.importMeterWaterFeeInfo.excelTemplate = null; |
| | | |
| | | // 获取用户选择的文件 |
| | | let file = e.target.files[0]; |
| | | if (!file) { |
| | | vc.toast('请选择文件'); |
| | | return; |
| | | } |
| | | |
| | | // 显示文件信息,方便调试 |
| | | console.log('选择的文件:', file.name, '大小:', file.size, '最后修改时间:', file.lastModified); |
| | | |
| | | // 保存文件对象到组件数据中 |
| | | vc.component.importMeterWaterFeeInfo.excelTemplate = file; |
| | | |
| | | // 重置input[type=file]的value,确保用户修改文件后再次选择同一文件时能触发change事件 |
| | | // 注意:这个重置必须在获取文件对象之后执行 |
| | | setTimeout(function() { |
| | | e.target.value = ''; |
| | | }, 100); |
| | | }, |
| | | checkFileType: function (fileType) { |
| | | const acceptTypes = ['xlsx']; |
| | |
| | | } |
| | | return true; |
| | | }, |
| | | _changeImportMeterWaterFeeTypeCd: function (_feeTypeCd){ |
| | | $that.importMeterWaterFeeInfo.secondaryFeeTypeCd=''; |
| | | $that.importMeterWaterFeeInfo.configId = ''; |
| | | _changeImportMeterWaterFeeTypeCd: function (_feeTypeCd){ |
| | | console.log('开始处理费用类型变更,feeTypeCd:', _feeTypeCd); |
| | | |
| | | // 立即清空当前选择,避免用户看到旧数据 |
| | | vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCd = ''; |
| | | vc.component.importMeterWaterFeeInfo.configId = ''; |
| | | |
| | | // 清空费用子类型数组,避免显示旧数据 |
| | | // 注意:vc框架中可能不支持$set,直接赋值 |
| | | vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCds = []; |
| | | |
| | | // 添加加载状态提示 |
| | | vc.toast('正在获取费用子类型...', { duration: 500 }); |
| | | |
| | | let param = { |
| | | params: { |
| | | feeTypeCd: _feeTypeCd, |
| | | communityId: vc.getCurrentCommunity().communityId |
| | | } |
| | | }; |
| | | |
| | | // 立即调用收费项目查询,传入空的费用子类型 |
| | | // 确保收费项目列表也能及时更新 |
| | | vc.component._changeSecondaryFeeTypeCdx(_feeTypeCd, ''); |
| | | |
| | | vc.http.apiGet('/secondaryFeeTypeCdGl.list.show', param, |
| | | function (json, res) { |
| | | let result = JSON.parse(json); |
| | | if (result.length ) { |
| | | $that.$set($that.importMeterWaterFeeInfo, 'secondaryFeeTypeCds', result); |
| | | } else { |
| | | $that.$set($that.importMeterWaterFeeInfo, 'secondaryFeeTypeCds', [{ |
| | | console.log('费用子类型API返回原始数据:', json); |
| | | |
| | | try { |
| | | let result = JSON.parse(json); |
| | | |
| | | // 处理数据,支持多种返回格式 |
| | | let dataArray = []; |
| | | if (result && result.code == 0 && Array.isArray(result.data)) { |
| | | // 标准组件API返回格式 |
| | | dataArray = result.data; |
| | | } else if (Array.isArray(result)) { |
| | | // 直接数组格式 |
| | | dataArray = result; |
| | | } else if (result && typeof result === 'object') { |
| | | // 单对象格式 |
| | | dataArray = [result]; |
| | | } |
| | | |
| | | console.log('费用子类型原始数据数组长度:', dataArray.length); |
| | | |
| | | // 去重处理,确保费用子类型不重复 |
| | | let secondaryFeeTypeCds = []; |
| | | let seenSecondaryFeeTypeCds = new Set(); |
| | | |
| | | for (let i = 0; i < dataArray.length; i++) { |
| | | let item = dataArray[i]; |
| | | console.log('处理费用子类型项:', i, item); |
| | | |
| | | // 严格验证数据项 |
| | | if (item && typeof item === 'object' && item.secondaryFeeTypeCd) { |
| | | // 确保secondaryFeeTypeName存在 |
| | | item.secondaryFeeTypeName = item.secondaryFeeTypeName || item.secondaryFeeTypeCd; |
| | | |
| | | if (!seenSecondaryFeeTypeCds.has(item.secondaryFeeTypeCd)) { |
| | | seenSecondaryFeeTypeCds.add(item.secondaryFeeTypeCd); |
| | | secondaryFeeTypeCds.push(item); |
| | | console.log('添加费用子类型:', item.secondaryFeeTypeCd, item.secondaryFeeTypeName); |
| | | } else { |
| | | console.log('跳过重复费用子类型:', item.secondaryFeeTypeCd); |
| | | } |
| | | } else { |
| | | console.log('跳过无效费用子类型项:', item); |
| | | } |
| | | } |
| | | |
| | | console.log('费用子类型数据去重后,共', secondaryFeeTypeCds.length, '条数据'); |
| | | |
| | | // 确保组件状态更新可靠 |
| | | if (secondaryFeeTypeCds.length > 0) { |
| | | // 使用去重后的数据,确保数据稳定 |
| | | vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCds = secondaryFeeTypeCds; |
| | | |
| | | // 自动选择第一个费用子类型 |
| | | vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCd = secondaryFeeTypeCds[0].secondaryFeeTypeCd; |
| | | |
| | | console.log('费用子类型数据处理完成,当前选择:', vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCd); |
| | | |
| | | // 重新调用收费项目查询,传入新选择的费用子类型 |
| | | // 确保收费项目列表与当前选择的费用子类型匹配 |
| | | vc.component._changeSecondaryFeeTypeCdx(_feeTypeCd, vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCd); |
| | | } else { |
| | | // 没有可用的费用子类型数据,显示友好提示 |
| | | let noDataOption = { |
| | | secondaryFeeTypeCd: "", |
| | | secondaryFeeTypeName: "无关联子类型,请直接选择收费项目" |
| | | }; |
| | | vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCds = [noDataOption]; |
| | | vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCd = ''; |
| | | |
| | | console.log('没有可用的费用子类型数据'); |
| | | } |
| | | } catch (e) { |
| | | // 解析失败,显示友好错误信息 |
| | | console.error('解析费用子类型失败:', e, json); |
| | | vc.toast('获取费用子类型失败: 数据格式错误'); |
| | | |
| | | // 恢复到初始状态 |
| | | vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCds = [{ |
| | | secondaryFeeTypeCd: "", |
| | | secondaryFeeTypeName: "无关联子类型,请直接选择收费项目" |
| | | }]); |
| | | secondaryFeeTypeName: "获取费用子类型失败,请直接选择收费项目" |
| | | }]; |
| | | vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCd = ''; |
| | | } |
| | | }, |
| | | function (errInfo, error) { |
| | | console.log('请求失败处理'); |
| | | vc.toast(errInfo); |
| | | console.error('获取费用子类型失败:', errInfo, error); |
| | | |
| | | // 显示友好错误信息 |
| | | vc.toast('获取费用子类型失败: 网络异常'); |
| | | |
| | | // 恢复到初始状态 |
| | | vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCds = [{ |
| | | secondaryFeeTypeCd: "", |
| | | secondaryFeeTypeName: "获取费用子类型失败,请直接选择收费项目" |
| | | }]; |
| | | vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCd = ''; |
| | | } |
| | | ); |
| | | $that._changeSecondaryFeeTypeCdx(_feeTypeCd, ''); |
| | | }, |
| | | _changeSecondaryFeeTypeCdx: function(_feeTypeCd,_secondaryFeeTypeCd) { |
| | | $that.importMeterWaterFeeInfo.configId = ''; |
| | | vc.component.importMeterWaterFeeInfo.configId = ''; |
| | | // 使用当前选择的费用子类型,而不是传入的参数 |
| | | var currentSecondaryFeeTypeCd = vc.component.importMeterWaterFeeInfo.secondaryFeeTypeCd; |
| | | var param = { |
| | | params: { |
| | | page: 1, |
| | | row: 20, |
| | | communityId: vc.getCurrentCommunity().communityId, |
| | | feeTypeCd: _feeTypeCd, |
| | | secondaryFeeTypeCd: _secondaryFeeTypeCd, |
| | | secondaryFeeTypeCd: currentSecondaryFeeTypeCd, |
| | | isDefault: 'F', |
| | | valid: '1' |
| | | } |
| | |
| | | vc.http.apiGet('/feeConfig.listFeeConfigs', param, |
| | | function (json, res) { |
| | | var _feeConfigManageInfo = JSON.parse(json); |
| | | $that.importMeterWaterFeeInfo.feeConfigs = _feeConfigManageInfo.feeConfigs; |
| | | vc.component.importMeterWaterFeeInfo.feeConfigs = _feeConfigManageInfo.feeConfigs; |
| | | }, |
| | | function (errInfo, error) { |
| | | console.log('请求失败处理'); |
| | | } |
| | | ); |
| | | }, |
| | | /** |
| | | * 刷新社区ID,确保使用最新的社区ID |
| | | */ |
| | | _refreshCommunityId: function () { |
| | | let currentCommunity = vc.getCurrentCommunity(); |
| | | console.log('当前社区信息:', currentCommunity); |
| | | if (currentCommunity && currentCommunity.communityId) { |
| | | vc.component.importMeterWaterFeeInfo.communityId = currentCommunity.communityId; |
| | | console.log('刷新社区ID成功:', vc.component.importMeterWaterFeeInfo.communityId); |
| | | } else { |
| | | console.error('获取社区ID失败,currentCommunity:', currentCommunity); |
| | | vc.component.importMeterWaterFeeInfo.communityId = ''; |
| | | } |
| | | }, |
| | | } |
| | | }); |
| | | })(window.vc); |