123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'custommain'], function ($, undefined, Backend, Table, Form, Template, Custommain) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'messagecustom/imagetextmedia/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 () { //加载成功时执行
- $('#table td').attr('rowspan', '1000');
- }
- });
- // 为表格绑定事件
- 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 '<div class="msg_popover_but_box">\
- <a href="javascript:;" class="btn-multi-ajax" data-href="/admin/messagecustom/imagetextmedia/multisendmessage?table=media&ids=' + ids + '&official_type=0">群发服务号</a>\
- <a href="javascript:;" class="btn-multi-ajax" data-href="/admin/messagecustom/imagetextmedia/multisendmessage?table=media&ids=' + ids + '&official_type=1">群发订阅号</a>\
- </div>';*/
- return '<div class="msg_popover_but_box">\
- <a href="javascript:;" class="btn-multi-ajax" data-href="/admin/messagecustom/imagetextmedia/multisendmessage?table=media&ids=' + ids + '&official_type=0">群发服务号</a>\
- </div>';
- }
- }).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'), '查看详情', {});
- });
- //消息图文素材库编辑列表
- $(document).on('click', '.anticon-title-edit', function () {
- var $this = $(this);
- var sid = $this.data('id');
- var stit = $this.parents('li').find('.article-item-title').text();
- layer.open({
- type: 1,
- title: false,
- maxmin: false,
- area: ['auto', 'auto'],
- btn: ['确认', '取消'],
- shadeClose: true,
- resize: false,
- skin: 'layui-layer-rim',
- content: '<div class="anticon_edit_box">\
- <div class="anticon_edit_select_tit_box">\
- <strong>当前标题:</strong>\
- <p>' + stit + '</p>\
- <a href="javascript:;"><i class="fa fa-pencil"></i></a>\
- </div>\
- <div class="anticon_edit_input_tit_box">\
- <strong>修改为:</strong>\
- <div class="anticon_edit_input_tit"><input type="text" value="' + stit + '" /></div>\
- </div>\
- </div>',
- 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: './messagecustom/imagetextmedia/edittitle?ids=' + sid + '&title=' + stit,
- success: function (data) {
- $this.parents('li').find('.article-item-title').text(data.data);
- }
- })
- layer.close(index);
- },
- btn2: function (index, node) {
- layer.close(index)
- }
- });
- });
- //修改 弹窗 title
- $(document).on('click', '.anticon_edit_select_tit_box a', function () {
- var $this = $(this);
- Fast.api.open('manage/title/select', '选择标题', {
- callback: function (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 sid = $this.data('id');
- var stit = $this.parents('li').find('.article-item-cover');
- Fast.api.open('manage/cover/select', '选择', {
- callback: function (data) {
- $.ajax({
- type: 'get',
- url: './messagecustom/imagetextmedia/editcover?ids=' + sid + '&cover=' + data.image,
- success: function (data) {
- $this.parents('li').find('.article-item-cover').css('background-image', 'url(' + data.data + ')');
- }
- })
- }
- });
- });
- //修改图文内容
- $(document).on('click', '.anticon-novel-edit', function () {
- console.log('修改图文内容');
- var $this = $(this);
- var nIndex = $this.parents('li').index();
- var sid = $this.data('id');
- $.ajax({
- type: 'get',
- url: 'messagecustom/imagetextmedia/getmediamessage?ids=' + sid,
- success: function (data) {
- console.log('AAA');
- console.log(data);
- console.log('BBB');
- if (!data.code) {
- Fast.api.open('custom/editimagetext?media_id=' + data.data.media_id, '修改内容', {
- callback: function (data) {
- var data = data;
- $.ajax({
- type: 'get',
- url: 'messagecustom/imagetextmedia/editLink?ids=' + sid + '&message_json=' + encodeURIComponent(JSON.stringify(data)),
- success: function (data) {
- if (data.code == 0) {
- Toastr.success('成功');
- } else {
- Toastr.error('失败');
- }
- }
- })
- }
- });
- }
- },
- error:function(data){
- console.log('Error');
- console.log(data);
- }
- })
- });
- },
- //图文客服消息 群发 订阅号 服务号
- multisendmessage: function () {
- var acc_type = $("#acc_type_hid").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: '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 () {
- Custommain.checkbox_relation('#dyhradio', '#dyhcheck');
- Form.api.bindevent($("form[role=form]"),
- function (data) {
- Fast.api.close(data);
- },
- function (data) {
- }
- );
-
- $(document).on('click', '.btn-close', function () {
- Fast.api.close();
- });
- //修改发送消息时间
- $(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;
- }
- },
- formatter: {
- showImage: function (value, row, index) {
- return '<img style="height:100px;" src="' + value + '"/>';
- },
- 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 = '<div class="wxb-card-list-scroll"><div class="wxb-card-item"><div class="wxb-card-item-inner"><div class="item-header"><div>';
- html += '<div class="tweets-card-title"><p>素材id:' + row.id + '</p></div>';
- html += '<div class="tweets-card-title"><p>创建时间:' + Table.api.formatter.datetime(row.createtime, row, index) + '</p></div>';
- html += '<div class="tweets-card-title"><p>修改时间:' + Table.api.formatter.datetime(row.updatetime, row, index) + '</p></div>';
- /*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 += '<div class="tweets-card-title"><p style="color:' + send_color + '">发送时间:' + Table.api.formatter.datetime(row.sendtime, row, index) + ' ' + send_text + '</p></div>';
- html += '<div class="tweets-card-title"><p>群发类型:' + offical_type + '</p></div>';*/
- html += '</div></div><ul class="article-list"><li> <a class="article-item">';
- html += '<div class="novel-img article-item-cover" style="background-image: url(' + message_data.image + ');"></div>';
- html += '<p class="article-item-title">' + message_data.title + '</p>';
- html += '</a><div class="article-actions">';
- html += '<div> <span class="action-item"> <i class="anticon anticon-title-edit" style="font-size: 17px;" data-id="' + row.id + '" data-toggle="tooltip" data-original-title="修改标题"></i> </span> <span class="action-item"> <i class="anticon anticon-cover-edit" data-toggle="tooltip" data-original-title="修改封面" data-id="' + row.id + '"></i> </span> <span class="action-item"> <i class="anticon anticon-novel-edit" style="font-size: 13px;" data-toggle="tooltip" data-original-title="编辑链接" data-id="' + row.id + '"></i> </span> <span class="action-item action-item-up"> <i class="anticon anticon-arrow-up" data-toggle="tooltip" data-original-title="上移"></i> </span> <span class="action-item action-item-down"> <i class="anticon anticon-arrow-down" data-toggle="tooltip" data-original-title="下移"></i> </span></div>';
- html += '</div></li></ul><ul class="footer-btns">';
- html += '<li><a class="btn-del-ajax" href="javascript:void(0);" data-href="/admin/messagecustom/imagetextmedia/del?table=media&ids=' + row.id + '">删除</a></li>';
- html += '<li><a class="btn-view-ajax" href="javascript:void(0);" data-href="/admin/messagecustom/imagetextmedia/viewdetail?ids=' + row.id + '">查看详情</a></li>';
- html += '<li><a rel="popover" data-rowid="' + row.id + '">群发</a></li>';
- html += '</ul></div></div></div>';
- return html;
- }
- }
- }
- };
- return Controller;
- });
|