goods.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. $(document).on('click', '#add_goods', function () {
  3. Fast.api.open('goods/select', '选择商品', {
  4. callback: function (data) {
  5. console.log(data);
  6. var goodsItem = data[0];
  7. var htmlstr = '<div><input type="hidden" name="row[goods_id][]" value="' + goodsItem.id + '"> ' +
  8. goodsItem.id +
  9. '<div>' + goodsItem.title + '</div>' +
  10. '<div>' + goodsItem.money + '</div>' +
  11. '<div>' + goodsItem.first_description + '</div>' +
  12. '<div>' + goodsItem.second_description + '</div>' +
  13. '<div>' + goodsItem.kandian + '</div>' +
  14. '<div>' + goodsItem.free_kandian + '</div>' +
  15. '<div>' + goodsItem.icon + '</div>' +
  16. '<div>' + goodsItem.show_type_text + '</div>' +
  17. '<div>--------</div>' +
  18. '</div>';
  19. $('#goods_list').append(htmlstr);
  20. }
  21. })
  22. });
  23. //活动赠送书币展示处理 选择分类
  24. $(document).on('change','input[name="row[category_id][]"]',function(){
  25. var category_selected = new Array();
  26. $('input[name="row[category_id][]"]:checked').each(function(){
  27. category_selected.push($(this).data('nickname'));
  28. });
  29. if( $.inArray('activity',category_selected) >= 0&& parseInt($('input[name="row[type]"]:checked').val()) == 1){
  30. $('.free_day').show();
  31. }else{
  32. $('.free_day').hide();
  33. }
  34. });
  35. //活动赠送书币展示处理 选择商品类型
  36. $(document).on('click','input[name="row[type]"]',function(){
  37. var type = $("input[name='row[type]']:checked").val();
  38. if(type==2){
  39. $('.day').removeAttr('style');
  40. $('.kandian').css('display','none');
  41. }
  42. if(type==1){
  43. $('.kandian').removeAttr('style');
  44. $('.day').css('display','none');
  45. }
  46. var category_selected = new Array();
  47. $('input[name="row[category_id][]"]:checked').each(function(){
  48. category_selected.push($(this).data('nickname'));
  49. });
  50. if( $.inArray('activity',category_selected) >= 0 && parseInt($('input[name="row[type]"]:checked').val()) == 1){
  51. $('.free_day').show();
  52. }else{
  53. $('.free_day').hide();
  54. }
  55. });
  56. var Controller = {
  57. index: function () {
  58. // 初始化表格参数配置
  59. Table.api.init({
  60. extend: {
  61. index_url: 'goods/index',
  62. add_url: 'goods/add',
  63. edit_url: 'goods/edit',
  64. del_url: 'goods/del',
  65. multi_url: 'goods/multi',
  66. table: 'goods',
  67. },
  68. showToggle:false,
  69. showColumns:false,
  70. showExport:false,
  71. searchFormVisible: true,
  72. });
  73. var table = $("#table");
  74. // 初始化表格
  75. table.bootstrapTable({
  76. url: $.fn.bootstrapTable.defaults.extend.index_url,
  77. pk: 'id',
  78. sortName: 'weigh',
  79. columns: [
  80. [
  81. {checkbox: true},
  82. {field: 'id', title: __('Id'),operate:false},
  83. {field: 'title', title: __('Title'),operate:false},
  84. {field: 'business_line', title: "业务线",searchList: Controller.api.formatter.business_search(),formatter: Controller.api.formatter.business_name,operate:'LIKE'},
  85. {field: 'category_id', title: __('Category_name'),searchList: $.getJSON('goods/categorylist'),formatter: Controller.api.formatter.category_name,operate:'LIKE'},
  86. {field: 'money', title: __('Money'),operate:false},
  87. {field: 'first_description', title: __('First_description'),operate:false},
  88. {field: 'second_description', title: __('Second_description'),operate:false},
  89. {field: 'type_text', title: __('Type'), operate:false},
  90. {field: 'kandian', title: __('Kandian'),operate:false},
  91. {field: 'free_kandian', title: __('Free_kandian'),operate:false},
  92. {field: 'day', title: __('Day'),operate:false},
  93. {field: 'icon', title: __('Icon'),operate:false},
  94. {field: 'show_type_text', title: __('Show_type'), operate:false},
  95. {field: 'weigh', title: __('Weigh'),operate:false},
  96. {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime,operate:false},
  97. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  98. ]
  99. ]
  100. });
  101. // 为表格绑定事件
  102. Table.api.bindevent(table);
  103. Controller.api.bindevent();
  104. },
  105. select: function () {
  106. Table.api.init({
  107. extend: {
  108. index_url: 'goods/select' + '?goods_category=' + Config.goods_category,
  109. add_url: 'goods/add',
  110. edit_url: 'goods/edit',
  111. del_url: 'goods/del',
  112. multi_url: 'goods/multi',
  113. table: 'goods',
  114. },
  115. showToggle: false,
  116. showColumns: false,
  117. showExport: false,
  118. searchFormVisible: true,
  119. search: false,
  120. commonSearch:true,
  121. });
  122. var table = $("#table");
  123. //快捷充值需要过滤已充值未充值
  124. var searchListTmp = {'0':'全部用户','1':'已充值用户','2':'未充值用户'};
  125. var recharge_show_type = Fast.api.query('recharge_show_type');
  126. if(recharge_show_type != "undefined"){
  127. if(recharge_show_type == -1){
  128. searchListTmp = {'0':'全部用户','1':'已充值用户'};
  129. }else if(recharge_show_type == -2){
  130. searchListTmp = {'0':'全部用户','2':'未充值用户'};
  131. }
  132. }
  133. // 初始化表格
  134. table.bootstrapTable({
  135. queryParams: function (params) { //自定义搜索条件
  136. params.selected_ids = Fast.api.query('selected_ids');
  137. params.recharge_show_type = Fast.api.query('recharge_show_type');
  138. params.business_line = Config.business_line;
  139. return params;
  140. },
  141. url: $.fn.bootstrapTable.defaults.extend.index_url,
  142. pk: 'id',
  143. sortName: 'weigh',
  144. columns: [
  145. [
  146. {field: 'title', title: __('Title'), operate: false},
  147. // {field: 'business_line', title: "业务线",searchList: Controller.api.formatter.business_search(),formatter: Controller.api.formatter.business_name,operate:'LIKE'},
  148. // {field: 'category_id', title: __('Category_name'),searchList: $.getJSON('goods/categorylist'),formatter: Controller.api.formatter.category_name,operate:'LIKE'},
  149. {field: 'money', title: __('Money'), operate: false},
  150. {field: 'first_description', title: __('First_description'), operate: false},
  151. {field: 'second_description', title: __('Second_description'), operate: false},
  152. {field: 'type_text', title: __('Type'), operate: false},
  153. {field: 'kandian', title: __('Kandian'), operate: false},
  154. {field: 'free_kandian', title: __('Free_kandian'), operate: false},
  155. {field: 'icon', title: __('Icon'), operate: false},
  156. {field: 'show_type', title: __('Show_type'),visible:false,searchList:searchListTmp},
  157. {field: 'show_type_text', title: __('Show_type'), operate: false},
  158. {
  159. field: 'operate', title: __('Operate'), events: {
  160. 'click .btn-chooseone': function (e, value, row, index) {
  161. Fast.api.close([row]);
  162. },
  163. }, formatter: function () {
  164. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  165. }
  166. }
  167. ]
  168. ]
  169. });
  170. // 为表格绑定事件
  171. Table.api.bindevent(table);
  172. Controller.api.bindevent();
  173. },
  174. add: function () {
  175. Controller.api.bindevent();
  176. },
  177. edit: function () {
  178. Controller.api.bindevent();
  179. },
  180. api: {
  181. bindevent: function () {
  182. Form.api.bindevent($("form[role=form]"));
  183. },
  184. formatter: {
  185. business_search:function(){
  186. var search = {}
  187. for (var key in Config.business) {
  188. search[key] = Config.business[key];
  189. }
  190. return search;
  191. },
  192. business_name:function(value, row, index){
  193. var c_name = [];
  194. $.each(Config.business,function(c_key,c_val){
  195. var ids = row.business_line.split(',');
  196. if(ids != undefined){
  197. $.each(ids,function(_,r_val){
  198. if(parseInt(c_key) == parseInt(r_val)){
  199. c_name.push(c_val);
  200. }
  201. });
  202. }else{
  203. if(parseInt(c_key) == parseInt(row.business_line)){
  204. c_name.push(c_val);
  205. }
  206. }
  207. });
  208. return c_name.join(',');
  209. },
  210. category_name:function (value, row, index) {
  211. var c_name = [];
  212. $.each(Config.category_list,function(_,c_val){
  213. var ids = row.category_id.split(',');
  214. $.each(ids,function(_,r_val){
  215. if(c_val.id == r_val){
  216. c_name.push(c_val.name);
  217. }
  218. });
  219. });
  220. return c_name.join(',');
  221. }
  222. }
  223. }
  224. };
  225. return Controller;
  226. });