log.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数
  5. Table.api.init({
  6. extend: {
  7. index_url: 'commission/log/index' + location.search,
  8. add_url: '',
  9. edit_url: '',
  10. del_url: 'commission/log/del',
  11. multi_url: 'commission/log/multi',
  12. import_url: 'commission/log/import',
  13. table: 'commission_log',
  14. }
  15. });
  16. var table = $("#table");
  17. // 获取后台配置
  18. var eventTypes = Controller.api.parseConfigJson('commission_log_event_types', {
  19. "agent": __('分销商日志'),
  20. "level": __('等级变动日志'),
  21. "order": __('分销业绩'),
  22. "team": __('团队日志'),
  23. "reward": __('佣金日志'),
  24. "share": __('分享日志'),
  25. "bind": __('绑定日志')
  26. });
  27. var operTypes = Controller.api.parseConfigJson('commission_log_oper_types', {
  28. "admin": __('管理员'),
  29. "system": __('系统'),
  30. "user": __('用户')
  31. });
  32. var displayConfig = Controller.api.parseConfigJson('commission_log_user_display_config', {
  33. showAvatar: true,
  34. avatarSize: 40,
  35. showMobile: true,
  36. showId: true,
  37. systemAvatarUrl: '/assets/img/system-avatar.png',
  38. defaultAvatarUrl: '/assets/img/avatar.png'
  39. });
  40. // 创建统一的代理商信息展示方法
  41. function formatAgentInfo(row) {
  42. if (!row.agent || !row.agent.user) {
  43. return '-';
  44. }
  45. return Controller.api.formatUserInfo(row.agent.user, row.agent_id, '分销商', displayConfig);
  46. }
  47. // 创建统一的操作人信息展示方法
  48. function formatOperatorInfo(row) {
  49. return Controller.api.formatOperatorInfo(row.oper, row.oper_type, displayConfig);
  50. }
  51. // 初始化表格
  52. table.bootstrapTable({
  53. url: $.fn.bootstrapTable.defaults.extend.index_url,
  54. pk: 'id',
  55. sortName: 'id',
  56. columns: [
  57. [
  58. {checkbox: true},
  59. {field: 'id', title: __('ID'), width: 60},
  60. {field: 'event_text', title: __('事件类型'), searchList: eventTypes},
  61. {
  62. field: 'agent.username',
  63. title: __('分销商'),
  64. operate: 'LIKE',
  65. formatter: function (value, row, index) {
  66. return formatAgentInfo(row);
  67. }
  68. },
  69. {field: 'remark', title: __('备注'), operate: 'LIKE'},
  70. {field: 'oper_type', title: __('操作人类型'), searchList: operTypes},
  71. {
  72. field: 'oper.oper_type_text',
  73. title: __('操作人'),
  74. operate: 'LIKE',
  75. formatter: function (value, row, index) {
  76. return formatOperatorInfo(row);
  77. }
  78. },
  79. {field: 'createtime', title: __('创建时间'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime},
  80. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  81. buttons: [
  82. {
  83. name: 'del',
  84. text: __('删除'),
  85. title: __('删除'),
  86. classname: 'btn btn-xs btn-danger btn-delone',
  87. icon: 'fa fa-trash',
  88. url: 'commission/log/del',
  89. callback: function (data) {
  90. table.bootstrapTable('refresh');
  91. }
  92. }
  93. ],
  94. formatter: Table.api.formatter.operate}
  95. ]
  96. ]
  97. });
  98. // 为表格绑定事件
  99. Table.api.bindevent(table);
  100. },
  101. api: {
  102. // 解析Config中的JSON字符串的辅助函数
  103. parseConfigJson: function(configKey, defaultValue) {
  104. var configValue = Config[configKey] || defaultValue || {};
  105. // 如果是字符串,尝试解析JSON
  106. if (typeof configValue === 'string') {
  107. try {
  108. return JSON.parse(configValue);
  109. } catch (e) {
  110. return defaultValue || {};
  111. }
  112. }
  113. return configValue;
  114. },
  115. // 统一的用户信息展示方法
  116. formatUserInfo: function(user, userId, userType, config) {
  117. if (!user) return '-';
  118. config = config || {
  119. showAvatar: true,
  120. avatarSize: 40,
  121. showMobile: true,
  122. showId: true,
  123. defaultAvatarUrl: '/assets/img/avatar.png'
  124. };
  125. var avatar = user.avatar ? user.avatar : config.defaultAvatarUrl;
  126. var nickname = user.nickname || user.username || (userType || '用户');
  127. var mobile = user.mobile || '';
  128. // 处理头像URL
  129. var avatarUrl = avatar;
  130. if (avatar && !avatar.startsWith('http') && !avatar.startsWith('//')) {
  131. avatarUrl = Fast.api.cdnurl ? Fast.api.cdnurl(avatar) : avatar;
  132. }
  133. var typeColor = userType === '管理员' ? '#dc3545' : (userType === '用户' ? '#17a2b8' : '#337ab7');
  134. var html = '<div style="display:flex;align-items:center;">';
  135. if (config.showAvatar) {
  136. html += '<img src="' + avatarUrl + '" style="width:' + config.avatarSize + 'px;height:' + config.avatarSize + 'px;border-radius:50%;margin-right:10px;" />';
  137. }
  138. html += '<div>' +
  139. '<div style="color:#337ab7;font-weight:bold;">' + nickname + '</div>' +
  140. '<div style="color:' + typeColor + ';font-size:12px;">';
  141. var info = [];
  142. if (config.showMobile && mobile) {
  143. info.push(mobile);
  144. }
  145. if (config.showId && userId) {
  146. info.push('ID: ' + userId);
  147. }
  148. html += info.join(' ') + '</div></div></div>';
  149. return html;
  150. },
  151. // 格式化代理商信息展示
  152. formatAgentInfo: function(agentData, config) {
  153. if (!agentData || !agentData.user) {
  154. return '-';
  155. }
  156. return this.formatUserInfo(agentData.user, agentData.user_id || agentData.id, '分销商', config);
  157. },
  158. // 格式化操作人信息展示
  159. formatOperatorInfo: function(operData, operType, config) {
  160. if (operType === 'system') {
  161. var sysConfig = config || { avatarSize: 40, systemAvatarUrl: '/assets/img/system-avatar.png' };
  162. var html = '<div style="display:flex;align-items:center;">';
  163. html += '<img src="' + sysConfig.systemAvatarUrl + '" style="width:' + sysConfig.avatarSize + 'px;height:' + sysConfig.avatarSize + 'px;border-radius:50%;margin-right:10px;" />';
  164. html += '<div>' +
  165. '<div style="color:#28a745;font-weight:bold;">系统</div>' +
  166. '<div style="color:#999;font-size:12px;">自动操作</div>' +
  167. '</div></div>';
  168. return html;
  169. }
  170. if (!operData) {
  171. return '-';
  172. }
  173. var userType = operType === 'admin' ? '管理员' : '用户';
  174. return this.formatUserInfo(operData, operData.id, userType, config);
  175. },
  176. bindevent: function () {
  177. Form.api.bindevent($("form[role=form]"));
  178. }
  179. }
  180. };
  181. return Controller;
  182. });