define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'selectpage', 'gridify', 'custommain'], function ($, undefined, Backend, Table, Form, Template, Selectpage, Gridify, Custommain) { function excludeSpecial(s) { s = s.replace(/[\\\/\b\f\n\r\t\'\[\]\@\#\$\%\^\&\*\{\}\:\"\L\<\>\?]/g,''); return s; }; $(document).on('keyup','#description, #description-book, #description-activity, #description-recent',function () { var descrp = $(this).val(); $(this).val(excludeSpecial(descrp)); }); var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'vipcustom/vipimagetextmedia/index?table=' + Config.table + '&table_status=' + Config.table_status, }, searchFormVisible: true, search: false }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', clickToSelect: false, pageSize: 12, //每页的记录行数(*) pageList: [12, 36, 72, 120], //可供选择的每页的行数(*) columns: [Controller.api.showFilterColumns(table)], onLoadSuccess: function () { //加载成功时执行 }, onPostBody: function () { $('#table td').attr('rowspan', '1000'); var ooptions = { srcNode: 'tr', // grid items (class, node) margin: '0', // margin in pixel, default: 0px width: '296px', // grid item width in pixel, default: 220px max_width: '', // dynamic gird item width if specified, (pixel) resizable: true, // re-layout if window resize transition: 'all 0.5s ease' // support transition for CSS3, default: all 0.5s ease } $('#table').gridify(ooptions); } }); // 为表格绑定事件 Table.api.bindevent(table); //tooltip $(document).on('mouseover', '#table td', function () { $('.wxb-card-list-scroll .anticon').tooltip(); $('[rel="popover"]').popover({ trigger: 'manual', placement: 'top', html: true, content: function () { var ids = $(this).data('rowid'); /*jshint multistr: true*/ return '
\ 群发服务号\ 群发订阅号\
'; } }).on("mouseenter", function () { var _this = this; $(this).popover("show"); $(this).siblings(".popover").on("mouseleave", function () { $(_this).popover('hide'); }); }).on("mouseleave", function () { var _this = this; setTimeout(function () { if (!$(".popover:hover").length) { $(_this).popover("hide"); } }, 100); }); }); //群发消息 $(document).on('click', '.btn-multi-ajax', function () { var stxt = $(this).text(); var multi_url = $(this).attr('data-href'); Fast.api.open(multi_url, stxt, { callback: function (data) { if(!data) return false; var data = data[0]; console.log(data); } }); }); //删除 $(document).on('click', '.btn-del-ajax', function () { var del_url = $(this).attr('data-href'); layer.confirm("确定删除此项?", { icon: 3, title: "温馨提示", shadeClose: true }, function (index) { layer.close(index); $.get(del_url, {}, function (data) { if (data.code) { var msg = data.msg != '' ? data.msg : '操作成功'; Toastr.success(msg); table.bootstrapTable('refresh'); } else { var msg = data.msg != '' ? data.msg : '操作失败'; Toastr.error(msg); } }); }, function () { layer.close(); }); }); // 打开详情页面 $(document).on('click', '.btn-view-ajax', function () { Fast.api.open($(this).attr('data-href'), '查看详情', {}); }); //消息图文素材库列表tit $(document).on('click', '.anticon-title-edit', function () { var $this = $(this); var sid = $this.data('id'); var nindex = $this.parents('li').index(); var stit = $this.parents('li').find('.article-item-title').text(); layer.open({ type: 1, title: false, maxmin: false, zIndex:1800, area: ['auto', 'auto'], btn: ['确认', '取消'], shadeClose: true, resize: false, skin: 'layui-layer-rim', content: '
\
\ 当前标题:\

' + stit + '

\ \
\
\ 修改为:\
\
\
', yes: function (index, layero) { var stit = $(layero.selector + ' p').text(); var sinputtit = $(layero.selector + ' input').val(); if (sinputtit) { stit = sinputtit; } //sid 列表id stit 修改的标题内容 // 修改Title $.ajax({ type: 'get', url: './vipcustom/vipimagetextmedia/edittitle?ids=' + sid + '&title=' + stit + '&index=' + nindex, success: function (data) { console.log(data); $this.parents('li').find('.article-item-title').text(data.data); } }) layer.close(index); }, btn2: function (index, node) { layer.close(index) } }); }); //修改封面 $(document).on('click', '.anticon-cover-edit', function () { var $this = $(this); var sid = $this.data('id'); var nindex = $this.parents('li').index(); var stit = $this.parents('li').find('.article-item-cover'); Fast.api.open('manage/cover/select', '选择', { callback: function (data) { // console.log('展示image回调', data); //sid 列表id image 修改封面image $.ajax({ type: 'get', url: './vipcustom/vipimagetextmedia/editcover?ids=' + sid + '&cover=' + data.image + '&index=' + nindex, success: function (data) { $this.parents('li').find('.article-item-cover').css('background-image', 'url(' + data.data + ')'); } }) } }); }); //修改图文内容 $(document).on('click', '.anticon-novel-edit', function () { var $this = $(this); var nIndex = $this.parents('li').index(); var sid = $this.data('id'); $.ajax({ type: 'get', url: 'vipcustom/vipimagetextmedia/getMediaMessage?ids=' + sid + '&index=' + nIndex, success: function (data) { if (!data.code) { Fast.api.open('vipcustom/vipimagetextmedia/editimagetext?ids=' + sid + '&index=' + nIndex + '&json=' + encodeURIComponent(data.data), '修改内容', { callback: function (data) { var data = data; $.ajax({ type: 'get', url: 'vipcustom/vipimagetextmedia/editLink?ids=' + sid + '&index=' + nIndex + '&message_json=' + encodeURIComponent(JSON.stringify(data)), success: function (data) { if (data.code == 0) { Toastr.success('成功'); } else { Toastr.error('失败'); } } }) } }); } } }) }); require(['vue', 'component', 'ELEMENT'], function (Vue, component, ELEMENT) { Vue.use(ELEMENT); Vue.use(component); var Main = { el: '#title-select', methods: { select: function (value) { $('.anticon_edit_input_tit').find('input').val(value); } } }; new Vue(Main) }); }, //编辑图文消息 editimagetext: function () { Controller.api.bindevent(); var spage = $('#c-book_book_name').val(); var sbl = true; var selectdata = ''; $('#c-book_book_name').selectPage({ eAjaxSuccess: function (d) { if (selectdata && JSON.stringify(selectdata) != JSON.stringify(d)) { $('#select_book_id').val(''); } selectdata = d; return d ? d : ''; }, eSelect: function (d) { selectdata = ''; $('#c-book_book_name').val(d.name); $('#select_book_id').val(d.id); $('#select_book_id').attr('data-sex_text', d.sex_text); $("#description-book").val(d.description); Custommain.get_channel_book_name(); }, eClear: function () { $('#select_book_id').val(''); } }); if(Config.bnotin.length>0){ $.each(Config.bnotin,function (index,value) { if($('#select_book_id').val().indexOf(value)!=-1){ $('#select_book_id').val(''); $('#c-book_book_name').val(''); $('#c-book_book_name_text').val(''); $('#description-book').val(''); return false; } }); } $(document).on('click','#c-mini_type',function () { $(this).change(function(){ var value = $(this).find('input:checked').val(); console.log(value); switch (value) { case "3": $('.mini-type3').show() break; case "4": $('.mini-type3').hide() break; } }) }) require(['upload'], function (Upload) { var data = {}; data.width=1080; data.height = 864; Upload.api.plupload(".mini_plupload", function (data, ret) { $('.mini-card').find('.img_card img').attr('src',data.url); $('.mini-image').val(data.url); $('.mini-card').find('.inner').hide(); $('.mini-card').find('.img_card').show(); }); }); }, //图文客服消息 群发 订阅号 服务号 multisendmessage: function () { //发送 订阅号/服务号 验证 $("#add-form").data("validator-options", { ignore: ':hidden', beforeSubmit: function (form) { var user_json = $.parseJSON($('.img_txt_hidde_input_no').val()) if (user_json.all==0 && !user_json.subscribe_time) { var sub_from = (new Moment($('input[name="row[sub_from]"]').val())).valueOf() / 1000 var sub_to = (new Moment($('input[name="row[sub_to]"]').val())).valueOf() / 1000 if(!sub_from && !sub_to){ Toastr.error("起止时间不能为空"); return false; }else{ user_json.subscribe_range = sub_from +'-'+ sub_to; } } $('.img_txt_hidde_input_no').val(JSON.stringify(user_json)); var senddyhradioval = $('#dyhradio input').val(); if ($(":checkbox[name^='row[sub_id]']", $("#add-form")).length) { if (!$('#c-name').val()) { Toastr.error("请选择需要发送的服务号"); return false; } var other_tips = $(":checked[name^='row[sub_id]']", $("#add-form")); if (other_tips.length <= 0) { Toastr.error("请选择需要发送的订阅号"); return false; } if (senddyhradioval < other_tips.length) { Toastr.error("最多可选择发送" + senddyhradioval + '个订阅号'); return false; } } if (!$('.js_selected_group_id').val()) { if ($(":checkbox[name^='row[service_id]']", $("#add-form")).length) { var other_tips = $(":checked[name^='row[service_id]']", $("#add-form")); if (other_tips.length <= 0) { Toastr.error("请选择需要发送的服务号"); return false; } if (senddyhradioval < other_tips.length) { Toastr.error("最多可选择发送" + senddyhradioval + '个服务号'); return false; } } } //发送时间必须大于当前时间 var sdatatime=$('#c-sendtime').val()+''; sdatatime = sdatatime.replace(/-/g,'/'); sdatatime =new Date(sdatatime).getTime(); if(sdatatime <= new Date().getTime()){ Toastr.error("发送时间必须大于当前时间"); return false; } } }); Controller.api.bindevent(); }, //查看详情 viewdetail: function () { // 初始化表格参数配置 Table.api.init({ extend: { getimage_url: window.location.href, }, search: false, showToggle: false, showColumns: false, showExport: false, commonSearch: false }); var table = $("#table"); //当表格数据加载完成时 table.on('load-success.bs.table', function (e, data) { //这里可以获取从服务端获取的JSON数据 //console.log(data); //这里我们手动设置底部的值 //$("#money").text(data.extend.money); //$("#price").text(data.extend.price); }); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.getimage_url, pk: 'id', sortName: 'id', columns: [Controller.api.getimagelist(table)] }); // 为表格绑定事件 Table.api.bindevent(table); }, api: { showFilterColumns: function (table) { var cols = new Array(); cols.push({ field: 'id', title: "素材ID", visible: false }); cols.push({ field: 'message_json$[*].book_name', title: "书籍名称", visible: false, operate: 'LIKE %...%' }); cols.push({ field: 'id', operate: false, formatter: Controller.api.formatter.showStyle }); return cols; }, getimagelist: function (table) { var cols = new Array(); cols.push({ field: 'title', title: "标题", operate: false }); cols.push({ field: 'image', title: "图片", operate: false, formatter: Controller.api.formatter.showImage }); /* cols.push({ field: 'push', title: "推广类型", operate: false, formatter: Controller.api.formatter.showPushType });*/ cols.push({ field: 'type', title: "链接类型", operate: false, formatter: Controller.api.formatter.showType }); cols.push({ field: 'book_id', title: "书籍ID", operate: false }); cols.push({ field: 'book_name', title: "书籍名称/活动名称/菜单名称", operate: false }); /* cols.push({ field: '', title: "推广位置", operate: false, formatter: Controller.api.formatter.showPosition });*/ //cols.push({field: 'book_id', title:"阅读原文连接"}); return cols; }, bindevent: function () { $('#c-menu_menu_id,#c-activity_activity_id').change(function(){ Custommain.get_channel_other_name(); }); $(document).on('click', "input[name='book[push]']", function () { var type = $(this).val(); $('.group-push').addClass('hide'); $('.group-push input').attr('disabled'); $('#group-push-' + type).removeClass('hide'); $('#group-push-' + type + ' input').removeAttr('disabled'); Custommain.get_channel_book_name(); }); Custommain.checkbox_relation('#dyhradio', '#dyhcheck'); //推广链接类型id var simgtexttype = $('input[name="row[imgtxt_type]"]:checked').val(); var oshowfrombox = $('#group-type-0 input[type="hidden"]'); Custommain.bind_form_validation(); Form.api.bindevent($("form[role=form]"), function (data) { if (data.jump) { window.location.href = data.jump; } else { Fast.api.close(data); } }, function (data) { console.log('TODO:这里需要处理。。。'); console.log('error', data); } ); if ($('#usercondition').val() && $('#usercondition').val().length > 0) { $tagval = JSON.parse($('#usercondition').val()); if ($tagval.all == 1) { //选择所有用户 $('#type-all').attr('checked', true); var type = 'all'; $('.group-tag-type').addClass('hide'); $('.group-tag-type input').attr('disabled'); $('#group-tag-type-' + type).removeClass('hide'); $('#group-tag-type-' + type + ' input').removeAttr('disabled'); } } $.ajax({ type: 'get', url: '/admin/custom/ajaxcategory', cache: false, async: false, success: function (res) { data = res.data; var htmlstr = ''; for (var i = 0; i < data.length; i++) { htmlstr += '' + data[i].name + ''; } $('#ctag').append(htmlstr); $('#mustbe').html('约' + res.ids + '人'); if ($('#usercondition').val() && $('#usercondition').val().length > 0) { $tagval = JSON.parse($('#usercondition').val()); $("#sex span[data-sex='" + $tagval.sex + "']").addClass('s_s_tag').siblings().removeClass('s_s_tag'); $("#ctag span[data-cid='" + $tagval.tag + "']").addClass('s_s_tag').siblings().removeClass('s_s_tag'); $("#consume span[data-fee='" + $tagval.consume + "']").addClass('s_s_tag').siblings().removeClass('s_s_tag'); $("#kandian span[data-kandian='" + $tagval.kandian + "']").addClass('s_s_tag').siblings().removeClass('s_s_tag'); // $("#subTime span[data-week='" + $tagval.subscribe_time + "']").addClass('s_s_tag').siblings().removeClass('s_s_tag'); // if ($tagval.subscribe_range) { // var t_l = $tagval.subscribe_range.split('-'); // $('input[name="row[sub_from]"]').val(Moment(parseInt(t_l[0]) * 1000).format("YYYY-MM-DD HH:mm:ss")); // $('input[name="row[sub_to]"]').val(Moment(parseInt(t_l[1]) * 1000).format("YYYY-MM-DD HH:mm:ss")); // } $('#subscribe_time2').hide(); if ($tagval.subscribe_time) { $("#subscribe_time1 span[data-fee='" + $tagval.subscribe_time + "']").addClass('s_s_tag').siblings().removeClass('s_s_tag'); $('#subscribe_time2').hide(); } else { $("#subscribe_time1 span").last().addClass('s_s_tag').siblings().removeClass('s_s_tag'); } } else { var tagObj1 = { sex: -1, mobile_system: 0, tag: -1, consume: -1, kandian: -1, subscribe_time: -1, subscribe_range:-1, all: "0" }; var ucon1 = JSON.stringify(tagObj1); $('#usercondition').val(ucon1); } }, error: function (err) { } }); $(document).on('click', '.s_tag_li_list span', function () { var $this = $(this); $this.addClass('s_s_tag').siblings('span').removeClass('s_s_tag'); var tagObj = { sex: $('#sex span.s_s_tag').data('sex'), mobile_system: $('#mobile_system span.s_s_tag').data('mobile_system'), tag: $('#ctag span.s_s_tag').data('cid'), consume: $('#consume span.s_s_tag').data('fee'), kandian: $('#kandian span.s_s_tag').data('kandian'), subscribe_time: $('#subscribe_time1 span.s_s_tag').data('fee'), all: "0" } if ($(this).parent().attr('id') == 'subscribe_time1') { if ($(this).data('fee')) { $('#cdstarttime').val(''); $('#cdendtime').val(''); $('#subscribe_time2').hide(); } else { $('#subscribe_time2').show(); } } var uconditon = JSON.stringify(tagObj); $('#usercondition').val(uconditon); }); //测试发送 $('.test_fans_but').click(function(){ Custommain.fans_send_message(); }); /** * 资源类型管理 */ $(document).on('click', "input[name='row[type]']", function () { var type = $(this).val(); if (type=='all'){ var tagObj = { all:"1" } }else{ var tagObj ={ sex:-1, mobile_system: 0, tag:-1, consume:-1, kandian: -1, subscribe_time:-1, all:"0" } } var ucon = JSON.stringify(tagObj); $('#usercondition').val(ucon); $('.group-tag-type').addClass('hide'); $('.group-tag-type input').attr('disabled'); $('#group-tag-type-' + type).removeClass('hide'); $('#group-tag-type-' + type+' input').removeAttr('disabled'); }); //切换推广链接类型 $(document).on('click', "input[name='row[imgtxt_type]']", function () { var type = $(this).val(); $('.group-type').addClass('hide'); $('.group-type input').attr('disabled'); $('#group-type-' + type).removeClass('hide'); $('#group-type-' + type + ' input').removeAttr('disabled'); oshowfrombox = $('#group-type-' + type + ' input[type="hidden"]'); simgtexttype = type; if(type == 0){ Custommain.get_channel_book_name(); }else{ Custommain.get_channel_other_name(); } }); //修改发送消息时间 $(document).on('click', '.s_time_box span', function () { var $this = $(this); var nval = parseInt($this.attr('stime')); var ntime = Date.parse(new Date()); var nt = ntime + nval; $('#c-sendtime').val(GetRTime(nt)); }); function GetRTime(time) { var stime; time = new Date(time); var year = time.getYear() + 1900; var month = time.getMonth() + 1; var day = time.getDate(); var hours = time.getHours(); var minutes = time.getMinutes(); var seconds = time.getSeconds(); stime = year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day) + ' ' + (hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes) + ':' + (seconds < 10 ? '0' + seconds : seconds); return stime; } $(document).on('click', '.btn-close', function () { Fast.api.close(); }); }, formatter: { showImage: function (value, row, index) { return ''; }, showType: function (value, row, index) { var type_arr = ['书籍', '活动', '继续阅读', '菜单']; return type_arr[value]; }, showPosition: function (value, row, index) { return index + 1; }, showPushType: function (value, row, index) { var push_arr = ['外推', '内推']; return push_arr[value]; }, showStyle: function (value, row, index) { var message_data = JSON.parse(row.message_json).shift(); /*jshint multistr: true */ var html = '
'; html += '

素材id:' + row.id + '

'; html += '

创建时间:' + Table.api.formatter.datetime(row.createtime, row, index) + '

'; html += '

修改时间:' + Table.api.formatter.datetime(row.updatetime, row, index) + '

'; var offical_type = parseInt(row.official_account_type) == 1 ? '订阅号' : '服务号'; /*var send_color = ''; var send_text = ''; switch (parseInt(row.status)) { case 0: send_color = 'red'; send_text = '待发送'; break; case 1: send_color = '#FF9900'; send_text = '群发中'; break; case 2: send_color = '#88d743'; send_text = '已群发'; break; } html += '

发送时间:' + Table.api.formatter.datetime(row.sendtime, row, index) + ' ' + send_text + '

'; html += '

群发类型:' + offical_type + '

'; */ html += '
'; return html; } } } }; return Controller; });