define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'clipboard'], function ($, undefined, Backend, Table, Form, Clipboard) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'referral/many/index', add_url: 'referral/many/add', edit_url: 'referral/many/edit', del_url: 'referral/many/del', multi_url: 'referral/many/multi', push_url: 'referral/many/push', table: 'referral_many', }, showColumns:false, showToggle:false, showExport:true, searchFormVisible: true, search:false, }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, {field: 'admin_id', title: __('Admin_id'), visible: false, operate: false}, {field: 'title', title: __('Title'),operate: 'LIKE %...%'}, {field: 'referral_book_name', title: '书籍名称', formatter: Controller.api.referral_book_name, operate: false}, {field: 'referral_title', title: '推广标题列表', formatter: Controller.api.referral_title, operate: false}, {field: 'referral_list', title: '链接列表', formatter: Controller.api.referral_list, operate: false}, {field: 'referral_ids', title: __('Referral_ids'), visible: false, operate: false}, { field: 'short_url_type', title: __('Short_url_type'), visible: false, searchList: { "short_url_type 1": __('Short_url_type 1'), "short_url_type 2": __('Short_url_type 2') }, operate: false }, {field: 'short_url_type_text', title: __('Short_url_type'), operate: false}, {field: 'push_json', title: __('Push_json'), formatter: Controller.api.push_json, operate: false}, { field: 'state', title: __('State'), visible: false, searchList: {"state 0": __('State 0'), "state 1": __('State 1')}, operate: false }, {field: 'state_text', title: __('State'), operate: false}, { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime }, { field: 'updatetime', title: __('Updatetime'), visible: false, operate: false, addclass: 'datetimerange', formatter: Table.api.formatter.datetime }, { field: 'copy', title: '复制', formatter: Controller.api.copy, operate: false }, { field: 'push', title: '推送', visible: (Config.group == 3), formatter: Controller.api.push, operate: false }, { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate } ] ], exportOptions: { type: 'excel', fileName:'推广链接多条', ignoreColumn: [0,1,10,11,12], onMsoNumberFormat: function(cell, row, col) { return (row > 0 && col == 1) ? '\\@' : ''; }} }); // 为表格绑定事件 Table.api.bindevent(table); var clipboard = new Clipboard('.many_index_copy', { target: function (trigger) { var stxt = trigger.getAttribute('data-copy-html'); trigger = document.querySelector('#many_copy_dom'); $('#many_copy_dom').html(decodeURIComponent(stxt)); return trigger; } }); clipboard.on('success',function (data) { Toastr.success('复制成功'); }).on('error',function (data) { Toastr.error('复制失败'); }); // 弹窗绑定 $(document).on('click','.layer-open',function () { Fast.api.open($(this).attr('href'), $(this).attr('title'), {}); return false; }) }, add: function () { Controller.api.bindevent(); }, edit: function () { Controller.api.bindevent(); }, push: function () { Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); //弹出选择 $(document).on('click', '.img_txt_add_but', function () { Fast.api.open('referral/referral/select', '选择', { callback: function (data) { var sVal = $('#group-type-' + getListType() + ' input').val(); var sid = sVal; var sids = ',' + sVal; for (var i = 0; i < data.length; i++) { var ssut = '书城首页'; if (data[i]['type'] == 1) { ssut = data[i]['book']['title'] ? data[i]['book']['title']:data[i]['book']['name']; } if (sids.indexOf(',' + data[i]['id'] + ',') < 0) { var sLi = '
\ \
\

' + ssut + '

\ ' + data[i]["short_url_" + getListType()] + '\
\
'; $('#group-type-' + getListType() + ' .img_txt_list').append($(sLi)); sid += data[i]['id'] + ','; } } $('#group-type-' + getListType() + ' input').val(sid); } }); }); /** * 获取当前选中的类型 */ function getListType() { if ($("#add-form")[0]['row[short_url_type]'].value == 1) { return 'qq'; } else { return 'weibo'; } } /** * 资源类型管理 */ $(document).on('click', "input[name='row[short_url_type]']", function () { var type = $(this).attr('sval'); $('.group-type').addClass('hide'); $('.group-type input').attr('disabled', ''); $('#group-type-' + type).removeClass('hide'); $('#group-type-' + type + ' input').removeAttr('disabled'); }); //删除短链接 $(document).on('click', '.img_txt_main i', function () { var $this = $(this); var sId = $this.parent().attr('url_id') + ','; var sval = $('#group-type-' + getListType() + ' input').val(); sval = sval.replace(sId, ''); $this.parent().remove(); $('#group-type-' + getListType() + ' input').val(sval); }); var clipboard = new Clipboard('.many_copy', { target: function(trigger) { trigger = document.querySelector('#many_copy_dom'); var stit = $('#title').val() + '

'; var $li = $('#group-type-' + getListType() + ' .img_txt_list .img_txt_one'); var stxt = stit; if ($('#title').val().length <= 0) { Toastr.error('标题不能为空'); return trigger; } if ($li.length <= 0) { Toastr.error('请添加推广短链接'); return trigger; } for (var i = 0; i < $li.length; i++) { stxt += $li.eq(i).find('p').text() + '
'; stxt += '' + $li.eq(i).find('a').text() + '
'; } $('#many_copy_dom').html(stxt); Toastr.success('复制成功'); return trigger; } }); clipboard.on('error',function (data) { Toastr.error('复制失败'); }) }, referral_book_name: function (value, row, index) { var html = []; var str = ''; value = row.referral_list; for (i in value) { if (value[i].type == 1) { str = value[i].book.name; } else { str = '书城首页'; } html.push(str); } return html.join('
'); }, referral_title: function (value, row, index) { var html = []; var str = ''; value = row.referral_list; for (i in value) { if (value[i].type == 1) { str = value[i].book.title?value[i].book.title:value[i].book.name; str = str.substr(0,12); } else { str = '书城首页'; } html.push(str); } return html.join('
'); }, referral_list: function (value, row, index) { var html = []; var str = ''; for (i in value) { // if (value[i].type == 1) { // str = ''+value[i].book.name+''; // if(value[i].book.title){ // str = str + ' ' + value[i].book.title; // } // } else { // str = '书城首页'; // } if (row.short_url_type == 1) { // str = str + '  ' + value[i].short_url_qq; str = value[i].short_url_qq; } else { // str = str + '  ' + value[i].short_url_weibo; str = value[i].short_url_weibo; } html.push(str); } return html.join('
'); }, push_json: function (value, row, index) { if (!value) { return '无'; } var html = []; for (i in value) { html.push((html.length ? '
' : '') + '时间: ' + value[i].time); str = '推送代理: '; agentNames = []; for (n in value[i].agent_list) { agentNames.push(value[i].agent_list[n].nickname); } str = str + agentNames.join('、'); html.push(str); } return html.join('
'); }, copy: function (value, row, index) { var html = []; html.push(row.title); html.push('
'); for (i in row.referral_list) { if (row.referral_list[i].type == 1) { html.push(row.referral_list[i].book.title ? row.referral_list[i].book.title : row.referral_list[i].book.name); } else { html.push('书城首页'); } html.push('' + (row.short_url_type == 1 ? row.referral_list[i].short_url_qq : row.referral_list[i].short_url_weibo) + ''); } return ' 复制'; }, push: function (value, row, index) { html = []; html.push('推送'); return html.join('  '); } } }; return Controller; });