define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'exclusive/index',
add_url: 'exclusive/add',
edit_url: 'exclusive/edit',
del_url: 'exclusive/del',
multi_url: 'exclusive/multi',
table: 'exclusive',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
search: false,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id'), operate:false},
{field: 'name', title: __('Name'), operate:false},
{field: 'channel_nickname', title: __('渠道昵称'),visible:false},
{field: 'channel_id', title: __('渠道ID'),visible:false},
{field: 'operate', title: __('关联渠道'), table: table, events: Table.api.events.operate, formatter: function(value, row){
var content = '';
content += '关联渠道 ';
content += '查看渠道 ';
return content;
}
},
{field: 'operate', title: __('关联书籍'), table: table, events: Table.api.events.operate, formatter: function(value, row){
var content = '';
content += '关联书籍 ';
content += '查看书籍 ';
return content;
}
},
{field: 'endtime', title: __('Endtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'createtime', title: __('创建时间'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{
field: 'status',
title: __('状态'),
searchList: {"1":__('生效'),"2":__('失效')},
formatter: function (value, row, index) {
var html = '';
if(row.status==1){
html += '有效';
}else{
html += '失效';
}
return html;
}
},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function(value, row){
var content = '';
content += ' ';
content += ' ';
return content;
}}
]
]
});
//关联渠道
$(document).on('click','.bind-channels',function () {
var ids = $(this).data('id');
Fast.api.open(
'/admin/exclusive/bindchannels/ids/'+ids,
'关联渠道'
);
});
//查看渠道
$(document).on('click','.show-channels',function () {
var ids = $(this).data('id');
Fast.api.open(
'/admin/exclusive/showchannels/ids/'+ids,
'查看渠道'
);
});
//关联书籍
$(document).on('click','.bind-books',function () {
var ids = $(this).data('id');
Fast.api.open(
'/admin/exclusive/bindbooks/ids/'+ids,
'关联书籍'
);
});
//查看书籍
$(document).on('click','.show-books',function () {
var ids = $(this).data('id');
Fast.api.open(
'/admin/exclusive/showbooks/ids/'+ids,
'查看书籍'
);
});
//修改
$(document).on('click','.btn-ex-edit',function () {
var ids = $(this).data('id');
Fast.api.open('/admin/exclusive/edit/ids/'+ids,'修改');
});
//删除
$(document).on('click','.btn-ex-danger',function () {
var ids = $(this).data('id');
layer.confirm("确定删除选中的 1 项?", { title: "温馨提示" }, function (index) {
Layer.close(index);
$.post('/admin/exclusive/del',{ids:ids},function(data){
if(data.code==1){
Toastr.success('操作成功!');
table.bootstrapTable('refresh');
}else{
Toastr.error(data.msg);
}
})
});
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
bindchannels: function (){
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'exclusive/bindchannels/ids/'+Config.ids,
}
});
var table = $("#bind-channels-table");
var mtotal = 0;
table.on('load-success.bs.table', function (e, data) {
//这里可以获取从服务端获取的JSON数据
mtotal = data.total;
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
search: false,
pageList: [10, 25, 50, 100, 1000],
columns: [
[
{checkbox: true},
{field: 'id', title: 'ID'},
{field: 'username', title: __('用户名'), operate:'LIKE'},
{field: 'nickname', title: __('昵称'), operate:'LIKE'},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function(value, row){
var content = '';
if(Config.bindids.split(',').indexOf(row.id) == -1){
content += '关联 ';
}else{
content += '已关联';
}
return content;
}}
]
]
});
//单项关联
$(document).on('click','.btn-single-edit',function () {
var rowid = $(this).data('row-id');
layer.confirm('确认要关联所选的1项吗??', {title: "关联渠道"}, function (index) {
Layer.closeAll();
$.ajax({
url:'/admin/exclusive/batch_bind_channels',
type:"post",
data: {
eid:Config.ids,
ids:{rowid}
},
success:function(datas){
Toastr.success('操作成功!');
setTimeout(function() {
window.location.reload();
},1000);
}
});
});
});
//批量关联
$('.btn-batch-bind').on('click',function () {
var ids = Table.api.selectedids(table);
var post_ids = [];
if (ids.length > 0) {
layer.confirm('确认要关联所选的'+ids.length+'项吗??', {title: "关联渠道"}, function (index) {
Layer.closeAll();
ids.forEach(function (v, k) {
if (Config.bindids.split(',').indexOf(v) == -1) {
post_ids.push(v);
}
});
if (post_ids.length > 0) {
$.ajax({
url: '/admin/exclusive/batch_bind_channels',
type: "post",
data: {
eid: Config.ids,
ids: post_ids
},
success: function (datas) {
Toastr.success('操作成功!');
setTimeout(function () {
window.location.reload();
}, 1000);
}
});
} else {
Toastr.error('选择的项已关联');
}
});
} else {
Toastr.error('请选择要关联的选项');
}
});
//全部关联
$('.btn-all-bind').on('click',function () {
if(mtotal>0){
layer.confirm('确认要关联所有项吗??', {title: "关联渠道"}, function (index) {
Layer.closeAll();
$.ajax({
url:'/admin/exclusive/bind_all_channels',
type:"post",
data: {
ids:Config.ids
},
success:function(datas){
Toastr.success('操作成功!');
setTimeout(function() {
window.location.reload();
},1000);
}
});
});
}else{
Toastr.error('无关联项!');
setTimeout(function() {
window.location.reload();
},1000);
}
});
Controller.api.bindevent();
},
showchannels: function (){
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'exclusive/showchannels/ids/'+Config.ids,
}
});
var table = $("#unbind-channels-table");
var mtotal = 0;
table.on('load-success.bs.table', function (e, data) {
//这里可以获取从服务端获取的JSON数据
mtotal = data.total;
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
search: false,
pageList: [10, 25, 50, 100, 1000],
columns: [
[
{checkbox: true},
{field: 'id', title: 'ID'},
{field: 'username', title: __('用户名'), operate:'LIKE'},
{field: 'nickname', title: __('昵称'), operate:'LIKE'},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function(value, row){
var content = '';
content += '取消关联 ';
return content;
}}
]
]
});
//单项取关
$(document).on('click','.btn-single-edit',function () {
var rowid = $(this).data('row-id');
layer.confirm('确认要取关所选的1项吗??', {title: "取关渠道"}, function (index) {
Layer.closeAll();
$.ajax({
url:'/admin/exclusive/batch_unbind_channels',
type:"post",
data: {
eid:Config.ids,
ids:{rowid}
},
success:function(datas){
Toastr.success('操作成功!');
setTimeout(function() {
window.location.reload();
},1000);
}
});
});
});
//批量取关
$('.btn-batch-unbind').on('click',function () {
var ids = Table.api.selectedids(table);
if(ids.length>0){
layer.confirm('确认要取关所选的'+ids.length+'项吗??', {title: "取关渠道"}, function (index) {
Layer.closeAll();
$.ajax({
url:'/admin/exclusive/batch_unbind_channels',
type:"post",
data: {
eid:Config.ids,
ids:ids
},
success:function(datas){
Toastr.success('操作成功!');
setTimeout(function() {
window.location.reload();
},1000);
}
});
});
}else{
Toastr.error('请选择要关联的选项');
}
});
//全部取关
$('.btn-all-unbind').on('click',function () {
if(mtotal>0){
layer.confirm('确认要取关所有项吗??', {title: "取关渠道"}, function (index) {
Layer.closeAll();
$.ajax({
url:'/admin/exclusive/unbind_all_channels',
type:"post",
data: {
ids:Config.ids
},
success:function(datas){
Toastr.success('操作成功!');
table.bootstrapTable('refresh');
}
});
});
}else{
Toastr.error('无关联项!');
setTimeout(function() {
window.location.reload();
},1000);
}
});
Controller.api.bindevent();
},
bindbooks: function (){
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'exclusive/bindbooks/ids/'+Config.ids,
}
});
var table = $("#bind-books-table");
var mtotal = 0;
table.on('load-success.bs.table', function (e, data) {
//这里可以获取从服务端获取的JSON数据
mtotal = data.total;
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
search: false,
columns: [
[
{checkbox: true},
{field: 'id', title: '书籍ID'},
{field: 'name', title: __('书籍名称'), operate:'LIKE'},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function(value, row){
var content = '';
if(Config.bindids.split(',').indexOf(row.id) == -1){
content += '关联 ';
}else{
content += '已关联';
}
return content;
}}
]
]
});
//单项关联
$(document).on('click','.btn-single-edit',function () {
var rowid = $(this).data('row-id');
layer.confirm('确认要关联所选的1项吗??', {title: "关联渠道"}, function (index) {
Layer.closeAll();
$.ajax({
url:'/admin/exclusive/batch_bind_books',
type:"post",
data: {
eid:Config.ids,
ids:{rowid}
},
success:function(datas){
Toastr.success('操作成功!');
setTimeout(function() {
window.location.reload();
},1000);
}
});
});
});
//批量关联
$('.btn-batch-bind').on('click',function () {
var ids = Table.api.selectedids(table);
var post_ids = [];
if (ids.length > 0) {
layer.confirm('确认要关联所选的'+ids.length+'项吗??', {title: "关联渠道"}, function (index) {
Layer.closeAll();
ids.forEach(function (v, k) {
if (Config.bindids.split(',').indexOf(v) == -1) {
post_ids.push(v);
}
});
if (post_ids.length > 0) {
$.ajax({
url: '/admin/exclusive/batch_bind_books',
type: "post",
data: {
eid: Config.ids,
ids: post_ids
},
success: function (datas) {
Toastr.success('操作成功!');
setTimeout(function () {
window.location.reload();
}, 1000);
}
});
} else {
Toastr.error('选择的项已关联');
}
});
} else {
Toastr.error('请选择要关联的选项');
}
});
//全部关联
$('.btn-all-bind').on('click',function () {
if(mtotal>0){
layer.confirm('确认要关联所有项吗??', {title: "关联渠道"}, function (index) {
Layer.closeAll();
$.ajax({
url:'/admin/exclusive/bind_all_books',
type:"post",
data: {
ids:Config.ids
},
success:function(datas){
Toastr.success('操作成功!');
setTimeout(function() {
window.location.reload();
},1000);
}
});
});
}else{
Toastr.error('无关联项!');
setTimeout(function() {
window.location.reload();
},1000);
}
});
Controller.api.bindevent();
},
showbooks: function (){
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'exclusive/showbooks/ids/'+Config.ids,
}
});
var table = $("#unbind-books-table");
var mtotal = 0;
table.on('load-success.bs.table', function (e, data) {
//这里可以获取从服务端获取的JSON数据
mtotal = data.total;
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
search: false,
columns: [
[
{checkbox: true},
{field: 'id', title: '书籍ID'},
{field: 'name', title: __('书籍名称'), operate:'LIKE'},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function(value, row){
var content = '';
content += '取消关联 ';
return content;
}}
]
]
});
//单项取关
$(document).on('click','.btn-single-edit',function () {
var rowid = $(this).data('row-id');
layer.confirm('确认要取关所选的1项吗??', {title: "取关渠道"}, function (index) {
Layer.closeAll();
$.ajax({
url:'/admin/exclusive/batch_unbind_books',
type:"post",
data: {
eid:Config.ids,
ids:{rowid}
},
success:function(datas){
Toastr.success('操作成功!');
setTimeout(function() {
window.location.reload();
},1000);
}
});
});
});
//批量取关
$('.btn-batch-unbind').on('click',function () {
var ids = Table.api.selectedids(table);
if(ids.length>0){
layer.confirm('确认要取关所选的'+ids.length+'项吗??', {title: "取关渠道"}, function (index) {
Layer.closeAll();
$.ajax({
url:'/admin/exclusive/batch_unbind_books',
type:"post",
data: {
eid:Config.ids,
ids:ids
},
success:function(datas){
Toastr.success('操作成功!');
setTimeout(function() {
window.location.reload();
},1000);
}
});
});
}else{
Toastr.error('请选择要关联的选项');
}
});
//全部取关
$('.btn-all-unbind').on('click',function () {
if(mtotal>0){
layer.confirm('确认要取关所有项吗??', {title: "取关渠道"}, function (index) {
Layer.closeAll();
$.ajax({
url:'/admin/exclusive/unbind_all_books',
type:"post",
data: {
ids:Config.ids
},
success:function(datas){
Toastr.success('操作成功!');
table.bootstrapTable('refresh');
}
});
});
}else{
Toastr.error('无关联项!');
setTimeout(function() {
window.location.reload();
},1000);
}
});
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});