define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template','gridify', 'selectpage', 'custommain'], function ($, undefined, Backend, Table, Form, Template,Gridify, Seletepage, 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/viplinktextmedia/index',
del_url:'vipcustom/viplinktextmedia/delsinglepiece',
},
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', '.anticon-delete', function () {
var $this = $(this);
var oLi = $this.parents('li');
var nIndex = $this.parents('li').index();
var sid = $this.data('id');
layer.confirm("确定删除此项?", {
icon: 3,
title: "温馨提示",
shadeClose: true
}, function (index) {
$.get($.fn.bootstrapTable.defaults.extend.del_url, {"ids":sid, "idx":nIndex}, function (data) {
if (data.code) {
var msg = data.msg != '' ? data.msg : '操作成功';
Toastr.success(msg);
} else {
var msg = data.msg != '' ? data.msg : '操作失败';
Toastr.error(msg);
}
layer.close(index);
table.bootstrapTable('refresh');
});
}, function () {
layer.close();
});
});
//删除文字链消息列表整列
$(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'), '查看详情', {});
});
//群发消息
$(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','.anticon-novel-edit',function(){
var $this=$(this);
var nIndex = $this.parents('li').index();
var sid = $this.data('id');
$.ajax({
type:'get',
url:'vipcustom/viplinktextmedia/getMediaMessage?ids='+ sid + '&idx='+ nIndex,
success:function(data){
if(!data.code){
Fast.api.open('vipcustom/viplinktextmedia/editlinktext?json=' + encodeURIComponent(data.data), '修改内容', {
callback: function (data) {
var data = data;
$.ajax({
type:'get',
url:'vipcustom/viplinktextmedia/editLink?idx='+ nIndex +'&ids='+ sid + '&message_json=' + encodeURIComponent(JSON.stringify(data)),
success:function(data){
if(data.code == 0){
Toastr.success('编辑成功');
}else{
Toastr.error('编辑失败');
}
}
})
}
});
}else{
Toastr.error('编辑失败');
}
}
})
});
},
//图文客服消息 群发 订阅号 服务号
multisendmessage:function(){
Controller.api.bindevent();
},
editlinktext: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;
}
});
}
Controller.api.eventTitle()
},
//查看详情
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: {
eventTitle: function () {
require(['vue', 'component', 'ELEMENT'], function (Vue, component, ELEMENT) {
Vue.use(ELEMENT);
Vue.use(component);
var Main = {
el: '#title-select',
methods: {
select: function (value) {
$('.group-type:visible').find('input').first().val(value)
}
}
};
new Vue(Main)
});
},
showFilterColumns: function (table) {
var cols = new Array();
cols.push({field: 'id', title: "素材ID", visible: false});
cols.push({field: 'message_text$[*].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: '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: 'push',
title: "推广类型",
operate: false,
formatter: Controller.api.formatter.showPushType
});*/
//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();
});
Custommain.checkbox_relation('#dyhradio', '#dyhcheck');
//推广链接类型id
var simgtexttype = $('input[name="row[imgtxt_type]"]:checked').val();
//资源管理
var ore={
arrma:[
{
'title':'',
'image':'',
'url':'http://'
}
],
imglis:[],
titlist:[],
sli:'',
pli:'\
\
\
sli_value
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
',
ptxtli:'\
sli_value
\
\
\
\
\
'
};
//图文切换为文字链
$(document).on('click','.switch_txt_but',function(){
layer.open({
type: 1,
title: '温馨提示',
maxmin: false,
area: ['300px', '200px'],
btn: ['确认', '取消'],
shadeClose: true,
resize: false,
// skin: 'layui-layer-rim',
content: '切换为文字链模式后将无法恢复为图文模式,确定切换吗?
',
yes: function (index, layero) {
var imgsval = $('.img_txt_hidden_input').val();
$('.textarea_txt_hidden_official_type').val('1');
$('#group-type-news').remove();
$('#group-type-news').show();
$('.textarea_txt_hidden_input').val(imgsval);
try{
imgsval = JSON.parse(imgsval);
txttext(imgsval);
}catch(e){
}
Toastr.success('切换成功');
layer.close(index);
},
btn2: function (index, node) {
layer.close(index)
}
});
})
//添加图文
$(document).on('click', '.img_txt_add_but', function () {
var $this = $(this);
Fast.api.open('custom/addimagetext', '添加图文', {
callback: function (data) {
console.log(data);
strImgtext = $('.img_txt_hidden_input').val();
var imgtext_data = [];
if (strImgtext.length > 0) {
imgtext_data = JSON.parse(strImgtext);
}
imgtext_data.push(data);
$('.img_txt_hidden_input').val(JSON.stringify(imgtext_data));
$('.textarea_txt_hidden_input').val(JSON.stringify(imgtext_data));
imagetext(imgtext_data);
txttext(imgtext_data);
$this.hide();
}
})
});
//渲染图文列表
function imagetext(data){
var lihtmls = '';
var sli = '';
for(var i=0; i';
$('.wxb-card-list-scroll').html(lihtmls);
//图文列表tip
$('.wxb-card-list-scroll .action-item i').tooltip();
}
//渲染文字列表
function txttext(data){
var lihtmls = '';
var sli = '';
for(var i=0; i';
$('#group-type-news .img_txt_list').html(lihtmls);
//图文列表tip
$('.img_txt_url i').tooltip();
}
//获取数组
function getimagetxtarr(val){
strImgtext = val;
var imgtext_data = [];
if (strImgtext.length > 0) {
try{
return JSON.parse(strImgtext);
}catch(err){
return '';
}
}
return '';
}
//数组上移下移
Array.prototype.swapItems = function(startindex,endindex){
this[startindex] = this.splice(endindex,1,this[startindex])[0];
return this;
}
//数组删除指定项
Array.prototype.removeItems = function(index){
this.splice(index,1);
return this;
}
//图文上移 下移
$('.wxb-card-list-scroll').on('click','.anticon-arrow-up,.anticon-arrow-down',function(){
var $this = $(this);
var nindex = $this.parents('li').index();
var arrimgtxt = getimagetxtarr($('.img_txt_hidden_input').val());
if(!arrimgtxt) return false;
if($this.hasClass('anticon-arrow-up')){
if(nindex == 0) return false;
arrimgtxt.swapItems(nindex,nindex-1);
}else{
if(nindex == arrimgtxt.length-1) return false;
arrimgtxt.swapItems(nindex,nindex+1);
}
$('.img_txt_hidden_input').val(JSON.stringify(arrimgtxt));
$('.textarea_txt_hidden_input').val(JSON.stringify(arrimgtxt));
imagetext(arrimgtxt);
});
//删除图文
$('.wxb-card-list-scroll').on('click','.anticon-delete',function(){
var $this = $(this);
layer.open({
type: 1,
title: '温馨提示',
maxmin: false,
area: ['260px', '160px'],
btn: ['确认', '取消'],
shadeClose: true,
resize: false,
// skin: 'layui-layer-rim',
content: '您确定删除此条信息?
',
yes: function (index, layero) {
var nindex = $this.parents('li').index();
var arrimgtxt = getimagetxtarr($('.img_txt_hidden_input').val());
if(!arrimgtxt) return false;
arrimgtxt.removeItems(nindex);
$('.img_txt_hidden_input').val(JSON.stringify(arrimgtxt));
$('.textarea_txt_hidden_input').val(JSON.stringify(arrimgtxt));
if(arrimgtxt.length == 0){
$('.wxb-card-list-scroll').html('');
$('.img_txt_add_but').show();
}else{
imagetext(arrimgtxt);
}
Toastr.success('删除成功');
layer.close(index);
},
btn2: function (index, node) {
layer.close(index)
}
});
});
//修改title
$(document).on('click','.anticon-title-edit',function(){
var $this=$(this);
var nIndex = $this.parents('li').index();
var stitle = $this.parents('li').find('p').text();
layer.open({
type: 1,
title: false,
maxmin: false,
area: ['auto', 'auto'],
btn: ['确认', '取消'],
shadeClose: true,
resize: false,
skin: 'layui-layer-rim',
content: '\
\
当前标题:\
' + stitle + '
\
\
\
\
',
yes: function (index, layero) {
var stit = $(layero.selector +' p').text();
var sinputtit = $(layero.selector +' input').val();
if(sinputtit){
stit = sinputtit;
}
editimglist('title',nIndex,stit);
layer.close(index);
},
btn2: function (index, node) {
layer.close(index)
}
});
});
//修改列表内容
function editimglist(name,item,val){
var strImgtext = JSON.parse($('.img_txt_hidden_input').val());
strImgtext[item][name] = val;
$('.img_txt_hidden_input').val(JSON.stringify(strImgtext));
$('.textarea_txt_hidden_input').val(JSON.stringify(strImgtext));
imagetext(strImgtext);
}
//修改title
$(document).on('click','.anticon_edit_select_tit_box a',function(){
var $this=$(this);
Fast.api.open('manage/title/select', '选择标题', {
callback: function (data) {
// console.log('展示title回调', data);
$this.siblings('p').text(data.title);
$this.parents('.anticon_edit_box').find('input').val(data.title);
}
});
});
//修改封面
$(document).on('click','.anticon-cover-edit',function(){
var $this=$(this);
var nIndex = $this.parents('li').index();
Fast.api.open('manage/cover/select', '选择', {
callback: function (data) {
// console.log('展示image回调', data);
editimglist('image',nIndex,data.image);
}
});
});
//修改文字内容
$(document).on('click','#group-type-news .anticon-novel-edit',function(){
var $this=$(this);
var nIndex = $this.parents('li').index();
var sjson = JSON.parse($('.textarea_txt_hidden_input').val());
Fast.api.open('custom/editlinktext?json=' + encodeURIComponent(JSON.stringify(sjson[nIndex])), '修改文字链接', {
callback: function (data) {
var data = data;
console.log('展示title回调', data);
var strImgtext = JSON.parse($('.textarea_txt_hidden_input').val());
strImgtext[nIndex] = data;
$('.textarea_txt_hidden_input').val(JSON.stringify(strImgtext));
txttext(strImgtext);
}
});
});
//删除文字列表
$('#group-type-news').on('click','.anticon-delete',function(){
var $this = $(this);
layer.open({
type: 1,
title: '温馨提示',
maxmin: false,
area: ['260px', '160px'],
btn: ['确认', '取消'],
shadeClose: true,
resize: false,
// skin: 'layui-layer-rim',
content: '您确定删除此条信息?
',
yes: function (index, layero) {
var nindex = $this.parents('li').index();
var arrimgtxt = getimagetxtarr($('.textarea_txt_hidden_input').val());
if(!arrimgtxt) return false;
arrimgtxt.removeItems(nindex);
$('.textarea_txt_hidden_input').val(JSON.stringify(arrimgtxt));
if(arrimgtxt.length == 0){
$('.img_txt_list').html('');
}else{
txttext(arrimgtxt);
}
Toastr.success('删除成功');
layer.close(index);
},
btn2: function (index, node) {
layer.close(index)
}
});
});
Custommain.bind_form_validation();
/**
* form表单验证
*/
// $("form[role=form]").data("validator-options", {
$("#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 (!$('.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;
}
sList = JSON.stringify(ore.arrma);
$('.img_txt_hidde_input').val(sList);
// console.log('验证');
// return false;
}
});
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);
}
);
/**
* 资源类型管理
*/
$(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');
var 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', "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();
});
/**
* 插入链接
*/
$(document).on('click', ".btn-insertlink", function () {
var textarea = $("textarea[name='row[content]']");
var cursorPos = textarea.prop('selectionStart');
var v = textarea.val();
var textBefore = v.substring(0, cursorPos);
var textAfter = v.substring(cursorPos, v.length);
Layer.prompt({title: '请输入显示的文字', formType: 3}, function (text, index) {
Layer.close(index);
Layer.prompt({title: '请输入跳转的链接URL(包含http/https)', formType: 3}, function (link, index) {
text = text == '' ? link : text;
textarea.val(textBefore + '' + text + '' + textAfter);
Layer.close(index);
});
});
});
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[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"));
// }
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){
}
});
$.ajax({
type:'get',
url:'/admin/manage/cover/ajax?sort=id&order=desc&offset=0&limit=10&filter={"status":"normal"}',
cache:false,
async:false,
success:function(data){
// console.log(data)
ore.imglis = data.rows;
},
error:function(err){
}
});
$.ajax({
type:'get',
url:'/admin/manage/title/ajax?sort=id&order=desc&offset=0&limit=10&filter={"status":"normal"}',
cache:false,
async:false,
success:function(data){
console.log(data)
// ore.titlist = data.rows;
// ore.arrma[0]['image'] = ore.imglis[parseInt(Math.random()*ore.imglis.length)]['image'];
// ore.arrma[0]['title'] = ore.titlist[parseInt(Math.random()*ore.titlist.length)]['title'];
//
// console.log($('.img_txt_hidde_input').val());
// if ($('.img_txt_hidde_input').val() && $('.img_txt_hidde_input').val().length > 0) {
// ore.arrma = JSON.parse($('.img_txt_hidde_input').val());
// for(var i=0; i\
// \
//
\
//
\
//
\
//
\
//
\
//
\
//
\
//
\
//
\
// \
// ');
// }else{
// var sLiImg=ore.sli.replace(/sli_img/g,ore.arrma[i]['image']);
// sLiImg=sLiImg.replace(/sli_value/g,ore.arrma[i]['title']);
// sLiImg=sLiImg.replace(/click_url/g,ore.arrma[i]['url']);
// $('.img_txt_list').append(sLiImg);
// }
// }
// }else{
// $('.img_txt_list').html('\
//
\
//
\
//
\
//
\
//
\
//
\
//
\
//
\
//
\
//
\
//
\
//
');
//
// }
},
error:function(err){
}
});
var flag = 0;
//测试发送
$('.test_fans_but').click(function(){
Custommain.fans_send_message();
})
//发送消息时间
$(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));
});
//删除文字列表
$('#group-type-news').on('click','.anticon-delete',function(){
var $this = $(this);
layer.open({
type: 1,
title: '温馨提示',
maxmin: false,
area: ['260px', '160px'],
btn: ['确认', '取消'],
shadeClose: true,
resize: false,
// skin: 'layui-layer-rim',
content: '您确定删除此条信息?
',
yes: function (index, layero) {
var nindex = $this.parents('li').index();
var arrimgtxt = getimagetxtarr($('.textarea_txt_hidden_input').val());
if(!arrimgtxt) return false;
arrimgtxt.removeItems(nindex);
$('.textarea_txt_hidden_input').val(JSON.stringify(arrimgtxt));
if(arrimgtxt.length == 0){
$('.img_txt_list').html('');
}else{
txttext(arrimgtxt);
}
Toastr.success('删除成功');
layer.close(index);
},
btn2: function (index, node) {
layer.close(index)
}
});
});
//修改文字内容
$(document).on('click','#group-type-news .anticon-novel-edit',function(){
var $this=$(this);
var nIndex = $this.parents('li').index();
var sjson = JSON.parse($('.textarea_txt_hidden_input').val());
Fast.api.open('custom/editlinktext?json=' + encodeURIComponent(JSON.stringify(sjson[nIndex])), '修改文字链接', {
callback: function (data) {
var data = data;
var strImgtext = JSON.parse($('.textarea_txt_hidden_input').val());
strImgtext[nIndex] = data;
$('.textarea_txt_hidden_input').val(JSON.stringify(strImgtext));
txttext(strImgtext);
}
});
});
$(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);
});
var ofansopen=true;
//tag切换
$(document).on('click','.s_tag_fans_num',function(){
var $this = $(this);
//防止重复点击
if(!ofansopen){
return false;
}
ofansopen = false;
$('.s_tag_footer').addClass('s_tag_fans_show');
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);
//console.log(tagObj);
$.ajax({
type:'post',
data:tagObj,
//dataType:'json',
url:'/admin/custom/ajaxcustom',
success:function(data){
//console.log(data);
$('#mustbe').html('约'+data.ids+'人');
ofansopen = true;
$('.s_tag_footer').removeClass('s_tag_fans_show');
},
error:function(err){
ofansopen = true;
$('.s_tag_footer').removeClass('s_tag_fans_show');
}
});
});
// $(document).on('click','.img_txt_add_but',function(){
// var $List=$('.img_txt_main');
// var oNowData = {
// image:ore.imglis[parseInt(Math.random()*ore.imglis.length)]['image'],
// title:ore.titlist[parseInt(Math.random()*ore.titlist.length)]['title'],
// url:'http://'
// };
// var sLiImg=ore.sli.replace(/sli_img/g,oNowData['image']);
// sLiImg=sLiImg.replace(/sli_value/g,oNowData['title']);
// sLiImg=sLiImg.replace(/click_url/g,'http://');
// if($List.length<8){
// $('.img_txt_list').append(sLiImg);
// ore.arrma.push(oNowData);
// }else{
// Toastr.error("不能超过8篇");
// }
// });
$(document).on('click','.img_txt_remvoe',function(){
var $this=$(this);
$this.parent().remove();
});
//修改菜单链接
$(document).on('click', '.img_txt_edit_bars', function () {
var $this = $(this);
Fast.api.open('link/select?one=1', '选择', {
callback: function (data) {
var data = data[0];
$this.parent().find('input').eq(1).val(data.menu_url);
}
});
});
//添加文字链
$(document).on('click', '.textarea_txt_add_but', function () {
Fast.api.open('custom/addlinktext', '添加消息', {
callback: function (data) {
strLinktext = $('.textarea_txt_hidden_input').val()
var linktext_data = [];
if (strLinktext.length > 0) {
linktext_data = JSON.parse(strLinktext);
}
linktext_data.push(data);
$('.textarea_txt_hidden_input').val(JSON.stringify(linktext_data));
txttext(linktext_data);
}
})
});
$(document).on('click', '.btn_save_media_but button', function () {
var saveval = $(this).data('save-val');
if(typeof saveval != 'undefined'){
$('.js_is_save_media').val(saveval);
}else{
Fast.api.close();
}
});
$(document).on('click', '.js_save_media', function () {
$('.js_is_save_media').val(1);
});
//修改最近阅读链接
$(document).on('click', '.img_txt_edit_bookmark_o', function () {
var $this = $(this);
$.ajax({
type: 'get',
url: '/admin/book/book/getrecenturl',
cache: false,
async: false,
success:function(data){
$this.parent().find('input').eq(1).val(data.url);
},
error:function(err){
ofansopen = true;
$('.s_tag_footer').removeClass('s_tag_fans_show');
}
});
});
//修改活动
$(document).on('click', '.img_txt_edit_card_o', function () {
var $this = $(this);
Fast.api.open('activity/select?one=1', '选择', {
callback: function (data) {
var data = data[0];
$this.parent().find('input').eq(1).val(data.activity_url);
}
});
});
//修改url
$(document).on('click','.img_txt_edit_url',function(){
var $this=$(this);
Fast.api.open('referral/referral/select?one=1', '选择', {
callback: function (data) {
var data = data[0];
// console.log('展示title回调', data);
$this.parent().find('input').eq(1).val(data.source_url);
}
});
});
//修改book
$(document).on('click','.img_txt_edit_book',function(){
var $this=$(this);
Fast.api.open('book.book/select?one=1', '选择', {
callback: function (data) {
var data = data[0];
$this.parent().find('input').eq(1).val(data.current_book_url);
}
});
});
//修改图片
$(document).on('click','.img_txt_edit_img',function(){
var $this=$(this);
Fast.api.open('manage/cover/select', '选择', {
callback: function (data) {
// console.log('展示image回调', data);
$this.find('img').attr('src',data.image);
}
});
});
//修改图片
$(document).on('click', '.add_img_txt_edit_img', function () {
var $this = $(this);
Fast.api.open('manage/cover/select', '选择', {
callback: function (data) {
$this.parent().find('img').attr('src', data.image);
$this.parent().find('input').eq(0).val(data.image);
}
});
});
//修改跳转链接
$(document).on('click','.img_txt_main a',function(){
var $this=$(this);
var nIndex = $this.parents('.img_txt_main').index();
layer.prompt({
formType: 2,
value: ore.arrma[nIndex].url,
title: '请输入跳转链接地址(http://)',
area: ['300px', '100px'] //自定义文本域宽高
}, function(value, index, elem){
var reg=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/;
if(reg.test(value)){
layer.close(index);
ore.arrma[nIndex].url = value;
$this.html(value);
}else{
Toastr.error("请输入正确的跳转地址。");
}
});
});
$(document).on('click', '.btn-close', function () {
Fast.api.close();
});
//禁止修改日期
// var csendtimeval = '';
// $(document).on('focus blur','#c-sendtime',function(){
// csendtimeval = $(this).val();
// }).on('keyup','#c-sendtime',function(e){
// $(this).val(csendtimeval);
// });
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;
}
},
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_text);
/*jshint multistr: true */
var html = '';
return html;
}
}
}
};
return Controller;
});