manage.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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: 'ad/manage/index',
  8. add_url: 'ad/manage/add',
  9. edit_url: 'ad/manage/edit',
  10. del_url: 'ad/manage/del',
  11. multi_url: 'ad/manage/multi',
  12. table: 'ad_manage',
  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'), operate: false},
  25. {field: 'name', title: __('Name'), operate: 'like'},
  26. {
  27. field: 'ad_type',
  28. title: __('Ad_type'),
  29. searchList: {'0': 'Banner广告', '1': '插屏广告', '2': '福利广告'},
  30. formatter: function (value) {
  31. if (value == 2) {
  32. return '福利广告';
  33. } else if (value == 1) {
  34. return '插屏广告';
  35. } else {
  36. return 'Banner广告';
  37. }
  38. }
  39. },
  40. {
  41. field: 'show_type', title: __('Show_type'), searchList: {'0': '不可轮播', '1': '可轮播'},
  42. formatter: function (value) {
  43. if (value) {
  44. return '可轮播';
  45. } else {
  46. return '不可轮播';
  47. }
  48. }
  49. },
  50. {field: 'chapter_num', title: __('间隔章节数(阅读器插屏位置)'), operate: false},
  51. {field: 'show_starttime', title: __('Show_starttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  52. {field: 'show_endtime', title: __('Show_endtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  53. {field: 'group_name', title: __('User_group_name'), operate: false},
  54. {field: 'weight', title: __('Weight'), operate: false},
  55. {
  56. field: 'state',
  57. title: __('State'),
  58. searchList: {'0': '失效', '1': '有效'},
  59. formatter: function (value) {
  60. if (value) {
  61. return '有效';
  62. } else {
  63. return '失效';
  64. }
  65. }
  66. },
  67. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Controller.api.formatter.operate}
  68. ]
  69. ]
  70. });
  71. // 为表格绑定事件
  72. Table.api.bindevent(table);
  73. $(document).on('click','.btn-usergroup',function (event) {
  74. var ad_manage_id = $(this).data('id');
  75. Fast.api.open('ad/user/group/viewgroup', '关联用户组', {
  76. callback: function (data) {
  77. var user_group_id = data[0]['id'];
  78. $.ajax({
  79. type:'post',
  80. url:'/admin/ad/manage/ajaxsaveusergroup',
  81. data:{
  82. 'ad_id': ad_manage_id,
  83. 'user_group_id': user_group_id,
  84. },
  85. dataType:'json',
  86. cache:false,
  87. async:false,
  88. success:function(data){
  89. if (data.code == 1){
  90. Toastr.error(data.msg);
  91. };
  92. if(data.code == 0){
  93. Toastr.success(data.msg);
  94. }
  95. }
  96. });
  97. }
  98. });
  99. return false;
  100. });
  101. //批量生效
  102. $('.btn-batch-validate').on('click', function () {
  103. var ids = Table.api.selectedids(table);
  104. Layer.confirm(
  105. '确定要把选中的' + ids.length + '项改为生效吗?',
  106. { icon: 3, title: __('Warning'), offset: 0, shadeClose: true },
  107. function () {
  108. $.ajax({
  109. url: '/admin/ad/manage/batchvalidate',
  110. type: "post",
  111. data: {
  112. ids: ids,
  113. state: 1
  114. },
  115. success: function () {
  116. layer.msg('操作成功');
  117. table.bootstrapTable('refresh');
  118. }
  119. });
  120. }
  121. );
  122. });
  123. //批量失效
  124. $('.btn-batch-invalidate').on('click', function () {
  125. var ids = Table.api.selectedids(table);
  126. Layer.confirm(
  127. '确定要把选中的' + ids.length + '项改为失效吗?',
  128. { icon: 3, title: __('Warning'), offset: 0, shadeClose: true },
  129. function () {
  130. $.ajax({
  131. url: '/admin/ad/manage/batchvalidate',
  132. type: "post",
  133. data: {
  134. ids: ids,
  135. state: 0
  136. },
  137. success: function () {
  138. layer.msg('操作成功');
  139. table.bootstrapTable('refresh');
  140. }
  141. });
  142. }
  143. );
  144. });
  145. // 更新所有缓存
  146. $(".btn-update-cache").click(function () {
  147. $.ajax({
  148. type:'post',
  149. url:'/admin/ad/manage/ajaxupdatecache',
  150. dataType:'json',
  151. cache:false,
  152. async:false,
  153. success:function(data){
  154. if (data.code == 1){
  155. Toastr.error(data.msg);
  156. };
  157. if(data.code == 0){
  158. Toastr.success(data.msg);
  159. }
  160. }
  161. });
  162. });
  163. },
  164. add: function () {
  165. Controller.api.bindevent();
  166. $('#c-ad_type').change(function () {
  167. var type = $(this).val(); // type= 2=> 福利广告 1 => 插屏广告 0 => banner广告
  168. if (type == 2) {
  169. $(".show-all-chapter-num").hide();
  170. $(".show_position_zone").hide();
  171. $(".welfare-zone").show();
  172. $("#show_position-2").show();
  173. $("#show_position-1").hide();
  174. $("#show_position-0").hide();
  175. $("#show_type").hide();
  176. } else if (type == 1) {
  177. if ($(".chapter-screen").is(":checked")) {
  178. $(".show-all-chapter-num").show();
  179. }
  180. $(".show_position_zone").show();
  181. $(".welfare-zone").hide();
  182. $("#show_position-2").hide();
  183. $("#show_position-1").show();
  184. $("#show_position-0").hide();
  185. $("#show_type").hide();
  186. } else {
  187. $(".show-all-chapter-num").hide();
  188. $(".show_position_zone").show();
  189. $(".welfare-zone").hide();
  190. $("#show_position-0").show();
  191. $("#show_position-1").hide();
  192. $("#show_position-2").hide();
  193. $("#show_type").show();
  194. }
  195. });
  196. // 勾选 阅读器插屏
  197. $(".read-screen").change(function () {
  198. if ($(this).is(":checked")) {
  199. $(".show-chapter-num").show();
  200. } else {
  201. $(".show-chapter-num").hide();
  202. }
  203. });
  204. // 勾选 阅读页插屏(整章)
  205. $(".chapter-screen").change(function () {
  206. if ($(this).is(":checked")) {
  207. $(".show-all-chapter-num").show();
  208. } else {
  209. $(".show-all-chapter-num").hide();
  210. }
  211. });
  212. },
  213. edit: function () {
  214. Controller.api.bindevent();
  215. $('#c-ad_type').change(function () {
  216. var type = $(this).val(); // type= 2=> 福利广告 1 => 插屏广告 0 => banner广告
  217. if (type == 2) {
  218. $(".show-all-chapter-num").hide();
  219. $(".show_position_zone").hide();
  220. $(".welfare-zone").show();
  221. $("#show_position-2").show();
  222. $("#show_position-1").hide();
  223. $("#show_position-0").hide();
  224. $("#show_type").hide();
  225. } else if (type == 1) {
  226. if ($(".chapter-screen").is(":checked")) {
  227. $(".show-all-chapter-num").show();
  228. }
  229. $(".show_position_zone").show();
  230. $(".welfare-zone").hide();
  231. $("#show_position-2").hide();
  232. $("#show_position-1").show();
  233. $("#show_position-0").hide();
  234. $("#show_type").hide();
  235. } else {
  236. $(".show-all-chapter-num").hide();
  237. $(".show_position_zone").show();
  238. $(".welfare-zone").hide();
  239. $("#show_position-0").show();
  240. $("#show_position-1").hide();
  241. $("#show_position-2").hide();
  242. $("#show_type").show();
  243. }
  244. });
  245. // 勾选 阅读器插屏
  246. $(".read-screen").change(function () {
  247. if ($(this).is(":checked")) {
  248. $(".show-chapter-num").show();
  249. } else {
  250. $(".show-chapter-num").hide();
  251. }
  252. });
  253. // 勾选 阅读页插屏(整章)
  254. $(".chapter-screen").change(function () {
  255. if ($(this).is(":checked")) {
  256. $(".show-all-chapter-num").show();
  257. } else {
  258. $(".show-all-chapter-num").hide();
  259. }
  260. });
  261. },
  262. api: {
  263. formatter: {
  264. operate: function (value, row, index) {
  265. var html = '';
  266. html += '<a href="/admin/ad/manage/edit/ids/' + row.id + '" class="btn btn-xs btn-success btn-editone" title="" data-table-id="table" data-field-index="8" data-row-index="0" data-button-index="1"><i class="fa fa-pencil"></i></a>';
  267. html += '<a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="" data-table-id="table" data-field-index="8" data-row-index="0" data-button-index="2"><i class="fa fa-trash"></i></a>';
  268. html += '<a href="/admin/ad/user/group/viewgroup" class="btn btn-xs btn-success btn-usergroup" data-id="' + row.id + '" title="">关联用户组</a>';
  269. return html;
  270. }
  271. },
  272. bindevent: function () {
  273. Form.api.bindevent($("form[role=form]"));
  274. }
  275. }
  276. };
  277. return Controller;
  278. });