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
/**
 添加费用明细
 **/
(function (vc) {
    var $that = {};
    vc.extends({
        data: {
            costDetailInfo: {
                flowCode: '',
                date: '',
                communityName: '',
                communityCode: '',
                projectContent: '',
                managementAmount: '',
                managementStamped: '1',
                committeeAmount: '',
                appraisalAmount: '',
                committeeStamped: '1',
                approvalDepartment: '',
                fundTypeLevel1: '',
                fundTypeLevel2: '',
                buildingType: '1',
                maintenanceType: '',
                fundType: 'repair', // 默认选中维修资金
                fundSystemType: 'out' // 默认选中系统外
            }
        },
        _initMethod: function () {
            $that = vc.component;
        },
        methods: {
            _saveCostDetail: function () {
                // 验证必填字段
                if (!$that.costDetailInfo.flowCode) {
                    vc.toast('请输入流转编码');
                    return;
                }
                if (!$that.costDetailInfo.date) {
                    vc.toast('请选择日期');
                    return;
                }
                if (!$that.costDetailInfo.communityName) {
                    vc.toast('请输入小区名称');
                    return;
                }
                if (!$that.costDetailInfo.communityCode) {
                    vc.toast('请输入小区编码');
                    return;
                }
                
                // 构建保存数据
                var saveData = {
                    flowNumber: $that.costDetailInfo.flowCode,
                    date: $that.costDetailInfo.date,
                    projectName: $that.costDetailInfo.communityName,
                    projectCode: $that.costDetailInfo.communityCode,
                    projectContent: $that.costDetailInfo.projectContent,
                    managementOfficeAmount: parseFloat($that.costDetailInfo.managementAmount) || 0,
                    managementOfficeSeal: $that.costDetailInfo.managementStamped === '1' ? '是' : '否',
                    ownersCommitteeAmount: parseFloat($that.costDetailInfo.committeeAmount) || 0,
                    auditAmount: parseFloat($that.costDetailInfo.appraisalAmount) || 0,
                    ownersCommitteeSeal: $that.costDetailInfo.committeeStamped === '1' ? '是' : '否',
                    reportDepartment: $that.costDetailInfo.approvalDepartment || '',
                    fundTypeLevel1: $that.costDetailInfo.fundType === 'repair' ? '维修资金' : '公共收益',
                    fundTypeLevel2: $that.costDetailInfo.fundType === 'public' ? ($that.costDetailInfo.fundSystemType === 'out' ? '系统外' : '系统内') : '',
                    buildingOrAll: $that.costDetailInfo.buildingType === '全体' ? '全体' : ($that.costDetailInfo.buildingType || '1'),
                    maintenanceType: $that.costDetailInfo.maintenanceType || '',
                    communityId: vc.getCurrentCommunity().communityId
                };
                
                // 解析日期
                if (saveData.date) {
                    var dateParts = saveData.date.split('-');
                    if (dateParts.length >= 2) {
                        saveData.year = parseInt(dateParts[0]);
                        saveData.month = parseInt(dateParts[1]);
                        if (dateParts.length >= 3) {
                            saveData.day = parseInt(dateParts[2]);
                        }
                    }
                }
                vc.http.apiPost('/maintenancePayment/saveMaintenancePayment',
                    JSON.stringify(saveData), {
                        emulateJSON: true
                    },
                    function (json, res) {
                        try {
                            var _json = JSON.parse(json);
                            if (_json.code === 0 || _json.code === '0') {
                                vc.toast('保存成功');
                                setTimeout(function() {
                                    vc.goBack();
                                }, 1000);
                            } else {
                                vc.toast(_json.msg || '保存失败');
                            }
                        } catch (e) {
                            console.error('保存响应解析失败:', e);
                            vc.toast('保存失败');
                        }
                    },
                    function (errInfo, error) {
                        console.error('保存请求失败:', errInfo, error);
                        vc.toast('保存失败,请检查网络连接');
                    }
                );
            },
            _cancel: function () {
                vc.goBack();
            }
        }
    });
})(window.vc);