define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template','gridify', 'custommain'], function ($, undefined, Backend, Table, Form, Template,Gridify, Custommain) {
//推送开关全选 add by liues@dianzhong.com at 2018-09-05 11:01:18
Form.events.selecttips = function (form,str) {
var all_tip = $("#dyhradio input", form);
var other_tips = $(":checkbox[name^='" + str + "']", form);
if(other_tips.length<=0) return false;
var all_tip_checked = function () {
var checked = (other_tips.length == other_tips.filter(":checked").length);
all_tip.prop("checked", checked);
};
var other_tips_checked = function () {
var checked = all_tip.prop("checked");
other_tips.prop("checked", checked);
};
all_tip.change(other_tips_checked);
other_tips.change(all_tip_checked);
all_tip_checked();
}
var Controller = {
index: function () {
Table.api.init({
extend: {
index_url: 'messagecustom/linktextmedia/index',
del_url:'messagecustom/linktextmedia/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 '
';*/
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);
table.bootstrapTable('refresh');
} else {
var msg = data.msg != '' ? data.msg : '操作失败';
Toastr.error(msg);
}
layer.close(index);
});
}, 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:'messagecustom/linktextmedia/getMediaMessage?ids='+ sid + '&idx='+ nIndex,
success:function(data){
if(!data.code){
Fast.api.open('custom/editlinktext?json=' + encodeURIComponent(data.data), '修改内容', {
callback: function (data) {
var data = data;
$.ajax({
type:'get',
url:'messagecustom/linktextmedia/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 () {
var acc_type = $("#acc_type_hid").val(); // 标记:群发订阅号 群发服务号
var media_id = $("#media_id").val();
if(acc_type){
//发送订阅号验证
$("#add-form").data("validator-options", {
ignore: ':hidden',
beforeSubmit: function (form) {
var senddyhradioval = $('#dyhradio input').val();
var other_tips = $(":checked[name^='row[sub_id]']", $("#add-form"));
if($('#dyhradio input').length){
if(other_tips.length <= 0){
Toastr.error("请选择需要发送的订阅号");
return false;
}
if(senddyhradioval < other_tips.length){
Toastr.error("最多可选择发送" + senddyhradioval + '个订阅号');
return false;
}
}
}
});
Controller.api.bindevent();
}
//测试发送
$('.test_fans_but').click(function(){
Custommain.fans_send_message();
});
},
//查看详情
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: '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 () {
Custommain.checkbox_relation('#dyhradio', '#dyhcheck');
Form.api.bindevent($("form[role=form]"));
//修改发送消息时间
$(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_text);
/*jshint multistr: true */
var html = '';
return html;
}
}
}
};
return Controller;
});