define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'postbackrules/index?type='+Config.type,
add_url: 'postbackrules/add?type='+Config.type,
edit_url: 'postbackrules/edit',
del_url: 'postbackrules/del',
table: 'postback_rules',
},
search:false
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{field: 'id', title: __('Id'), operate: false},
{field: 'name', title: __('Name'), operate: 'LIKE'},
{field: 'channel_ids', title: __('Channel_ids'), operate: false, formatter: function (value, row, table) {
var content = '';
if (value == '*') {
content = '已关联所有渠道';
} else {
content = '关联';
}
content += '查看';
return content;
}},
{field: 'referral_ids', title: __('Referral_ids'), operate: false, formatter: function (value, row, table) {
var content = '';
if (row.channel_ids == '') {
content = '请先关联渠道';
} else {
if (value == '*') {
content = '已关联所有推广id';
} else {
content += '推广id配置';
content = '关联';
}
content += '查看';
}
return content;
}},
{field: 'money', title: __('Money'), operate: false},
/*{field: 'kl', title: __('Kl'), operate: false},*/
{field: 'man_val', title: __('回传订单'),operate:false, formatter: function (val, row, index) {
console.log(row);
if (row.man_val == 0 || row.kou_val == 0) {
return "-";
}
return "满"+ row.man_val + "扣" + row.kou_val;
}},
{field: 'weight', title: __('Weight'), operate: false},
{field: 'state', title: __('State'), visible:false, searchList: {"show":__('state show'),"hide":__('state hide')}},
{field: 'state_text', title: __('State'), operate:false, formatter: function(value, row){
if (value == __('state show')) {
return value+''
} else {
return value+''
}
}},
{field: 'createtime', title: __('Createtime'), operate: false,formatter:Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate: false,formatter:Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
$(document).on('click','.layer-open',function () {
Fast.api.open($(this).attr('href'), $(this).data('title')?$(this).data('title'):'全局配置', {
callback: function(){
table.bootstrapTable('refresh');
}
});
return false;
});
// 为表格绑定事件
Table.api.bindevent(table);
table.delegate('.changestate', 'click', function () {
var data = $(this).data();
$.ajax({
data:data,
url:'/admin/postbackrules/changestate',
success:function () {
Layer.alert('修改成功');
table.bootstrapTable('refresh');
},
error: function(){
Layer.alert('修改失败');
}
});
})
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
globalconfig: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});