123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- 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 || data[i]['type'] == 3) {
- ssut = data[i]['book']['title'] ? data[i]['book']['title']:data[i]['book']['name'];
- }
- if (sids.indexOf(',' + data[i]['id'] + ',') < 0) {
- var sLi = '<div class="img_txt_one img_txt_main" url_id="' + data[i]['id'] + '">\
- <i class="fa fa-trash img_txt_edit_tit" title="删除"></i>\
- <div class="img_txt_one_tit">\
- <div class="img_txt_one_h3"><p>' + ssut + '</p></div>\
- <a href="javascript:;">' + data[i]["short_url_" + getListType()] + '</a>\
- </div>\
- </div>';
- $('#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() + '<br><br>';
- 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() + '<br>';
- stxt += '<a href="' + $li.eq(i).find('a').text() + '">' + $li.eq(i).find('a').text() + '</a><br>';
- }
- $('#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 || value[i].type == 3) {
- str = value[i].book.name;
- } else {
- str = '书城首页';
- }
- html.push(str);
- }
- return html.join('<br>');
- },
- referral_title: function (value, row, index) {
- var html = [];
- var str = '';
- value = row.referral_list;
- for (i in value) {
- if (value[i].type == 1 || value[i].type == 3) {
- 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('<br>');
- },
- referral_list: function (value, row, index) {
- var html = [];
- var str = '';
- for (i in value) {
- // if (value[i].type == 1) {
- // str = '<i style="color: blue;">'+value[i].book.name+'</i>';
- // if(value[i].book.title){
- // str = str + ' ' + value[i].book.title;
- // }
- // } else {
- // str = '书城首页';
- // }
- if(Config.open_wechat_share == 1){
- str = value[i].skin_url;
- }else{
- 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('<br>');
- },
- push_json: function (value, row, index) {
- if (!value) {
- return '无';
- }
- var html = [];
- for (i in value) {
- html.push((html.length ? '<br>' : '') + '时间: ' + 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('<br>');
- },
- copy: function (value, row, index) {
- var html = [];
- html.push(row.title);
- html.push('<br>');
- for (i in row.referral_list) {
- if (row.referral_list[i].type == 1 || row.referral_list[i].type == 3) {
- html.push(row.referral_list[i].book.title ? row.referral_list[i].book.title : row.referral_list[i].book.name);
- } else {
- html.push('书城首页');
- }
- if(Config.open_wechat_share == 1){
- html.push('<a href="' + ( row.referral_list[i].skin_url) + '">' + ( row.referral_list[i].skin_url) + '</a>');
- }else {
- html.push('<a href="' + (row.short_url_type == 1 ? row.referral_list[i].short_url_qq : row.referral_list[i].short_url_weibo) + '">' + (row.short_url_type == 1 ? row.referral_list[i].short_url_qq : row.referral_list[i].short_url_weibo) + '</a>');
- }
- }
- return '<a href="javascript:;" class="btn btn-xs btn-primary many_index_copy" title="复制链接列表" data-copy-html="' + encodeURIComponent(html.join('<br>')) + '"><i class="fa fa-copy"></i> 复制</a>';
- },
- push: function (value, row, index) {
- html = [];
- html.push('<a href="/admin/referral/many/push?id=' + row.id + '" class="layer-open btn btn-xs btn-warning" data-toggle="tooltip" title="推送给代理">推送</a>');
- return html.join(' ');
- }
- }
- };
- return Controller;
- });
|