123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574 |
- 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: '',
- edit_url: 'commission/agent/edit',
- del_url: 'commission/agent/del',
- 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 '<span class="label label-' + color + '">' + text + '</span>';
- }},
- {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');
- }
- },
- {
- name: 'edit_status',
- text: __('编辑状态'),
- title: __('编辑状态'),
- classname: 'btn btn-xs btn-success btn-click',
- icon: 'fa fa-edit',
- click: function (data) {
- Layer.prompt({
- title: '修改状态',
- formType: 2,
- value: data.status,
- select: ['normal', 'pending', 'freeze', 'forbidden', 'reject'],
- selectTips: ['正常', '审核中', '冻结', '禁用', '拒绝']
- }, function(value, index, elem) {
- Fast.api.ajax({
- url: 'commission/agent/edit',
- data: {ids: data.user_id, status: value}
- }, function(data, ret) {
- table.bootstrapTable('refresh');
- Layer.close(index);
- });
- });
- }
- }
- ],
- 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 = '<form class="form-horizontal">';
- data.apply_info.forEach(function(item) {
- applyHtml += '<div class="form-group">';
- applyHtml += '<label class="col-sm-3 control-label">' + item.name + ':</label>';
- applyHtml += '<div class="col-sm-9">';
- if (item.type === 'image') {
- applyHtml += '<img src="' + item.value + '" style="max-width: 200px; max-height: 120px;">';
- } else {
- applyHtml += '<p class="form-control-static">' + item.value + '</p>';
- }
- applyHtml += '</div></div>';
- });
- applyHtml += '</form>';
- $('#apply-info').html(applyHtml);
- } else {
- $('#apply-info').html('<p class="text-muted">暂无申请信息</p>');
- }
- }
- // 详情页面特有的全局函数
- 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 = '<label>当前推荐人:</label>';
- if (data.user && data.user.parent_user) {
- html += '<img src="' + (data.user.parent_user.avatar || '/assets/img/avatar.png') + '" ';
- html += 'style="width: 20px; height: 20px; border-radius: 50%; margin-right: 5px;">';
- html += (data.user.parent_user.nickname || '用户' + data.user.parent_user_id);
- selectedParentId = data.user.parent_user_id;
- } else {
- html += '无';
- selectedParentId = 0;
- }
- $('#current-parent').html(html);
- });
- }
- // 获取分销商列表
- function getAgentList() {
- var searchType = $('#search-type').val();
- var searchValue = $('#search-value').val();
- var searchData = {
- page: currentPage,
- limit: pageSize
- };
- if (searchValue) {
- searchData[searchType] = searchValue;
- }
- Fast.api.ajax({
- url: 'commission/agent/select',
- data: searchData
- }, function(ret) {
- var html = '';
- if (ret.data.rows && ret.data.rows.length > 0) {
- ret.data.rows.forEach(function(item) {
- var statusClass = '';
- var statusText = '';
- switch(item.status) {
- case 'normal':
- statusClass = 'label-success';
- statusText = '正常';
- break;
- case 'pending':
- statusClass = 'label-warning';
- statusText = '审核中';
- break;
- case 'freeze':
- statusClass = 'label-info';
- statusText = '冻结';
- break;
- case 'forbidden':
- statusClass = 'label-danger';
- statusText = '禁用';
- break;
- case 'reject':
- statusClass = 'label-danger';
- statusText = '拒绝';
- break;
- default:
- statusClass = 'label-default';
- statusText = item.status;
- }
- html += '<tr' + (selectedParentId == item.user_id ? ' class="warning"' : '') + '>';
- html += '<td><input type="radio" name="parent_agent" value="' + item.user_id + '"' + (selectedParentId == item.user_id ? ' checked' : '') + '></td>';
- html += '<td>' + item.user_id + '</td>';
- html += '<td>';
- html += '<img src="' + (item.user.avatar || '/assets/img/avatar.png') + '" style="width: 32px; height: 32px; border-radius: 50%; margin-right: 5px;">';
- html += (item.user.nickname || '用户' + item.user_id);
- html += '</td>';
- html += '<td>';
- if (item.level_info) {
- html += item.level_info.name + '<br><small>等级' + item.level_info.level + '</small>';
- } else {
- html += '等级' + item.level;
- }
- html += '</td>';
- html += '<td>' + (item.user.mobile || '-') + '</td>';
- html += '<td><span class="label ' + statusClass + '">' + statusText + '</span></td>';
- html += '<td>';
- if (selectedParentId == item.user_id) {
- html += '<span class="text-success">已选择</span>';
- } else {
- html += '<button type="button" class="btn btn-xs btn-primary" onclick="selectAgent(' + item.user_id + ')">选择</button>';
- }
- html += '</td>';
- html += '</tr>';
- });
- } else {
- html = '<tr><td colspan="7" class="text-center">暂无数据</td></tr>';
- }
- $('#agent-list').html(html);
- // 更新分页
- updatePagination(ret.data.total);
- });
- }
- // 更新分页
- function updatePagination(total) {
- var totalPages = Math.ceil(total / pageSize);
- var html = '<ul class="pagination">';
-
- // 上一页
- if (currentPage > 1) {
- html += '<li><a href="javascript:;" onclick="changePage(' + (currentPage - 1) + ')">上一页</a></li>';
- }
-
- // 页码
- for (var i = 1; i <= totalPages; i++) {
- if (i == currentPage) {
- html += '<li class="active"><a href="javascript:;">' + i + '</a></li>';
- } else {
- html += '<li><a href="javascript:;" onclick="changePage(' + i + ')">' + i + '</a></li>';
- }
- }
-
- // 下一页
- if (currentPage < totalPages) {
- html += '<li><a href="javascript:;" onclick="changePage(' + (currentPage + 1) + ')">下一页</a></li>';
- }
-
- html += '</ul>';
- $('#pagination').html(html);
- }
- // 选择页面特有的全局函数
- window.searchAgent = function() {
- currentPage = 1;
- getAgentList();
- };
- window.selectAgent = function(agentId) {
- selectedParentId = agentId;
- $('input[name="parent_agent"]').prop('checked', false);
- $('input[value="' + agentId + '"]').prop('checked', true);
- $('#agent-table tbody tr').removeClass('warning');
- $('input[value="' + agentId + '"]').closest('tr').addClass('warning');
- $('#set-platform').prop('checked', false);
- };
- window.changePage = function(page) {
- currentPage = page;
- getAgentList();
- };
- window.confirmChange = function() {
- if (selectedParentId === null) {
- Toastr.error('请选择上级分销商');
- return;
- }
- Fast.api.ajax({
- url: 'commission/agent/changeParentUser',
- data: {
- id: userId,
- parent_user_id: selectedParentId
- }
- }, function() {
- Toastr.success('更换成功');
- Fast.api.close();
- });
- };
- // 事件绑定
- $(document).ready(function() {
- // 设为平台直推
- $('#set-platform').change(function() {
- if ($(this).is(':checked')) {
- selectedParentId = 0;
- $('input[name="parent_agent"]').prop('checked', false);
- $('#agent-table tbody tr').removeClass('warning');
- }
- });
- // 搜索框回车事件
- $('#search-value').keypress(function(e) {
- if (e.which == 13) {
- searchAgent();
- }
- });
- // 初始化
- getCurrentUserInfo();
- getAgentList();
- });
- },
- team: function () {
- // 团队页面特有的全局函数
- window.viewTeam = function(userId) {
- Fast.api.open('commission/agent/team?id=' + userId, '查看团队');
- };
- window.viewDetail = function(userId) {
- Fast.api.open('commission/agent/detail?id=' + userId, '分销商详情');
- };
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|