From c1fd6952f42461bc7e83c97f594a52fc1af934eb Mon Sep 17 00:00:00 2001
From: liubp <1535785116@qq.com>
Date: 星期四, 25 十二月 2025 18:15:43 +0800
Subject: [PATCH] 费用明细表,查询,编辑,删除,添加接口对接,公益金表接口对接,页面样式优化

---
 public/pages/property/costDetail/costDetail.js |  256 +++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 195 insertions(+), 61 deletions(-)

diff --git a/public/pages/property/costDetail/costDetail.js b/public/pages/property/costDetail/costDetail.js
index 2f0d8cf..fd62347 100644
--- a/public/pages/property/costDetail/costDetail.js
+++ b/public/pages/property/costDetail/costDetail.js
@@ -9,6 +9,7 @@
         data: {
             costDetailInfo: {
                 costDetails: [],
+                communityList: [],
                 paginationInfo: {
                     currentPage: 1,
                     rows: DEFAULT_ROWS,
@@ -20,14 +21,21 @@
                 conditions: {
                     date: '',
                     communityName: '',
-                    communityCode: ''
+                    communityCode: '',
+                    communityId: vc.getCurrentCommunity().communityId,
+                    flowNumber: '',
+                    projectCode: '',
+                    year: '',
+                    projectName: '',
+                    _communityName: vc.getCurrentCommunity().name
                 }
             }
         },
         _initMethod: function () {
             $that = vc.component;
-            $that._injectStyles();
-            $that._listCostDetails(DEFAULT_PAGE, DEFAULT_ROWS);
+            $that.costDetailInfo.conditions.communityId = vc.getCurrentCommunity().communityId;
+            $that.costDetailInfo.conditions._communityName = vc.getCurrentCommunity().name;
+            $that._loadCommunityList();
             $that._initDate();
         },
         _initEvent: function () {
@@ -37,48 +45,118 @@
         },
         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();
-                    });
+                // 骞翠唤杈撳叆妗嗕笉闇�瑕佺壒娈婂垵濮嬪寲锛屼娇鐢� v-model 鍙屽悜缁戝畾鍗冲彲
+            },
+            _loadCommunityList: function () {
+                // 鑾峰彇鎵�鏈夊皬鍖哄垪琛�
+                var communityInfos = vc.getCommunitys();
+                if (communityInfos && Array.isArray(communityInfos) && communityInfos.length > 0) {
+                    $that.costDetailInfo.communityList = communityInfos;
+                    // 榛樿閫夋嫨绗竴涓皬鍖�
+                    $that.costDetailInfo.conditions.communityName = communityInfos[0].name;
+                } else {
+                    // 濡傛灉鑾峰彇涓嶅埌鍒楄〃锛屼娇鐢ㄥ綋鍓嶅皬鍖�
+                    var currentCommunity = vc.getCurrentCommunity();
+                    if (currentCommunity && currentCommunity.name) {
+                        $that.costDetailInfo.communityList = [currentCommunity];
+                        $that.costDetailInfo.conditions.communityName = currentCommunity.name;
+                    }
                 }
+                // 鍔犺浇鏁版嵁
+                $that._listCostDetails(DEFAULT_PAGE, DEFAULT_ROWS);
             },
             _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
+                // 浣跨敤閫変腑鐨勫皬鍖哄悕绉帮紝濡傛灉娌℃湁閫変腑鍒欎娇鐢ㄥ綋鍓嶅皬鍖哄悕绉�
+                var selectedCommunityName = $that.costDetailInfo.conditions.communityName || vc.getCurrentCommunity().name;
+                var params = {
+                    communityName: selectedCommunityName,
+                    page: _page,
+                    row: _rows
                 };
