123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- 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;
- });
|