liubp
2025-12-26 c08d1c10fbafd7f57eb51c51269a95c281383ae3
public/pages/property/costDetail/edit/edit.js
@@ -22,51 +22,234 @@
                fundTypeLevel2: '',
                buildingType: '1',
                maintenanceType: '',
                fundType: 'repair', // 默认选中维修资金
                fundSystemType: 'out' // 默认选中系统外
            }
                fundType: 'repair',
                fundSystemType: 'out',
                ownerScope: [],
                buildingScope: []
            },
            ownerScopeOptions: [
                '机动车停车库(位)',
                '小区道路',
                '交通附属设施',
                '非机动车车库(相朋)',
                '小区公共照明',
                '锅炉',
                '排水、排污设施',
                '消防系统',
                '安防设施',
                '公共景观绿化',
                '健身、游乐设施',
                '小区宣传、标识',
                '强电',
                '弱电',
                '通信设施',
                '公共用房',
                '平屋面',
                '楼栋外立面',
                '供电设施',
                '暖通系统',
                '供水系统',
                '通用设施(配件)'
            ],
            ownerScopeDropdownOpen: false,
            buildingScopeOptions: [
                '机动车停车库(位)',
                '交通附属设施',
                '小区道路',
                '公共景观绿化',
                '非机动车车库(棚)',
                '锅炉',
                '排水、排污设施',
                '消防系统',
                '安防设施',
                '健身、游乐设施',
                '小区宣传、标识',
                '强电',
                '弱电',
                '通信设施',
                '公共用房',
                '平屋面',
                '太阳能设施',
                '坡屋面',
                '结构',
                '楼栋外立面',
                '楼幢入口',
                '楼幢公共',
                '楼道设施',
                '供电设施',
                '暖通系统',
                '供水系统',
                '通用设施(配件)',
                '法院强制执行'
            ],
            buildingScopeDropdownOpen: false
        },
        _initMethod: function () {
            $that = vc.component;
            // 从URL获取costDetailId
            if (!$that.costDetailInfo) {
                $that.costDetailInfo = {};
            }
            if (!$that.costDetailInfo.ownerScope || !Array.isArray($that.costDetailInfo.ownerScope)) {
                $that.costDetailInfo.ownerScope = [];
            }
            if (!$that.costDetailInfo.buildingScope || !Array.isArray($that.costDetailInfo.buildingScope)) {
                $that.costDetailInfo.buildingScope = [];
            }
            if (!$that.ownerScopeOptions || !Array.isArray($that.ownerScopeOptions)) {
                $that.ownerScopeOptions = [
                    '机动车停车库(位)',
                    '小区道路',
                    '交通附属设施',
                    '非机动车车库(相朋)',
                    '小区公共照明',
                    '锅炉',
                    '排水、排污设施',
                    '消防系统',
                    '安防设施',
                    '公共景观绿化',
                    '健身、游乐设施',
                    '小区宣传、标识',
                    '强电',
                    '弱电',
                    '通信设施',
                    '公共用房',
                    '平屋面',
                    '楼栋外立面',
                    '供电设施',
                    '暖通系统',
                    '供水系统',
                    '通用设施(配件)'
                ];
            }
            if ($that.ownerScopeDropdownOpen === undefined) {
                $that.ownerScopeDropdownOpen = false;
            }
            if (!$that.buildingScopeOptions || !Array.isArray($that.buildingScopeOptions)) {
                $that.buildingScopeOptions = [
                    '机动车停车库(位)',
                    '交通附属设施',
                    '小区道路',
                    '公共景观绿化',
                    '非机动车车库(棚)',
                    '锅炉',
                    '排水、排污设施',
                    '消防系统',
                    '安防设施',
                    '健身、游乐设施',
                    '小区宣传、标识',
                    '强电',
                    '弱电',
                    '通信设施',
                    '公共用房',
                    '平屋面',
                    '太阳能设施',
                    '坡屋面',
                    '结构',
                    '楼栋外立面',
                    '楼幢入口',
                    '楼幢公共',
                    '楼道设施',
                    '供电设施',
                    '暖通系统',
                    '供水系统',
                    '通用设施(配件)',
                    '法院强制执行'
                ];
            }
            if ($that.buildingScopeDropdownOpen === undefined) {
                $that.buildingScopeDropdownOpen = false;
            }
            var clickHandler = function (e) {
                if (!e.target.closest('.multi-select-wrapper')) {
                    if ($that && $that.ownerScopeDropdownOpen !== undefined) {
                        $that.ownerScopeDropdownOpen = false;
                    }
                    if ($that && $that.buildingScopeDropdownOpen !== undefined) {
                        $that.buildingScopeDropdownOpen = false;
                    }
                }
            };
            setTimeout(function () {
                document.addEventListener('click', clickHandler);
            }, 100);
            var costDetailId = vc.getParam('costDetailId');
            if (costDetailId) {
                $that.costDetailInfo.costDetailId = costDetailId;
                $that._loadCostDetail();
            } else {
                vc.toast('缺少费用明细ID');
                setTimeout(function() {
                setTimeout(function () {
                    vc.goBack();
                }, 1500);
            }
        },
        methods: {
            toggleOwnerScopeDropdown: function () {
                if ($that && $that.ownerScopeDropdownOpen !== undefined) {
                    $that.ownerScopeDropdownOpen = !$that.ownerScopeDropdownOpen;
                }
            },
            toggleOwnerScopeOption: function (option) {
                if (!$that || !$that.costDetailInfo || !$that.costDetailInfo.ownerScope) {
                    return;
                }
                var index = $that.costDetailInfo.ownerScope.indexOf(option);
                if (index === -1) {
                    $that.costDetailInfo.ownerScope.push(option);
                } else {
                    $that.costDetailInfo.ownerScope.splice(index, 1);
                }
            },
            removeOwnerScopeItem: function (index) {
                if ($that && $that.costDetailInfo && $that.costDetailInfo.ownerScope) {
                    $that.costDetailInfo.ownerScope.splice(index, 1);
                }
            },
            toggleBuildingScopeDropdown: function () {
                if ($that && $that.buildingScopeDropdownOpen !== undefined) {
                    $that.buildingScopeDropdownOpen = !$that.buildingScopeDropdownOpen;
                }
            },
            toggleBuildingScopeOption: function (option) {
                if (!$that || !$that.costDetailInfo || !$that.costDetailInfo.buildingScope) {
                    return;
                }
                var index = $that.costDetailInfo.buildingScope.indexOf(option);
                if (index === -1) {
                    $that.costDetailInfo.buildingScope.push(option);
                } else {
                    $that.costDetailInfo.buildingScope.splice(index, 1);
                }
            },
            removeBuildingScopeItem: function (index) {
                if ($that && $that.costDetailInfo && $that.costDetailInfo.buildingScope) {
                    $that.costDetailInfo.buildingScope.splice(index, 1);
                }
            },
            _loadCostDetail: function () {
                // 查询所有数据,然后找到匹配的记录
                var params = {
                    communityName: vc.getCurrentCommunity().name,
                    page: 1,
                    row: 1000  // 查询足够多的数据以找到目标记录
                    row: 1000
                };
                var param = {
                    params: params
                };
                console.log('开始加载费用明细,ID:', $that.costDetailInfo.costDetailId);
                vc.http.apiGet('/maintenancePayment/queryMaintenancePayment',
                    param,
                    function (json, res) {
                        try {
                            var _json = JSON.parse(json);
                            console.log('API返回数据:', _json);
                            if (_json.code === 0 && _json.data) {
                                var records = Array.isArray(_json.data) ? _json.data : [];
                                console.log('查询到记录数:', records.length);
                                // 查找匹配的记录 - 支持字符串和数字类型的ID比较
                                var foundItem = null;
                                var targetId = String($that.costDetailInfo.costDetailId);
                                for (var i = 0; i < records.length; i++) {
@@ -78,21 +261,21 @@
                                        break;
                                    }
                                }
                                if (foundItem) {
                                    $that._fillFormData(foundItem);
                                    console.log('表单数据已填充:', $that.costDetailInfo);
                                } else {
                                    console.error('未找到匹配的记录,目标ID:', $that.costDetailInfo.costDetailId);
                                    vc.toast('未找到该费用明细,ID: ' + $that.costDetailInfo.costDetailId);
                                    setTimeout(function() {
                                    setTimeout(function () {
                                        vc.goBack();
                                    }, 1500);
                                }
                            } else {
                                console.error('API返回错误:', _json);
                                vc.toast('未找到该费用明细');
                                setTimeout(function() {
                                setTimeout(function () {
                                    vc.goBack();
                                }, 1500);
                            }
@@ -109,18 +292,16 @@
            },
            _fillFormData: function (item) {
                console.log('开始填充表单数据,原始数据:', item);
                // 填充表单数据
                var dateStr = '';
                if (item.date) {
                    dateStr = item.date.substring(0, 10); // 取日期部分 yyyy-mm-dd
                    dateStr = item.date.substring(0, 10);
                } else if (item.year && item.month) {
                    var monthStr = item.month < 10 ? '0' + item.month : String(item.month);
                    var dayStr = item.day ? (item.day < 10 ? '0' + item.day : String(item.day)) : '01';
                    dateStr = item.year + '-' + monthStr + '-' + dayStr;
                }
                // 使用Vue.set或者直接赋值来确保响应式更新
                vc.component.costDetailInfo.flowCode = item.flowNumber || '';
                vc.component.costDetailInfo.date = dateStr;
                vc.component.costDetailInfo.communityName = item.projectName || '';
@@ -132,36 +313,61 @@
                vc.component.costDetailInfo.appraisalAmount = item.auditAmount || '';
                vc.component.costDetailInfo.committeeStamped = (item.ownersCommitteeSeal === '是' || item.ownersCommitteeSeal === '1') ? '1' : '0';
                vc.component.costDetailInfo.approvalDepartment = item.reportDepartment || '';
                if (item.fundTypeLevel1 === '维修资金') {
                    vc.component.costDetailInfo.fundType = 'repair';
                    if (item.fundTypeLevel2) {
                        vc.component.costDetailInfo.ownerScope = typeof item.fundTypeLevel2 === 'string'
                            ? item.fundTypeLevel2.split(',').filter(function (item) { return item.trim(); })
                            : [];
                    } else {
                        vc.component.costDetailInfo.ownerScope = [];
                    }
                    if (item.buildingOrAll) {
                        vc.component.costDetailInfo.buildingScope = typeof item.buildingOrAll === 'string'
                            ? item.buildingOrAll.split(',').filter(function (item) { return item.trim(); })
                            : [];
                    } else {
                        vc.component.costDetailInfo.buildingScope = [];
                    }
                    vc.component.costDetailInfo.fundSystemType = 'out';
                } else if (item.fundTypeLevel1 === '公共收益') {
                    vc.component.costDetailInfo.fundType = 'public';
                    if (item.fundTypeLevel2 === '系统外') {
                        vc.component.costDetailInfo.fundSystemType = 'out';
                    } else if (item.fundTypeLevel2 === '系统内') {
                        vc.component.costDetailInfo.fundSystemType = 'in';
                    } else {
                        vc.component.costDetailInfo.fundSystemType = 'out';
                    }
                    vc.component.costDetailInfo.ownerScope = [];
                    vc.component.costDetailInfo.buildingScope = [];
                } else {
                    vc.component.costDetailInfo.fundType = 'repair';
                    vc.component.costDetailInfo.ownerScope = [];
                    vc.component.costDetailInfo.buildingScope = [];
                    vc.component.costDetailInfo.fundSystemType = 'out';
                }
                vc.component.costDetailInfo.fundTypeLevel1 = item.fundTypeLevel1 || '';
                vc.component.costDetailInfo.fundTypeLevel2 = item.fundTypeLevel2 || '';
                // 处理buildingType字段
                var buildingType = item.buildingOrAll || '1';
                if (buildingType === '全体' || buildingType === '2' || buildingType === 2) {
                    vc.component.costDetailInfo.buildingType = '全体';
                } else {
                    vc.component.costDetailInfo.buildingType = '1';
                    if (buildingType && buildingType.indexOf(',') !== -1) {
                        vc.component.costDetailInfo.buildingType = '1';
                    } else {
                        vc.component.costDetailInfo.buildingType = buildingType || '1';
                    }
                }
                vc.component.costDetailInfo.maintenanceType = item.maintenanceType || '';
                // 设置基金类型
                if (item.fundTypeLevel1) {
                    vc.component.costDetailInfo.fundType = (item.fundTypeLevel1 === '维修资金' || item.fundTypeLevel1 === '1') ? 'repair' : 'public';
                } else {
                    vc.component.costDetailInfo.fundType = 'repair'; // 默认值
                }
                if (item.fundTypeLevel2) {
                    vc.component.costDetailInfo.fundSystemType = (item.fundTypeLevel2 === '系统外' || item.fundTypeLevel2 === 'out') ? 'out' : 'in';
                } else {
                    vc.component.costDetailInfo.fundSystemType = 'out'; // 默认值
                }
                console.log('表单数据填充完成:', vc.component.costDetailInfo);
            },
            _saveCostDetail: function () {
                // 验证必填字段
                if (!$that.costDetailInfo.flowCode) {
                    vc.toast('请输入流转编码');
                    return;
@@ -178,8 +384,35 @@
                    vc.toast('请输入小区编码');
                    return;
                }
                // 构建保存数据
                var fundTypeLevel1 = '';
                if ($that.costDetailInfo.fundType === 'repair') {
                    fundTypeLevel1 = '维修资金';
                } else if ($that.costDetailInfo.fundType === 'public') {
                    fundTypeLevel1 = '公共收益';
                }
                var fundTypeLevel2 = '';
                var buildingOrAll = '';
                if ($that.costDetailInfo.fundType === 'repair') {
                    fundTypeLevel2 = ($that.costDetailInfo.ownerScope && $that.costDetailInfo.ownerScope.length > 0)
                        ? $that.costDetailInfo.ownerScope.join(',')
                        : '';
                    buildingOrAll = ($that.costDetailInfo.buildingScope && $that.costDetailInfo.buildingScope.length > 0)
                        ? $that.costDetailInfo.buildingScope.join(',')
                        : '';
                } else if ($that.costDetailInfo.fundType === 'public') {
                    if ($that.costDetailInfo.fundSystemType === 'out') {
                        fundTypeLevel2 = '系统外';
                    } else if ($that.costDetailInfo.fundSystemType === 'in') {
                        fundTypeLevel2 = '系统内';
                    }
                    buildingOrAll = '';
                } else {
                    buildingOrAll = '';
                }
                var saveData = {
                    id: $that.costDetailInfo.costDetailId,
                    flowNumber: $that.costDetailInfo.flowCode,
@@ -193,14 +426,16 @@
                    auditAmount: parseFloat($that.costDetailInfo.appraisalAmount) || 0,
                    ownersCommitteeSeal: $that.costDetailInfo.committeeStamped === '1' ? '是' : '否',
                    reportDepartment: $that.costDetailInfo.approvalDepartment || '',
                    fundTypeLevel1: $that.costDetailInfo.fundType === 'repair' ? '维修资金' : '公共收益',
                    fundTypeLevel2: $that.costDetailInfo.fundType === 'public' ? ($that.costDetailInfo.fundSystemType === 'out' ? '系统外' : '系统内') : '',
                    buildingOrAll: $that.costDetailInfo.buildingType === '全体' ? '全体' : ($that.costDetailInfo.buildingType || '1'),
                    fundTypeLevel1: fundTypeLevel1,
                    fundTypeLevel2: fundTypeLevel2,
                    maintenanceType: $that.costDetailInfo.maintenanceType || '',
                    communityId: vc.getCurrentCommunity().communityId
                };
                // 解析日期
                if ($that.costDetailInfo.fundType === 'repair') {
                    saveData.buildingOrAll = buildingOrAll;
                }
                if (saveData.date) {
                    var dateParts = saveData.date.split('-');
                    if (dateParts.length >= 2) {
@@ -211,18 +446,17 @@
                        }
                    }
                }
                // 调用更新API
                vc.http.apiPost('/maintenancePayment/updateMaintenancePayment',
                    JSON.stringify(saveData), {
                        emulateJSON: true
                    },
                    emulateJSON: true
                },
                    function (json, res) {
                        try {
                            var _json = JSON.parse(json);
                            if (_json.code === 0) {
                                vc.toast('保存成功');
                                setTimeout(function() {
                                setTimeout(function () {
                                    vc.goBack();
                                }, 1000);
                            } else {