liubp
2025-12-26 c08d1c10fbafd7f57eb51c51269a95c281383ae3
public/pages/property/costDetail/detail/detail.js
@@ -0,0 +1,157 @@
/**
 费用明细详情
 **/
(function (vc) {
    var $that = {};
    vc.extends({
        data: {
            costDetailInfo: {
                costDetailId: '',
                flowCode: '',
                date: '',
                communityName: '',
                communityCode: '',
                projectContent: '',
                managementAmount: '',
                managementStamped: '0',
                committeeAmount: '',
                appraisalAmount: '',
                committeeStamped: '0',
                approvalDepartment: '',
                fundTypeLevel1: '',
                fundTypeLevel2: '',
                buildingType: '1',
                maintenanceType: '',
                ownerScope: '',
                buildingScope: ''
            }
        },
        _initMethod: function () {
            $that = vc.component;
            var costDetailId = vc.getParam('costDetailId');
            if (costDetailId) {
                $that.costDetailInfo.costDetailId = costDetailId;
                $that._loadCostDetail();
            } else {
                vc.toast('缺少费用明细ID');
                setTimeout(function () {
                    vc.goBack();
                }, 1500);
            }
        },
        _initEvent: function () {
        },
        methods: {
            _loadCostDetail: function () {
                var params = {
                    communityName: vc.getCurrentCommunity().name,
                    page: 1,
                    row: 1000
                };
                var param = {
                    params: params
                };
                console.log('开始加载费用明细详情,ID:', $that.costDetailInfo.costDetailId);
                vc.http.apiGet('/maintenancePayment/queryMaintenancePayment',
                    param,
                    function (json, res) {
                        try {
                            var _json = JSON.parse(json);
                            console.log('API返回数据:', _json);
                            if (_json.code === 0 && _json.data) {
                                var records = Array.isArray(_json.data) ? _json.data : [];
                                console.log('查询到记录数:', records.length);
                                var foundItem = null;
                                var targetId = String($that.costDetailInfo.costDetailId);
                                for (var i = 0; i < records.length; i++) {
                                    var recordId = String(records[i].id);
                                    console.log('比较ID: 目标=' + targetId + ', 记录=' + recordId);
                                    if (recordId === targetId || records[i].id == $that.costDetailInfo.costDetailId) {
                                        foundItem = records[i];
                                        console.log('找到匹配记录:', foundItem);
                                        break;
                                    }
                                }
                                if (foundItem) {
                                    $that._fillDetailData(foundItem);
                                    console.log('详情数据已填充:', $that.costDetailInfo);
                                } else {
                                    console.error('未找到匹配的记录,目标ID:', $that.costDetailInfo.costDetailId);
                                    vc.toast('未找到该费用明细,ID: ' + $that.costDetailInfo.costDetailId);
                                    setTimeout(function () {
                                        vc.goBack();
                                    }, 1500);
                                }
                            } else {
                                console.error('API返回错误:', _json);
                                vc.toast(_json.msg || '未找到该费用明细');
                                setTimeout(function () {
                                    vc.goBack();
                                }, 1500);
                            }
                        } catch (e) {
                            console.error('数据解析失败:', e);
                            vc.toast('数据解析失败: ' + e.message);
                        }
                    },
                    function (errInfo, error) {
                        console.error('请求失败:', errInfo, error);
                        vc.toast('请求失败,请检查网络连接');
                    }
                );
            },
            _fillDetailData: function (item) {
                console.log('开始填充详情数据,原始数据:', item);
                var dateStr = '';
                if (item.date) {
                    dateStr = item.date.substring(0, 10);
                } else if (item.year && item.month) {
                    var monthStr = item.month < 10 ? '0' + item.month : String(item.month);
                    var dayStr = item.day ? (item.day < 10 ? '0' + item.day : String(item.day)) : '01';
                    dateStr = item.year + '-' + monthStr + '-' + dayStr;
                } else if (item.year && item.month) {
                    var monthStr = item.month < 10 ? '0' + item.month : String(item.month);
                    dateStr = item.year + '-' + monthStr;
                }
                vc.component.costDetailInfo.flowCode = item.flowNumber || '';
                vc.component.costDetailInfo.date = dateStr;
                vc.component.costDetailInfo.communityName = item.projectName || '';
                vc.component.costDetailInfo.communityCode = item.projectCode || '';
                vc.component.costDetailInfo.projectContent = item.projectContent || '';
                vc.component.costDetailInfo.managementAmount = item.managementOfficeAmount || '';
                vc.component.costDetailInfo.managementStamped = (item.managementOfficeSeal === '是' || item.managementOfficeSeal === '1') ? '1' : '0';
                vc.component.costDetailInfo.committeeAmount = item.ownersCommitteeAmount || '';
                vc.component.costDetailInfo.appraisalAmount = item.auditAmount || '';
                vc.component.costDetailInfo.committeeStamped = (item.ownersCommitteeSeal === '是' || item.ownersCommitteeSeal === '1') ? '1' : '0';
                vc.component.costDetailInfo.approvalDepartment = item.reportDepartment || '';
                vc.component.costDetailInfo.fundTypeLevel1 = item.fundTypeLevel1 || '';
                vc.component.costDetailInfo.fundTypeLevel2 = item.fundTypeLevel2 || '';
                var buildingType = item.buildingOrAll || '1';
                if (buildingType === '全体' || buildingType === '2' || buildingType === 2) {
                    vc.component.costDetailInfo.buildingType = '全体';
                } else {
                    vc.component.costDetailInfo.buildingType = '1';
                }
                vc.component.costDetailInfo.maintenanceType = item.maintenanceType || '';
                vc.component.costDetailInfo.ownerScope = item.ownerScope || '';
                vc.component.costDetailInfo.buildingScope = item.buildingScope || '';
                console.log('详情数据填充完成:', vc.component.costDetailInfo);
            },
            _goBack: function () {
                vc.goBack();
            }
        }
    });
})(window.vc);