blockresource.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'adminlte'], function ($, undefined, Backend, Table, Form, Adminlte) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'clientmanage/bookcity/blockresource/index',
  8. add_url: 'clientmanage/bookcity/blockresource/add?block_id='+Config.block_id+'&page_id='+Config.page_id,
  9. edit_url: 'clientmanage/bookcity/blockresource/edit?block_id='+Config.block_id+'&page_id='+Config.page_id,
  10. del_url: 'clientmanage/bookcity/blockresource/del?block_id='+Config.block_id+'&page_id='+Config.page_id,
  11. },
  12. showToggle:false,
  13. showColumns:false,
  14. showExport:false
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'weigh',
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: __('Id')},
  26. {field: 'block_id', title: __('Block_id')},
  27. {field: 'image', title: __('Image'), formatter: Table.api.formatter.image},
  28. {field: 'type_text', title: __('Type'), operate:false},
  29. {field: 'book.name', title: __('Book_name')},
  30. //{field: 'activity.name', title: __('Book_name')},
  31. {field: 'url', title: __('Url'), formatter: Table.api.formatter.url},
  32. {field: 'free_stime', title: __('Free_stime'), formatter: Table.api.formatter.datetime},
  33. {field: 'free_etime', title: __('Free_etime'), formatter: Table.api.formatter.datetime},
  34. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
  35. {field: 'weigh', title: __('Weigh')},
  36. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  37. ]
  38. ],
  39. onPostBody:function () {
  40. $(".btn-dragsort").hide();
  41. }
  42. });
  43. // 为表格绑定事件
  44. Table.api.bindevent(table);
  45. Controller.api.bindevent();
  46. },
  47. add: function () {
  48. var blockType = $("#c-block_id").find("option:selected").data('option-type');
  49. if (blockType == 11) {
  50. $(".image").remove();
  51. }
  52. Controller.api.bindevent();
  53. Controller.api.onload();
  54. },
  55. edit: function () {
  56. Controller.api.bindevent();
  57. Controller.api.onload();
  58. $("#c-activity_id").val(Config.row.client_activity_id);
  59. var blockType = $("#c-block_id").find("option:selected").data('option-type');
  60. var type = Config.row.type;
  61. if (blockType == 11) {
  62. //活动运营位
  63. if(type==1){
  64. $('.book').removeClass('hide');
  65. $('.url').addClass('hide');
  66. $('.activity').addClass('hide');
  67. }
  68. if(type==2){
  69. $('.book').addClass('hide');
  70. $('.url').removeClass('hide');
  71. $('.activity').addClass('hide');
  72. }
  73. if(type==3){
  74. $('.book').addClass('hide');
  75. $('.url').addClass('hide');
  76. $('.activity').addClass('hide');
  77. }
  78. if(type==4){
  79. $('.book').addClass('hide');
  80. $('.url').addClass('hide');
  81. $('.activity').removeClass('hide');
  82. }
  83. } else {
  84. if(type==1){
  85. $('.book').removeClass('hide');
  86. $('.url').addClass('hide');
  87. $('.activity').addClass('hide');
  88. }
  89. if(type==2){
  90. $('.book').addClass('hide');
  91. $('.url').removeClass('hide');
  92. $('.activity').addClass('hide');
  93. }
  94. if(type==3){
  95. $('.book').addClass('hide');
  96. $('.url').addClass('hide');
  97. $('.activity').addClass('hide');
  98. }
  99. if(type==4){
  100. $('.book').addClass('hide');
  101. $('.url').addClass('hide');
  102. $('.activity').removeClass('hide');
  103. }
  104. }
  105. },
  106. api: {
  107. bindevent: function () {
  108. $("#add-form, #edit-form").data("validator-options", {
  109. ignore: ':hidden',
  110. beforeSubmit: function (form) {
  111. var blockType = $("#c-block_id").find("option:selected").data('option-type');
  112. if (blockType == 11) {
  113. if ($("#c-activity_title").val() == '') {
  114. Toastr.error("请填写活动文案");
  115. return false;
  116. }
  117. var type = $(".resource_type:checked").val();
  118. if (type == 1) {
  119. if ($("#c-book_id").val() == '') {
  120. Toastr.error("请选择书籍");
  121. return false;
  122. }
  123. }
  124. if (type == 2) {
  125. if ($("#c-url").val() == '') {
  126. Toastr.error("请填写url");
  127. return false;
  128. }
  129. }
  130. if (type == 4) {
  131. if ($("#c-activity_id").val() == null) {
  132. Toastr.error("请选择活动");
  133. return false;
  134. }
  135. }
  136. } else {
  137. if ($("#c-image").val() == '') {
  138. Toastr.error("请上传图片");
  139. return false;
  140. }
  141. if (type == 1) {
  142. if ($("#c-book_id").val() == '') {
  143. Toastr.error("请选择书籍");
  144. return false;
  145. }
  146. }
  147. if (type == 2) {
  148. if ($("#c-url").val() == '') {
  149. Toastr.error("请填写url");
  150. return false;
  151. }
  152. }
  153. if (type == 4) {
  154. if ($("#c-activity_id").val() == null) {
  155. Toastr.error("请选择活动");
  156. return false;
  157. }
  158. }
  159. }
  160. return true;
  161. }
  162. });
  163. Form.api.bindevent($("form[role=form]"));
  164. var refreshkey = function (data) {
  165. Layer.closeAll();
  166. $('#c-book_id_text').val(data[0].id);
  167. $('#c-book_id').val(data[0].id);
  168. $('#c-image').val(data[0].image);
  169. $('#c-image').trigger('change');
  170. $('#c-book_id_text').trigger('change');
  171. };
  172. $(document).on("click", ".resource_type", function () {
  173. var type = $("input[name='row[type]']:checked").val();
  174. var blockType = $("#c-block_id").find("option:selected").data('option-type');
  175. if (blockType == 11) {
  176. //活动运营位
  177. if(type==1){
  178. $('.book').removeClass('hide');
  179. $('.url').addClass('hide');
  180. $('.activity').addClass('hide');
  181. }
  182. if(type==2){
  183. $('.book').addClass('hide');
  184. $('.url').removeClass('hide');
  185. $('.activity').addClass('hide');
  186. }
  187. if(type==3){
  188. $('.book').addClass('hide');
  189. $('.url').addClass('hide');
  190. $('.activity').addClass('hide');
  191. }
  192. if(type==4){
  193. $('.book').addClass('hide');
  194. $('.url').addClass('hide');
  195. $('.activity').removeClass('hide');
  196. }
  197. } else {
  198. if(type==1){
  199. $('.book').removeClass('hide');
  200. $('.url').addClass('hide');
  201. $('.activity').addClass('hide');
  202. }
  203. if(type==2){
  204. $('.book').addClass('hide');
  205. $('.url').removeClass('hide');
  206. $('.activity').addClass('hide');
  207. }
  208. if(type==3){
  209. $('.book').addClass('hide');
  210. $('.url').addClass('hide');
  211. $('.activity').addClass('hide');
  212. }
  213. if(type==4){
  214. $('.book').addClass('hide');
  215. $('.url').addClass('hide');
  216. $('.activity').removeClass('hide');
  217. }
  218. }
  219. });
  220. var refreshactkey = function (data) {
  221. Layer.closeAll();
  222. $('#c-activity_id').val(data[0].id);
  223. $('#c-client_activity_name').val(data[0].name);
  224. };
  225. $(document).on('click', "#select-resources", function () {
  226. var block_id = Config.block_id;
  227. parent.Backend.api.open($(this).attr("href") + "?action=blockresoure&state=1&block_id=" + block_id, __('Select'), {callback: refreshkey});
  228. return false;
  229. });
  230. $(document).on("change", "#c-block_id", function () {
  231. var type = $(this).find("option:selected").data('option-type');
  232. Controller.api.showTypeOptions(type);
  233. });
  234. $(document).on('click', "#select-activity-resources", function () {
  235. parent.Backend.api.open($(this).attr("href") + "?type=2&action=blockresoure&state=1", __('Select'), {callback: refreshactkey});
  236. return false;
  237. });
  238. },
  239. onload: function () {
  240. var type = $("#c-block_id").find("option:selected").data('option-type');
  241. this.showTypeOptions(type);
  242. },
  243. showTypeOptions: function (type) {
  244. if (type == 11) {
  245. //运营位
  246. $('.activity_title').removeClass('hide');
  247. $('.image').addClass('hide');
  248. $('.url').addClass('hide');
  249. $('.activity').addClass('hide');
  250. } else {
  251. $('.activity_title').addClass('hide');
  252. $('.image').removeClass('hide');
  253. $('.url').addClass('hide');
  254. $('.activity').addClass('hide');
  255. }
  256. }
  257. }
  258. };
  259. return Controller;
  260. });