linktextmediapush.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'gridify', 'custommain'], function ($, undefined, Backend, Table, Form, Template, Gridify, Custommain) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'messagecustom/linktextmediapush/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. },
  24. onPostBody:function(){
  25. $('#table td').attr('rowspan', '1000');
  26. var ooptions = {
  27. srcNode: 'tr', // grid items (class, node)
  28. margin: '0', // margin in pixel, default: 0px
  29. width: '296px', // grid item width in pixel, default: 220px
  30. max_width: '', // dynamic gird item width if specified, (pixel)
  31. resizable: true, // re-layout if window resize
  32. transition: 'all 0.5s ease' // support transition for CSS3, default: all 0.5s ease
  33. }
  34. $('#table').gridify(ooptions);
  35. }
  36. });
  37. // 为表格绑定事件
  38. Table.api.bindevent(table);
  39. //tooltip
  40. $(document).on('mouseover', '#table td', function () {
  41. $('.wxb-card-list-scroll .anticon').tooltip();
  42. $('[rel="popover"]').popover({
  43. trigger: 'manual',
  44. placement: 'top',
  45. html: true,
  46. content: function () {
  47. var ids = $(this).data('rowid');
  48. /*jshint multistr: true*/
  49. return '<div class="msg_popover_but_box">\
  50. <a href="javascript:;" class="btn-multi-ajax" data-href="/admin/messagecustom/imagetextmedia/multisendmessage?table=media&ids=' + ids + '&official_type=0">群发服务号</a>\
  51. <a href="javascript:;" class="btn-multi-ajax" data-href="/admin/messagecustom/imagetextmedia/multisendmessage?table=media&ids=' + ids + '&official_type=1">群发订阅号</a>\
  52. </div>';
  53. }
  54. }).on("mouseenter", function () {
  55. var _this = this;
  56. $(this).popover("show");
  57. $(this).siblings(".popover").on("mouseleave", function () {
  58. $(_this).popover('hide');
  59. });
  60. }).on("mouseleave", function () {
  61. var _this = this;
  62. setTimeout(function () {
  63. if (!$(".popover:hover").length) {
  64. $(_this).popover("hide")
  65. }
  66. }, 100);
  67. })
  68. });
  69. //删除文字链消息列表单列
  70. $(document).on('click', '.anticon-delete', function () {
  71. var $this = $(this);
  72. var oLi = $this.parents('li');
  73. var nIndex = $this.parents('li').index();
  74. var sid = $this.data('id');
  75. layer.confirm("确定删除此项?", {
  76. icon: 3,
  77. title: "温馨提示",
  78. shadeClose: true
  79. }, function (index) {
  80. $.get($.fn.bootstrapTable.defaults.extend.del_url, {"ids":sid, "idx":nIndex}, function (data) {
  81. if (data.code) {
  82. var msg = data.msg != '' ? data.msg : '操作成功';
  83. Toastr.success(msg);
  84. table.bootstrapTable('refresh');
  85. } else {
  86. var msg = data.msg != '' ? data.msg : '操作失败';
  87. Toastr.error(msg);
  88. }
  89. layer.close(index);
  90. });
  91. }, function () {
  92. layer.close();
  93. });
  94. });
  95. //删除文字链消息列表整列
  96. $(document).on('click', '.btn-del-ajax', function () {
  97. if(!Custommain.check_waiting_send_editable($(this).attr('data_send_time'))){
  98. Toastr.error("发送前10分钟不可操作");
  99. return;
  100. }
  101. var del_url = $(this).attr('data-href');
  102. layer.confirm("确定删除此项?", {
  103. icon: 3,
  104. title: "温馨提示",
  105. shadeClose: true
  106. }, function (index) {
  107. layer.close(index);
  108. $.get(del_url, {}, function (data) {
  109. if (data.code) {
  110. var msg = data.msg != '' ? data.msg : '操作成功';
  111. Toastr.success(msg);
  112. table.bootstrapTable('refresh');
  113. } else {
  114. var msg = data.msg != '' ? data.msg : '操作失败';
  115. Toastr.error(msg);
  116. }
  117. });
  118. }, function () {
  119. layer.close();
  120. });
  121. });
  122. // 打开详情页面
  123. $(document).on('click', '.btn-view-ajax', function () {
  124. Fast.api.open($(this).attr('data-href'), '查看详情', {});
  125. });
  126. // 打开详情页面
  127. $(document).on('click', '.btn-editwaitmsg-ajax', function () {
  128. if(!Custommain.check_waiting_send_editable($(this).attr('data_send_time'))){
  129. Toastr.error("发送前10分钟不可操作");
  130. return;
  131. }
  132. Fast.api.open($(this).attr('data-href'), '编辑', {});
  133. });
  134. //群发消息
  135. $(document).on('click', '.btn-multi-ajax', function () {
  136. var multi_url = $(this).attr('data-href');
  137. $.get(multi_url, {}, function (data) {
  138. if (data.code) {
  139. var msg = data.msg != '' ? data.msg : '操作成功';
  140. Toastr.success(msg);
  141. } else {
  142. var msg = data.msg != '' ? data.msg : '操作失败';
  143. Toastr.error(msg);
  144. }
  145. });
  146. });
  147. //修改图文内容
  148. $(document).on('click','.anticon-novel-edit',function(){
  149. var $this=$(this);
  150. var nIndex = $this.parents('li').index();
  151. var sid = $this.data('id');
  152. $.ajax({
  153. type:'get',
  154. url:'messagecustom/linktextmedia/getMediaMessage?ids='+ sid + '&idx='+ nIndex,
  155. success:function(data){
  156. if(!data.code){
  157. Fast.api.open('custom/editlinktext?json=' + encodeURIComponent(data.data), '修改内容', {
  158. callback: function (data) {
  159. var data = data;
  160. $.ajax({
  161. type:'get',
  162. url:'messagecustom/linktextmedia/editLink?idx='+ nIndex +'&ids='+ sid + '&message_json=' + encodeURIComponent(JSON.stringify(data)),
  163. success:function(data){
  164. if(data.code == 0){
  165. Toastr.success('编辑成功');
  166. }else{
  167. Toastr.error('编辑失败');
  168. }
  169. }
  170. })
  171. }
  172. });
  173. }else{
  174. Toastr.error('编辑失败');
  175. }
  176. }
  177. })
  178. });
  179. },
  180. //查看详情
  181. viewdetail: function () {
  182. // 初始化表格参数配置
  183. Table.api.init({
  184. extend: {
  185. getimage_url: window.location.href,
  186. },
  187. search: false,
  188. showToggle: false,
  189. showColumns: false,
  190. showExport: false,
  191. commonSearch: false
  192. });
  193. var table = $("#table");
  194. //当表格数据加载完成时
  195. table.on('load-success.bs.table', function (e, data) {
  196. //这里可以获取从服务端获取的JSON数据
  197. //console.log(data);
  198. //这里我们手动设置底部的值
  199. //$("#money").text(data.extend.money);
  200. //$("#price").text(data.extend.price);
  201. });
  202. // 初始化表格
  203. table.bootstrapTable({
  204. url: $.fn.bootstrapTable.defaults.extend.getimage_url,
  205. pk: 'id',
  206. sortName: 'id',
  207. columns: [Controller.api.getimagelist(table)]
  208. });
  209. // 为表格绑定事件
  210. Table.api.bindevent(table);
  211. $(document).on('click', '.btn-close', function () {
  212. Fast.api.close();
  213. });
  214. },
  215. api: {
  216. showFilterColumns:function(table){
  217. var cols = new Array();
  218. cols.push({field: 'sendtime', title:"发送时间",operate:'RANGE', addclass:'datetimerange', visible:false});
  219. cols.push({field: 'official_account_type', title:"群发类型",searchList: {"0":__('服务号'),"1":__('订阅号')}, visible:false});
  220. cols.push({field: 'wechat_name', title:"公众号名称", visible:false});
  221. cols.push({field: 'id', title: "推广ID", formatter: Controller.api.formatter.showStyle});
  222. cols.push({field: "message_text$[*].book_name", title:"书籍名称", visible:false,operate:'LIKE %...%'});
  223. return cols;
  224. },
  225. bindevent: function () {
  226. Custommain.checkbox_relation('#dyhradio', '#dyhcheck');
  227. //群发测试
  228. $('.test_fans_but').click(function(){
  229. Custommain.fans_send_message();
  230. })
  231. Form.api.bindevent($("form[role=form]"));
  232. },
  233. formatter:{
  234. showType: function (value, row, index) {
  235. var type_arr = ['书籍', '活动', '继续阅读', '菜单'];
  236. return type_arr[value];
  237. },
  238. showPosition: function (value, row, index) {
  239. return index + 1;
  240. },
  241. showPushType: function (value, row, index) {
  242. var push_arr = ['外推', '内推'];
  243. return push_arr[value];
  244. },
  245. showStyle:function(value, row, index){
  246. var message_data = JSON.parse(row.message_text);
  247. /*jshint multistr: true */
  248. var html = '<div class="wxb-card-list-scroll"><div class="wxb-card-item"><div class="wxb-card-item-inner"><div class="item-header"><div>';
  249. html += '<div class="tweets-card-title"><p>素材id:' + row.id + '</p></div>';
  250. html += '<div class="tweets-card-title"><p>创建时间:' + Table.api.formatter.datetime(row.createtime, row, index) + '</p></div>';
  251. html += '<div class="tweets-card-title"><p>修改时间:' + Table.api.formatter.datetime(row.updatetime, row, index) + '</p></div>';
  252. var offical_type = parseInt(row.official_account_type) == 1 ? '订阅号' : '服务号';
  253. var send_color = '';
  254. var send_text = '';
  255. switch (parseInt(row.status)) {
  256. case 0:
  257. send_color = 'red';
  258. send_text = '待发送';
  259. break;
  260. case 1:
  261. send_color = '#FF9900';
  262. send_text = '群发中';
  263. break;
  264. case 2:
  265. send_color = '#88d743';
  266. send_text = '已群发';
  267. break;
  268. }
  269. html += '<div class="tweets-card-title"><p style="color:' + send_color + '">发送时间:' + Table.api.formatter.datetime(row.sendtime, row, index) + ' ' + send_text + '</p></div>';
  270. html += '<div class="tweets-card-title"><p>群发类型:' + offical_type + '</p></div>';
  271. html += '</div></div><div class="img_txt_url"><ul>';
  272. var txtlis = '';
  273. for(var i=0; i<message_data.length; i++){
  274. var scolor = '';
  275. if(message_data[i]['type'] == 4) scolor = 'style="color:#333"';
  276. txtlis += '<li>\
  277. <p '+ scolor +'>' + message_data[i]['title'] + '</p>\
  278. </li>'
  279. }
  280. html += txtlis +'</ul></div><ul class="footer-btns">';
  281. if (parseInt(Config.status) == 0) {
  282. if(Custommain.check_waiting_send_editable(row.sendtime)){
  283. html += '<li><a class="btn-del-ajax" data_send_time="'+row.sendtime+'" href="javascript:void(0);" data-href="/admin/messagecustom/linktextmediapush/del?table=push&ids=' + row.id + '">删除</a></li>';
  284. 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>';
  285. }
  286. } else if (parseInt(Config.status) == 2) {
  287. html += '<li><a class="btn-view-ajax" href="javascript:void(0);" data-href="/admin/messagecustom/linktextmediapush/viewdetail?ids=' + row.id + '">查看详情</a></li>';
  288. html += '<li><a href="/admin/customurl/index?push_id=' + row.id +'">查看数据分析</a></li>';
  289. }
  290. html += '</ul></div></div></div>';
  291. return html;
  292. }
  293. },
  294. getimagelist: function (table) {
  295. var cols = new Array();
  296. cols.push({
  297. field: 'title',
  298. title: "标题",
  299. operate: false
  300. });
  301. cols.push({
  302. field: 'type',
  303. title: "链接类型",
  304. operate: false,
  305. formatter: Controller.api.formatter.showType
  306. });
  307. cols.push({
  308. field: 'book_id',
  309. title: "书籍ID",
  310. operate: false,
  311. });
  312. cols.push({
  313. field: 'book_name',
  314. title: "书籍名称/活动名称/菜单名称",
  315. operate: false,
  316. });
  317. cols.push({
  318. field: 'push',
  319. title: "推广类型",
  320. operate: false,
  321. formatter: Controller.api.formatter.showPushType
  322. });
  323. return cols;
  324. }
  325. }
  326. };
  327. return Controller;
  328. });