123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数
- Table.api.init({
- extend: {
- index_url: 'commission/log/index' + location.search,
- add_url: '',
- edit_url: '',
- del_url: 'commission/log/del',
- multi_url: 'commission/log/multi',
- import_url: 'commission/log/import',
- table: 'commission_log',
- }
- });
- var table = $("#table");
-
- // 获取后台配置
- var eventTypes = Controller.api.parseConfigJson('commission_log_event_types', {
- "agent": __('分销商日志'),
- "level": __('等级变动日志'),
- "order": __('分销业绩'),
- "team": __('团队日志'),
- "reward": __('佣金日志'),
- "share": __('分享日志'),
- "bind": __('绑定日志')
- });
-
- var operTypes = Controller.api.parseConfigJson('commission_log_oper_types', {
- "admin": __('管理员'),
- "system": __('系统'),
- "user": __('用户')
- });
-
- var displayConfig = Controller.api.parseConfigJson('commission_log_user_display_config', {
- showAvatar: true,
- avatarSize: 40,
- showMobile: true,
- showId: true,
- systemAvatarUrl: '/assets/img/system-avatar.png',
- defaultAvatarUrl: '/assets/img/avatar.png'
- });
- // 创建统一的代理商信息展示方法
- function formatAgentInfo(row) {
- if (!row.agent || !row.agent.user) {
- return '-';
- }
- return Controller.api.formatUserInfo(row.agent.user, row.agent_id, '分销商', displayConfig);
- }
- // 创建统一的操作人信息展示方法
- function formatOperatorInfo(row) {
- return Controller.api.formatOperatorInfo(row.oper, row.oper_type, displayConfig);
- }
-
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('ID'), width: 60},
- {field: 'event_text', title: __('事件类型'), searchList: eventTypes},
- {
- field: 'agent.username',
- title: __('分销商'),
- operate: 'LIKE',
- formatter: function (value, row, index) {
- return formatAgentInfo(row);
- }
- },
- {field: 'remark', title: __('备注'), operate: 'LIKE'},
- {field: 'oper_type', title: __('操作人类型'), searchList: operTypes},
- {
- field: 'oper.oper_type_text',
- title: __('操作人'),
- operate: 'LIKE',
- formatter: function (value, row, index) {
- return formatOperatorInfo(row);
- }
- },
- {field: 'createtime', 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: 'del',
- text: __('删除'),
- title: __('删除'),
- classname: 'btn btn-xs btn-danger btn-delone',
- icon: 'fa fa-trash',
- url: 'commission/log/del',
- callback: function (data) {
- table.bootstrapTable('refresh');
- }
- }
- ],
- formatter: Table.api.formatter.operate}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- 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;
- },
-
- // 统一的用户信息展示方法
- formatUserInfo: function(user, userId, userType, config) {
- if (!user) return '-';
-
- config = config || {
- showAvatar: true,
- avatarSize: 40,
- showMobile: true,
- showId: true,
- defaultAvatarUrl: '/assets/img/avatar.png'
- };
-
- var avatar = user.avatar ? user.avatar : config.defaultAvatarUrl;
- var nickname = user.nickname || user.username || (userType || '用户');
- var mobile = user.mobile || '';
-
- // 处理头像URL
- var avatarUrl = avatar;
- if (avatar && !avatar.startsWith('http') && !avatar.startsWith('//')) {
- avatarUrl = Fast.api.cdnurl ? Fast.api.cdnurl(avatar) : avatar;
- }
-
- var typeColor = userType === '管理员' ? '#dc3545' : (userType === '用户' ? '#17a2b8' : '#337ab7');
-
- var html = '<div style="display:flex;align-items:center;">';
-
- if (config.showAvatar) {
- html += '<img src="' + avatarUrl + '" style="width:' + config.avatarSize + 'px;height:' + config.avatarSize + 'px;border-radius:50%;margin-right:10px;" />';
- }
-
- html += '<div>' +
- '<div style="color:#337ab7;font-weight:bold;">' + nickname + '</div>' +
- '<div style="color:' + typeColor + ';font-size:12px;">';
-
- var info = [];
- if (config.showMobile && mobile) {
- info.push(mobile);
- }
- if (config.showId && userId) {
- info.push('ID: ' + userId);
- }
-
- html += info.join(' ') + '</div></div></div>';
- return html;
- },
-
- // 格式化代理商信息展示
- formatAgentInfo: function(agentData, config) {
- if (!agentData || !agentData.user) {
- return '-';
- }
- return this.formatUserInfo(agentData.user, agentData.user_id || agentData.id, '分销商', config);
- },
-
- // 格式化操作人信息展示
- formatOperatorInfo: function(operData, operType, config) {
- if (operType === 'system') {
- var sysConfig = config || { avatarSize: 40, systemAvatarUrl: '/assets/img/system-avatar.png' };
- var html = '<div style="display:flex;align-items:center;">';
- html += '<img src="' + sysConfig.systemAvatarUrl + '" style="width:' + sysConfig.avatarSize + 'px;height:' + sysConfig.avatarSize + 'px;border-radius:50%;margin-right:10px;" />';
- html += '<div>' +
- '<div style="color:#28a745;font-weight:bold;">系统</div>' +
- '<div style="color:#999;font-size:12px;">自动操作</div>' +
- '</div></div>';
- return html;
- }
-
- if (!operData) {
- return '-';
- }
-
- var userType = operType === 'admin' ? '管理员' : '用户';
- return this.formatUserInfo(operData, operData.id, userType, config);
- },
-
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|