goods.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. {checkbox: true},
  41. {field: '订单编号', title: __('订单编号'), },
  42. {field: '客户编号', title: __('客户编号'), },
  43. {field: '生产款号', title: __('生产款号'), },
  44. {field: '款式', title: __('款式'), },
  45. {field: '订单数量', title: __('订单数量'), },
  46. {field: '面料', title: __('面料'), },
  47. {field: 'Sys_rq', title: __('下单日期'), },
  48. ]
  49. ],
  50. search:false,//搜索
  51. commonSearch: false,//放大镜搜索
  52. showToggle: false,//切换
  53. showColumns: false,//列
  54. showExport: false,//导出数据
  55. queryParams: function (params) {
  56. params.categoryids=categoryids
  57. return params;
  58. },
  59. onPostBody: function () {
  60. $(".btn-detailone").data("area", ['90%', '90%']);
  61. }
  62. });
  63. $(function () {
  64. var autoWidth = $(window).width() - 220;
  65. $('.table-content').css({'width': autoWidth, "position": "absolute", "left": "210px"});
  66. $("#treeview").jstree({
  67. "themes": {"stripes": true},
  68. "checkbox": {
  69. "keep_selected_style": true,
  70. "whole_node":false,
  71. three_state:false,
  72. },
  73. "plugins": ["checkbox"],
  74. "core": {
  75. 'check_callback': true,
  76. "data": {
  77. url: "stock/goodscategory/getjsTree",
  78. }
  79. }
  80. }).on("select_node.jstree deselect_node.jstree", function (e, data) {
  81. var treenode=$("#treeview").jstree(true);
  82. categoryids=treenode.get_checked().join(",");
  83. $("#table").bootstrapTable("refresh", {query: {categoryids: treenode.get_checked().join(",")}});
  84. });
  85. });
  86. // 出入明细事件
  87. $('.btn-detail').click(function (event) {
  88. var that = this;
  89. var selectedrow = table.bootstrapTable('getSelections');
  90. if (selectedrow.length == 1) {
  91. var url = 'stock/goods/detail';
  92. var url = Table.api.replaceurl(url, {ids: selectedrow[0]['id']}, table);
  93. Fast.api.open(url, __('Inoutdetail'), $(that).data() || {});
  94. } else {
  95. Toastr.error(selectedrow.length > 1 ? 'Only one record can be selected!' : 'Please select a record!')
  96. }
  97. });
  98. // 为表格绑定事件
  99. Table.api.bindevent(table);
  100. },
  101. add: function () {
  102. Controller.api.bindevent();
  103. },
  104. edit: function () {
  105. Controller.api.bindevent();
  106. },
  107. detail: function () {
  108. Table.api.init({
  109. extend: {
  110. detail_url: 'stock/goods/detail',
  111. },
  112. showFooter: true
  113. });
  114. var table = $("#table");
  115. // 初始化表格
  116. var ids = $('#c-ids').val();
  117. table.bootstrapTable({
  118. url: $.fn.bootstrapTable.defaults.extend.detail_url,
  119. queryParams: function (params) {
  120. params.ids = ids;
  121. return params;
  122. },
  123. pk: 'id',
  124. sortName: 'a.riqi',
  125. height: $(window).height() - 97,
  126. columns: [
  127. [
  128. {checkbox: true},
  129. {
  130. field: 'leixing', title: __('InoutType'), sortable: true,
  131. footerFormatter: function () {
  132. return '';
  133. }
  134. },
  135. {
  136. field: 'volnum', title: __('Volnum'), sortable: true,
  137. footerFormatter: function () {
  138. return '';
  139. }
  140. },
  141. {
  142. field: 'goodsname', title: __('Goodsname'), sortable: true,
  143. footerFormatter: function () {
  144. return '';
  145. }
  146. },
  147. {
  148. field: 'productmodel', title: __('Productmodel'),
  149. footerFormatter: function () {
  150. return '';
  151. }
  152. },
  153. {
  154. field: 'measureunit', title: __('Measureunit'),
  155. footerFormatter: function () {
  156. return '';
  157. }
  158. },
  159. {
  160. field: 'univalence', title: '单桶重量(kg)', operate: 'BETWEEN',
  161. footerFormatter: function () {
  162. return '';
  163. }
  164. },
  165. {
  166. field: 'stockinnums', title: __('stockInNum'),
  167. footerFormatter: function (data) {
  168. if (data.length > 0) {
  169. return data[0].sum.totalstockinnums;
  170. }
  171. }
  172. },
  173. {
  174. field: 'stockinamount', title: '入库总重(kg)',
  175. footerFormatter: function (data) {
  176. if (data.length > 0) {
  177. return data[0].sum.totalstockinamount;
  178. }
  179. }
  180. },
  181. {
  182. field: 'stockoutnums', title: __('stockOutNum'),
  183. footerFormatter: function (data) {
  184. if (data.length > 0) {
  185. return data[0].sum.totalstockoutnums;
  186. }
  187. }
  188. },
  189. {
  190. field: 'stockoutamount', title: '出库总重(kg)',
  191. footerFormatter: function (data) {
  192. if (data.length > 0) {
  193. return data[0].sum.totalstockoutamount;
  194. }
  195. }
  196. },
  197. {
  198. field: 'riqi', title: __('InoutTime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime, datetimeFormat: "YYYY-MM-DD",
  199. footerFormatter: function () {
  200. return '';
  201. }
  202. },
  203. ]
  204. ]
  205. });
  206. },
  207. api: {
  208. bindevent: function () {
  209. Form.api.bindevent($("form[role=form]"));
  210. function getPinyin() {
  211. var value = document.getElementById('c-goodsname').value;
  212. var result = '';
  213. result = pinyinUtil.getFirstLetter(value, false);
  214. document.getElementById('c-spell').value = result;
  215. }
  216. document.getElementById('c-goodsname').addEventListener('input', getPinyin);
  217. //ajax请求根据商品类别产生商品商品代码
  218. function madevolnum() {
  219. if ($('#c-goodscategoryid').val() != "") {
  220. Fast.api.ajax({
  221. url: 'stock/goods/madevolnum',
  222. type: 'POST', //GET
  223. async: true, //或false,是否异步
  224. timeout: 5000, //超时时间
  225. dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text
  226. data: {goodscategoryid: $('#c-goodscategoryid').val()}
  227. },
  228. function (data) {
  229. $('#c-volnum').val(data.volnum);
  230. $('#c-goodscategoryid').val(data.goodscategory);
  231. }
  232. );
  233. }
  234. }
  235. $('#c-goodscategoryid').change(madevolnum);
  236. }
  237. }
  238. };
  239. return Controller;
  240. });