liubp
2025-12-19 5bdaf416d66b675131004de1aba5d161772a52b0
public/pages/property/costDetail/costDetail.js
@@ -0,0 +1,244 @@
/**
 费用明细表
 **/
(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);