|
@@ -25,28 +25,40 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
|
|
columns: [
|
|
|
[
|
|
|
{checkbox: true},
|
|
|
- {field: 'level', title: __('等级权重'), width: 80},
|
|
|
+ {field: 'level', title: __('等级权重'), width: 80, formatter: function(value, row, index) {
|
|
|
+ return '等级' + value;
|
|
|
+ }},
|
|
|
{field: 'name', title: __('等级名称'), operate: 'LIKE'},
|
|
|
{field: 'image', title: __('等级徽章'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
|
|
|
- {field: 'commission_rules.commission_1', title: __('一级佣金比例'), operate: false, formatter: function(value, row, index) {
|
|
|
- return (value || '0.00') + '%';
|
|
|
+ {field: 'commission_rules', title: __('一级佣金比例'), operate: false, formatter: function(value, row, index) {
|
|
|
+ if (typeof value === 'string') {
|
|
|
+ try {
|
|
|
+ value = JSON.parse(value);
|
|
|
+ } catch (e) {
|
|
|
+ value = {};
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return (value.commission_1 || '0.00') + '%';
|
|
|
}},
|
|
|
- {field: 'commission_rules.commission_2', title: __('二级佣金比例'), operate: false, formatter: function(value, row, index) {
|
|
|
- return (value || '0.00') + '%';
|
|
|
+ {field: 'commission_rules', title: __('二级佣金比例'), operate: false, formatter: function(value, row, index) {
|
|
|
+ if (typeof value === 'string') {
|
|
|
+ try {
|
|
|
+ value = JSON.parse(value);
|
|
|
+ } catch (e) {
|
|
|
+ value = {};
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return (value.commission_2 || '0.00') + '%';
|
|
|
}},
|
|
|
- {field: 'commission_rules.commission_3', title: __('三级佣金比例'), operate: false, formatter: function(value, row, index) {
|
|
|
- return (value || '0.00') + '%';
|
|
|
- }},
|
|
|
- {field: 'upgrade_type', title: __('升级方式'), searchList: {
|
|
|
- "0": __('手动升级'),
|
|
|
- "1": __('自动升级')
|
|
|
- }, formatter: function(value, row, index) {
|
|
|
- var typeMap = {
|
|
|
- '0': {text: '手动升级', color: 'info'},
|
|
|
- '1': {text: '自动升级', color: 'success'}
|
|
|
- };
|
|
|
- var type = typeMap[value] || {text: value, color: 'default'};
|
|
|
- return '<span class="label label-' + type.color + '">' + type.text + '</span>';
|
|
|
+ {field: 'commission_rules', title: __('三级佣金比例'), operate: false, formatter: function(value, row, index) {
|
|
|
+ if (typeof value === 'string') {
|
|
|
+ try {
|
|
|
+ value = JSON.parse(value);
|
|
|
+ } catch (e) {
|
|
|
+ value = {};
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return (value.commission_3 || '0.00') + '%';
|
|
|
}},
|
|
|
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
|
|
|
buttons: [
|
|
@@ -60,20 +72,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
|
|
callback: function (data) {
|
|
|
table.bootstrapTable('refresh');
|
|
|
}
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'del',
|
|
|
- text: __('删除'),
|
|
|
- title: __('删除'),
|
|
|
- classname: 'btn btn-xs btn-danger btn-delone',
|
|
|
- icon: 'fa fa-trash',
|
|
|
- url: 'commission/level/delete',
|
|
|
- visible: function (row) {
|
|
|
- return row.level != 1; // 默认等级不能删除
|
|
|
- },
|
|
|
- callback: function (data) {
|
|
|
- table.bootstrapTable('refresh');
|
|
|
- }
|
|
|
}
|
|
|
],
|
|
|
formatter: Table.api.formatter.operate}
|
|
@@ -138,36 +136,106 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
|
|
Table.api.bindevent(table);
|
|
|
},
|
|
|
api: {
|
|
|
+ // 默认等级选项
|
|
|
+ defaultLevels: [
|
|
|
+ {name: '一级', level: 1},
|
|
|
+ {name: '二级', level: 2},
|
|
|
+ {name: '三级', level: 3},
|
|
|
+ {name: '四级', level: 4},
|
|
|
+ {name: '五级', level: 5},
|
|
|
+ {name: '六级', level: 6},
|
|
|
+ {name: '七级', level: 7},
|
|
|
+ {name: '八级', level: 8},
|
|
|
+ {name: '九级', level: 9},
|
|
|
+ {name: '十级', level: 10}
|
|
|
+ ],
|
|
|
+
|
|
|
bindevent: function () {
|
|
|
Form.api.bindevent($("form[role=form]"));
|
|
|
|
|
|
- // 绑定升级类型变化事件
|
|
|
- $(document).on('change', 'input[name="row[upgrade_type]"]', function() {
|
|
|
- var value = $(this).val();
|
|
|
- var upgradeRulesContainer = $('.upgrade-rules-container');
|
|
|
- if (value == '1') {
|
|
|
- upgradeRulesContainer.show();
|
|
|
- } else {
|
|
|
- upgradeRulesContainer.hide();
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ // 初始化页面数据
|
|
|
+ self.initPageData();
|
|
|
+
|
|
|
+ // 绑定等级选择事件
|
|
|
+ $(document).on('click', '.level-select-item', function() {
|
|
|
+ var level = $(this).data('level');
|
|
|
+
|
|
|
+ // 如果是禁用的按钮,不执行任何操作
|
|
|
+ if ($(this).hasClass('disabled')) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var existLevels = $('.level-select-item.disabled').map(function() {
|
|
|
+ return $(this).data('level');
|
|
|
+ }).get();
|
|
|
+
|
|
|
+ if (existLevels.indexOf(level) === -1) {
|
|
|
+ $('.level-select-item').removeClass('active');
|
|
|
+ $(this).addClass('active');
|
|
|
+ $('input[name="row[level]"]').val(level);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
- // 添加升级条件
|
|
|
- $(document).on('click', '.add-upgrade-rule', function() {
|
|
|
- var container = $(this).closest('.upgrade-rules-container').find('.upgrade-rules-list');
|
|
|
- var template = container.find('.upgrade-rule-item:first').clone();
|
|
|
- template.find('input').val('');
|
|
|
- container.append(template);
|
|
|
- });
|
|
|
-
|
|
|
- // 删除升级条件
|
|
|
- $(document).on('click', '.remove-upgrade-rule', function() {
|
|
|
- var item = $(this).closest('.upgrade-rule-item');
|
|
|
- var container = item.closest('.upgrade-rules-list');
|
|
|
- if (container.find('.upgrade-rule-item').length > 1) {
|
|
|
- item.remove();
|
|
|
+ },
|
|
|
+
|
|
|
+ initPageData: function() {
|
|
|
+ var self = this;
|
|
|
+ var currentLevel = $('input[name="row[level]"]').val();
|
|
|
+ var isEdit = currentLevel ? true : false;
|
|
|
+
|
|
|
+ // 获取已存在的等级
|
|
|
+ $.ajax({
|
|
|
+ url: Fast.api.fixurl('commission/level/select'),
|
|
|
+ type: 'GET',
|
|
|
+ success: function(ret) {
|
|
|
+ if (ret.code === 1) {
|
|
|
+ var existLevels = ret.data.map(function(item) {
|
|
|
+ return parseInt(item.level);
|
|
|
+ });
|
|
|
+
|
|
|
+ if (isEdit) {
|
|
|
+ // 编辑模式,移除当前编辑的等级
|
|
|
+ var index = existLevels.indexOf(parseInt(currentLevel));
|
|
|
+ if (index > -1) {
|
|
|
+ existLevels.splice(index, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.renderLevelSelect(existLevels, currentLevel);
|
|
|
+ } else {
|
|
|
+ // 请求成功但返回错误,至少显示基本的等级选择器
|
|
|
+ self.renderLevelSelect([], currentLevel);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function(xhr, status, error) {
|
|
|
+ // Ajax请求失败,至少显示基本的等级选择器
|
|
|
+ self.renderLevelSelect([], currentLevel);
|
|
|
}
|
|
|
});
|
|
|
+ },
|
|
|
+
|
|
|
+ renderLevelSelect: function(existLevels, currentLevel) {
|
|
|
+ var html = '';
|
|
|
+
|
|
|
+ // 如果是编辑1级(默认等级),只显示1级并禁用选择
|
|
|
+ if (currentLevel && parseInt(currentLevel) === 1) {
|
|
|
+ html += '<div class="level-select-item btn btn-default active disabled" data-level="1">';
|
|
|
+ html += '一级(默认等级,不可修改)';
|
|
|
+ html += '</div>';
|
|
|
+ } else {
|
|
|
+ // 非1级或新建时,显示可选等级
|
|
|
+ this.defaultLevels.forEach(function(item) {
|
|
|
+ var disabled = existLevels.indexOf(item.level) !== -1 ? 'disabled' : '';
|
|
|
+ var active = (currentLevel && parseInt(currentLevel) === item.level) ? 'active' : '';
|
|
|
+
|
|
|
+ html += '<div class="level-select-item btn btn-default ' + disabled + ' ' + active + '" data-level="' + item.level + '">';
|
|
|
+ html += item.name;
|
|
|
+ html += '</div>';
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ $('.level-select-container').html(html);
|
|
|
}
|
|
|
}
|
|
|
};
|