-                //鍙戦�乬et璇锋眰
-                vc.http.apiGet('/costDetail/queryCostDetail',
+                
+                // 娣诲姞鍙�夋煡璇㈠弬鏁�
+                if ($that.costDetailInfo.conditions.flowNumber) {
+                    params.flowNumber = $that.costDetailInfo.conditions.flowNumber;
+                }
+                if ($that.costDetailInfo.conditions.projectCode) {
+                    params.projectCode = $that.costDetailInfo.conditions.projectCode;
+                }
+                if ($that.costDetailInfo.conditions.year) {
+                    params.year = parseInt($that.costDetailInfo.conditions.year);
+                }
+                if ($that.costDetailInfo.conditions.projectName) {
+                    params.projectName = $that.costDetailInfo.conditions.projectName;
+                }
+                
+                var param = {
+                    params: params
+                };
+                
+                vc.http.apiGet('/maintenancePayment/queryMaintenancePayment',
                     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();
+                        try {
+                            var _json = JSON.parse(json);
+                            
+                            if (_json.code === 0 && _json.data) {
+                                var records = Array.isArray(_json.data) ? _json.data : [];
+                                
+                                var mappedRecords = records.map(function(item) {
+                                    var dateStr = '';
+                                    if (item.date) {
+                                        dateStr = item.date.substring(0, 7);
+                                    } else if (item.year && item.month) {
+                                        var monthStr = item.month < 10 ? '0' + item.month : String(item.month);
+                                        dateStr = item.year + '-' + monthStr;
+                                    }
+                                    
+                                    return {
+                                        flowCode: item.flowNumber || '--',
+                                        communityCode: item.projectCode || '--',
+                                        communityName: item.projectName || '--',
+                                        date: dateStr,
+                                        projectContent: item.projectContent || '--',
+                                        managementAmount: item.managementOfficeAmount || '--',
+                                        managementStamped: item.managementOfficeSeal === '鏄�' ? '1' : '0',
+                                        committeeAmount: item.ownersCommitteeAmount || '--',
+                                        appraisalAmount: item.auditAmount || '--',
+                                        committeeStamped: item.ownersCommitteeSeal === '鏄�' ? '1' : '0',
+                                        approvalDepartment: item.reportDepartment || '--',
+                                        fundTypeLevel1: item.fundTypeLevel1 || '--',
+                                        fundTypeLevel2: item.fundTypeLevel2 || '--',
+                                        buildingType: item.buildingOrAll || '--',
+                                        maintenanceType: item.maintenanceType || '--',
+                                        costDetailId: item.id,
+                                        _originalData: item
+                                    };
+                                });
+                                
+                                var total = _json.total || 0;
+                                var totalPages = _json.records || 1;
+                                
+                                $that.costDetailInfo.paginationInfo.dataCount = total;
+                                $that.costDetailInfo.paginationInfo.total = totalPages;
+                                $that.costDetailInfo.costDetails = mappedRecords;
+                                $that.costDetailInfo.paginationInfo.currentPage = _page;
+                                $that._freshPageList();
+                            } else {
+                                console.error('鎺ュ彛杩斿洖閿欒:', _json.msg || '鏈煡閿欒', _json);
+                                vc.toast(_json.msg || '鏌ヨ澶辫触');
+                                $that.costDetailInfo.costDetails = [];
+                                $that.costDetailInfo.paginationInfo.dataCount = 0;
+                                $that.costDetailInfo.paginationInfo.total = 1;
+                                $that._freshPageList();
+                            }
+                        } catch (e) {
+                            vc.toast('鏁版嵁瑙f瀽澶辫触');
+                            $that.costDetailInfo.costDetails = [];
+                            $that.costDetailInfo.paginationInfo.dataCount = 0;
+                            $that.costDetailInfo.paginationInfo.total = 1;
+                            $that._freshPageList();
+                        }
                     },
                     function (errInfo, error) {
-                        console.log('璇锋眰澶辫触澶勭悊');
+                        vc.toast('璇锋眰澶辫触锛岃妫�鏌ョ綉缁滆繛鎺�');
                         $that.costDetailInfo.costDetails = [];
                         $that.costDetailInfo.paginationInfo.dataCount = 0;
                         $that.costDetailInfo.paginationInfo.total = 1;
@@ -92,7 +170,6 @@
                 var pageList = [];
                 
                 if (total <= 7) {
-                    // 鎬婚〉鏁板皬浜庣瓑浜�7锛屾樉绀烘墍鏈夐〉鐮�
                     for (var i = 1; i <= total; i++) {
                         pageList.push({
                             page: i,
@@ -101,9 +178,7 @@
                         });
                     }
                 } else {
-                    // 鎬婚〉鏁板ぇ浜�7锛屾樉绀洪儴鍒嗛〉鐮�
                     if (currentPage <= 4) {
-                        // 褰撳墠椤靛湪鍓�4椤�
                         for (var i = 1; i <= 5; i++) {
                             pageList.push({
                                 page: i,
@@ -122,7 +197,6 @@
                             currentPage: false
                         });
                     } else if (currentPage >= total - 3) {
-                        // 褰撳墠椤靛湪鍚�4椤�
                         pageList.push({
                             page: 1,
                             pageView: 1,
@@ -141,7 +215,6 @@
                             });
                         }
                     } else {
-                        // 褰撳墠椤靛湪涓棿
                         pageList.push({
                             page: 1,
                             pageView: 1,
@@ -178,9 +251,17 @@
                 $that._listCostDetails(DEFAULT_PAGE, $that.costDetailInfo.paginationInfo.rows);
             },
             _resetQuery: function () {
-                $that.costDetailInfo.conditions.date = '';
-                $that.costDetailInfo.conditions.communityName = '';
+                // 閲嶇疆鏃舵仮澶嶄负绗竴涓皬鍖�
+                if ($that.costDetailInfo.communityList && $that.costDetailInfo.communityList.length > 0) {
+                    $that.costDetailInfo.conditions.communityName = $that.costDetailInfo.communityList[0].name;
+                } else {
+                    $that.costDetailInfo.conditions.communityName = '';
+                }
                 $that.costDetailInfo.conditions.communityCode = '';
+                $that.costDetailInfo.conditions.flowNumber = '';
+                $that.costDetailInfo.conditions.projectCode = '';
+                $that.costDetailInfo.conditions.year = '';
+                $that.costDetailInfo.conditions.projectName = '';
                 $('.queryDate').val('');
                 $that._listCostDetails(DEFAULT_PAGE, $that.costDetailInfo.paginationInfo.rows);
             },
@@ -228,23 +309,76 @@
                 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);
-                        }
-                    );
-                });
+                if (!_item || !_item.costDetailId) {
+                    vc.toast('鍒犻櫎澶辫触锛氱己灏戝繀瑕佺殑鏁版嵁');
+                    return;
+                }
+                if (typeof vc.confirm === 'function') {
+                    vc.confirm('纭畾瑕佸垹闄よ繖鏉¤垂鐢ㄦ槑缁嗗悧锛�', function () {
+                        var param = {
+                            id: _item.costDetailId,
+                            communityId: vc.getCurrentCommunity().communityId
+                        };
+                        vc.http.apiPost('/maintenancePayment/deleteMaintenancePayment',
+                            JSON.stringify(param), {
+                                headers: {
+                                    'Content-Type': 'application/json'
+                                }
+                            },
+                            function (json, res) {
+                                try {
+                                    var _json = JSON.parse(json);
+                                    if (_json.code === 0 || _json.code === '0') {
+                                        vc.toast(_json.msg || '鍒犻櫎鎴愬姛');
+                                        $that._listCostDetails($that.costDetailInfo.paginationInfo.currentPage, $that.costDetailInfo.paginationInfo.rows);
+                                    } else {
+                                        vc.toast(_json.msg || '鍒犻櫎澶辫触');
+                                    }
+                                } catch (e) {
+                                    console.error('鍒犻櫎鍝嶅簲瑙f瀽澶辫触:', e);
+                                    vc.toast('鍒犻櫎澶辫触锛岃閲嶈瘯');
+                                }
+                            },
+                            function (errInfo, error) {
+                                console.error('鍒犻櫎璇锋眰澶辫触:', errInfo, error);
+                                vc.toast(errInfo || '鍒犻櫎澶辫触锛岃妫�鏌ョ綉缁滆繛鎺�');
+                            }
+                        );
+                    });
+                } else {
+                    // 濡傛灉 vc.confirm 涓嶅瓨鍦紝浣跨敤 window.confirm 浣滀负鍚庡鏂规
+                    if (window.confirm('纭畾瑕佸垹闄よ繖鏉¤垂鐢ㄦ槑缁嗗悧锛�')) {
+                        var param = {
+                            id: _item.costDetailId,
+                            communityId: vc.getCurrentCommunity().communityId
+                        };
+                        vc.http.apiPost('/maintenancePayment/deleteMaintenancePayment',
+                            JSON.stringify(param), {
+                                headers: {
+                                    'Content-Type': 'application/json'
+                                }
+                            },
+                            function (json, res) {
+                                try {
+                                    var _json = JSON.parse(json);
+                                    if (_json.code === 0 || _json.code === '0') {
+                                        vc.toast(_json.msg || '鍒犻櫎鎴愬姛');
+                                        $that._listCostDetails($that.costDetailInfo.paginationInfo.currentPage, $that.costDetailInfo.paginationInfo.rows);
+                                    } else {
+                                        vc.toast(_json.msg || '鍒犻櫎澶辫触');
+                                    }
+                                } catch (e) {
+                                    console.error('鍒犻櫎鍝嶅簲瑙f瀽澶辫触:', e);
+                                    vc.toast('鍒犻櫎澶辫触锛岃閲嶈瘯');
+                                }
+                            },
+                            function (errInfo, error) {
+                                console.error('鍒犻櫎璇锋眰澶辫触:', errInfo, error);
+                                vc.toast(errInfo || '鍒犻櫎澶辫触锛岃妫�鏌ョ綉缁滆繛鎺�');
+                            }
+                        );
+                    }
+                }
             }
         }
     });

--
Gitblit v1.8.0