linktextmedia.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template','gridify', 'custommain'], function ($, undefined, Backend, Table, Form, Template,Gridify, Custommain) {
  2. //推送开关全选 add by liues@dianzhong.com at 2018-09-05 11:01:18
  3. Form.events.selecttips = function (form,str) {
  4. var all_tip = $("#dyhradio input", form);
  5. var other_tips = $(":checkbox[name^='" + str + "']", form);
  6. if(other_tips.length<=0) return false;
  7. var all_tip_checked = function () {
  8. var checked = (other_tips.length == other_tips.filter(":checked").length);
  9. all_tip.prop("checked", checked);
  10. };
  11. var other_tips_checked = function () {
  12. var checked = all_tip.prop("checked");
  13. other_tips.prop("checked", checked);
  14. };
  15. all_tip.change(other_tips_checked);
  16. other_tips.change(all_tip_checked);
  17. all_tip_checked();
  18. }
  19. var Controller = {
  20. index: function () {
  21. Table.api.init({
  22. extend: {
  23. index_url: 'messagecustom/linktextmedia/index',
  24. del_url:'messagecustom/linktextmedia/delsinglepiece',
  25. },
  26. searchFormVisible: true,
  27. search: false
  28. });
  29. var table = $("#table");
  30. // 初始化表格
  31. table.bootstrapTable({
  32. url: $.fn.bootstrapTable.defaults.extend.index_url,
  33. pk: 'id',
  34. sortName: 'id',
  35. clickToSelect: false,
  36. pageSize: 12, //每页的记录行数(*)
  37. pageList: [12, 36, 72, 120], //可供选择的每页的行数(*)
  38. columns: [Controller.api.showFilterColumns(table)],
  39. onLoadSuccess: function () { //加载成功时执行
  40. },
  41. onPostBody:function(){
  42. $('#table td').attr('rowspan', '1000');
  43. var ooptions = {
  44. srcNode: 'tr', // grid items (class, node)
  45. margin: '0', // margin in pixel, default: 0px
  46. width: '296px', // grid item width in pixel, default: 220px
  47. max_width: '', // dynamic gird item width if specified, (pixel)
  48. resizable: true, // re-layout if window resize
  49. transition: 'all 0.5s ease' // support transition for CSS3, default: all 0.5s ease
  50. }
  51. $('#table').gridify(ooptions);
  52. }
  53. });
  54. // 为表格绑定事件
  55. Table.api.bindevent(table);
  56. //tooltip
  57. $(document).on('mouseover', '#table td', function () {
  58. $('.wxb-card-list-scroll .anticon').tooltip();
  59. $('[rel="popover"]').popover({
  60. trigger: 'manual',
  61. placement: 'top',
  62. html: true,
  63. content: function () {
  64. var ids = $(this).data('rowid');
  65. /*jshint multistr: true*/
  66. /*return '<div class="msg_popover_but_box">\
  67. <a href="javascript:;" class="btn-multi-ajax" data-href="/admin/messagecustom/linktextmedia/multisendmessage?table=media&ids=' + ids + '&official_type=0">群发服务号</a>\
  68. <a href="javascript:;" class="btn-multi-ajax" data-href="/admin/messagecustom/linktextmedia/multisendmessage?table=media&ids=' + ids + '&official_type=1">群发订阅号</a>\
  69. </div>';*/
  70. return '<div class="msg_popover_but_box">\
  71. <a href="javascript:;" class="btn-multi-ajax" data-href="/admin/messagecustom/linktextmedia/multisendmessage?table=media&ids=' + ids + '&official_type=0">群发服务号</a>\
  72. </div>';
  73. }
  74. }).on("mouseenter", function () {
  75. var _this = this;
  76. $(this).popover("show");
  77. $(this).siblings(".popover").on("mouseleave", function () {
  78. $(_this).popover('hide');
  79. });
  80. }).on("mouseleave", function () {
  81. var _this = this;
  82. setTimeout(function () {
  83. if (!$(".popover:hover").length) {
  84. $(_this).popover("hide");
  85. }
  86. }, 100);
  87. });
  88. });
  89. //删除文字链消息列表单列
  90. $(document).on('click', '.anticon-delete', function () {
  91. var $this = $(this);
  92. var oLi = $this.parents('li');
  93. var nIndex = $this.parents('li').index();
  94. var sid = $this.data('id');
  95. layer.confirm("确定删除此项?", {
  96. icon: 3,
  97. title: "温馨提示",
  98. shadeClose: true
  99. }, function (index) {
  100. $.get($.fn.bootstrapTable.defaults.extend.del_url, {"ids":sid, "idx":nIndex}, function (data) {
  101. if (data.code) {
  102. var msg = data.msg != '' ? data.msg : '操作成功';
  103. Toastr.success(msg);
  104. table.bootstrapTable('refresh');
  105. } else {
  106. var msg = data.msg != '' ? data.msg : '操作失败';
  107. Toastr.error(msg);
  108. }
  109. layer.close(index);
  110. });
  111. }, function () {
  112. layer.close();
  113. });
  114. });
  115. //删除文字链消息列表整列
  116. $(document).on('click', '.btn-del-ajax', function () {
  117. var del_url = $(this).attr('data-href');
  118. layer.confirm("确定删除此项?", {
  119. icon: 3,
  120. title: "温馨提示",
  121. shadeClose: true
  122. }, function (index) {
  123. layer.close(index);
  124. $.get(del_url, {}, function (data) {
  125. if (data.code) {
  126. var msg = data.msg != '' ? data.msg : '操作成功';
  127. Toastr.success(msg);
  128. table.bootstrapTable('refresh');
  129. } else {
  130. var msg = data.msg != '' ? data.msg : '操作失败';
  131. Toastr.error(msg);
  132. }
  133. });
  134. }, function () {
  135. layer.close();
  136. });
  137. });
  138. // 打开详情页面
  139. $(document).on('click', '.btn-view-ajax', function () {
  140. Fast.api.open($(this).attr('data-href'), '查看详情', {});
  141. });
  142. //群发消息
  143. $(document).on('click', '.btn-multi-ajax', function () {
  144. var stxt = $(this).text();
  145. var multi_url = $(this).attr('data-href');
  146. Fast.api.open(multi_url, stxt, {
  147. callback: function (data) {
  148. if(!data) return false;
  149. var data = data[0];
  150. console.log(data);
  151. }
  152. });
  153. });
  154. //修改图文内容
  155. $(document).on('click','.anticon-novel-edit',function(){
  156. var $this=$(this);
  157. var nIndex = $this.parents('li').index();
  158. var sid = $this.data('id');
  159. $.ajax({
  160. type:'get',
  161. url:'messagecustom/linktextmedia/getMediaMessage?ids='+ sid + '&idx='+ nIndex,
  162. success:function(data){
  163. if(!data.code){
  164. Fast.api.open('custom/editlinktext?json=' + encodeURIComponent(data.data), '修改内容', {
  165. callback: function (data) {
  166. var data = data;
  167. $.ajax({
  168. type:'get',
  169. url:'messagecustom/linktextmedia/editLink?idx='+ nIndex +'&ids='+ sid + '&message_json=' + encodeURIComponent(JSON.stringify(data)),
  170. success:function(data){
  171. if(data.code == 0){
  172. Toastr.success('编辑成功');
  173. }else{
  174. Toastr.error('编辑失败');
  175. }
  176. }
  177. })
  178. }
  179. });
  180. }else{
  181. Toastr.error('编辑失败');
  182. }
  183. }
  184. })
  185. });
  186. },
  187. //图文客服消息 群发 订阅号 服务号
  188. multisendmessage: function () {
  189. var acc_type = $("#acc_type_hid").val(); // 标记:群发订阅号 群发服务号
  190. var media_id = $("#media_id").val();
  191. if(acc_type){
  192. //发送订阅号验证
  193. $("#add-form").data("validator-options", {
  194. ignore: ':hidden',
  195. beforeSubmit: function (form) {
  196. var senddyhradioval = $('#dyhradio input').val();
  197. var other_tips = $(":checked[name^='row[sub_id]']", $("#add-form"));
  198. if($('#dyhradio input').length){
  199. if(other_tips.length <= 0){
  200. Toastr.error("请选择需要发送的订阅号");
  201. return false;
  202. }
  203. if(senddyhradioval < other_tips.length){
  204. Toastr.error("最多可选择发送" + senddyhradioval + '个订阅号');
  205. return false;
  206. }
  207. }
  208. }
  209. });
  210. Controller.api.bindevent();
  211. }
  212. //测试发送
  213. $('.test_fans_but').click(function(){
  214. Custommain.fans_send_message();
  215. });
  216. },
  217. //查看详情
  218. viewdetail: function () {
  219. // 初始化表格参数配置
  220. Table.api.init({
  221. extend: {
  222. getimage_url: window.location.href,
  223. },
  224. search: false,
  225. showToggle: false,
  226. showColumns: false,
  227. showExport: false,
  228. commonSearch: false
  229. });
  230. var table = $("#table");
  231. //当表格数据加载完成时
  232. table.on('load-success.bs.table', function (e, data) {
  233. //这里可以获取从服务端获取的JSON数据
  234. //console.log(data);
  235. //这里我们手动设置底部的值
  236. //$("#money").text(data.extend.money);
  237. //$("#price").text(data.extend.price);
  238. });
  239. // 初始化表格
  240. table.bootstrapTable({
  241. url: $.fn.bootstrapTable.defaults.extend.getimage_url,
  242. pk: 'id',
  243. sortName: 'id',
  244. columns: [Controller.api.getimagelist(table)]
  245. });
  246. // 为表格绑定事件
  247. Table.api.bindevent(table);
  248. },
  249. api: {
  250. showFilterColumns: function (table) {
  251. var cols = new Array();
  252. cols.push({field: 'id', title: "素材ID", visible: false});
  253. cols.push({field: 'message_json$[*].book_name', title: "书籍名称", visible: false, operate: 'LIKE %...%'});
  254. cols.push({field: 'id', operate: false, formatter: Controller.api.formatter.showStyle});
  255. return cols;
  256. },
  257. getimagelist: function (table) {
  258. var cols = new Array();
  259. cols.push({field: 'title', title: "标题", operate: false});
  260. cols.push({field: 'type', title: "链接类型", operate: false, formatter: Controller.api.formatter.showType});
  261. cols.push({field: 'book_id', title: "书籍ID", operate: false});
  262. cols.push({field: 'book_name', title: "书籍名称/活动名称/菜单名称", operate: false});
  263. cols.push({field: '', title: "推广位置", operate: false, formatter: Controller.api.formatter.showPosition});
  264. cols.push({
  265. field: 'push',
  266. title: "推广类型",
  267. operate: false,
  268. formatter: Controller.api.formatter.showPushType
  269. });
  270. //cols.push({field: 'book_id', title:"阅读原文连接"});
  271. return cols;
  272. },
  273. bindevent: function () {
  274. Custommain.checkbox_relation('#dyhradio', '#dyhcheck');
  275. Form.api.bindevent($("form[role=form]"));
  276. //修改发送消息时间
  277. $(document).on('click','.s_time_box span',function(){
  278. var $this = $(this);
  279. var nval = parseInt($this.attr('stime'));
  280. var ntime = Date.parse(new Date());
  281. var nt = ntime + nval;
  282. $('#c-sendtime').val(GetRTime(nt));
  283. });
  284. function GetRTime(time){
  285. var stime;
  286. time = new Date(time);
  287. var year = time.getYear() + 1900;
  288. var month = time.getMonth()+1;
  289. var day = time.getDate();
  290. var hours = time.getHours();
  291. var minutes = time.getMinutes();
  292. var seconds = time.getSeconds();
  293. stime = year + '-' +
  294. (month < 10 ? '0'+month : month) + '-' +
  295. (day < 10 ? '0'+day : day) + ' ' +
  296. (hours < 10 ? '0'+hours : hours) + ':' +
  297. (minutes < 10 ? '0'+minutes : minutes) + ':' +
  298. (seconds < 10 ? '0'+seconds : seconds);
  299. return stime;
  300. }
  301. //关闭弹窗
  302. $(document).on('click', '.btn-close', function () {
  303. Fast.api.close();
  304. });
  305. },
  306. formatter: {
  307. showImage: function (value, row, index) {
  308. return '<img style="height:100px;" src="' + value + '"/>';
  309. },
  310. showType: function (value, row, index) {
  311. var type_arr = ['书籍', '活动', '继续阅读', '菜单'];
  312. return type_arr[value];
  313. },
  314. showPosition: function (value, row, index) {
  315. return index + 1;
  316. },
  317. showPushType: function (value, row, index) {
  318. var push_arr = ['外推', '内推'];
  319. return push_arr[value];
  320. },
  321. showStyle: function (value, row, index) {
  322. var message_data = JSON.parse(row.message_text);
  323. /*jshint multistr: true */
  324. var html = '<div class="wxb-card-list-scroll"><div class="wxb-card-item"><div class="wxb-card-item-inner"><div class="item-header"><div>';
  325. html += '<div class="tweets-card-title"><p>素材id:' + row.id + '</p></div>';
  326. html += '<div class="tweets-card-title"><p>创建时间:' + Table.api.formatter.datetime(row.createtime, row, index) + '</p></div>';
  327. html += '<div class="tweets-card-title"><p>修改时间:' + Table.api.formatter.datetime(row.updatetime, row, index) + '</p></div>';
  328. /*var offical_type = parseInt(row.official_account_type) == 1 ? '订阅号' : '服务号';
  329. var send_color = '';
  330. var send_text = '';
  331. switch (parseInt(row.status)) {
  332. case 0:
  333. send_color = 'red';
  334. send_text = '待发送';
  335. break;
  336. case 1:
  337. send_color = '#FF9900';
  338. send_text = '群发中';
  339. break;
  340. case 2:
  341. send_color = '#88d743';
  342. send_text = '已群发';
  343. break;
  344. }
  345. html += '<div class="tweets-card-title"><p style="color:' + send_color + '">发送时间:' + Table.api.formatter.datetime(row.sendtime, row, index) + ' ' + send_text + '</p></div>';
  346. html += '<div class="tweets-card-title"><p>群发类型:' + offical_type + '</p></div>';*/
  347. html += '</div></div><div class="img_txt_url"><ul>';
  348. var txtlis = '';
  349. for(var i=0; i<message_data.length; i++){
  350. var scolor = '';
  351. if(message_data[i]['type'] == 4) scolor = 'style="color:#333"';
  352. txtlis += '<li>\
  353. <p '+ scolor +'>' + message_data[i]['title'] + '</p>\
  354. <div class="img_txt_tip_box">\
  355. <i class="anticon anticon-novel-edit" style="font-size: 13px;" data-toggle="tooltip" data-original-title="编辑链接" data-id="'+row.id+'"></i>\
  356. <i class="anticon anticon-delete" data-toggle="tooltip" data-original-title="删除链接" data-id="'+row.id+'"></i>\
  357. </div>\
  358. </li>'
  359. }
  360. html += txtlis +'</ul></div><ul class="footer-btns">';
  361. html += '<li><a class="btn-del-ajax" href="javascript:void(0);" data-href="/admin/messagecustom/linktextmedia/del?table=media&ids=' + row.id + '">删除</a></li>';
  362. html += '<li><a class="btn-view-ajax" href="javascript:void(0);" data-href="/admin/messagecustom/linktextmedia/viewdetail?ids=' + row.id + '">查看详情</a></li>';
  363. html += '<li><a rel="popover" data-rowid="' + row.id + '">群发</a></li>';
  364. html += '</ul></div></div></div>';
  365. return html;
  366. }
  367. }
  368. }
  369. };
  370. return Controller;
  371. });