imagetextmediapush.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'custommain'], function ($, undefined, Backend, Table, Form, Template, Custommain) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'messagecustom/imagetextmediapush/index?status=' + Config.status,
  8. },
  9. searchFormVisible: true,
  10. search:false
  11. });
  12. var table = $("#table");
  13. // 初始化表格
  14. table.bootstrapTable({
  15. url: $.fn.bootstrapTable.defaults.extend.index_url,
  16. pk: 'id',
  17. sortName: 'id',
  18. clickToSelect:false,
  19. pageSize: 12, //每页的记录行数(*)
  20. pageList: [12, 36, 72, 120], //可供选择的每页的行数(*)
  21. columns: [Controller.api.showFilterColumns(table)],
  22. onLoadSuccess: function(){ //加载成功时执行
  23. $('#table td').attr('rowspan','1000');
  24. $('[rel="popover"]').popover({
  25. trigger:'manual',
  26. placement:'top',
  27. html:true,
  28. content:function(){
  29. var ids = $(this).data('rowid');
  30. /*jshint multistr: true*/
  31. return '<div class="msg_popover_but_box">\
  32. <a href="javascript:;" class="btn-multi-ajax" data-href="/admin/messagecustom/imagetext/multisendmessage?table=media&ids='+ids+'&official_type=0">群发服务号</a>\
  33. <a href="javascript:;" class="btn-multi-ajax" data-href="/admin/messagecustom/imagetext/multisendmessage?table=media&ids=\'+ids+\'&official_type=1">群发订阅号</a>\
  34. </div>';
  35. }
  36. }).on("mouseenter", function () {
  37. var _this = this;
  38. $(this).popover("show");
  39. $(this).siblings(".popover").on("mouseleave", function () {
  40. $(_this).popover('hide');
  41. });
  42. }).on("mouseleave", function () {
  43. var _this = this;
  44. setTimeout(function () {
  45. if (!$(".popover:hover").length) {
  46. $(_this).popover("hide");
  47. }
  48. }, 100);
  49. });
  50. }
  51. });
  52. // 为表格绑定事件
  53. Table.api.bindevent(table);
  54. $(document).on('mouseover','#table td',function(){
  55. $('.wxb-card-list-scroll .anticon').tooltip();
  56. });
  57. //群发消息
  58. $(document).on('click','.btn-multi-ajax',function(){
  59. var multi_url = $(this).attr('data-href');
  60. $.get(multi_url,{},function(data){
  61. if(data.code){
  62. var msg = data.msg != '' ? data.msg : '操作成功';
  63. Toastr.success(msg);
  64. }else{
  65. var msg = data.msg != '' ? data.msg : '操作失败';
  66. Toastr.error(msg);
  67. }
  68. });
  69. });
  70. //删除
  71. $(document).on('click','.btn-del-ajax',function(){
  72. if(!Custommain.check_waiting_send_editable($(this).attr('data_send_time'))){
  73. Toastr.error("发送前10分钟不可操作");
  74. return;
  75. }
  76. var del_url = $(this).attr('data-href');
  77. layer.confirm("确定删除此项?", {icon: 3, title: "温馨提示", shadeClose: true}, function (index) {
  78. layer.close(index);
  79. $.get(del_url,{},function(data){
  80. if(data.code){
  81. var msg = data.msg != '' ? data.msg : '操作成功';
  82. Toastr.success(msg);
  83. table.bootstrapTable('refresh');
  84. }else{
  85. var msg = data.msg != '' ? data.msg : '操作失败';
  86. Toastr.error(msg);
  87. }
  88. });
  89. }, function(){
  90. layer.close();
  91. });
  92. });
  93. //编辑 待发送 消息
  94. $(document).on('click','.btn-editwaitmsg-ajax',function(){
  95. if(!Custommain.check_waiting_send_editable($(this).attr('data_send_time'))){
  96. Toastr.error("发送前10分钟不可操作");
  97. return;
  98. }
  99. Fast.api.open($(this).attr('data-href'), '编辑', {});
  100. });
  101. // 打开详情页面
  102. $(document).on('click', '.btn-view-ajax', function () {
  103. Fast.api.open($(this).attr('data-href'), '查看详情', {});
  104. });
  105. },
  106. //待发图文客服消息
  107. editwaitingimgmsg:function(){
  108. Controller.api.bindevent();
  109. },
  110. //查看详情
  111. viewdetail: function () {
  112. // 初始化表格参数配置
  113. Table.api.init({
  114. extend: {
  115. getimage_url: window.location.href,
  116. },
  117. search: false,
  118. showToggle: false,
  119. showColumns: false,
  120. showExport: false,
  121. commonSearch: false
  122. });
  123. var table = $("#table");
  124. //当表格数据加载完成时
  125. table.on('load-success.bs.table', function (e, data) {
  126. //这里可以获取从服务端获取的JSON数据
  127. //console.log(data);
  128. //这里我们手动设置底部的值
  129. //$("#money").text(data.extend.money);
  130. //$("#price").text(data.extend.price);
  131. });
  132. // 初始化表格
  133. table.bootstrapTable({
  134. url: $.fn.bootstrapTable.defaults.extend.getimage_url,
  135. pk: 'id',
  136. sortName: 'id',
  137. columns: [Controller.api.getimagelist(table)]
  138. });
  139. // 为表格绑定事件
  140. Table.api.bindevent(table);
  141. $(document).on('click', '.btn-close', function () {
  142. Fast.api.close();
  143. });
  144. },
  145. api: {
  146. showFilterColumns:function(table){
  147. var cols = new Array();
  148. cols.push({field: 'sendtime', title:"发送时间",operate:'RANGE', addclass:'datetimerange', visible:false});
  149. cols.push({field: 'official_account_type', title:"群发类型",searchList: {"0":__('服务号'),"1":__('订阅号')}, visible:false});
  150. cols.push({field: 'wechat_name', title:"公众号名称", visible:false});
  151. cols.push({field: 'id', title: "推广ID", formatter: Controller.api.formatter.showStyle});
  152. cols.push({field: "message_json$[*].book_name", title:"书籍名称", visible:false,operate:'LIKE %...%'});
  153. return cols;
  154. },
  155. bindevent: function () {
  156. Custommain.checkbox_relation('#dyhradio', '#dyhcheck');
  157. //群发测试
  158. $('.test_fans_but').click(function(){
  159. Custommain.fans_send_message();
  160. })
  161. Form.api.bindevent($("form[role=form]"));
  162. //修改发送消息时间
  163. $(document).on('click','.s_time_box span',function(){
  164. var $this = $(this);
  165. var nval = parseInt($this.attr('stime'));
  166. var ntime = Date.parse(new Date());
  167. var nt = ntime + nval;
  168. $('#c-sendtime').val(GetRTime(nt));
  169. });
  170. function GetRTime(time){
  171. var stime;
  172. time = new Date(time);
  173. var year = time.getYear() + 1900;
  174. var month = time.getMonth()+1;
  175. var day = time.getDate();
  176. var hours = time.getHours();
  177. var minutes = time.getMinutes();
  178. var seconds = time.getSeconds();
  179. stime = year + '-' +
  180. (month < 10 ? '0'+month : month) + '-' +
  181. (day < 10 ? '0'+day : day) + ' ' +
  182. (hours < 10 ? '0'+hours : hours) + ':' +
  183. (minutes < 10 ? '0'+minutes : minutes) + ':' +
  184. (seconds < 10 ? '0'+seconds : seconds);
  185. return stime;
  186. }
  187. },
  188. formatter:{
  189. showImage: function (value, row, index) {
  190. return '<img style="height:100px;" src="' + value + '"/>';
  191. },
  192. showType: function (value, row, index) {
  193. var type_arr = ['书籍', '活动', '继续阅读', '菜单'];
  194. return type_arr[value];
  195. },
  196. showPosition: function (value, row, index) {
  197. return index + 1;
  198. },
  199. showPushType: function (value, row, index) {
  200. var push_arr = ['外推', '内推'];
  201. return push_arr[value];
  202. },
  203. showStyle:function(value, row, index){
  204. var message_data = JSON.parse(row.message_json).shift();
  205. /*jshint multistr: true */
  206. var html = '<div class="wxb-card-list-scroll"><div class="wxb-card-item"><div class="wxb-card-item-inner"><div class="item-header"><div>';
  207. html += '<div class="tweets-card-title"><p>推广id:' + row.id + '</p></div>';
  208. html += '<div class="tweets-card-title"><p>创建时间:'+Table.api.formatter.datetime(row.createtime,row,index)+'</p></div>';
  209. html += '<div class="tweets-card-title"><p>修改时间:'+Table.api.formatter.datetime(row.updatetime,row,index)+'</p></div>';
  210. var offical_type = parseInt(row.official_account_type) == 1 ? '订阅号' : '服务号';
  211. var send_color = '';
  212. var send_text = '';
  213. switch (parseInt(row.status)) {
  214. case 0:
  215. send_color = 'red';
  216. send_text = '待发送';
  217. break;
  218. case 1:
  219. send_color = '#FF9900';
  220. send_text = '群发中';
  221. break;
  222. case 2:
  223. send_color = '#88d743';
  224. send_text = '已群发';
  225. break;
  226. }
  227. html += '<div class="tweets-card-title"><p style="color:' + send_color + '">发送时间:' + Table.api.formatter.datetime(row.sendtime, row, index) + ' ' + send_text + '</p></div>';
  228. html += '<div class="tweets-card-title"><p>群发类型:' + offical_type + '</p></div>';
  229. html += '</div></div><ul class="article-list"><li> <a class="article-item">';
  230. html += '<div class="novel-img article-item-cover" style="background-image: url('+message_data.image+');"></div>';
  231. html += '<p class="article-item-title">'+message_data.title+'</p>';
  232. html +='</a>';
  233. html += '</li></ul><ul class="footer-btns">';
  234. if (parseInt(Config.status) == 0) {
  235. if(Custommain.check_waiting_send_editable(row.sendtime)){
  236. html += '<li><a class="btn-del-ajax" data_send_time="'+row.sendtime+'" href="javascript:void(0);" data-href="/admin/messagecustom/imagetextmediapush/del?table=push&ids=' + row.id + '">删除</a></li>';
  237. html += '<li><a class="btn-editwaitmsg-ajax" data_send_time="'+row.sendtime+'" href="javascript:void(0);" data-href="/admin/messagecustom/imagetextmediapush/editWaitingImgMsg?table=push&ids=' + row.id + '">编辑</a></li>';
  238. }
  239. } else if (parseInt(Config.status) == 2) {
  240. html += '<li><a class="btn-view-ajax" href="javascript:void(0);" data-href="/admin/messagecustom/imagetextmediapush/viewdetail?ids=' + row.id + '">查看详情</a></li>';
  241. html += '<li><a href="/admin/customurl/index?push_id=' + row.id +'">查看数据分析</a></li>';
  242. }
  243. html += '</ul></div></div></div>';
  244. return html;
  245. }
  246. },
  247. getimagelist: function (table) {
  248. var cols = new Array();
  249. cols.push({
  250. field: 'title',
  251. title: "标题",
  252. operate: false
  253. });
  254. cols.push({
  255. field: 'image',
  256. title: "图片",
  257. operate: false,
  258. formatter: Controller.api.formatter.showImage
  259. });
  260. cols.push({
  261. field: 'push',
  262. title: "推广类型",
  263. operate: false,
  264. formatter: Controller.api.formatter.showPushType
  265. });
  266. cols.push({
  267. field: 'type',
  268. title: "链接类型",
  269. operate: false,
  270. formatter: Controller.api.formatter.showType
  271. });
  272. cols.push({
  273. field: 'book_name',
  274. title: "书籍名称/活动名称/菜单名称",
  275. operate: false
  276. });
  277. return cols;
  278. }
  279. }
  280. };
  281. return Controller;
  282. });