define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数 Table.api.init({ extend: { index_url: 'commission/agent/index' + location.search, add_url: '', multi_url: 'commission/agent/multi', import_url: 'commission/agent/import', table: 'commission_agent', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'user_id', sortName: 'user_id', columns: [ [ {checkbox: true}, {field: 'user_id', title: __('ID'), width: 60}, {field: 'user.nickname', title: __('用户昵称'), operate: 'LIKE'}, {field: 'user.mobile', title: __('手机号'), operate: 'LIKE'}, {field: 'level_info.name', title: __('分销等级'), formatter: function(value, row, index) { if (row.level_info) { return row.level_info.name + '(等级' + row.level_info.level + ')'; } return row.level || '-'; }}, {field: 'status', title: __('状态'), searchList: { "normal": __('正常'), "pending": __('审核中'), "freeze": __('冻结'), "forbidden": __('禁用'), "reject": __('拒绝') }, formatter: function(value, row, index) { var colorMap = { 'normal': 'success', 'pending': 'warning', 'freeze': 'info', 'forbidden': 'danger', 'reject': 'danger' }; var textMap = { 'normal': '正常', 'pending': '审核中', 'freeze': '冻结', 'forbidden': '禁用', 'reject': '拒绝' }; var color = colorMap[value] || 'default'; var text = textMap[value] || value; return '' + text + ''; }}, {field: 'total_income', title: __('总收益'), operate: 'BETWEEN'}, {field: 'child_agent_count_1', title: __('直推分销商'), width: 80}, {field: 'child_agent_count_all', title: __('团队分销商'), width: 80}, {field: 'child_user_count_all', title: __('团队人数'), width: 80}, {field: 'pending_reward', title: __('待结算佣金'), width: 80}, {field: 'become_time', title: __('成为分销商时间'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [ { name: 'detail', text: __('详情'), title: __('详情'), classname: 'btn btn-xs btn-primary btn-dialog', icon: 'fa fa-list', url: 'commission/agent/detail', callback: function (data) { table.bootstrapTable('refresh'); } }, { name: 'team', text: __('团队'), title: __('团队'), classname: 'btn btn-xs btn-info btn-dialog', icon: 'fa fa-users', url: 'commission/agent/team', callback: function (data) { table.bootstrapTable('refresh'); } }, ], formatter: Table.api.formatter.operate} ] ] }); // 为表格绑定事件 Table.api.bindevent(table); }, detail: function () { var agentId = Fast.api.query('id'); var agentData = {}; // 获取分销商详情 function getDetail() { Fast.api.ajax({ url: 'commission/agent/detail', data: {id: agentId} }, function(data) { agentData = data; updateDetailView(data); }); } // 更新详情视图 function updateDetailView(data) { if (data.user) { $('#user-avatar').attr('src', data.user.avatar || '/assets/img/avatar.png'); $('#user-nickname').text(data.user.nickname || data.user_id); } // 状态 var statusMap = { 'normal': {text: '正常', class: 'label-success'}, 'pending': {text: '审核中', class: 'label-warning'}, 'freeze': {text: '冻结', class: 'label-info'}, 'forbidden': {text: '禁用', class: 'label-danger'}, 'reject': {text: '拒绝', class: 'label-danger'} }; var status = statusMap[data.status] || {text: data.status, class: 'label-default'}; $('#agent-status').text(status.text).attr('class', 'label ' + status.class); // 等级 if (data.level_info) { $('#agent-level').text(data.level_info.name + '(等级' + data.level_info.level + ')'); if (data.level_info.commission_rules) { $('#commission-1').text(data.level_info.commission_rules.commission_1 || '0.00'); $('#commission-2').text(data.level_info.commission_rules.commission_2 || '0.00'); $('#commission-3').text(data.level_info.commission_rules.commission_3 || '0.00'); } } else { $('#agent-level').text(data.level); } // 待升级等级 if (data.level_status > 0 && data.level_status_info) { $('#upgrade-level-group').show(); $('#upgrade-level').text(data.level_status_info.name + '(等级' + data.level_status + ')'); } else { $('#upgrade-level-group').hide(); } // 上级分销商 if (data.user && data.user.parent_user) { $('#parent-agent').text(data.user.parent_user.nickname || '用户' + data.user.parent_user_id); } else { $('#parent-agent').text('无'); } // 允许升级 $('#upgrade-lock').prop('checked', data.upgrade_lock == 0); // 统计数据 $('#child-user-count-all').text(data.child_user_count_all || 0); $('#child-user-count-1').text(data.child_user_count_1 || 0); $('#child-agent-count-all').text(data.child_agent_count_all || 0); $('#child-agent-count-1').text(data.child_agent_count_1 || 0); $('#child-order-money-all').text((data.child_order_money_all || 0) + '元'); $('#child-order-count-all').text(data.child_order_count_all || 0); $('#child-order-money-1').text((data.child_order_money_1 || 0) + '元'); $('#child-order-count-1').text(data.child_order_count_1 || 0); $('#total-income').text((data.total_income || 0) + '元'); $('#pending-reward').text((data.pending_reward || 0) + '元'); $('#total-consume').text(((data.user && data.user.total_consume) || 0) + '元'); // 申请信息 if (data.apply_info && data.apply_info.length > 0) { var applyHtml = '
'; $('#apply-info').html(applyHtml); } else { $('#apply-info').html('暂无申请信息
'); } } // 详情页面特有的全局函数 window.changeStatus = function(userId, currentStatus) { Layer.prompt({ title: '修改状态', formType: 2, value: currentStatus, select: ['normal', 'pending', 'freeze', 'forbidden', 'reject'], selectTips: ['正常', '审核中', '冻结', '禁用', '拒绝'] }, function(value, index) { Fast.api.ajax({ url: 'commission/agent/edit', data: {ids: userId, status: value} }, function() { Layer.close(index); location.reload(); }); }); }; window.changeLevel = function(userId) { Toastr.info('等级修改功能待完善'); }; window.changeParentUser = function(userId) { Fast.api.open('commission/agent/select?id=' + userId, '更换上级分销商', { callback: function() { location.reload(); } }); }; window.approveLevel = function(userId, levelStatus) { Fast.api.ajax({ url: 'commission/agent/edit', data: {ids: userId, level_status: levelStatus} }, function() { location.reload(); }); }; window.rejectLevel = function(userId) { Fast.api.ajax({ url: 'commission/agent/edit', data: {ids: userId, level_status: 0} }, function() { location.reload(); }); }; window.toggleUpgradeLock = function(userId, currentLock) { var newLock = currentLock == 0 ? 1 : 0; Fast.api.ajax({ url: 'commission/agent/edit', data: {ids: userId, upgrade_lock: newLock} }, function() { location.reload(); }); }; window.viewTeam = function(userId) { Fast.api.open('commission/agent/team?id=' + userId, '查看团队'); }; // 事件绑定 $(document).ready(function() { $('.btn-refresh').click(function() { location.reload(); }); $('#refresh-detail').click(function() { getDetail(); }); $('#edit-status').click(function() { Layer.prompt({ title: '修改状态', formType: 2, value: agentData.status, select: ['normal', 'pending', 'freeze', 'forbidden', 'reject'], selectTips: ['正常', '审核中', '冻结', '禁用', '拒绝'] }, function(value, index) { Fast.api.ajax({ url: 'commission/agent/edit', data: {ids: agentId, status: value} }, function() { Layer.close(index); getDetail(); }); }); }); $('#change-parent').click(function() { Fast.api.open('commission/agent/select?id=' + agentId, '更换上级分销商', { callback: function() { getDetail(); } }); }); $('#upgrade-lock').change(function() { var value = $(this).is(':checked') ? 0 : 1; Fast.api.ajax({ url: 'commission/agent/edit', data: {ids: agentId, upgrade_lock: value} }, function() { getDetail(); }); }); $('#approve-level').click(function() { Fast.api.ajax({ url: 'commission/agent/edit', data: {ids: agentId, level_status: agentData.level_status} }, function() { getDetail(); }); }); $('#reject-level').click(function() { Fast.api.ajax({ url: 'commission/agent/edit', data: {ids: agentId, level_status: 0} }, function() { getDetail(); }); }); // 初始化 if (agentId) { getDetail(); } }); Controller.api.bindevent(); }, select: function () { var userId = Fast.api.query('id'); var selectedParentId = null; var currentPage = 1; var pageSize = 10; // 获取当前用户信息 function getCurrentUserInfo() { Fast.api.ajax({ url: 'commission/agent/detail', data: {id: userId} }, function(data) { var html = ''; if (data.user && data.user.parent_user) { html += '