Files
2025-12-09 20:22:03 +08:00

236 lines
11 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
入驻小区
**/
(function (vc) {
var DEFAULT_PAGE = 1;
var DEFAULT_ROWS = 10;
vc.extends({
data: {
communitySpaceManageInfo: {
communitySpaces: [],
venues: [],
total: 0,
records: 1,
moreCondition: false,
spaceId: '',
conditions: {
spaceId: '',
name: '',
state: '',
bookingType: '',
venueId: '',
communityId: vc.getCurrentCommunity().communityId
}
}
},
_initMethod: function () {
$that._listCommunityVenues();
vc.component._listCommunitySpaces(DEFAULT_PAGE, DEFAULT_ROWS);
},
_initEvent: function () {
vc.on('communitySpaceManage', 'listCommunityVenue', function (_param) {
vc.component._listCommunityVenues(DEFAULT_PAGE, DEFAULT_ROWS);
});
vc.on('communitySpaceManage', 'listCommunitySpace', function (_param) {
vc.component._listCommunitySpaces(DEFAULT_PAGE, DEFAULT_ROWS);
});
vc.on('pagination', 'page_event', function (_currentPage) {
vc.component._listCommunitySpaces(_currentPage, DEFAULT_ROWS);
});
},
methods: {
_listCommunitySpaces: function (_page, _rows) {
vc.component.communitySpaceManageInfo.conditions.page = _page;
vc.component.communitySpaceManageInfo.conditions.row = _rows;
var param = {
params: vc.component.communitySpaceManageInfo.conditions
};
param.params.spaceId = param.params.spaceId.trim();
param.params.name = param.params.name.trim();
//发送get请求
vc.http.apiGet('/communitySpace.listCommunitySpace',
param,
function (json, res) {
let _communitySpaceManageInfo = JSON.parse(json);
vc.component.communitySpaceManageInfo.total = _communitySpaceManageInfo.total;
vc.component.communitySpaceManageInfo.records = _communitySpaceManageInfo.records;
vc.component.communitySpaceManageInfo.communitySpaces = _communitySpaceManageInfo.data;
// 处理每个场地的价格规则数据
vc.component._processPriceRules();
vc.emit('pagination', 'init', {
total: vc.component.communitySpaceManageInfo.records,
dataCount: vc.component.communitySpaceManageInfo.total,
currentPage: _page
});
},
function (errInfo, error) {
console.log('请求失败处理');
}
);
},
_listCommunityVenues: function (_page, _rows) {
let param = {
params: {
page: 1,
row: 100,
communityId: vc.getCurrentCommunity().communityId
}
};
//发送get请求
vc.http.apiGet('/communityVenue.listCommunityVenue',
param,
function (json, res) {
let _communityVenue = JSON.parse(json);
$that.communitySpaceManageInfo.venues = _communityVenue.data;
if (_communityVenue.data && _communityVenue.data.length > 0) {
$that.swatchVenue(_communityVenue.data[0]);
}
},
function (errInfo, error) {
console.log('请求失败处理');
}
);
},
/**
* 处理场地的价格规则数据
*/
_processPriceRules: function () {
let communitySpaces = vc.component.communitySpaceManageInfo.communitySpaces;
if (!communitySpaces || communitySpaces.length === 0) {
return;
}
// 处理每个场地的价格规则
communitySpaces.forEach(space => {
// 初始化全场和半场价格
space.fullPrice = 0;
space.halfPrice = 0;
// 检查是否有价格规则数据
if (space.priceRules && space.priceRules.length > 0) {
space.priceRules.forEach(rule => {
// 根据ruleType字段区分全场和半场价格
// ruleType = "1001" 表示全场价格
// ruleType = "2002" 表示半场价格
if (rule.ruleType === '1001') {
// 全场价格
space.fullPrice = parseFloat(rule.price) || 0;
} else if (rule.ruleType === '2002') {
// 半场价格
space.halfPrice = parseFloat(rule.price) || 0;
}
});
}
// 如果没有从价格规则中获取到价格使用原有的feeMoney字段作为全场价格
if (space.fullPrice === 0 && space.feeMoney) {
space.fullPrice = parseFloat(space.feeMoney) || 0;
}
});
},
_openAddCommunitySpaceModal: function () {
if (!$that.communitySpaceManageInfo.conditions.venueId) {
vc.toast('未选择场馆');
return;
}
vc.emit('addCommunitySpace', 'openAddCommunitySpaceModal', {
venueId: $that.communitySpaceManageInfo.conditions.venueId
});
},
_openEditCommunitySpaceModel: function (_communitySpace) {
console.log('打开编辑场地模态框,原始数据:', _communitySpace);
// 确保priceRules字段被传递给editCommunitySpace组件
// 如果priceRules不存在但fullPrice和halfPrice存在则创建priceRules数组
if (!_communitySpace.priceRules && (_communitySpace.fullPrice || _communitySpace.halfPrice)) {
console.log('priceRules不存在但fullPrice或halfPrice存在创建priceRules数组');
_communitySpace.priceRules = [];
// 添加全场价格规则
if (_communitySpace.fullPrice) {
_communitySpace.priceRules.push({
ruleType: '1001',
price: _communitySpace.fullPrice
});
console.log('添加全场价格规则:', {
ruleType: '1001',
price: _communitySpace.fullPrice
});
}
// 添加半场价格规则
if (_communitySpace.halfPrice) {
_communitySpace.priceRules.push({
ruleType: '2002',
price: _communitySpace.halfPrice
});
console.log('添加半场价格规则:', {
ruleType: '2002',
price: _communitySpace.halfPrice
});
}
} else if (_communitySpace.priceRules) {
console.log('priceRules已存在数据:', _communitySpace.priceRules);
} else {
console.log('priceRules不存在且fullPrice和halfPrice也不存在');
}
console.log('最终传递给editCommunitySpace的数据:', _communitySpace);
vc.emit('editCommunitySpace', 'openEditCommunitySpaceModal', _communitySpace);
},
_openEditOpenTime: function (_communitySpace) {
vc.emit('editCommunitySpaceOpenTime', 'openEditCommunitySpaceModal', _communitySpace);
},
_openDeleteCommunitySpaceModel: function (_communitySpace) {
vc.emit('deleteCommunitySpace', 'openDeleteCommunitySpaceModal', _communitySpace);
},
//查询
_queryCommunitySpaceMethod: function () {
vc.component._listCommunitySpaces(DEFAULT_PAGE, DEFAULT_ROWS);
},
//重置
_resetCommunitySpaceMethod: function () {
vc.component.communitySpaceManageInfo.conditions.spaceId = "";
vc.component.communitySpaceManageInfo.conditions.name = "";
vc.component.communitySpaceManageInfo.conditions.state = "";
vc.component.communitySpaceManageInfo.conditions.bookingType = "";
vc.component._listCommunitySpaces(DEFAULT_PAGE, DEFAULT_ROWS);
},
_openAddCommunityVenueModal: function () {
vc.emit('addCommunityVenue', 'openAddCommunityVenueModal', {});
},
_openEditCommunityVenueModel: function (_communityVenue) {
if (!$that.communitySpaceManageInfo.conditions.venueId) {
vc.toast('未选择场馆');
return;
}
vc.emit('editCommunityVenue', 'openEditCommunityVenueModal', {
venueId: $that.communitySpaceManageInfo.conditions.venueId
});
},
_openDeleteCommunityVenueModel: function (_communityVenue) {
if (!$that.communitySpaceManageInfo.conditions.venueId) {
vc.toast('未选择场馆');
return;
}
vc.emit('deleteCommunityVenue', 'openDeleteCommunityVenueModal', {
venueId: $that.communitySpaceManageInfo.conditions.venueId
});
},
swatchVenue: function (_venue) {
$that.communitySpaceManageInfo.conditions.venueId = _venue.venueId;
$that._listCommunitySpaces(DEFAULT_PAGE, DEFAULT_ROWS);
},
_moreCondition: function () {
if (vc.component.communitySpaceManageInfo.moreCondition) {
vc.component.communitySpaceManageInfo.moreCondition = false;
} else {
vc.component.communitySpaceManageInfo.moreCondition = true;
}
}
}
});
})(window.vc);