zhangjq
2026-01-27 6f51f667ae7b13dca029045c221d0b1722cf98df
public/components/property/simplifyRoomFee/simplifyRoomFee.js
@@ -38,16 +38,28 @@
        _initEvent: function () {
            //切换 至费用页面
            vc.on('simplifyRoomFee', 'switch', function (_param) {
                console.log('Received switch event with room info:', _param);
                $that.clearSimplifyRoomFeeInfo();
                if (_param.roomId == '') {
                if (!_param.roomId) {
                    console.error('No roomId provided in switch event:', _param);
                    return;
                }
                vc.copyObject(_param, $that.simplifyRoomFeeInfo)
                $that._changeSimplifyRoomFeeFeeTypeCd($that.simplifyRoomFeeInfo.feeTypeCd);
                $that._listSimplifyRoomFee(DEFAULT_PAGE, DEFAULT_ROWS);
                // 先复制所有参数到组件数据
                vc.copyObject(_param, $that.simplifyRoomFeeInfo);
                console.log('After copying room info:', $that.simplifyRoomFeeInfo);
                // 先获取字典数据
                vc.getDict('pay_fee_config', "fee_type_cd", function (_data) {
                    $that.simplifyRoomFeeInfo.feeTypeCds = _data;
                    console.log('Fetched fee type CDs:', _data);
                    // 再加载费用数据
                    console.log('Loading fee data for roomId:', $that.simplifyRoomFeeInfo.roomId);
                    $that._listSimplifyRoomFee(DEFAULT_PAGE, DEFAULT_ROWS);
                });
            });
            vc.on('simplifyRoomFee', 'notify', function () {
@@ -90,30 +102,116 @@
                //发送get请求
                vc.http.apiGet('/fee.listFee',
                    param,
                    function (json) {
                        let _feeConfigInfo = JSON.parse(json);
                        $that.simplifyRoomFeeInfo.total = _feeConfigInfo.total;
                        $that.simplifyRoomFeeInfo.records = _feeConfigInfo.records;
                        let _totalAmount = 0.0;
                        _feeConfigInfo.fees.forEach(item => {
                            _totalAmount += parseFloat(item.amountOwed);
                        })
                        $that.simplifyRoomFeeInfo.totalAmount = _totalAmount.toFixed(2);
                        $that.simplifyRoomFeeInfo.fees = _feeConfigInfo.fees.sort($that._roomFeeCompare);
                        vc.emit('simplifyRoomFee', 'paginationPlus', 'init', {
                            total: $that.simplifyRoomFeeInfo.records,
                            dataCount: $that.simplifyRoomFeeInfo.total,
                            currentPage: _page
                        });
                    function (json, res) {
                        console.log('Fee API response:', json);
                        console.log('Response status:', res.status);
                        try {
                            let _feeConfigInfo = JSON.parse(json);
                            console.log('Parsed fee config info:', _feeConfigInfo);
                            // 处理不同的数据格式
                            let feeData = [];
                            let total = 0;
                            let records = 0;
                            // 检查数据格式
                            if (_feeConfigInfo.fees && Array.isArray(_feeConfigInfo.fees)) {
                                // 格式1: { fees: [...], total: 10, records: 10 }
                                feeData = _feeConfigInfo.fees;
                                total = _feeConfigInfo.total || feeData.length;
                                records = _feeConfigInfo.records || feeData.length;
                            } else if (Array.isArray(_feeConfigInfo)) {
                                // 格式2: [...]直接返回数组
                                feeData = _feeConfigInfo;
                                total = feeData.length;
                                records = feeData.length;
                            } else if (_feeConfigInfo.data && Array.isArray(_feeConfigInfo.data)) {
                                // 格式3: { data: [...], total: 10, records: 10 }
                                feeData = _feeConfigInfo.data;
                                total = _feeConfigInfo.total || feeData.length;
                                records = _feeConfigInfo.records || feeData.length;
                            } else {
                                // 其他格式
                                console.error('Unknown fee data format:', _feeConfigInfo);
                                feeData = [];
                                total = 0;
                                records = 0;
                            }
                            console.log('Processed fee data:', {
                                feeData: feeData,
                                total: total,
                                records: records,
                                feeCount: feeData.length
                            });
                            // 直接更新组件数据,不使用sort,避免排序问题
                            $that.simplifyRoomFeeInfo.total = total;
                            $that.simplifyRoomFeeInfo.records = records;
                            let _totalAmount = 0.0;
                            feeData.forEach(item => {
                                if (item && item.amountOwed) {
                                    _totalAmount += parseFloat(item.amountOwed);
                                }
                            });
                            $that.simplifyRoomFeeInfo.totalAmount = _totalAmount.toFixed(2);
                            // 直接赋值,不排序,避免排序问题
                            $that.simplifyRoomFeeInfo.fees = feeData;
                            console.log('Assigned fees to component:', $that.simplifyRoomFeeInfo.fees);
                            console.log('Fees length:', $that.simplifyRoomFeeInfo.fees.length);
                            // 确保showFlag设置正确
                            if ($that.simplifyRoomFeeInfo.showFlag !== 'DEFAULT') {
                                $that.simplifyRoomFeeInfo.showFlag = 'DEFAULT';
                                console.log('Reset showFlag to DEFAULT');
                            }
                            // 初始化分页
                            vc.emit('simplifyRoomFee', 'paginationPlus', 'init', {
                                total: records,
                                dataCount: total,
                                currentPage: _page
                            });
                            console.log('Component data after update:', {
                                feesLength: $that.simplifyRoomFeeInfo.fees.length,
                                total: $that.simplifyRoomFeeInfo.total,
                                records: $that.simplifyRoomFeeInfo.records,
                                totalAmount: $that.simplifyRoomFeeInfo.totalAmount,
                                showFlag: $that.simplifyRoomFeeInfo.showFlag
                            });
                        } catch (error) {
                            console.error('Error processing fee data:', error);
                            // 出错时重置数据
                            $that.simplifyRoomFeeInfo.fees = [];
                            $that.simplifyRoomFeeInfo.total = 0;
                            $that.simplifyRoomFeeInfo.records = 0;
                            $that.simplifyRoomFeeInfo.totalAmount = '0.00';
                        }
                    },
                    function () {
                        console.log('请求失败处理');
                    function (errInfo, error) {
                        console.error('请求失败处理:', errInfo, error);
                        // 出错时重置数据
                        $that.simplifyRoomFeeInfo.fees = [];
                        $that.simplifyRoomFeeInfo.total = 0;
                        $that.simplifyRoomFeeInfo.records = 0;
                        $that.simplifyRoomFeeInfo.totalAmount = '0.00';
                    }
                );
            },
            _roomFeeCompare: function (a, b) {
                var val1 = a.payerObjName;
                var val2 = b.payerObjName;
                // 添加安全检查,避免字段不存在导致的错误
                if (!a || !b) {
                    return 0;
                }
                var val1 = a.payerObjName || '';
                var val2 = b.payerObjName || '';
                if (val1 < val2) {
                    return -1;
                } else if (val1 > val2) {
@@ -210,7 +308,10 @@
                })
            },
            clearSimplifyRoomFeeInfo: function () {
                let _feeConfigs = $that.roomCreateFeeAddInfo.feeTypeCds;
                let _feeConfigs = [];
                if ($that.roomCreateFeeAddInfo && $that.roomCreateFeeAddInfo.feeTypeCds) {
                    _feeConfigs = $that.roomCreateFeeAddInfo.feeTypeCds;
                }
                $that.simplifyRoomFeeInfo = {
                    total: 0,
                    records: 1,