123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'cp/vip/manage/index',
- add_url: 'cp/vip/manage/add',
- //edit_url: 'cp/vip/manage/edit',
- del_url: 'cp/vip/manage/del',
- multi_url: 'cp/vip/manage/multi',
- manage_url: 'cp/vip/manage/bookcplist',
- table: 'cp_vip_list',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id'), operate: false},
- {field: 'book_id', title: __('Book_id')},
- {field: 'name', title: __('书籍名称'), operate:'like'},
- {field: 'cp_name', title: __('Cp_name')},
- {
- field: 'createtime',
- title: __('Createtime'),
- operate: false,
- formatter: Table.api.formatter.datetime
- },
- {
- field: 'operate',
- title: __('Operate'),
- table: table,
- events: Table.api.events.operate,
- formatter: Table.api.formatter.operate
- }
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- // btn-add-cp
- $(document).on('click', ".btn-add-cp", function () {
- Backend.api.open('cp/vip/manage/bookcplist' , __('Select'), {callback: function () {
- table.bootstrapTable('refresh');
- }});
- return false;
- });
- },
- bookcplist: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- manage_url: 'cp/vip/manage/bookcplist',
- }
- });
- var table = $("#book-cp-table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.manage_url,
- pk: 'id',
- sortName: 'id',
- search: false,
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Book_id')},
- {field: 'name', title: __('书籍名称'), operate:'like'},
- {field: 'cp_name', title: __('Cp_name')},
- {
- field: 'operate',
- title: __('Operate'),
- table: table,
- events: Table.api.events.operate,
- formatter: function (value, row, index) {
- var html = '';
- html += '<a href="javascript:void(0);" data-book_id ="' + row.id + '" data-cp_id = "' + row.cp_id + '" data-cpname="' + row.cp_name + '" class="btn btn-xs btn-success btn-danger add-cp-book">添加</a>';
- return html;
- }
- }
- ]
- ]
- });
- // 单个添加
- $(document).on('click', ".add-cp-book", function(){
- $.post(
- 'cp/vip/manage/ajaxsavedata',
- {
- 'row': {
- 'book_id': $(this).data('book_id'),
- 'cp_id': $(this).data('cp_id'),
- 'cp_name': $(this).data('cpname'),
- }
- },
- function (data) {
- if (data.code) {
- Toastr.success('添加成功');
- setTimeout( "Fast.api.close()", 1000 );
- } else {
- layer.error(data.message);
- }
- }
- );
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- //
- $('.btn-add-cp-batch').on('click',function () {
- var ids = Table.api.selectedids(table);
- Layer.confirm(
- '确定要添加选中的'+ids.length+'项么?',
- {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
- function () {
- $.ajax({
- url:'cp/vip/manage/ajaxbatchsave',
- type:"post",
- data: {
- ids:ids,
- },
- success:function(data){
- if(data.code == 0){
- Layer.msg(data.msg);
- return false;
- }else{
- layer.msg('操作成功');
- Fast.api.close();
- }
- }
- });
- }
- );
- });
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- },
- }
- };
- return Controller;
- });
|