zhangjq
2026-01-23 20a3911ce6da5ea40aee2a5f39b80f766442a4c7
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
(function (vc) {
    vc.extends({
        data: {
            importMeterWaterFeeInfo: {
                communityId: vc.getCurrentCommunity().communityId,
                excelTemplate: '',
                configId: '',
                feeConfigs: [],
                secondaryFeeTypeCds: [],
                secondaryFeeTypeCd: '',
                feeTypeCd: '',
                meterTypes: [],
                meterType: ''
            }
        },
        _initMethod: function () {
            vc.getDict('pay_fee_config', "fee_type_cd", function (_data) {
                $that.importMeterWaterFeeInfo.feeTypeCds = _data;
            });
        },
        _initEvent: function () {
            vc.on('importMeterWaterFee', 'openImportMeterWaterFeeModal',
                function (_room) {
                    $that._listImportMeterTypes();
                    $('#importMeterWaterFeeModel').modal('show');
                }
            );
        },
        methods: {
            importMeterWaterFeeValidate() {
                return vc.validate.validate({
                    importMeterWaterFeeInfo: $that.importMeterWaterFeeInfo
                }, {
                    'importMeterWaterFeeInfo.communityId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "数据异常还没有入驻小区"
                        }
                    ],
                    'importMeterWaterFeeInfo.excelTemplate': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "文件不能为空"
                        }
                    ]
                });
            },
            _importMeterWaterData: function () {
                if (!$that.importMeterWaterFeeValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                // 导入数据
                if (!$that.checkFileType($that.importMeterWaterFeeInfo.excelTemplate.name.split('.')[1])) {
                    vc.toast('不是有效的Excel格式');
                    return;
                }
                if (!$that.checkFileSize($that.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('userId', '-1'); // 添加userId参数
                param.append('USER-ID', '-1'); // 添加USER-ID参数(大写形式)
                // 根据费用类型选择对应的适配器
if ($that.importMeterWaterFeeInfo.feeTypeCd === '630000017') {
    // 水费使用 importMeterWaterFeeV2
    param.append('importAdapt', "importMeterWaterFeeV2");
} else if ($that.importMeterWaterFeeInfo.feeTypeCd === '630000007') {
    // 电费使用 importElectricityFeeV2
    param.append('importAdapt', "importElectricityFeeV2");
} else {
    // 其他费用使用原有适配器
    param.append('importAdapt', "importMeterWaterFee");
}
                vc.http.upload(
                    'assetImport',
                    'importData',
                    param, {
                        // 移除emulateJSON,避免与Content-Type冲突
                        headers: {
                            "Content-Type": "multipart/form-data"
                        }
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            vc.toast("处理成功");
                            $('#importMeterWaterFeeModel').modal('hide');
                            vc.jumpToPage('/#/pages/property/assetImportLogDetail?logId=' + _json.data.logId + '&logType=importMeterWaterFee');
                            return;
                        }
                        vc.toast(_json.msg, 10000);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo, 10000);
                    });
            },
            _exportMeterWaterFeeTemplate: function () {
                let _feeTypeCd = $that.importMeterWaterFeeInfo.feeTypeCd;
                
                if (!vc.notNull(_feeTypeCd)) {
                    vc.toast('请选择费用类型');
                    return;
                }
                
                // 根据费用类型选择对应的模板
                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 = {
                    params: {
                        page: 1,
                        row: 50,
                        communityId: vc.getCurrentCommunity().communityId
                    }
                };
                //发送get请求
                vc.http.apiGet('meterType.listMeterType',
                    param,
                    function (json, res) {
                        var _meterTypeManageInfo = JSON.parse(json);
                        $that.importMeterWaterFeeInfo.meterTypes = _meterTypeManageInfo.data;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            clearAddFeeConfigInfo: function () {
                $that.importMeterWaterFeeInfo = {
                    communityId: vc.getCurrentCommunity().communityId,
                    excelTemplate: '',
                    secondaryFeeTypeCd: '',
                    configId: '',
                    feeConfigs: [],
                    feeTypeCd: '',
                    meterTypes: [],
                    meterType: ''
                };
            },
            getExcelTemplate: function (e) {
                //console.log("getExcelTemplate 开始调用")
                $that.importMeterWaterFeeInfo.excelTemplate = e.target.files[0];
            },
            checkFileType: function (fileType) {
                const acceptTypes = ['xlsx'];
                for (var i = 0; i < acceptTypes.length; i++) {
                    if (fileType === acceptTypes[i]) {
                        return true;
                    }
                }
                return false;
            },
            checkFileSize: function (fileSize) {
                //2M
                const MAX_SIZE = 20 * 1024 * 1024;
                if (fileSize > MAX_SIZE) {
                    return false;
                }
                return true;
            },
            _changeImportMeterWaterFeeTypeCd:  function (_feeTypeCd){
                $that.importMeterWaterFeeInfo.secondaryFeeTypeCd='';
                $that.importMeterWaterFeeInfo.configId = '';
                let param = {
                    params: {
                        feeTypeCd: _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', [{
                                secondaryFeeTypeCd: "",
                                secondaryFeeTypeName: "无关联子类型,请直接选择收费项目"
                            }]);
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    }
                );
                $that._changeSecondaryFeeTypeCdx(_feeTypeCd, '');
            },
            _changeSecondaryFeeTypeCdx: function(_feeTypeCd,_secondaryFeeTypeCd) {
                $that.importMeterWaterFeeInfo.configId = '';
                var param = {
                    params: {
                        page: 1,
                        row: 20,
                        communityId: vc.getCurrentCommunity().communityId,
                        feeTypeCd: _feeTypeCd,
                        secondaryFeeTypeCd: _secondaryFeeTypeCd,
                        isDefault: 'F',
                        valid: '1'
                    }
                };
                //发送get请求
                vc.http.apiGet('/feeConfig.listFeeConfigs', param,
                    function (json, res) {
                        var _feeConfigManageInfo = JSON.parse(json);
                        $that.importMeterWaterFeeInfo.feeConfigs = _feeConfigManageInfo.feeConfigs;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
        }
    });
})(window.vc);