liubp
2025-12-26 c08d1c10fbafd7f57eb51c51269a95c281383ae3
public/pages/property/costDetail/more/more.js
@@ -1,5 +1,5 @@
/**
 业委会公约管理
 费用明细更多管理
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
@@ -17,24 +17,45 @@
                    pageList: []
                },
                jumpPage: 1,
                currentTab: 'convention',
                currentTab: 'publicIncome',
                conditions: {
                    startDate: '',
                    endDate: ''
                },
                editForm: {
                    id: '',
                    amount: '',
                    meetingResolution: '1',
                    consultationForm: '1'
                },
                addForm: {
                    plannedAnnouncementStart: '',
                    plannedAnnouncementEnd: '',
                    publishedAnnouncementStart: '',
                    publishedAnnouncementEnd: ''
                },
                editAnnouncementForm: {
                    id: '',
                    mpId: '',
                    plannedAnnouncementStart: '',
                    plannedAnnouncementEnd: '',
                    publishedAnnouncementStart: '',
                    publishedAnnouncementEnd: ''
                }
            }
        },
        _initMethod: function () {
            $that = vc.component;
            $that._injectStyles();
            $that._initDate();
            $that._listData(DEFAULT_PAGE, DEFAULT_ROWS);
            $that._loadPublicIncomeData(DEFAULT_PAGE, DEFAULT_ROWS);
            if ($that.moreInfo.currentTab !== 'publicIncome') {
                $that._listData(DEFAULT_PAGE, DEFAULT_ROWS);
            }
        },
        _initEvent: function () {
        },
        methods: {
            _initDate: function () {
                // 初始化日期选择器
                $(".startDate").datetimepicker({
                    minView: "month",
                    language: 'zh-CN',
@@ -57,20 +78,19 @@
                    todayBtn: true,
                    clearBtn: true
                });
                // 设置默认日期为当前月份
                var now = new Date();
                var year = now.getFullYear();
                var month = now.getMonth() + 1;
                var startDateStr = year + '-' + (month < 10 ? '0' + month : month) + '-01';
                var endDate = new Date(year, month, 0); // 获取当月最后一天
                var endDate = new Date(year, month, 0);
                var endDateStr = year + '-' + (month < 10 ? '0' + month : month) + '-' + endDate.getDate();
                $that.moreInfo.conditions.startDate = startDateStr;
                $that.moreInfo.conditions.endDate = endDateStr;
                $(".startDate").val(startDateStr);
                $(".endDate").val(endDateStr);
                $('.startDate').datetimepicker()
                    .on('changeDate', function (ev) {
                        var value = $(".startDate").val();
@@ -89,25 +109,207 @@
                            $that.moreInfo.conditions.endDate = value;
                        }
                    });
                // 防止多次点击时间插件失去焦点
                var startDateElements = document.getElementsByClassName('form-control startDate');
                if (startDateElements.length > 0) {
                    startDateElements[0].addEventListener('click', function(e) {
                    startDateElements[0].addEventListener('click', function (e) {
                        e.currentTarget.blur();
                    });
                }
                var endDateElements = document.getElementsByClassName('form-control endDate');
                if (endDateElements.length > 0) {
                    endDateElements[0].addEventListener('click', function(e) {
                    endDateElements[0].addEventListener('click', function (e) {
                        e.currentTarget.blur();
                    });
                }
            },
            changeTab: function (_tab) {
                $that.moreInfo.currentTab = _tab;
                // 根据标签页加载不同数据
                $that._listData(DEFAULT_PAGE, $that.moreInfo.paginationInfo.rows);
                if (_tab === 'publicIncome') {
                    $that._loadPublicIncomeData(DEFAULT_PAGE, $that.moreInfo.paginationInfo.rows);
                } else if (_tab === 'convention') {
                    $that._loadConventionData(DEFAULT_PAGE, $that.moreInfo.paginationInfo.rows);
                } else {
                    $that._listData(DEFAULT_PAGE, $that.moreInfo.paginationInfo.rows);
                }
            },
            _loadPublicIncomeData: function (_page, _rows) {
                var costDetailId = vc.getParam('costDetailId');
                if (!costDetailId) {
                    var hash = location.hash;
                    if (hash && hash.indexOf('?') !== -1) {
                        var hashParams = hash.substring(hash.indexOf('?') + 1);
                        var params = hashParams.split('&');
                        for (var i = 0; i < params.length; i++) {
                            var param = params[i].split('=');
                            if (param[0] === 'costDetailId') {
                                costDetailId = decodeURIComponent(param[1] || '');
                                break;
                            }
                        }
                    }
                }
                if (!costDetailId) {
                    vc.toast('缺少costDetailId参数');
                    return;
                }
                var param = {
                    params: {
                        mpId: costDetailId,
                        page: _page,
                        row: _rows
                    }
                };
                vc.http.apiGet('/announcementTimeRange/queryAnnouncementTimeRangeInfo',
                    param,
                    function (json, res) {
                        try {
                            var _json = JSON.parse(json);
                            if (_json.code === "0000") {
                                var total = _json.total || 0;
                                var rows = _rows || DEFAULT_ROWS;
                                var totalPages = Math.ceil(total / rows);
                                if (totalPages === 0) {
                                    totalPages = 1;
                                }
                                $that.moreInfo.paginationInfo.dataCount = total;
                                $that.moreInfo.paginationInfo.total = totalPages;
                                var dataList = [];
                                if (_json.data && Array.isArray(_json.data)) {
                                    dataList = _json.data.map(function (item) {
                                        return {
                                            id: item.id,
                                            mpId: item.mpId,
                                            proposedStartDate: item.plannedAnnouncementStart || '-',
                                            proposedEndDate: item.plannedAnnouncementEnd || '-',
                                            publishedStartDate: item.publishedAnnouncementStart || '-',
                                            publishedEndDate: item.publishedAnnouncementEnd || '-',
                                            createTime: item.createTime || '',
                                            updateTime: item.updateTime || '',
                                            _originalData: item
                                        };
                                    });
                                }
                                $that.moreInfo.dataList = dataList;
                                $that.moreInfo.paginationInfo.currentPage = _page;
                                $that._freshPageList();
                            } else {
                                vc.toast(_json.msg || '查询失败');
                                $that.moreInfo.dataList = [];
                                $that.moreInfo.paginationInfo.dataCount = 0;
                                $that.moreInfo.paginationInfo.total = 1;
                                $that.moreInfo.paginationInfo.currentPage = _page;
                                $that._freshPageList();
                            }
                        } catch (e) {
                            console.error('数据解析失败:', e);
                            vc.toast('数据解析失败');
                            $that.moreInfo.dataList = [];
                            $that.moreInfo.paginationInfo.dataCount = 0;
                            $that.moreInfo.paginationInfo.total = 1;
                            $that.moreInfo.paginationInfo.currentPage = _page;
                            $that._freshPageList();
                        }
                    },
                    function (errInfo, error) {
                        console.error('请求失败:', errInfo, error);
                        vc.toast(errInfo || '请求失败,请检查网络连接');
                        $that.moreInfo.dataList = [];
                        $that.moreInfo.paginationInfo.dataCount = 0;
                        $that.moreInfo.paginationInfo.total = 1;
                        $that.moreInfo.paginationInfo.currentPage = _page;
                        $that._freshPageList();
                    }
                );
            },
            _loadConventionData: function (_page, _rows) {
                var costDetailId = vc.getParam('costDetailId');
                if (!costDetailId) {
                    var hash = location.hash;
                    if (hash && hash.indexOf('?') !== -1) {
                        var hashParams = hash.substring(hash.indexOf('?') + 1);
                        var params = hashParams.split('&');
                        for (var i = 0; i < params.length; i++) {
                            var param = params[i].split('=');
                            if (param[0] === 'costDetailId') {
                                costDetailId = decodeURIComponent(param[1] || '');
                                break;
                            }
                        }
                    }
                }
                if (!costDetailId) {
                    vc.toast('缺少costDetailId参数');
                    return;
                }
                var param = {
                    params: {
                        mpId: costDetailId,
                        page: _page || 1,
                        row: _rows || DEFAULT_ROWS
                    }
                };
                vc.http.apiGet('/ownersCommitteeConvention/queryOwnersCommitteeConvention',
                    param,
                    function (json, res) {
                        try {
                            var _json = JSON.parse(json);
                            if (_json.code === "0000") {
                                var total = _json.total || 0;
                                var rows = _rows || DEFAULT_ROWS;
                                var totalPages = Math.ceil(total / rows);
                                if (totalPages === 0) {
                                    totalPages = 1;
                                }
                                $that.moreInfo.paginationInfo.dataCount = total;
                                $that.moreInfo.paginationInfo.total = totalPages;
                                var dataList = [];
                                if (_json.data && Array.isArray(_json.data)) {
                                    dataList = _json.data;
                                }
                                $that.moreInfo.dataList = dataList;
                                $that.moreInfo.paginationInfo.currentPage = _page;
                                $that._freshPageList();
                            } else {
                                vc.toast(_json.msg || '查询失败');
                                $that.moreInfo.dataList = [];
                                $that.moreInfo.paginationInfo.dataCount = 0;
                                $that.moreInfo.paginationInfo.total = 1;
                                $that.moreInfo.paginationInfo.currentPage = _page;
                                $that._freshPageList();
                            }
                        } catch (e) {
                            console.error('数据解析失败:', e);
                            vc.toast('数据解析失败');
                            $that.moreInfo.dataList = [];
                            $that.moreInfo.paginationInfo.dataCount = 0;
                            $that.moreInfo.paginationInfo.total = 1;
                            $that.moreInfo.paginationInfo.currentPage = _page;
                            $that._freshPageList();
                        }
                    },
                    function (errInfo, error) {
                        console.error('请求失败:', errInfo, error);
                        vc.toast(errInfo || '请求失败,请检查网络连接');
                        $that.moreInfo.dataList = [];
                        $that.moreInfo.paginationInfo.dataCount = 0;
                        $that.moreInfo.paginationInfo.total = 1;
                        $that.moreInfo.paginationInfo.currentPage = _page;
                        $that._freshPageList();
                    }
                );
            },
            _listData: function (_page, _rows) {
                $that.moreInfo.conditions.page = _page;
@@ -117,7 +319,6 @@
                var param = {
                    params: $that.moreInfo.conditions
                };
                // 发送get请求 - 这里需要根据实际API调整
                vc.http.apiGet('/costDetail/queryMore',
                    param,
                    function (json, res) {
@@ -130,7 +331,6 @@
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        // 模拟数据用于演示
                        $that.moreInfo.dataList = [
                            {
                                amount: '张三三',
@@ -149,9 +349,8 @@
                var currentPage = $that.moreInfo.paginationInfo.currentPage;
                var total = $that.moreInfo.paginationInfo.total;
                var pageList = [];
                if (total <= 7) {
                    // 总页数小于等于7,显示所有页码
                    for (var i = 1; i <= total; i++) {
                        pageList.push({
                            page: i,
@@ -160,9 +359,7 @@
                        });
                    }
                } else {
                    // 总页数大于7,显示部分页码
                    if (currentPage <= 4) {
                        // 当前页在前4页
                        for (var i = 1; i <= 5; i++) {
                            pageList.push({
                                page: i,
@@ -181,7 +378,6 @@
                            currentPage: false
                        });
                    } else if (currentPage >= total - 3) {
                        // 当前页在后4页
                        pageList.push({
                            page: 1,
                            pageView: 1,
@@ -200,7 +396,6 @@
                            });
                        }
                    } else {
                        // 当前页在中间
                        pageList.push({
                            page: 1,
                            pageView: 1,
@@ -230,17 +425,29 @@
                        });
                    }
                }
                $that.moreInfo.paginationInfo.pageList = pageList;
            },
            _changePageSize: function () {
                $that._listData(DEFAULT_PAGE, $that.moreInfo.paginationInfo.rows);
                if ($that.moreInfo.currentTab === 'publicIncome') {
                    $that._loadPublicIncomeData(DEFAULT_PAGE, $that.moreInfo.paginationInfo.rows);
                } else if ($that.moreInfo.currentTab === 'convention') {
                    $that._loadConventionData(DEFAULT_PAGE, $that.moreInfo.paginationInfo.rows);
                } else {
                    $that._listData(DEFAULT_PAGE, $that.moreInfo.paginationInfo.rows);
                }
            },
            _goToPage: function (_page) {
                if (!_page || _page < 1 || _page > $that.moreInfo.paginationInfo.total) {
                    return;
                }
                $that._listData(_page, $that.moreInfo.paginationInfo.rows);
                if ($that.moreInfo.currentTab === 'publicIncome') {
                    $that._loadPublicIncomeData(_page, $that.moreInfo.paginationInfo.rows);
                } else if ($that.moreInfo.currentTab === 'convention') {
                    $that._loadConventionData(_page, $that.moreInfo.paginationInfo.rows);
                } else {
                    $that._listData(_page, $that.moreInfo.paginationInfo.rows);
                }
            },
            _jumpToPage: function () {
                var page = parseInt($that.moreInfo.jumpPage);
@@ -250,42 +457,295 @@
                if (page > $that.moreInfo.paginationInfo.total) {
                    page = $that.moreInfo.paginationInfo.total;
                }
                $that._listData(page, $that.moreInfo.paginationInfo.rows);
                if ($that.moreInfo.currentTab === 'publicIncome') {
                    $that._loadPublicIncomeData(page, $that.moreInfo.paginationInfo.rows);
                } else if ($that.moreInfo.currentTab === 'convention') {
                    $that._loadConventionData(page, $that.moreInfo.paginationInfo.rows);
                } else {
                    $that._listData(page, $that.moreInfo.paginationInfo.rows);
                }
            },
            _add: function () {
                // 添加功能
                vc.toast('添加功能');
                if ($that.moreInfo.currentTab !== 'publicIncome') {
                    return;
                }
                $that.moreInfo.addForm = {
                    plannedAnnouncementStart: '',
                    plannedAnnouncementEnd: '',
                    publishedAnnouncementStart: '',
                    publishedAnnouncementEnd: ''
                };
                $that._showAddAnnouncementModal();
            },
            _showAddAnnouncementModal: function () {
                const modal = document.getElementById('addAnnouncementTimeRangeModal');
                modal.classList.add('show');
                modal.style.display = 'block';
                modal.removeAttribute('inert');
                modal.removeAttribute('aria-hidden');
                modal.setAttribute('aria-modal', 'true');
                modal.focus();
            },
            _hideAddAnnouncementModal: function () {
                const modal = document.getElementById('addAnnouncementTimeRangeModal');
                modal.classList.remove('show');
                modal.style.display = 'none';
                modal.setAttribute('inert', '');
                modal.setAttribute('aria-hidden', 'true');
                modal.removeAttribute('aria-modal');
            },
            _saveAddAnnouncementTimeRange: function () {
                var costDetailId = vc.getParam('costDetailId');
                if (!costDetailId) {
                    var hash = location.hash;
                    if (hash && hash.indexOf('?') !== -1) {
                        var hashParams = hash.substring(hash.indexOf('?') + 1);
                        var params = hashParams.split('&');
                        for (var i = 0; i < params.length; i++) {
                            var param = params[i].split('=');
                            if (param[0] === 'costDetailId') {
                                costDetailId = decodeURIComponent(param[1] || '');
                                break;
                            }
                        }
                    }
                }
                if (!costDetailId) {
                    vc.toast('缺少costDetailId参数');
                    return;
                }
                var requestData = {
                    mpId: costDetailId,
                    plannedAnnouncementStart: $that.moreInfo.addForm.plannedAnnouncementStart || '',
                    plannedAnnouncementEnd: $that.moreInfo.addForm.plannedAnnouncementEnd || '',
                    publishedAnnouncementStart: $that.moreInfo.addForm.publishedAnnouncementStart || '',
                    publishedAnnouncementEnd: $that.moreInfo.addForm.publishedAnnouncementEnd || ''
                };
                vc.http.apiPost('/announcementTimeRange/saveAnnouncementTimeRangeInfo',
                    JSON.stringify(requestData),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        try {
                            var _json = JSON.parse(json);
                            if (_json.code === "0000") {
                                vc.toast(_json.msg || '保存成功');
                                $that._hideAddAnnouncementModal();
                                $that._loadPublicIncomeData($that.moreInfo.paginationInfo.currentPage, $that.moreInfo.paginationInfo.rows);
                            } else {
                                vc.toast(_json.msg || '保存失败');
                            }
                        } catch (e) {
                            console.error('数据解析失败:', e);
                            vc.toast('数据解析失败');
                        }
                    },
                    function (errInfo, error) {
                        console.error('请求失败:', errInfo, error);
                        vc.toast(errInfo || '保存失败,请检查网络连接');
                    }
                );
            },
            _export: function () {
                // 导出功能
                vc.toast('导出功能');
            },
            _viewDetail: function (_item) {
                // 查看详情
            _viewDetailPublicIncome: function (_item) {
                vc.toast('查看详情功能');
            },
            _edit: function (_item) {
                // 编辑
                vc.toast('编辑功能');
            _showEditPublicModal: function () {
                const modal = document.getElementById('editPublicIncomeModal');
                modal.classList.add('show');
                modal.style.display = 'block';
                modal.removeAttribute('inert');
                modal.removeAttribute('aria-hidden');
                modal.setAttribute('aria-modal', 'true');
                modal.focus();
            },
            _hideEditPublicModal: function () {
                const modal = document.getElementById('editPublicIncomeModal');
                modal.classList.remove('show');
                modal.style.display = 'none';
                modal.setAttribute('inert', '');
                modal.setAttribute('aria-hidden', 'true');
                modal.removeAttribute('aria-modal');
            },
            _editPublicIncome: function (_item) {
                if (!_item || !_item.id) {
                    vc.toast('数据错误,无法编辑');
                    return;
                }
                var costDetailId = vc.getParam('costDetailId');
                if (!costDetailId) {
                    var hash = location.hash;
                    if (hash && hash.indexOf('?') !== -1) {
                        var hashParams = hash.substring(hash.indexOf('?') + 1);
                        var params = hashParams.split('&');
                        for (var i = 0; i < params.length; i++) {
                            var param = params[i].split('=');
                            if (param[0] === 'costDetailId') {
                                costDetailId = decodeURIComponent(param[1] || '');
                                break;
                            }
                        }
                    }
                }
                var formatDate = function (dateStr) {
                    if (!dateStr || dateStr === '-' || dateStr.trim() === '') {
                        return '';
                    }
                    return dateStr.trim();
                };
                $that.moreInfo.editAnnouncementForm = {
                    id: _item.id || '',
                    mpId: costDetailId || _item.mpId || '',
                    plannedAnnouncementStart: formatDate(_item.proposedStartDate),
                    plannedAnnouncementEnd: formatDate(_item.proposedEndDate),
                    publishedAnnouncementStart: formatDate(_item.publishedStartDate),
                    publishedAnnouncementEnd: formatDate(_item.publishedEndDate)
                };
                $that._showEditAnnouncementModal();
            },
            _showEditAnnouncementModal: function () {
                const modal = document.getElementById('editAnnouncementTimeRangeModal');
                modal.classList.add('show');
                modal.style.display = 'block';
                modal.removeAttribute('inert');
                modal.removeAttribute('aria-hidden');
                modal.setAttribute('aria-modal', 'true');
                modal.focus();
            },
            _hideEditAnnouncementModal: function () {
                const modal = document.getElementById('editAnnouncementTimeRangeModal');
                modal.classList.remove('show');
                modal.style.display = 'none';
                modal.setAttribute('inert', '');
                modal.setAttribute('aria-hidden', 'true');
                modal.removeAttribute('aria-modal');
            },
            _saveEditAnnouncementTimeRange: function () {
                if (!$that.moreInfo.editAnnouncementForm.id) {
                    vc.toast('缺少主键ID,无法保存');
                    return;
                }
                var requestData = {
                    id: $that.moreInfo.editAnnouncementForm.id,
                    mpId: $that.moreInfo.editAnnouncementForm.mpId || '',
                    plannedAnnouncementStart: $that.moreInfo.editAnnouncementForm.plannedAnnouncementStart || '',
                    plannedAnnouncementEnd: $that.moreInfo.editAnnouncementForm.plannedAnnouncementEnd || '',
                    publishedAnnouncementStart: $that.moreInfo.editAnnouncementForm.publishedAnnouncementStart || '',
                    publishedAnnouncementEnd: $that.moreInfo.editAnnouncementForm.publishedAnnouncementEnd || ''
                };
                vc.http.apiPost('/announcementTimeRange/updateAnnouncementTimeRangeInfo',
                    JSON.stringify(requestData),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        try {
                            var _json = JSON.parse(json);
                            if (_json.code === "0000") {
                                vc.toast(_json.msg || '修改成功');
                                $that._hideEditAnnouncementModal();
                                $that._loadPublicIncomeData($that.moreInfo.paginationInfo.currentPage, $that.moreInfo.paginationInfo.rows);
                            } else {
                                vc.toast(_json.msg || '修改失败');
                            }
                        } catch (e) {
                            console.error('数据解析失败:', e);
                            vc.toast('数据解析失败');
                        }
                    },
                    function (errInfo, error) {
                        console.error('请求失败:', errInfo, error);
                        vc.toast(errInfo || '修改失败,请检查网络连接');
                    }
                );
            },
            _saveEditPublicIncome: function () {
                var param = {
                    params: {
                        id: $that.moreInfo.editForm.id,
                        amount: $that.moreInfo.editForm.amount,
                        meetingResolution: $that.moreInfo.editForm.meetingResolution,
                        consultationForm: $that.moreInfo.editForm.consultationForm,
                        communityId: vc.getCurrentCommunity().communityId
                    }
                };
                vc.http.apiPost('/costDetail/updatePublicIncome',
                    param,
                    function (json, res) {
                        vc.toast('保存成功');
                        $that._hideEditPublicModal();
                        $that._listData($that.moreInfo.paginationInfo.currentPage, $that.moreInfo.paginationInfo.rows);
                    },
                    function (errInfo, error) {
                        vc.message(errInfo);
                    }
                );
            },
            _delete: function (_item) {
                if (!_item || !_item.id) {
                    vc.toast('数据错误,无法删除');
                    return;
                }
                vc.confirm('确定要删除这条记录吗?', function () {
                    var param = {
                        params: {
                    if ($that.moreInfo.currentTab === 'publicIncome') {
                        var requestData = {
                            id: _item.id
                        }
                    };
                    // 这里需要根据实际API调整
                    vc.http.apiPost('/costDetail/deleteMore',
                        param,
                        function (json, res) {
                            vc.toast('删除成功');
                            $that._listData($that.moreInfo.paginationInfo.currentPage, $that.moreInfo.paginationInfo.rows);
                        },
                        function (errInfo, error) {
                            vc.message(errInfo);
                        }
                    );
                        };
                        vc.http.apiPost('/announcementTimeRange/deleteAnnouncementTimeRangeInfo',
                            JSON.stringify(requestData),
                            {
                                emulateJSON: true
                            },
                            function (json, res) {
                                try {
                                    var _json = JSON.parse(json);
                                    if (_json.code === "0000") {
                                        vc.toast(_json.msg || '删除成功');
                                        $that._loadPublicIncomeData($that.moreInfo.paginationInfo.currentPage, $that.moreInfo.paginationInfo.rows);
                                    } else {
                                        vc.toast(_json.msg || '删除失败');
                                    }
                                } catch (e) {
                                    console.error('数据解析失败:', e);
                                    vc.toast('数据解析失败');
                                }
                            },
                            function (errInfo, error) {
                                console.error('请求失败:', errInfo, error);
                                vc.toast(errInfo || '删除失败,请检查网络连接');
                            }
                        );
                    } else {
                        var param = {
                            params: {
                                id: _item.id
                            }
                        };
                        vc.http.apiPost('/costDetail/deleteMore',
                            param,
                            function (json, res) {
                                vc.toast('删除成功');
                                $that._listData($that.moreInfo.paginationInfo.currentPage, $that.moreInfo.paginationInfo.rows);
                            },
                            function (errInfo, error) {
                                vc.message(errInfo);
                            }
                        );
                    }
                });
            }
        }