tpl.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'clipboard'], function ($, undefined, Backend, Table, Form, Clipboard) {
  2. function goodsShowStatus(type) {
  3. if (type == '1') {//书币充值
  4. $('.js_vip_group').addClass('hide');
  5. $('.js_kandian_group').removeClass('hide');
  6. } else if (type == '2') {//VIP充值
  7. $('.js_vip_group').removeClass('hide');
  8. $('.js_kandian_group').addClass('hide');
  9. }
  10. }
  11. function ajaxReturn(id) {
  12. var trigger;
  13. $.ajax({
  14. url: 'special/recharge/tpl/copy',
  15. data: {'tpl_id': id},
  16. type: 'post',
  17. async: false,
  18. success: function (res) {
  19. if (res.code == 1) {
  20. var stxt = res.data.url;
  21. trigger = document.querySelector('#many_copy_dom');
  22. $('#many_copy_dom').html(stxt);
  23. } else {
  24. Toastr.error(res.msg);
  25. }
  26. }
  27. });
  28. return trigger;
  29. }
  30. var clipboard = new Clipboard('.btn-operate-copy', {
  31. target: function (trigger) {
  32. var id = $(trigger).parent().parent().find('td').eq(1).text();
  33. return ajaxReturn(id);
  34. }
  35. });
  36. clipboard.on('success',function (data) {
  37. Toastr.success('复制成功');
  38. }).on('error',function (data) {
  39. Toastr.error('复制失败');
  40. });
  41. $(document).on('click', '.js_choose_goods', function () {
  42. Fast.api.open('goods/select?goods_category=activity&business_line=' + Config.business_line, '选择商品', {
  43. callback: function (data) {
  44. var goodsItem = data[0];
  45. $('.js_selected_goods_show_type_text').text(goodsItem.show_type_text);
  46. $('.js_selected_goods_type_text').text(goodsItem.type_text);
  47. $('.js_selected_goods_money').text(goodsItem.money);
  48. $('.js_selected_goods_kandian').text(goodsItem.kandian);
  49. $('.js_selected_goods_free_kandian').text(goodsItem.free_kandian);
  50. $('.js_selected_goods_icon').text(goodsItem.icon);
  51. $('.js_selected_goods_id').val(goodsItem.id);
  52. $('.js_selected_goods_free_day').text(goodsItem.free_day);
  53. $('.js_selected_goods_day').text(goodsItem.day);
  54. goodsShowStatus(goodsItem.type);
  55. }
  56. });
  57. });
  58. var Controller = {
  59. index: function () {
  60. // 初始化表格参数配置
  61. Table.api.init({
  62. extend: {
  63. index_url: 'special/recharge/tpl/index',
  64. add_url: 'special/recharge/tpl/add',
  65. edit_url: 'special/recharge/tpl/edit',
  66. del_url: 'special/recharge/tpl/del',
  67. multi_url: 'special/recharge/tpl/multi',
  68. table: 'special_recharge_tpl',
  69. }
  70. });
  71. var table = $("#table");
  72. // 初始化表格
  73. table.bootstrapTable({
  74. url: $.fn.bootstrapTable.defaults.extend.index_url,
  75. pk: 'id',
  76. sortName: 'id',
  77. columns: [
  78. [
  79. {checkbox: true},
  80. {field: 'id', title: __('Id')},
  81. {field: 'title', title: __('标题'), operate: 'LIKE %...%'},
  82. {field: 'goods_id', title: __('Goods_id')},
  83. {field: 'type', title: __('商品类型'), formatter: function (value, row) {
  84. return value == 1 ? "书币" : "VIP";
  85. }, operate:false},
  86. {field: 'money', title: __('金额'), operate:false},
  87. {field: 'kandian', title: __('书币'), operate:false},
  88. {field: 'free_kandian', title: __('免费书币'), operate:false},
  89. {field: 'day', title: __('VIP天数'), operate:false},
  90. {field: 'channel_id', title: __('Channel_id')},
  91. {field: 'cost', title: __('Cost'), operate:'BETWEEN'},
  92. {field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('status normal'),"hidden":__('status hidden')}},
  93. {field: 'status_text', title: __('Status'), operate:false},
  94. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:Controller.api.formatter.showChBtn()}
  95. ]
  96. ]
  97. });
  98. // 为表格绑定事件
  99. Table.api.bindevent(table);
  100. },
  101. add: function () {
  102. $("#add-form").data("validator-options", {
  103. ignore: ':hidden',
  104. beforeSubmit: function (form) {
  105. if ($("#c-goods_id").val() == '' || $("#c-goods_id").val() <= 0) {
  106. Toastr.error("请选择商品");
  107. return false;
  108. }
  109. if ($("#c-channel_id").val() == '' || $("#c-channel_id").val() <= 0) {
  110. Toastr.error("请填写渠道ID");
  111. $("#c-channel_id").focus();
  112. return false;
  113. }
  114. if ($(".js_vip_group").hasClass("hide")) {
  115. //看点
  116. if ($("#c-cost").val() == '' || $("#c-cost").val() <= 0) {
  117. Toastr.error("请填写原价");
  118. $("#c-cost").focus();
  119. return false;
  120. }
  121. }
  122. }
  123. });
  124. Controller.api.bindevent();
  125. },
  126. edit: function () {
  127. goodsType = $('.js_selected_goods_type').val();
  128. goodsShowStatus(goodsType);
  129. window.canSubmit = false;
  130. $("#edit-form").data("validator-options", {
  131. ignore: ':hidden',
  132. beforeSubmit: function (form) {
  133. console.log($(this));
  134. if (window.canSubmit) {
  135. return true;
  136. }
  137. if ($("#c-goods_id").val() == '' || $("#c-goods_id").val() <= 0) {
  138. Toastr.error("请选择商品");
  139. return false;
  140. }
  141. if ($("#c-channel_id").val() == '' || $("#c-channel_id").val() <= 0) {
  142. Toastr.error("请填写渠道ID");
  143. $("#c-channel_id").focus();
  144. return false;
  145. }
  146. if ($(".js_vip_group").hasClass("hide")) {
  147. //看点
  148. if ($("#c-cost").val() == '' || $("#c-cost").val() <= 0) {
  149. Toastr.error("请填写原价");
  150. $("#c-cost").focus();
  151. return false;
  152. }
  153. }
  154. //弹出提示
  155. layer.confirm('当前活动正在进行中,如果编辑可能会影响进行中的活动,是否编辑?', {title: "确定编辑"}, function (index) {
  156. layer.close(index);
  157. window.canSubmit = true;
  158. $("form").submit();
  159. }, function (index) {
  160. layer.close(index);
  161. });
  162. return false;
  163. }
  164. });
  165. Controller.api.bindevent();
  166. },
  167. api: {
  168. bindevent: function () {
  169. Form.api.bindevent($("form[role=form]"));
  170. },
  171. formatter: {
  172. showChBtn: function(){
  173. return [
  174. {
  175. name: 'copy_url',
  176. text: '复制链接',
  177. title: '复制链接',
  178. classname: 'btn btn-click btn-operate-copy',
  179. icon: 'fa fa-copy copy',
  180. }
  181. ];
  182. },
  183. }
  184. }
  185. };
  186. return Controller;
  187. });