define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'manage/lightrule/index',
add_url: 'manage/lightrule/add',
edit_url: 'manage/lightrule/edit',
del_url: 'manage/lightrule/del',
multi_url: 'manage/lightrule/multi',
table: 'config_light_rule',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('ID')},
{field: 'name', title: __('Name')},
// {field: 'city_ids', title: __('City_ids')},
// {field: 'channel_ids', title: __('Channel_ids')},
{
field: 'id',
operate:false,
title: __('关联渠道'),
formatter: Controller.api.formatter.fm_associate_channels
},
{
field: 'id',
operate:false,
title: __('一键清除'),
formatter: function (index, row, value) {
return "清除所有渠道";
}
},
{field: 'push_type', title: __('Code'), formatter: Controller.api.formatter.pushType,operate:false},
{field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
//一键清除
$(document).on('click', '.qd-associate-all', function () {
var rule_id = $(this).data("rule_id");
Layer.confirm(
'确定要清理所有渠道吗',
{icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
function (index) {
$.post('/admin/manage/lightrule/operate',
{
'id': rule_id,
'channel_ids': "*",
'method': 'remove'
},
function (result) {
if (result.code == 1) {
Toastr.success('操作成功');
//刷新页面
table.bootstrapTable('refresh');
} else {
Toastr.error(result.msg);
}
});
Layer.close(index);
}
);
});
// 列表关联
$(document).on('click', '.qd-associate', function () {
var rule_id = $(this).data("rule_id");
var channel_ids = $(this).data("channel_id");
if (channel_ids == 'undefined') {
channel_ids = '';
}
Fast.api.open('/admin/auth/channel/select?operate=add&type=3&group_ids=3&source_id=' + rule_id, "关联渠道", {callback: function (data) {
$.post('/admin/manage/lightrule/operate',
{
'id': rule_id,
'channel_ids': data,
'method': 'add'
},
function (result) {
if (result.code == 1) {
Toastr.success('操作成功');
//刷新页面
table.bootstrapTable('refresh');
} else {
Toastr.error(result.msg);
}
});
}
});
});
// 列表 查看
$(document).on('click', '.qd-view', function () {
var rule_id = $(this).data("rule_id");
var channel_ids = $(this).data("channel_id");
if (channel_ids == 'undefined') {
channel_ids = '';
}
Fast.api.open('/admin/auth/channel/select?operate=remove&type=3&group_ids=3&source_id=' + rule_id, "关联渠道", {callback: function (data) {
$.post('/admin/manage/lightrule/operate',
{
'id': rule_id,
'channel_ids': data,
'method': 'remove'
},
function (result) {
if (result.code == 1) {
Toastr.success('操作成功');
//刷新页面
table.bootstrapTable('refresh');
} else {
Toastr.error(result.msg);
}
});
}
});
});
$(document).on("click", ".qd-edit", function () {
var rule_id = $(this).data("rule_id");
var channel_ids = $(this).data("channel_id");
if (channel_ids == 'undefined') {
channel_ids = '';
}
layer.open({
type: 1,
title: '批量关联',
maxmin: true,
area: ['60%', '80%'],
btn: ['确定', '取消'],
shadeClose: true, //点击遮罩关闭层
content: $("#qd_multi_edit"),
yes: function (data) {
var channel_ids = $("#c-channel_id").val();
$("#c-channel_id").val("");
$.post('/admin/manage/lightrule/operate',
{
'id': rule_id,
'channel_ids': channel_ids,
'method': 'add'
},
function (result) {
// aResult = JSON.parse(result);
if (result.code == 1) {
Toastr.success('操作成功');
//刷新页面
table.bootstrapTable('refresh');
} else {
Toastr.error(result.msg);
}
});
layer.closeAll();
}
});
});
$('.btn-refresh-cache').click(function () {
$.get('/admin/manage/lightrule/refreshcache', {}, function (result) {
if (result.code == 1) {
Toastr.success('操作成功');
} else {
Toastr.error(result.msg);
}
});
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},
formatter: {
fm_associate_channels:function (value, row, index) {
html = '';
if(row.channel_ids == '*'){
html += "已关联所有渠道";
}else{
html += "关联 ";
html += "查看 ";
// html += "批量关联";
}
return html;
},
pushType: function (value) {
if (value == 0) {
return '全部书籍';
} else if (value == 1) {
return '清水书籍';
}
// else if (value == 2) {
// return '限定城市推送清水书籍';
// }
}
}
}
};
return Controller;
});