product.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 : 'qingdongams/product/product/index',
  8. add_url : 'qingdongams/product/product/add',
  9. detail_url : 'qingdongams/product/product/detail',
  10. del_url : 'qingdongams/product/product/del',
  11. table : 'product',
  12. }
  13. });
  14. var table = $("#table");
  15. var q = {};
  16. location.search.replace(/([^?&=]+)=([^&]+)/g,(_,k,v)=>q[k]=v);
  17. var isselect=false;
  18. if (q.isselect == 1) {
  19. isselect= true;
  20. }
  21. // 初始化表格
  22. table.bootstrapTable({
  23. url : $.fn.bootstrapTable.defaults.extend.index_url,
  24. pk : 'id',
  25. sortName : 'id',
  26. fixedColumns : true,
  27. fixedNumber : 2,
  28. columns : [
  29. [
  30. {checkbox : true},
  31. {field: 'goods.name', title: __('商品名称'), operate:false},
  32. // {
  33. // field : 'type_id', title : '产品分类', operate : '=', searchList:$.getJSON("qingdongams/product/product/get_type?type=search")
  34. // },
  35. {
  36. field : 'name', title : '产品名称', operate : 'like', fixedColumns : true, formatter : function (value, row, index) {
  37. return "<a href='javascript:void(0);' data-area=[\"90%\",\"90%\"] class='btn-dialog' " +
  38. "data-url='qingdongams/product/product/detail/ids/"+row.id+"' data-shade='0.3' data-title='产品详情' >" + value + "</a>";
  39. }
  40. },
  41. {field : 'num', title : '产品编码', operate : 'like'},
  42. {field: 'img', title: '产品图片', operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  43. {field : 'unit', title : '产品单位', operate : false},
  44. {field : 'price', title : '零售价', operate : false},
  45. {field : 'wholesale', title : '批发价', operate : false},
  46. {field: 'cost_price', title: __('采购价'), operate: 'LIKE'},
  47. {field : 'status', title : '状态',formatter: Table.api.formatter.status, searchList: { '下架': __('下架'),'上架': __('上架')}},
  48. {
  49. field: 'operate2', title: __('Operate'), operate:false, visible:isselect, events: {
  50. 'click .btn-chooseone': function (e, value, row, index) {
  51. Fast.api.close(row);
  52. },
  53. }, formatter: function () {
  54. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  55. }
  56. },
  57. {
  58. field: 'operate', title: __('Operate'), operate:false, table: table,visible:!isselect,
  59. events: Table.api.events.operate, formatter: Table.api.formatter.buttons,
  60. buttons: [
  61. {
  62. name: 'edit',
  63. text: __('编辑'),
  64. title: __('编辑'),
  65. extend:'data-area=["90%","90%"]',
  66. classname: 'records btn-dialog',
  67. url: 'qingdongams/product/product/edit',
  68. },
  69. {
  70. name: 'detail',
  71. text: __('详情'),
  72. title: __('详情'),
  73. extend:'data-area=["90%","90%"]',
  74. classname: 'records btn-dialog',
  75. url: 'qingdongams/product/product/detail',
  76. },
  77. ]
  78. },
  79. ]
  80. ],
  81. search:false,
  82. //启用普通表单搜索
  83. commonSearch : true,
  84. searchFormVisible:true,
  85. showSearch : true,
  86. pageSize : 10
  87. });
  88. // 为表格绑定事件
  89. Table.api.bindevent(table);
  90. },
  91. add : function () {
  92. Controller.api.bindevent();
  93. },
  94. add_part : function () {
  95. Controller.api.bindevent();
  96. },
  97. edit : function () {
  98. Controller.api.bindevent();
  99. },
  100. import : function () {
  101. Controller.api.bindevent();
  102. },
  103. recyclebin: function () {
  104. // 初始化表格参数配置
  105. Table.api.init({
  106. extend: {
  107. 'dragsort_url': ''
  108. }
  109. });
  110. var table = $("#table");
  111. // 初始化表格
  112. table.bootstrapTable({
  113. url: 'qingdongams/product/product/recyclebin' + location.search,
  114. pk: 'id',
  115. sortName: 'id',
  116. columns: [
  117. [
  118. {checkbox: true},
  119. {field: 'id', title: __('Id')},
  120. {field: 'name', title: __('Name'), align: 'left'},
  121. {
  122. field: 'deletetime',
  123. title: __('Deletetime'),
  124. operate: 'RANGE',
  125. addclass: 'datetimerange',
  126. formatter: Table.api.formatter.datetime
  127. },
  128. {
  129. field: 'operate',
  130. width: '130px',
  131. title: __('Operate'),
  132. table: table,
  133. events: Table.api.events.operate,
  134. buttons: [
  135. {
  136. name: 'Restore',
  137. text: __('Restore'),
  138. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  139. icon: 'fa fa-rotate-left',
  140. url: 'qingdongams/product/product/restore',
  141. refresh: true
  142. },
  143. {
  144. name: 'Destroy',
  145. text: __('Destroy'),
  146. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  147. icon: 'fa fa-times',
  148. url: 'qingdongams/product/product/destroy',
  149. refresh: true
  150. }
  151. ],
  152. formatter: Table.api.formatter.operate
  153. }
  154. ]
  155. ]
  156. });
  157. // 为表格绑定事件
  158. Table.api.bindevent(table);
  159. },
  160. edit_part : function () {
  161. Controller.api.bindevent();
  162. },
  163. tabledetail: {
  164. basic: function () {
  165. },
  166. },
  167. detail : function () {
  168. Table.api.init({});
  169. // 初始化表格参数配置
  170. //绑定事件
  171. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  172. var panel = $($(this).attr("href"));
  173. if (panel.length > 0) {
  174. Controller.tabledetail[panel.attr("id")].call(this);
  175. $(this).on('click', function (e) {
  176. $($(this).attr("href")).find(".btn-refresh").trigger("click");
  177. });
  178. }
  179. //移除绑定的事件
  180. $(this).unbind('shown.bs.tab');
  181. });
  182. //必须默认触发shown.bs.tab事件
  183. $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  184. //编辑
  185. $(document).on('click', ".btn-del", function () {//删除
  186. var id = $('#ids').val();
  187. Layer.confirm('确定删除当前产品吗?', {
  188. btn : ['确定', '取消'],
  189. title : '提示',
  190. }, function (index, layero) {
  191. Fast.api.ajax("qingdongams/product/product/del?ids=" + id, function (data, ret) {
  192. if (ret.code == 1) {
  193. Layer.close(index);
  194. parent.location.reload();
  195. }
  196. }, function (data, ret) {
  197. });
  198. });
  199. });
  200. Controller.api.bindevent();
  201. },
  202. api : {
  203. bindevent : function () {
  204. Form.api.bindevent($("form[role=form]"), function(data, ret){
  205. //这里是表单提交处理成功后的回调函数,接收来自php的返回数据
  206. Fast.api.close(data);//这里是重点
  207. });
  208. }
  209. }
  210. };
  211. return Controller;
  212. });