define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 平台列表页面逻辑 this.bindPlatformEvents(); }, // 绑定平台相关事件 bindPlatformEvents: function () { // 平台配置按钮点击事件 $(document).on('click', '.platform-btn', function (e) { e.preventDefault(); var url = $(this).data('url'); var title = $(this).data('title'); if (url) { // 打开配置弹窗 Fast.api.open(url, title, { area: ['80%', '80%'], callback: function(data) { // 配置保存成功后刷新状态 Controller.loadPlatformStatus(); } }); } }); Form.api.bindevent($("form[role=form]"), function (data, ret) { Layer.alert(data.data); }); }, // 更新平台状态显示 updatePlatformStatus: function (statusData) { $.each(statusData, function (platform, status) { var $card = $('[data-platform="' + platform + '"]'); if ($card.length > 0) { var $badge = $card.find('.status-badge'); var $btn = $card.find('.platform-btn'); if (status) { $card.addClass('platform-enabled'); $badge.removeClass('status-disabled').addClass('status-enabled').text('已启用'); $btn.removeClass('btn-default').addClass('btn-success'); } else { $card.removeClass('platform-enabled'); $badge.removeClass('status-enabled').addClass('status-disabled').text('未启用'); $btn.removeClass('btn-success').addClass('btn-default'); } } }); }, // 平台配置页面逻辑 edit: function () { $(document).on('click', '.btn-success', function () { Form.api.submit($("form[role=form]")); setTimeout(refresh, 1500) }) // 然后绑定其他事件 Controller.bindVisibilityEvents(); // 延迟初始化,确保DOM完全加载 // 初始化支付配置的显示状态 Controller.initializePaymentConfig(); // 初始化分享配置的显示状态 Controller.initializeShareConfig(); // 在所有初始化完成后绑定表单事件 Controller.api.bindevent(); }, // 初始化支付配置显示状态 initializePaymentConfig: function() { Controller.updatePaymentConfigVisibility(); }, // 初始化分享配置显示状态 initializeShareConfig: function() { Controller.updateShareConfigVisibility(); }, // 绑定显示隐藏事件 bindVisibilityEvents: function () { // 支付方式选择事件 $(document).on('change', 'input[name="row[payment][methods][]"]', function () { Controller.updatePaymentConfigVisibility(); }); // 分享方式选择事件 $(document).on('change', 'input[name="row[share][methods][]"]', function () { Controller.updateShareConfigVisibility(); }); // 状态切换事件 $(document).on('change', 'input[name="row[status]"]', function () { var status = $(this).val(); if (status == '1') { $('.config-section').show(); } else { $('.config-section').hide(); } }); }, // 更新支付配置显示状态 updatePaymentConfigVisibility: function() { var selectedMethods = []; $('input[name="row[payment][methods][]"]:checked').each(function () { selectedMethods.push($(this).val()); }); // 显示隐藏对应的配置项 $('.payment-config').hide(); // 遍历所有payment-config元素,检查是否应该显示 $('.payment-config').each(function() { var $this = $(this); var showMethods = $this.data('show'); if (showMethods) { // 将字符串转换为数组(支持逗号分隔) var methodsArray = showMethods.toString().split(','); // 检查选中的方法是否与当前元素的显示条件匹配 var shouldShow = false; $.each(methodsArray, function(index, method) { if (selectedMethods.indexOf(method.trim()) !== -1) { shouldShow = true; return false; // 跳出循环 } }); if (shouldShow) { $this.show(); } } }); }, // 更新分享配置显示状态 updateShareConfigVisibility: function() { var selectedMethods = []; $('input[name="row[share][methods][]"]:checked').each(function () { selectedMethods.push($(this).val()); }); // 显示隐藏对应的配置项 $('.share-config').hide(); // 遍历所有share-config元素,检查是否应该显示 $('.share-config').each(function() { var $this = $(this); var showMethods = $this.data('show'); if (showMethods) { // 将字符串转换为数组(支持逗号分隔) var methodsArray = showMethods.toString().split(','); // 检查选中的方法是否与当前元素的显示条件匹配 var shouldShow = false; $.each(methodsArray, function(index, method) { if (selectedMethods.indexOf(method.trim()) !== -1) { shouldShow = true; return false; // 跳出循环 } }); if (shouldShow) { $this.show(); } } }); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); }, } }; return Controller; });