liubp
2025-12-19 5bdaf416d66b675131004de1aba5d161772a52b0
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
/**
 费用明细表
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 15;
    var $that = {};
    vc.extends({
        data: {
            costDetailInfo: {
                costDetails: [],
                paginationInfo: {
                    currentPage: 1,
                    rows: DEFAULT_ROWS,
                    total: 1,
                    dataCount: 0,
                    pageList: []
                },
                jumpPage: 1,
                conditions: {
                    date: '',
                    communityName: '',
                    communityCode: ''
                }
            }
        },
        _initMethod: function () {
            $that = vc.component;
            $that._injectStyles();
            $that._listCostDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            $that._initDate();
        },
        _initEvent: function () {
            vc.on('costDetail', 'listCostDetail', function (_param) {
                $that._listCostDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            });
        },
        methods: {
            _initDate: function () {
                $(".queryDate").datetimepicker({
                    language: 'zh-CN',
                    fontAwesome: 'fa',
                    format: 'yyyy-mm-dd hh:ii:ss',
                    initTime: true,
                    initialDate: new Date(),
                    autoClose: 1,
                    todayBtn: true
                });
                $('.queryDate').datetimepicker()
                    .on('changeDate', function (ev) {
                        var value = $(".queryDate").val();
                        $that.costDetailInfo.conditions.date = value;
                    });
                //防止多次点击时间插件失去焦点
                var queryDateElements = document.getElementsByClassName('form-control queryDate');
                if (queryDateElements.length > 0) {
                    queryDateElements[0].addEventListener('click', function(e) {
                        e.currentTarget.blur();
                    });
                }
            },
            _listCostDetails: function (_page, _rows) {
                $that.costDetailInfo.conditions.page = _page;
                $that.costDetailInfo.conditions.row = _rows;
                $that.costDetailInfo.conditions.communityId = vc.getCurrentCommunity().communityId;
                var param = {
                    params: $that.costDetailInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/costDetail/queryCostDetail',
                    param,
                    function (json, res) {
                        var _json = JSON.parse(json);
                        $that.costDetailInfo.paginationInfo.dataCount = _json.total || 0;
                        $that.costDetailInfo.paginationInfo.total = _json.records || 1;
                        $that.costDetailInfo.costDetails = _json.data || [];
                        $that.costDetailInfo.paginationInfo.currentPage = _page;
                        $that._freshPageList();
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        $that.costDetailInfo.costDetails = [];
                        $that.costDetailInfo.paginationInfo.dataCount = 0;
                        $that.costDetailInfo.paginationInfo.total = 1;
                        $that._freshPageList();
                    }
                );
            },
            _freshPageList: function () {
                var currentPage = $that.costDetailInfo.paginationInfo.currentPage;
                var total = $that.costDetailInfo.paginationInfo.total;
                var pageList = [];
                
                if (total <= 7) {
                    // 总页数小于等于7,显示所有页码
                    for (var i = 1; i <= total; i++) {
                        pageList.push({
                            page: i,
                            pageView: i,
                            currentPage: i == currentPage
                        });
                    }
                } else {
                    // 总页数大于7,显示部分页码
                    if (currentPage <= 4) {
                        // 当前页在前4页
                        for (var i = 1; i <= 5; i++) {
                            pageList.push({
                                page: i,
                                pageView: i,
                                currentPage: i == currentPage
                            });
                        }
                        pageList.push({
                            page: 0,
                            pageView: '...',
                            currentPage: false
                        });
                        pageList.push({
                            page: total,
                            pageView: total,
                            currentPage: false
                        });
                    } else if (currentPage >= total - 3) {
                        // 当前页在后4页
                        pageList.push({
                            page: 1,
                            pageView: 1,
                            currentPage: false
                        });
                        pageList.push({
                            page: 0,
                            pageView: '...',
                            currentPage: false
                        });
                        for (var i = total - 4; i <= total; i++) {
                            pageList.push({
                                page: i,
                                pageView: i,
                                currentPage: i == currentPage
                            });
                        }
                    } else {
                        // 当前页在中间
                        pageList.push({
                            page: 1,
                            pageView: 1,
                            currentPage: false
                        });
                        pageList.push({
                            page: 0,
                            pageView: '...',
                            currentPage: false
                        });
                        for (var i = currentPage - 1; i <= currentPage + 1; i++) {
                            pageList.push({
                                page: i,
                                pageView: i,
                                currentPage: i == currentPage
                            });
                        }
                        pageList.push({
                            page: 0,
                            pageView: '...',
                            currentPage: false
                        });
                        pageList.push({
                            page: total,
                            pageView: total,
                            currentPage: false
                        });
                    }
                }
                
                $that.costDetailInfo.paginationInfo.pageList = pageList;
            },
            _queryCostDetails: function () {
                $that._listCostDetails(DEFAULT_PAGE, $that.costDetailInfo.paginationInfo.rows);
            },
            _resetQuery: function () {
                $that.costDetailInfo.conditions.date = '';
                $that.costDetailInfo.conditions.communityName = '';
                $that.costDetailInfo.conditions.communityCode = '';
                $('.queryDate').val('');
                $that._listCostDetails(DEFAULT_PAGE, $that.costDetailInfo.paginationInfo.rows);
            },
            _changePageSize: function () {
                $that._listCostDetails(DEFAULT_PAGE, $that.costDetailInfo.paginationInfo.rows);
            },
            _goToPage: function (_page) {
                if (!_page || _page < 1 || _page > $that.costDetailInfo.paginationInfo.total) {
                    return;
                }
                $that._listCostDetails(_page, $that.costDetailInfo.paginationInfo.rows);
            },
            _jumpToPage: function () {
                var page = parseInt($that.costDetailInfo.jumpPage);
                if (isNaN(page) || page < 1) {
                    page = 1;
                }
                if (page > $that.costDetailInfo.paginationInfo.total) {
                    page = $that.costDetailInfo.paginationInfo.total;
                }
                $that._listCostDetails(page, $that.costDetailInfo.paginationInfo.rows);
            },
            _addCostDetail: function () {
                // 跳转到添加页面或打开添加弹窗
                vc.jumpToPage('/#/pages/property/costDetail/add');
            },
            _importCostDetail: function () {
                // 打开导入弹窗或跳转到导入页面
                vc.toast('费用导入功能');
            },
            _viewMore: function (_item) {
                // 查看详情
                vc.jumpToPage('/#/pages/property/costDetail/detail?costDetailId=' + _item.costDetailId);
            },
            _editCostDetail: function (_item) {
                // 编辑
                vc.jumpToPage('/#/pages/property/costDetail/edit?costDetailId=' + _item.costDetailId);
            },
            _deleteCostDetail: function (_item) {
                vc.confirm('确定要删除这条费用明细吗?', function () {
                    var param = {
                        params: {
                            costDetailId: _item.costDetailId
                        }
                    };
                    vc.http.apiPost('/costDetail/deleteCostDetail',
                        param,
                        function (json, res) {
                            vc.toast('删除成功');
                            $that._listCostDetails($that.costDetailInfo.paginationInfo.currentPage, $that.costDetailInfo.paginationInfo.rows);
                        },
                        function (errInfo, error) {
                            vc.message(errInfo);
                        }
                    );
                });
            }
        }
    });
})(window.vc);