zhangjiaqing
昨天 350fd63763da0d3a2ca9a7107dc30c6a007a7b70
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
(function (vc) {
    vc.extends({
        propTypes: {
            callBackListener: vc.propTypes.string, //父组件名称
            callBackFunction: vc.propTypes.string //父组件监听方法
        },
        data: {
            addMeterWaterInfo: {
                // 地址相关字段(使用后端给的字段名)
floorNum: '', // 弄
unitNum: '', // 门
roomNum: '', // 室
// 收费区间字段(使用后端给的字段名)
chargeStart: '', // 收费区间-起始日期
chargeEtart: '', // 收费区间-终止日期
                waterId: '',
                meterType: '',
                preDegrees: '',
                curDegrees: '',
                preReadingTime: '',
                curReadingTime: '',
                secondaryFeeTypeCds: [],
                secondaryFeeTypeCd: '',
                remark: '',
                roomId: '',
                objId: '',
                objName: '',
                feeTypeCd: '',
                feeConfigs: [],
                configId: '',
                objType: '3333',
                hasRoom: false,
                ownerName: '',
                meterTypes: [],
                computingFormula: '',
                price: 0,
                // 原有字段
                powerSupplyBureau: '',
                // 费用类型相关字段
                householdName: '',
                householdNumber: '',
                electricMeterId: '',
                handler: '',
                isTransferred: '',
                companyNameAfterTransfer: '',
                transferDate: '',
                correspondingHouseholdCount: 0,
                lastPaymentDate: '',
                readingType: '',
                multiplyingFactor: 0,
                unitPrice: 0,
                invoiceAmount: 0,
                amountDifference: 0,
                autoDeduction: '',
                remark2: '',
                address: '',
                writeTime: '',
                writer: '',
                // 水费专用字段
                checkApplyCompanyName: '',
                checkApplyDeptProject: '',
                waterFeePayer: '',
                accountNumber: '',
                meterReadBookNo: '',
                waterConsumption: '',
                sewageTreatmentWater: '',
                collectionStandard: '',
                arrearsUnpaid: '',
                latePaymentFine: '',
                latePaymentSurcharge: '',
                feePaymentStatus: '',
                carryOverBalance: '',
                totalPayableAmount: '',
                // 其他缺失字段
                statusCd: '',
                meterTypeName: '',
                feeId: '',
                roadName: '',
                createTime: ''
            }
        },
        _initMethod: function () {
            $that._initAddMeterWaterDateInfo();
            $that._listAddMeterTypes();
        },
         _initEvent: function () {
            vc.on('addMeterWater', 'openAddMeterWaterModal', function (_param) {
                $that.clearAddMeterWaterInfo();
                if (_param.hasOwnProperty("objType")) {
                    $that.addMeterWaterInfo.objType = _param.objType;
                }
                if (_param.hasOwnProperty('roomId')) {
                    $that.addMeterWaterInfo.hasRoom = true;
                    $that.addMeterWaterInfo.roomId = _param.roomId;
                    $that.addMeterWaterInfo.objId = _param.roomId;
                    // $that.addMeterWaterInfo.objName = _param.roomName.replace('0单元', ''); //处理商铺
                    $that.addMeterWaterInfo.objName = $that.transRoomName(_param.roomName);
                    let _ownerName = _param.roomName;
                    if (_param.ownerName) {
                        _ownerName += ('(' + _param.ownerName + ')');
                    }
                    $that.addMeterWaterInfo.ownerName = _ownerName;
                    $that._queryPreMeterWater(_param.roomId);
                }
                $that.addMeterWaterInfo.preReadingTime = vcFramework.dateTimeFormat(new Date().getTime());
                $that.addMeterWaterInfo.preDegrees = 0;
                $('#addMeterWaterModel').modal('show');
                $that._listAddMeterTypes();
            });
            vc.on("addMeterWater", "notify", function (_param) {
                if (_param.hasOwnProperty("roomId") && _param.roomId != "") {
                    $that.addMeterWaterInfo.roomId = _param.roomId;
                    $that.addMeterWaterInfo.objId = _param.roomId;
                    // $that.addMeterWaterInfo.objName = _param.name.replace('0单元', ''); //处理商铺;
                    $that.addMeterWaterInfo.objName = $that.transRoomName(_param.name);
                    $that._queryPreMeterWater(_param.roomId);
                }
            });
        },
        methods: {
            // 将1-1-1 转化为 1栋1单元1室
            transRoomName: function (roomName) {
                // 没有-则返回
                if (roomName.indexOf('-') < 0) {
                    return roomName;
                }
                roomName = roomName.split('-');
                return roomName[0] + '栋' + roomName[1] + '单元' + roomName[2] + '室';
            },
            _initAddMeterWaterDateInfo: function () {
                $('.addPreReadingTime').datetimepicker({
                    language: 'zh-CN',
                    fontAwesome: 'fa',
                    format: 'yyyy-mm-dd hh:ii:ss',
                    initTime: true,
                    initialDate: new Date(),
                    autoClose: 1,
                    todayBtn: true
                });
                $('.addPreReadingTime').datetimepicker()
                    .on('changeDate', function (ev) {
                        var value = $(".addPreReadingTime").val();
                        var start = Date.parse(new Date(value));
                        var end = Date.parse(new Date($that.addMeterWaterInfo.curReadingTime));
                        if (start - end >= 0) {
                            vc.toast("上期读表时间必须小于本期读表时间");
                            $(".addPreReadingTime").val('');
                            $that.addMeterWaterInfo.preReadingTime = "";
                        } else {
                            $that.addMeterWaterInfo.preReadingTime = value;
                        }
                    });
                $('.addCurReadingTime').datetimepicker({
                    language: 'zh-CN',
                    fontAwesome: 'fa',
                    format: 'yyyy-mm-dd hh:ii:ss',
                    initTime: true,
                    initialDate: new Date(),
                    autoClose: 1,
                    todayBtn: true
                });
                $('.addCurReadingTime').datetimepicker()
                    .on('changeDate', function (ev) {
                        var value = $(".addCurReadingTime").val();
                        var start = Date.parse(new Date($that.addMeterWaterInfo.preReadingTime))
                        var end = Date.parse(new Date(value))
                        if (start - end >= 0) {
                            vc.toast("本期读表时间必须大于上期读表时间");
                            $(".addCurReadingTime").val('');
                            $that.addMeterWaterInfo.curReadingTime = "";
                        } else {
                            $that.addMeterWaterInfo.curReadingTime = value;
                        }
                    });
                //防止多次点击时间插件失去焦点
                var preReadingTimeElement = document.getElementsByClassName('form-control addPreReadingTime')[0];
                if (preReadingTimeElement) {
                    preReadingTimeElement.addEventListener('click', function(e) {
                        e.currentTarget.blur();
                    });
                }
 
                var curReadingTimeElement = document.getElementsByClassName("form-control addCurReadingTime")[0];
                if (curReadingTimeElement) {
                    curReadingTimeElement.addEventListener('click', function(e) {
                        e.currentTarget.blur();
                    });
                }
            },
            addMeterWaterValidate() {
                return vc.validate.validate({
                    addMeterWaterInfo: $that.addMeterWaterInfo
                }, {
                    'addMeterWaterInfo.preDegrees': [{
                            limit: "required",
                            param: "",
                            errInfo: "上期度数不能为空"
                        },
                        {
                            limit: "money",
                            param: "",
                            errInfo: "上期度数格式错误"
                        }
                    ],
                    'addMeterWaterInfo.curDegrees': [{
                            limit: "required",
                            param: "",
                            errInfo: "本期度数不能为空"
                        },
                        {
                            limit: "money",
                            param: "",
                            errInfo: "本期度数格式错误"
                        }
                    ],
                    'addMeterWaterInfo.preReadingTime': [{
                            limit: "required",
                            param: "",
                            errInfo: "上期读表时间不能为空"
                        },
                        {
                            limit: "dateTime",
                            param: "",
                            errInfo: "上期读表时间格式错误"
                        }
                    ],
                    'addMeterWaterInfo.curReadingTime': [{
                            limit: "required",
                            param: "",
                            errInfo: "本期读表时间不能为空"
                        },
                        {
                            limit: "dateTime",
                            param: "",
                            errInfo: "本期读表时间格式错误"
                        }
                    ],
                    'addMeterWaterInfo.roomId': [{
                        limit: "required",
                        param: "",
                        errInfo: "房屋必填"
                    }],
                    'addMeterWaterInfo.meterType': [{
                        limit: "required",
                        param: "",
                        errInfo: "抄表类型必填"
                    }],
                    'addMeterWaterInfo.configId': [{
                        limit: "required",
                        param: "",
                        errInfo: "费用必填"
                    }],
                    'addMeterWaterInfo.remark': [{
                        limit: "maxLength",
                        param: "500",
                        errInfo: "备注格式错误"
                    }]
                });
            },
            saveMeterWaterInfo: function () {
                if (!$that.addMeterWaterValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                if ($that.addMeterWaterInfo.computingFormula != '9009') {
                    $that.addMeterWaterInfo.price = 0;
                }
                $that.addMeterWaterInfo.communityId = vc.getCurrentCommunity().communityId;
                //不提交数据将数据 回调给侦听处理
                if (vc.notNull($props.callBackListener)) {
                    vc.emit($props.callBackListener, $props.callBackFunction, $that.addMeterWaterInfo);
                    $('#addMeterWaterModel').modal('hide');
                    return;
                }
                vc.http.apiPost(
                    '/meterWater.saveMeterWater',
                    JSON.stringify($that.addMeterWaterInfo), {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        var _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addMeterWaterModel').modal('hide');
                            $that.clearAddMeterWaterInfo();
                            vc.emit('meterWaterManage', 'listMeterWater', {});
                            vc.emit('roomCreateFee', 'notify', {});
                            vc.emit('listParkingSpaceFee', 'notify', {});
                            vc.emit('simplifyRoomFee', 'notify', {});
                            vc.emit('simplifyCarFee', 'notify', {});
                            vc.emit('addMeterWater', 'floorSelect2', 'clearFloor', {});
                            vc.toast("添加成功");
                            return;
                        } else {
                            vc.toast(_json.msg);
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.message(errInfo);
                    });
            },
            _changeAddMeterWaterFeeTypeCd: function (_feeTypeCd) {
                $that.addMeterWaterInfo.secondaryFeeTypeCd = '';
                $that.addMeterWaterInfo.configId = '';
                
                // 获取社区ID
                let communityId = vc.getCurrentCommunity().communityId;
                console.log('当前社区ID:', communityId);
                
                let param = {
                    params: {
                        feeTypeCd: _feeTypeCd
                    }
                };
                
                // 只有当社区ID有效时,才添加到参数中
                if (communityId && communityId.trim() !== '') {
                    param.params.communityId = communityId;
                }
                
                console.log('请求参数:', JSON.stringify(param));
                
                vc.http.apiGet('/secondaryFeeTypeCdGl.list.show', param,
                    function (json, res) {
                        console.log('费用子类型API返回:', json);
                        try {
                            let _json = JSON.parse(json);
                            if (_json.length) {
                                $that.addMeterWaterInfo.secondaryFeeTypeCds = _json;
                            } else {
                                $that.addMeterWaterInfo.secondaryFeeTypeCds = [{
                                    secondaryFeeTypeCd: "",
                                    secondaryFeeTypeName: "无关联子类型,请直接选择收费项目"
                                }];
                            }
                        } catch (e) {
                            console.error('解析费用子类型失败:', e, json);
                            vc.toast('获取费用子类型失败: 数据格式错误');
                            $that.addMeterWaterInfo.secondaryFeeTypeCds = [{
                                secondaryFeeTypeCd: "",
                                secondaryFeeTypeName: "无关联子类型,请直接选择收费项目"
                            }];
                        } finally {
                            // 无论费用子类型是否加载成功,都直接加载收费项目
                            console.log('直接加载收费项目,费用类型:', _feeTypeCd);
                            $that._changeSecondaryFeeTypeCdz(_feeTypeCd, '');
                        }
                    },
                    function (errInfo, error) {
                        console.error('获取费用子类型失败:', errInfo, error);
                        vc.toast('获取费用子类型失败: ' + errInfo);
                        $that.addMeterWaterInfo.secondaryFeeTypeCds = [{
                            secondaryFeeTypeCd: "",
                            secondaryFeeTypeName: "无关联子类型,请直接选择收费项目"
                        }];
                        // 即使费用子类型加载失败,也要加载收费项目
                        console.log('费用子类型加载失败,直接加载收费项目,费用类型:', _feeTypeCd);
                        $that._changeSecondaryFeeTypeCdz(_feeTypeCd, '');
                    }
                );
            },
            _changeSecondaryFeeTypeCdz: function (_feeTypeCd, _secondaryFeeTypeCd) {
                $that.addMeterWaterInfo.configId = '';
                
                // 获取社区ID
                let communityId = vc.getCurrentCommunity().communityId;
                console.log('当前社区ID:', communityId);
                
                var param = {
                    params: {
                        page: 1,
                        row: 50,
                        feeTypeCd: _feeTypeCd,
                        secondaryFeeTypeCd: _secondaryFeeTypeCd,
                        valid: '1'
                    }
                };
                
                // 只有当社区ID有效时,才添加到参数中
                if (communityId && communityId.trim() !== '') {
                    param.params.communityId = communityId;
                }
                
                console.log('请求参数:', JSON.stringify(param));
                
                //发送get请求
                vc.http.apiGet('/feeConfig.listFeeConfigs', param,
                    function (json, res) {
                        console.log('收费项目API返回:', json);
                        try {
                            var _feeConfigManageInfo = JSON.parse(json);
                            $that.addMeterWaterInfo.feeConfigs = _feeConfigManageInfo.feeConfigs || [];
                            
                            if ($that.addMeterWaterInfo.feeConfigs.length === 0) {
                                vc.toast('未找到对应收费项目,请先设置费用项目');
                            }
                        } catch (e) {
                            console.error('解析收费项目失败:', e, json);
                            vc.toast('获取收费项目失败: 数据格式错误');
                            $that.addMeterWaterInfo.feeConfigs = [];
                        }
                    },
                    function (errInfo, error) {
                        console.error('获取收费项目失败:', errInfo, error);
                        vc.toast('获取收费项目失败: ' + errInfo);
                        $that.addMeterWaterInfo.feeConfigs = [];
                    }
                );
            },
            _changeAddMeterType: function () {
                $that._queryPreMeterWater($that.addMeterWaterInfo.roomId);
            },
            _queryPreMeterWater: function (_roomId) {
                if (!_roomId || !$that.addMeterWaterInfo) {
                    return;
                }
                let param = {
                    params: {
                        communityId: vc.getCurrentCommunity().communityId,
                        objId: _roomId,
                        objType: $that.addMeterWaterInfo.objType,
                        meterType: $that.addMeterWaterInfo.meterType
                    }
                };
                //发送get请求
                vc.http.apiGet('/meterWater/queryPreMeterWater', param,
                    function (json, res) {
                        if (json) {
                            let _meterWaterInfo = JSON.parse(json);
                            if (_meterWaterInfo && $that.addMeterWaterInfo) {
                                let _total = _meterWaterInfo.total || 0;
                                if (_total < 1) {
                                    $that.addMeterWaterInfo.preDegrees = '0';
                                    $that.addMeterWaterInfo.preReadingTime = vcFramework.dateTimeFormat(new Date().getTime());
                                    return;
                                }
                                if (_meterWaterInfo.data && _meterWaterInfo.data.length > 0) {
                                    $that.addMeterWaterInfo.preDegrees = _meterWaterInfo.data[0].curDegrees;
                                    $that.addMeterWaterInfo.preReadingTime = _meterWaterInfo.data[0].curReadingTime;
                                    if ($that.addMeterWaterInfo.computingFormula == '9009') {
                                        $that.addMeterWaterInfo.price = _meterWaterInfo.data[0].price;
                                    }
                                }
                            }
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    });
            },
            _getChange: function () {
                //上期度数
                var preDegrees = parseFloat($that.addMeterWaterInfo.preDegrees);
                //本期度数
                var curDegrees = parseFloat($that.addMeterWaterInfo.curDegrees);
                if (preDegrees > curDegrees) {
                    vc.toast("本期度数不能小于上期度数!");
                    $that.addMeterWaterInfo.curDegrees = "";
                }
            },
           _listAddMeterTypes: function (_page, _rows) {
                var param = {
                    params: {
                        page: 1,
                        row: 50,
                        communityId: vc.getCurrentCommunity().communityId
                    }
                };
                
               vc.http.apiGet('meterType.listMeterType',
                    param,
                    function (json, res) {
                        var _meterTypeManageInfo = JSON.parse(json);
                        $that.addMeterWaterInfo.meterTypes = _meterTypeManageInfo.data;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            clearAddMeterWaterInfo: function () {
                var meterTypes = $that.addMeterWaterInfo.meterTypes || [];
    
                $that.addMeterWaterInfo = {
                    floorNum: '', // 弄
unitNum: '', // 门
roomNum: '', // 室
chargeStart: '', // 收费区间-起始日期
chargeEtart: '', // 收费区间-终止日期
                    waterId: '',
                    meterType: '',
                    preDegrees: '',
                    curDegrees: '',
                    preReadingTime: '',
                    curReadingTime: '',
                    secondaryFeeTypeCd: '',
                    remark: '',
                    roomId: '',
                    objId: '',
                    objName: '',
                    feeTypeCd: '',
                    feeConfigs: [],
                    configId: '',
                    objType: '3333',
                    hasRoom: false,
                    ownerName: '',
                  meterTypes: meterTypes, // 保留抄表类型数据
                    computingFormula: '',
                    price: 0,
                    powerSupplyBureau: '',
                    // 费用类型相关字段
                    householdName: '',
                    householdNumber: '',
                    electricMeterId: '',
                    handler: '',
                    isTransferred: '',
                    companyNameAfterTransfer: '',
                    transferDate: '',
                    correspondingHouseholdCount: 0,
                lastPaymentDate: '',
                readingType: '',
                multiplyingFactor: 0,
                unitPrice: 0,
                invoiceAmount: 0,
                amountDifference: 0,
                autoDeduction: '',
                remark2: '',
                address: '',
                writeTime: '',
                writer: '',
                // 水费专用字段
                checkApplyCompanyName: '',
                checkApplyDeptProject: '',
                waterFeePayer: '',
                accountNumber: '',
                meterReadBookNo: '',
                waterConsumption: '',
                sewageTreatmentWater: '',
                collectionStandard: '',
                arrearsUnpaid: '',
                latePaymentFine: '',
                latePaymentSurcharge: '',
                feePaymentStatus: '',
                carryOverBalance: '',
                totalPayableAmount: '',
                // 其他缺失字段
                statusCd: '',
                meterTypeName: '',
                feeId: '',
                roadName: '',
                createTime: ''
                };
            },
            changeFeeConfig: function () {
                let _configId = $that.addMeterWaterInfo.configId;
                $that.addMeterWaterInfo.feeConfigs.forEach(item => {
                    if (_configId == item.configId) {
                        $that.addMeterWaterInfo.computingFormula = item.computingFormula;
                    }
                });
            }
        }
    });
})(window.vc);