lightrule.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'manage/lightrule/index',
  8. add_url: 'manage/lightrule/add',
  9. edit_url: 'manage/lightrule/edit',
  10. del_url: 'manage/lightrule/del',
  11. multi_url: 'manage/lightrule/multi',
  12. table: 'config_light_rule',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. columns: [
  22. [
  23. {checkbox: true},
  24. {field: 'id', title: __('ID')},
  25. {field: 'name', title: __('Name')},
  26. // {field: 'city_ids', title: __('City_ids')},
  27. // {field: 'channel_ids', title: __('Channel_ids')},
  28. {
  29. field: 'id',
  30. operate:false,
  31. title: __('关联渠道'),
  32. formatter: Controller.api.formatter.fm_associate_channels
  33. },
  34. {
  35. field: 'id',
  36. operate:false,
  37. title: __('一键清除'),
  38. formatter: function (index, row, value) {
  39. return "<a href='javascript:;' class='qd-associate-all' data-rule_id='" + index + "' data-channel_id='"+ row.channel_id+"'>清除所有渠道</a>";
  40. }
  41. },
  42. {field: 'push_type', title: __('Code'), formatter: Controller.api.formatter.pushType,operate:false},
  43. {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  44. {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  45. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  46. ]
  47. ]
  48. });
  49. //一键清除
  50. $(document).on('click', '.qd-associate-all', function () {
  51. var rule_id = $(this).data("rule_id");
  52. Layer.confirm(
  53. '确定要清理所有渠道吗',
  54. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  55. function (index) {
  56. $.post('/admin/manage/lightrule/operate',
  57. {
  58. 'id': rule_id,
  59. 'channel_ids': "*",
  60. 'method': 'remove'
  61. },
  62. function (result) {
  63. if (result.code == 1) {
  64. Toastr.success('操作成功');
  65. //刷新页面
  66. table.bootstrapTable('refresh');
  67. } else {
  68. Toastr.error(result.msg);
  69. }
  70. });
  71. Layer.close(index);
  72. }
  73. );
  74. });
  75. // 列表关联
  76. $(document).on('click', '.qd-associate', function () {
  77. var rule_id = $(this).data("rule_id");
  78. var channel_ids = $(this).data("channel_id");
  79. if (channel_ids == 'undefined') {
  80. channel_ids = '';
  81. }
  82. Fast.api.open('/admin/auth/channel/select?operate=add&type=3&group_ids=3&source_id=' + rule_id, "关联渠道", {callback: function (data) {
  83. $.post('/admin/manage/lightrule/operate',
  84. {
  85. 'id': rule_id,
  86. 'channel_ids': data,
  87. 'method': 'add'
  88. },
  89. function (result) {
  90. if (result.code == 1) {
  91. Toastr.success('操作成功');
  92. //刷新页面
  93. table.bootstrapTable('refresh');
  94. } else {
  95. Toastr.error(result.msg);
  96. }
  97. });
  98. }
  99. });
  100. });
  101. // 列表 查看
  102. $(document).on('click', '.qd-view', function () {
  103. var rule_id = $(this).data("rule_id");
  104. var channel_ids = $(this).data("channel_id");
  105. if (channel_ids == 'undefined') {
  106. channel_ids = '';
  107. }
  108. Fast.api.open('/admin/auth/channel/select?operate=remove&type=3&group_ids=3&source_id=' + rule_id, "关联渠道", {callback: function (data) {
  109. $.post('/admin/manage/lightrule/operate',
  110. {
  111. 'id': rule_id,
  112. 'channel_ids': data,
  113. 'method': 'remove'
  114. },
  115. function (result) {
  116. if (result.code == 1) {
  117. Toastr.success('操作成功');
  118. //刷新页面
  119. table.bootstrapTable('refresh');
  120. } else {
  121. Toastr.error(result.msg);
  122. }
  123. });
  124. }
  125. });
  126. });
  127. $(document).on("click", ".qd-edit", function () {
  128. var rule_id = $(this).data("rule_id");
  129. var channel_ids = $(this).data("channel_id");
  130. if (channel_ids == 'undefined') {
  131. channel_ids = '';
  132. }
  133. layer.open({
  134. type: 1,
  135. title: '批量关联',
  136. maxmin: true,
  137. area: ['60%', '80%'],
  138. btn: ['确定', '取消'],
  139. shadeClose: true, //点击遮罩关闭层
  140. content: $("#qd_multi_edit"),
  141. yes: function (data) {
  142. var channel_ids = $("#c-channel_id").val();
  143. $("#c-channel_id").val("");
  144. $.post('/admin/manage/lightrule/operate',
  145. {
  146. 'id': rule_id,
  147. 'channel_ids': channel_ids,
  148. 'method': 'add'
  149. },
  150. function (result) {
  151. // aResult = JSON.parse(result);
  152. if (result.code == 1) {
  153. Toastr.success('操作成功');
  154. //刷新页面
  155. table.bootstrapTable('refresh');
  156. } else {
  157. Toastr.error(result.msg);
  158. }
  159. });
  160. layer.closeAll();
  161. }
  162. });
  163. });
  164. $('.btn-refresh-cache').click(function () {
  165. $.get('/admin/manage/lightrule/refreshcache', {}, function (result) {
  166. if (result.code == 1) {
  167. Toastr.success('操作成功');
  168. } else {
  169. Toastr.error(result.msg);
  170. }
  171. });
  172. });
  173. // 为表格绑定事件
  174. Table.api.bindevent(table);
  175. },
  176. add: function () {
  177. Controller.api.bindevent();
  178. },
  179. edit: function () {
  180. Controller.api.bindevent();
  181. },
  182. api: {
  183. bindevent: function () {
  184. Form.api.bindevent($("form[role=form]"));
  185. },
  186. formatter: {
  187. fm_associate_channels:function (value, row, index) {
  188. html = '';
  189. if(row.channel_ids == '*'){
  190. html += "已关联所有渠道";
  191. }else{
  192. html += "<a href='javascript:;' class='qd-associate' data-rule_id='" + value + "' data-channel_id='"+ row.channel_ids+"'>关联</a>&nbsp;&nbsp;";
  193. html += "<a href='javascript:;' class='qd-view' data-rule_id='" + value + "' data-channel_id='"+ row.channel_ids+"'>查看</a>&nbsp;&nbsp;";
  194. // html += "<a href='javascript:;' class='qd-edit' data-rule_id='" + value + "' data-channel_id='"+ row.channel_ids+"'>批量关联</a>";
  195. }
  196. return html;
  197. },
  198. pushType: function (value) {
  199. if (value == 0) {
  200. return '全部书籍';
  201. } else if (value == 1) {
  202. return '清水书籍';
  203. }
  204. // else if (value == 2) {
  205. // return '限定城市推送清水书籍';
  206. // }
  207. }
  208. }
  209. }
  210. };
  211. return Controller;
  212. });