123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'pay/config/index' + location.search,
- add_url: 'pay/config/add',
- edit_url: 'pay/config/edit',
- del_url: 'pay/config/del',
- multi_url: 'pay/config/multi',
- import_url: 'pay/config/import',
- table: 'shop_pay_config',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'name', title: __('Name'), table: table, class: 'autocontent', formatter: Table.api.formatter.content},
- {field: 'type_text', title: __('Type'),searchList: Controller.api.parseConfigJson('methodList')},
- // {field: 'params', title: __('Params'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
- {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0')}, formatter: Table.api.formatter.status},
- {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
- {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- recyclebin: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- 'dragsort_url': ''
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: 'pay/config/recyclebin' + location.search,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'name', title: __('Name'), align: 'left'},
- {
- field: 'deletetime',
- title: __('Deletetime'),
- operate: 'RANGE',
- addclass: 'datetimerange',
- formatter: Table.api.formatter.datetime
- },
- {
- field: 'operate',
- width: '140px',
- title: __('Operate'),
- table: table,
- events: Table.api.events.operate,
- buttons: [
- {
- name: 'Restore',
- text: __('Restore'),
- classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
- icon: 'fa fa-rotate-left',
- url: 'pay/config/restore',
- refresh: true
- },
- {
- name: 'Destroy',
- text: __('Destroy'),
- classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
- icon: 'fa fa-times',
- url: 'pay/config/destroy',
- refresh: true
- }
- ],
- formatter: Table.api.formatter.operate
- }
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- Controller.api.bindevent();
- Controller.api.initFormFieldsVisibility();
- },
- edit: function () {
- Controller.api.bindevent();
- Controller.api.initFormFieldsVisibility();
- },
- api: {
- // 解析Config中的JSON字符串的辅助函数
- parseConfigJson: function(configKey, defaultValue) {
- var configValue = Config[configKey] || defaultValue || {};
-
- // 如果是字符串,尝试解析JSON
- if (typeof configValue === 'string') {
- try {
- return JSON.parse(configValue);
- } catch (e) {
- return defaultValue || {};
- }
- }
-
- return configValue;
- },
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
-
- // 监听支付类型变化
- $(document).on('change', 'input[name="row[type]"]', function() {
- Controller.api.toggleFieldsVisibility();
- });
-
- // 监听商户类型变化
- $(document).on('change', 'input[name="row[params][mode]"]', function() {
- Controller.api.toggleFieldsVisibility();
- });
- },
-
- // 初始化字段显示状态
- initFormFieldsVisibility: function() {
- // 延迟执行,确保DOM已加载
- setTimeout(function() {
- console.log('初始化字段显示状态...');
- Controller.api.toggleFieldsVisibility();
- }, 100);
- },
-
- // 切换字段显示状态
- toggleFieldsVisibility: function() {
- var payType = $('input[name="row[type]"]:checked').val();
- var mode = $('input[name="row[params][mode]"]:checked').val();
-
- console.log('支付类型:', payType, '商户模式:', mode);
-
- // 隐藏所有条件字段并移除验证
- $('[data-visible]').hide().find('input[data-rule], textarea[data-rule]').each(function() {
- $(this).attr('data-rule-backup', $(this).attr('data-rule') || '');
- $(this).removeAttr('data-rule');
- });
-
- // 根据支付类型显示相应区域
- if (payType === 'wechat') {
- $('[data-visible="type=wechat"]').show().find('input[data-rule-backup], textarea[data-rule-backup]').each(function() {
- var rule = $(this).attr('data-rule-backup');
- if (rule) {
- $(this).attr('data-rule', rule);
- }
- });
-
- // 根据商户模式显示字段
- if (mode === '2') {
- // 服务商模式:显示主商户AppId和子商户相关字段
- $('[data-visible="type=wechat&mode=2"]').show().find('input[data-rule-backup], textarea[data-rule-backup]').each(function() {
- var rule = $(this).attr('data-rule-backup');
- if (rule) {
- $(this).attr('data-rule', rule);
- }
- });
- }
- } else if (payType === 'alipay') {
- $('[data-visible="type=alipay"]').show().find('input[data-rule-backup], textarea[data-rule-backup]').each(function() {
- var rule = $(this).attr('data-rule-backup');
- if (rule) {
- $(this).attr('data-rule', rule);
- }
- });
-
- // 根据商户模式显示字段
- if (mode === '2') {
- // 服务商模式:显示主商户ID
- $('[data-visible="type=alipay&mode=2"]').show().find('input[data-rule-backup], textarea[data-rule-backup]').each(function() {
- var rule = $(this).attr('data-rule-backup');
- if (rule) {
- $(this).attr('data-rule', rule);
- }
- });
- }
- } else if (payType === 'douyin') {
- $('[data-visible="type=douyin"]').show().find('input[data-rule-backup], textarea[data-rule-backup]').each(function() {
- var rule = $(this).attr('data-rule-backup');
- if (rule) {
- $(this).attr('data-rule', rule);
- }
- });
- }
-
- // 处理标签显示
- Controller.api.toggleLabelVisibility(payType, mode);
-
- // 重新初始化表单验证
- setTimeout(function() {
- if (typeof Form !== 'undefined' && Form.api && Form.api.bindevent) {
- Form.api.bindevent($("form[role=form]"));
- }
- }, 100);
- },
-
- // 切换标签显示
- toggleLabelVisibility: function(payType, mode) {
- // 先隐藏所有条件标签
- $('[data-visible] span[data-visible]').hide();
-
- // 显示匹配的标签
- if (payType) {
- $('span[data-visible="type=' + payType + '"]').show();
- }
-
- if (mode !== undefined && mode !== '') {
- $('span[data-visible="mode=' + mode + '"]').show();
- }
- },
-
- }
- };
- return Controller;
- });
|