/** 业委会公约管理 **/ (function (vc) { var DEFAULT_PAGE = 1; var DEFAULT_ROWS = 15; var $that = {}; vc.extends({ data: { moreInfo: { dataList: [], paginationInfo: { currentPage: 1, rows: DEFAULT_ROWS, total: 1, dataCount: 0, pageList: [] }, jumpPage: 1, currentTab: 'convention', conditions: { startDate: '', endDate: '' } } }, _initMethod: function () { $that = vc.component; $that._injectStyles(); $that._initDate(); $that._listData(DEFAULT_PAGE, DEFAULT_ROWS); }, _initEvent: function () { }, methods: { _initDate: function () { // 初始化日期选择器 $(".startDate").datetimepicker({ minView: "month", language: 'zh-CN', fontAwesome: 'fa', format: 'yyyy-mm-dd', initTime: true, initialDate: new Date(), autoClose: 1, todayBtn: true, clearBtn: true }); $(".endDate").datetimepicker({ minView: "month", language: 'zh-CN', fontAwesome: 'fa', format: 'yyyy-mm-dd', initTime: true, initialDate: new Date(), autoClose: 1, 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 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(); $that.moreInfo.conditions.startDate = value; }); $('.endDate').datetimepicker() .on('changeDate', function (ev) { var value = $(".endDate").val(); var start = Date.parse(new Date($that.moreInfo.conditions.startDate)) var end = Date.parse(new Date(value)) if (start - end >= 0) { vc.toast("结束时间必须大于开始时间") $that.moreInfo.conditions.endDate = ''; $(".endDate").val(''); } else { $that.moreInfo.conditions.endDate = value; } }); // 防止多次点击时间插件失去焦点 var startDateElements = document.getElementsByClassName('form-control startDate'); if (startDateElements.length > 0) { 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) { e.currentTarget.blur(); }); } }, changeTab: function (_tab) { $that.moreInfo.currentTab = _tab; // 根据标签页加载不同数据 $that._listData(DEFAULT_PAGE, $that.moreInfo.paginationInfo.rows); }, _listData: function (_page, _rows) { $that.moreInfo.conditions.page = _page; $that.moreInfo.conditions.row = _rows; $that.moreInfo.conditions.tab = $that.moreInfo.currentTab; $that.moreInfo.conditions.communityId = vc.getCurrentCommunity().communityId; var param = { params: $that.moreInfo.conditions }; // 发送get请求 - 这里需要根据实际API调整 vc.http.apiGet('/costDetail/queryMore', param, function (json, res) { var _json = JSON.parse(json); $that.moreInfo.paginationInfo.dataCount = _json.total || 0; $that.moreInfo.paginationInfo.total = _json.records || 1; $that.moreInfo.dataList = _json.data || []; $that.moreInfo.paginationInfo.currentPage = _page; $that._freshPageList(); }, function (errInfo, error) { console.log('请求失败处理'); // 模拟数据用于演示 $that.moreInfo.dataList = [ { amount: '张三三', meetingResolution: '1', consultationForm: '0' } ]; $that.moreInfo.paginationInfo.dataCount = 100; $that.moreInfo.paginationInfo.total = 7; $that.moreInfo.paginationInfo.currentPage = _page; $that._freshPageList(); } ); }, _freshPageList: function () { 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, 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.moreInfo.paginationInfo.pageList = pageList; }, _changePageSize: function () { $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); }, _jumpToPage: function () { var page = parseInt($that.moreInfo.jumpPage); if (isNaN(page) || page < 1) { page = 1; } if (page > $that.moreInfo.paginationInfo.total) { page = $that.moreInfo.paginationInfo.total; } $that._listData(page, $that.moreInfo.paginationInfo.rows); }, _add: function () { // 添加功能 vc.toast('添加功能'); }, _export: function () { // 导出功能 vc.toast('导出功能'); }, _viewDetail: function (_item) { // 查看详情 vc.toast('查看详情功能'); }, _edit: function (_item) { // 编辑 vc.toast('编辑功能'); }, _delete: function (_item) { vc.confirm('确定要删除这条记录吗?', function () { var param = { params: { 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); } ); }); } } }); })(window.vc);