goods.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'pingyinUntil', 'jstree'], function ($, undefined, Backend, Table, Form, pingyinUntil, jstree) {
  2. var Controller = {
  3. index: function () {
  4. $(".btn-detail").data("area", ['90%', '90%']);
  5. // 初始化表格参数配置
  6. Table.api.init({
  7. extend: {
  8. index_url: 'stock/goods/index',
  9. add_url: 'stock/goods/add',
  10. edit_url: 'stock/goods/edit',
  11. del_url: 'stock/goods/del',
  12. import_url: 'stock/goods/import',
  13. multi_url: 'stock/goods/multi',
  14. detail_url: 'stock/goods/detail',
  15. table: 'stock_goods',
  16. }
  17. });
  18. var table = $("#table");
  19. var categoryids="";
  20. // 初始化表格
  21. table.bootstrapTable({
  22. url: $.fn.bootstrapTable.defaults.extend.index_url,
  23. pk: 'id',
  24. sortName: 'goods.id',
  25. height: $(window).height() - 97,
  26. columns: [
  27. [
  28. {checkbox: true},
  29. {field: 'id', title: __('Id'), },
  30. {field: 'goodscategory.name', title: __('goodscategory'), sortable: true},
  31. {field: 'volnum', title: __('volnum'), sortable: true},
  32. {field: 'goodsname', title: __('Goodsname'), sortable: true},
  33. {field: 'productmodel', title: __('Productmodel')},
  34. {field: 'barcode', title: __('Barcode')},
  35. {field: 'measureunit', title: __('Measureunit')},
  36. {field: 'univalence', title: '单桶重量(kg)', operate: 'BETWEEN'},
  37. {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  38. {field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  39. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  40. ]
  41. ],
  42. queryParams: function (params) {
  43. params.categoryids=categoryids
  44. return params;
  45. },
  46. onPostBody: function () {
  47. $(".btn-detailone").data("area", ['90%', '90%']);
  48. }
  49. });
  50. $(function () {
  51. var autoWidth = $(window).width() - 220;
  52. $('.table-content').css({'width': autoWidth, "position": "absolute", "left": "210px"});
  53. $("#treeview").jstree({
  54. "themes": {"stripes": true},
  55. "checkbox": {
  56. "keep_selected_style": true,
  57. "whole_node":false,
  58. three_state:false,
  59. },
  60. "plugins": ["checkbox"],
  61. "core": {
  62. 'check_callback': true,
  63. "data": {
  64. url: "stock/goodscategory/getjsTree",
  65. }
  66. }
  67. }).on("select_node.jstree deselect_node.jstree", function (e, data) {
  68. var treenode=$("#treeview").jstree(true);
  69. categoryids=treenode.get_checked().join(",");
  70. $("#table").bootstrapTable("refresh", {query: {categoryids: treenode.get_checked().join(",")}});
  71. });
  72. });
  73. // 出入明细事件
  74. $('.btn-detail').click(function (event) {
  75. var that = this;
  76. var selectedrow = table.bootstrapTable('getSelections');
  77. if (selectedrow.length == 1) {
  78. var url = 'stock/goods/detail';
  79. var url = Table.api.replaceurl(url, {ids: selectedrow[0]['id']}, table);
  80. Fast.api.open(url, __('Inoutdetail'), $(that).data() || {});
  81. } else {
  82. Toastr.error(selectedrow.length > 1 ? 'Only one record can be selected!' : 'Please select a record!')
  83. }
  84. });
  85. // 为表格绑定事件
  86. Table.api.bindevent(table);
  87. },
  88. add: function () {
  89. Controller.api.bindevent();
  90. },
  91. edit: function () {
  92. Controller.api.bindevent();
  93. },
  94. detail: function () {
  95. Table.api.init({
  96. extend: {
  97. detail_url: 'stock/goods/detail',
  98. },
  99. showFooter: true
  100. });
  101. var table = $("#table");
  102. // 初始化表格
  103. var ids = $('#c-ids').val();
  104. table.bootstrapTable({
  105. url: $.fn.bootstrapTable.defaults.extend.detail_url,
  106. queryParams: function (params) {
  107. params.ids = ids;
  108. return params;
  109. },
  110. pk: 'id',
  111. sortName: 'a.riqi',
  112. height: $(window).height() - 97,
  113. columns: [
  114. [
  115. {checkbox: true},
  116. {
  117. field: 'leixing', title: __('InoutType'), sortable: true,
  118. footerFormatter: function () {
  119. return '';
  120. }
  121. },
  122. {
  123. field: 'volnum', title: __('Volnum'), sortable: true,
  124. footerFormatter: function () {
  125. return '';
  126. }
  127. },
  128. {
  129. field: 'goodsname', title: __('Goodsname'), sortable: true,
  130. footerFormatter: function () {
  131. return '';
  132. }
  133. },
  134. {
  135. field: 'productmodel', title: __('Productmodel'),
  136. footerFormatter: function () {
  137. return '';
  138. }
  139. },
  140. {
  141. field: 'measureunit', title: __('Measureunit'),
  142. footerFormatter: function () {
  143. return '';
  144. }
  145. },
  146. {
  147. field: 'univalence', title: '单桶重量(kg)', operate: 'BETWEEN',
  148. footerFormatter: function () {
  149. return '';
  150. }
  151. },
  152. {
  153. field: 'stockinnums', title: __('stockInNum'),
  154. footerFormatter: function (data) {
  155. if (data.length > 0) {
  156. return data[0].sum.totalstockinnums;
  157. }
  158. }
  159. },
  160. {
  161. field: 'stockinamount', title: '入库总重(kg)',
  162. footerFormatter: function (data) {
  163. if (data.length > 0) {
  164. return data[0].sum.totalstockinamount;
  165. }
  166. }
  167. },
  168. {
  169. field: 'stockoutnums', title: __('stockOutNum'),
  170. footerFormatter: function (data) {
  171. if (data.length > 0) {
  172. return data[0].sum.totalstockoutnums;
  173. }
  174. }
  175. },
  176. {
  177. field: 'stockoutamount', title: '出库总重(kg)',
  178. footerFormatter: function (data) {
  179. if (data.length > 0) {
  180. return data[0].sum.totalstockoutamount;
  181. }
  182. }
  183. },
  184. {
  185. field: 'riqi', title: __('InoutTime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime, datetimeFormat: "YYYY-MM-DD",
  186. footerFormatter: function () {
  187. return '';
  188. }
  189. },
  190. ]
  191. ]
  192. });
  193. },
  194. api: {
  195. bindevent: function () {
  196. Form.api.bindevent($("form[role=form]"));
  197. function getPinyin() {
  198. var value = document.getElementById('c-goodsname').value;
  199. var result = '';
  200. result = pinyinUtil.getFirstLetter(value, false);
  201. document.getElementById('c-spell').value = result;
  202. }
  203. document.getElementById('c-goodsname').addEventListener('input', getPinyin);
  204. //ajax请求根据商品类别产生商品商品代码
  205. function madevolnum() {
  206. if ($('#c-goodscategoryid').val() != "") {
  207. Fast.api.ajax({
  208. url: 'stock/goods/madevolnum',
  209. type: 'POST', //GET
  210. async: true, //或false,是否异步
  211. timeout: 5000, //超时时间
  212. dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text
  213. data: {goodscategoryid: $('#c-goodscategoryid').val()}
  214. },
  215. function (data) {
  216. $('#c-volnum').val(data.volnum);
  217. $('#c-goodscategoryid').val(data.goodscategory);
  218. }
  219. );
  220. }
  221. }
  222. $('#c-goodscategoryid').change(madevolnum);
  223. }
  224. }
  225. };
  226. return Controller;
  227. });