1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
 费用明细详情
 **/
(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;
            // 从URL获取costDetailId
            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);
                                
                                // 查找匹配的记录 - 支持字符串和数字类型的ID比较
                                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) {
                    // 如果日期格式是 yyyy-mm-dd 或 yyyy-mm-dd HH:mm:ss,只取日期部分
                    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;
                }
                
                // 使用Vue.set或者直接赋值来确保响应式更新
                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 || '';
                
                // 处理buildingType字段
                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);