zhangjiaqing
8 天以前 1cef3adee31c6934c0da4b4f0b8a6f5ac03b364f
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
(function (vc) {
    vc.extends({
        data: {
            batchPayFeeOrderInfo: {
                batchFees: [],
                allBatchFees: [],
                selectPayFeeIds: [],
                feePrices: 0.00,
                communityId: vc.getCurrentCommunity().communityId,
                ownerId: '',
                payerObjType: '',
                remark: '',
                payerObjNames: [],
                payObjs: [],
                accountAmount: 0.0,
                acctId: ''
            }
        },
        watch: {
            'batchPayFeeOrderInfo.selectPayFeeIds': {
                deep: true,
                handler: function () {
                    $that._doComputeTotalFee();
                    let checkObj = document.querySelectorAll('.all-check'); // 获取所有checkbox项
                    let _selectPayFeeIds = $that.batchPayFeeOrderInfo.selectPayFeeIds;
                    let _batchFees = $that.batchPayFeeOrderInfo.batchFees;
                    if (_selectPayFeeIds.length < _batchFees.length) {
                        checkObj[0].checked = false;
                    } else {
                        checkObj[0].checked = true;
                    }
                }
            }
        },
        _initMethod: function () {
            let _ownerId = vc.getParam('ownerId');
            let _payerObjType = vc.getParam('payerObjType');
            if (!vc.notNull(_ownerId)) {
                vc.toast('非法操作');
                vc.getBack();
                return;
            }
            $that.batchPayFeeOrderInfo.ownerId = _ownerId;
            $that.batchPayFeeOrderInfo.payerObjType = _payerObjType;
            $that._loadBatchFees();
            vc.emit('payFeeUserAccount', 'computeFeeUserAmount', {
                ownerId: _ownerId
            });
            vc.emit('payFeeDeposit', 'computeFeeDeposit', {
                ownerId: _ownerId
            });
 
        },
        _initEvent: function () {
            vc.on('batchPayFeeOrder', 'changeMonth', function (_fee) {
                $that._changeMonth(_fee.cycle, _fee);
            });
            // 用户账户组件事件
            vc.on('batchPayFeeOrder', 'changeUserAmountPrice', function (_param) {
                $that.batchPayFeeOrderInfo.accountAmount = _param.totalUserAmount;
                if (_param.selectAccount && _param.selectAccount.length > 0) {
                    _param.selectAccount.forEach(_acct => {
                        if (_acct.acctType == '2003') {
                            $that.batchPayFeeOrderInfo.acctId = _acct.acctId;
                        }
                    })
                }
                $that._doComputeTotalFee();
            });
            vc.on('batchPayFeeOrder', 'loadBatchFees', function () {
                $that._loadBatchFees();
                vc.emit('payFeeUserAccount', 'computeFeeUserAmount', {
                    ownerId: $that.batchPayFeeOrderInfo.ownerId
                });
            });
        },
        methods: {
            _loadBatchFees: function () {
                let param = {
                    params: {
                        page: 1,
                        row: 500,
                        communityId: vc.getCurrentCommunity().communityId,
                        ownerId: $that.batchPayFeeOrderInfo.ownerId,
                        payerObjType: $that.batchPayFeeOrderInfo.payerObjType,
                        state: '2008001'
                    }
                };
                let _batchFees = [];
                let _selectPayFeeIds = [];
                //发送get请求
                vc.http.apiGet('/fee.listFee',
                    param,
                    function (json) {
                        let _json = JSON.parse(json);
                        let _fees = _json.fees;
                        if (!_fees || _fees.length < 1) {
                            return;
                        }
                        _fees = _fees.sort($that._batchRoomFeeCompare);
                        //todo 过滤 费用为0 的场景
                        _fees.forEach(_feeItem => {
                            //这里注释考虑 水电抄表 费用为0 的场景,所以这里暂时注释
                            // if (parseFloat(_feeItem.amountOwed) == 0 && _feeItem.feeFlag == '2006012') {
                            //     return;
                            // }
                            _batchFees.push(_feeItem);
                        });
                        _batchFees.forEach(item => {
                            item.cycles = item.paymentCycle;
                            item.receivableAmount = item.feeTotalPrice;
                            item.receivedAmount = item.receivableAmount;
                            item.tempCycle = '-100';
                            _selectPayFeeIds.push(item.feeId);
                        });
                        $that.batchPayFeeOrderInfo.allBatchFees = _batchFees;
                        $that.batchPayFeeOrderInfo.selectPayFeeIds = _selectPayFeeIds;
                        $that.batchPayFeeOrderInfo.batchFees = _batchFees;
                        $that._pushPayObjs();
                        $that._doComputeTotalFee();
                    },
                    function () {
                        console.log('请求失败处理');
                    }
                );
            },
            _batchRoomFeeCompare: function (a, b) {
                let val1 = a.payerObjName;
                let val2 = b.payerObjName;
                if (val1 < val2) {
                    return -1;
                } else if (val1 > val2) {
                    return 1;
                } else {
                    return 0;
                }
            },
            _pushPayObjs: function () {
                let _allBatchFees = $that.batchPayFeeOrderInfo.allBatchFees;
                let _payObjs = $that.batchPayFeeOrderInfo.payObjs;
                let _payerObjNames = $that.batchPayFeeOrderInfo.payerObjNames;
                let _payerObjName = '';
                _allBatchFees.forEach(_fee => {
                    _payerObjName = '';
                    if (!_fee.feeAttrs) {
                        return;
                    }
                    _fee.feeAttrs.forEach(item => {
                        if (item.specCd == '390012') {
                            _payerObjName = item.value;
                        }
                    })
                    if (_payerObjName && !$that._hasPayObjsIn(_payerObjName)) {
                        _payObjs.push(_payerObjName);
                        _payerObjNames.push(_payerObjName);
                    }
                });
            },
            _chanagePayerObjName: function () {
                let _allBatchFees = $that.batchPayFeeOrderInfo.allBatchFees;
                $that.batchPayFeeOrderInfo.batchFees = [];
                _allBatchFees.forEach(_fee => {
                    _payerObjName = '';
                    _fee.feeAttrs.forEach(item => {
                        if (item.specCd == '390012') {
                            _payerObjName = item.value;
                        }
                    })
                    if (_payerObjName && $that._hasPayObjNamesIn(_payerObjName)) {
                        $that.batchPayFeeOrderInfo.batchFees.push(_fee)
                    }
                });
                $that._doComputeTotalFee();
            },
            _hasPayObjsIn: function (_payerObjName) {
                let _payObjs = $that.batchPayFeeOrderInfo.payObjs;
                let _hasIn = false;
                _payObjs.forEach(item => {
                    if (item == _payerObjName) {
                        _hasIn = true;
                    }
                });
                return _hasIn;
            },
            _hasPayObjNamesIn: function (_payerObjName) {
                let _payObjs = $that.batchPayFeeOrderInfo.payerObjNames;
                let _hasIn = false;
                _payObjs.forEach(item => {
                    if (item == _payerObjName) {
                        _hasIn = true;
                    }
                });
                return _hasIn;
            },
            _openPayFee: function (_payType) {
                if ($that.batchPayFeeOrderInfo.selectPayFeeIds.length <= 0) {
                    vc.toast('未选择费用');
                    return;
                }
                let _payerObjName = $that.batchPayFeeOrderInfo.payerObjNames.join(',')
                //打开model
                vc.emit('batchPayConfirm', 'openBatchPayFee', {
                    fees: $that._getPayFees(),
                    payType: _payType,
                    feePrices: $that.batchPayFeeOrderInfo.feePrices,
                    payerObjName: _payerObjName,
                    acctId: $that.batchPayFeeOrderInfo.acctId,
                    accountAmount: $that.batchPayFeeOrderInfo.accountAmount,
                });
            },
            _getPayFees: function () {
                let _fees = [];
                let _selectPayFeeIds = $that.batchPayFeeOrderInfo.selectPayFeeIds;
                let _batchFees = $that.batchPayFeeOrderInfo.batchFees;
                _selectPayFeeIds.forEach(function (_item) {
                    _batchFees.forEach(function (_batchFeeItem) {
                        if (_item == _batchFeeItem.feeId) {
                            _fees.push(_batchFeeItem);
                        }
                    })
                });
                return _fees;
            },
 
            _goBack: function () {
                vc.goBack();
            },
            _printOwnOrder: function () {
                vc.saveData('java110_printFee', {
                    fees: $that.batchPayFeeOrderInfo.batchFees,
                    roomName: $that.batchPayFeeOrderInfo.roomName
                });
                //打印催交单
                window.open('/print.html#/pages/property/printBatchFee?roomId=' + $that.batchPayFeeOrderInfo.payObjId)
            },
            _getDeadlineTime: function (_fee) {
                if (_fee.amountOwed == 0 && _fee.endTime == _fee.deadlineTime) {
                    return "-";
                }
                if (_fee.state == '2009001') {
                    return "-";
                }
                return vc.dateFormat(_fee.deadlineTime);
            },
            _getEndTime: function (_fee) {
                if (_fee.state == '2009001') {
                    return "-";
                }
                return vc.dateFormat(_fee.endTime);
            },
            checkAll: function (e) {
                var checkObj = document.querySelectorAll('.checkItem'); // 获取所有checkbox项
                if (e.target.checked) { // 判定全选checkbox的勾选状态
                    for (var i = 0; i < checkObj.length; i++) {
                        if (!checkObj[i].checked) { // 将未勾选的checkbox选项push到绑定数组中
                            $that.batchPayFeeOrderInfo.selectPayFeeIds.push(checkObj[i].value);
                        }
                    }
                } else { // 如果是去掉全选则清空checkbox选项绑定数组
                    $that.batchPayFeeOrderInfo.selectPayFeeIds = [];
                }
            },
            _getBatchPayFeeRoomName: function (fee) {
                let _feeName = ''
                if (!fee.feeAttrs) {
                    return "";
                }
                fee.feeAttrs.forEach(item => {
                    if (item.specCd == '390012') {
                        _feeName = item.value;
                    }
                })
                return _feeName;
            },
            _getBatchPaymentCycles: function (fee) {
                let paymentCycles = [];
                for (let _index = 1; _index < 13; _index++) {
                    paymentCycles.push(_index * parseFloat(fee.paymentCycle))
                }
                return paymentCycles;
            },
            _doComputeTotalFee: function () {
                let _selectPayFeeIds = $that.batchPayFeeOrderInfo.selectPayFeeIds;
                let _batchFees = $that.batchPayFeeOrderInfo.batchFees;
                let _accountAmount = $that.batchPayFeeOrderInfo.accountAmount;
                let _totalFee = 0;
                _selectPayFeeIds.forEach(selectItem => {
                    _batchFees.forEach(feeItem => {
                        if (selectItem == feeItem.feeId && feeItem.receivedAmount) {
                            _totalFee += parseFloat(feeItem.receivedAmount)
                        }
                    })
                });
                if (_accountAmount) {
                    _totalFee = _totalFee - parseFloat(_accountAmount);
                }
                if (_totalFee < 0) {
                    _totalFee = 0;
                }
                $that.batchPayFeeOrderInfo.feePrices = _totalFee.toFixed(2);
            },
            _changeMonth: function (_cycles, _fee) {
                if (!_cycles) {
                    _cycles = _fee.cycles;
                }
                let param = {
                    params: {
                        communityId: vc.getCurrentCommunity().communityId,
                        feeId: _fee.feeId,
                        page: 1,
                        row: 1,
                        cycle: _cycles
                    }
                };
 
                if (_fee.tempCycle == '-103') {
                    let _custEndTime = vc.dateAdd(_fee.custEndTime);
                    //前端选择会默认 少一天 所以 加上一天
                    param.params.custEndTime = _custEndTime;
                }
                //todo 自定义金额时不计算
                if (_fee.tempCycle == '-101') {
                    $that._doComputeTotalFee();
                    $that.$forceUpdate();
                    return;
                }
 
                //发送get请求
                vc.http.apiGet('/feeApi/listFeeObj',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        _fee.receivableAmount = _json.data.feeTotalPrice;
                        _fee.receivedAmount = _fee.receivableAmount;
                        $that._doComputeTotalFee();
                        $that.$forceUpdate();
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _settingsFeeCycle: function (_batchFee) {
                vc.emit('batchFeeCycle', 'openBatchCycle', _batchFee);
            }
        }
    });
})(window.vc);