stockcur.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form, jstree, Echarts, undefined) {
  2. var Controller = {
  3. index: function () {
  4. $(".btn-detail").data("area", ['90%', '90%']);
  5. // 初始化表格参数配置
  6. Table.api.init({
  7. extend: {
  8. index_url: 'stock/stockcur/index',
  9. add_url: 'stock/stockcur/add',
  10. edit_url: 'stock/stockcur/edit',
  11. del_url: 'stock/stockcur/del',
  12. multi_url: 'stock/stockcur/multi',
  13. table: 'stock_stockcur',
  14. }
  15. });
  16. var table = $("#table");
  17. $(function () {
  18. var autoWidth = $(window).width() - 220;
  19. $('.table-content').css({ 'width': autoWidth, "position": "absolute", "left": "210px" });
  20. $("#treeview").jstree({
  21. "themes": { "stripes": true },
  22. "checkbox": {
  23. "keep_selected_style": false,
  24. },
  25. "plugins": ["checkbox"],
  26. "core": {
  27. 'check_callback': true,
  28. "data": {
  29. url: "stock/goodscategory/getjsTree",
  30. }
  31. }
  32. }).on("select_node.jstree deselect_node.jstree", function (e, data) {
  33. $("#table").bootstrapTable("refresh", { query: { categoryids: data.selected.join(",") } });
  34. });
  35. $.fn.bootstrapTable.locales[Table.defaults.locale]['formatSearch'] = function () {
  36. return '搜索[商品代码、商品名]';
  37. };
  38. });
  39. // 初始化表格
  40. table.bootstrapTable({
  41. url: $.fn.bootstrapTable.defaults.extend.index_url,
  42. pk: 'id',
  43. sortName: 'id',
  44. height: $(window).height() - 97,
  45. columns: [
  46. [
  47. { checkbox: true },
  48. {
  49. field: 'id',
  50. title: __('Id'),
  51. width: 50,
  52. searchable: false
  53. },
  54. { field: 'stockgoods.volnum', title: __('商品代码'), sortable: true, operate: "LIKE" },
  55. { field: 'stockgoods.goodsname', title: __('stock_goods.goodsname'), sortable: true, operate: "LIKE" },
  56. { field: 'stockgoods.productmodel', title: '型号', searchable: false },
  57. { field: 'stockgoods.measureunit', title: '单位', searchable: false },
  58. { field: 'stockgoods.univalence', title: '单桶重量', searchable: false },
  59. { field: 'totalcurnums', title: __('库存数量'), searchable: false },
  60. ]
  61. ]
  62. });
  63. // 为表格绑定事件
  64. Table.api.bindevent(table);
  65. // 出入明细事件
  66. $('.btn-detail').click(function (event) {
  67. var that = this;
  68. var selectedrow = table.bootstrapTable('getSelections');
  69. if (selectedrow.length == 1) {
  70. var url = 'stock/goods/detail';
  71. var url = Table.api.replaceurl(url, { ids: selectedrow[0]['stock_goods_id'] }, table);
  72. Fast.api.open(url, __('出入明细'), $(that).data() || {});
  73. } else {
  74. Toastr.error(selectedrow.length > 1 ? '只能选择一条记录' : '请选择一条记录')
  75. }
  76. });
  77. },
  78. mainpage: function () {
  79. var goodscategory_list = [];
  80. var linechartdata = [];
  81. //商品分类
  82. $.ajax({
  83. url: 'stock/goodscategory/category',
  84. type: 'GET', //GET
  85. async: false, //或false,是否异步
  86. timeout: 5000, //超时时间
  87. dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text
  88. success: function (data) {
  89. goodscategory_list = [];
  90. if (data) {
  91. for (var i = 0; i < data.length; i++) {
  92. var value = data[i]['id'];
  93. goodscategory_list[value] = data[i]['name'];
  94. }
  95. }
  96. }
  97. });
  98. //库存饼状图
  99. $.ajax({
  100. url: 'stock/stockcur/countData',
  101. type: 'POST', //GET
  102. async: true, //或false,是否异步
  103. timeout: 5000, //超时时间
  104. dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text
  105. success: function (data) {
  106. var datalist = data.rows;
  107. var legendData = [];
  108. for (var i = 0; i < datalist.length; i++) {
  109. legendData.push(goodscategory_list[datalist[i]['stock_goods']['goodscategoryid']]);
  110. }
  111. var totalItemAmount = [];
  112. var totalAmount = 0;
  113. for (var i = 0; i < datalist.length; i++) {
  114. totalItemAmount[i] = { 'value': datalist[i].totalitemamount, 'name': goodscategory_list[datalist[i]['stock_goods']['goodscategoryid']] };
  115. totalAmount += parseFloat(datalist[i].totalitemamount);
  116. }
  117. var totalNum = [];
  118. var totalNumAdd = 0;
  119. for (var i = 0; i < datalist.length; i++) {
  120. totalNum[i] = { 'value': datalist[i].totalnum, 'name': goodscategory_list[datalist[i]['stock_goods']['goodscategoryid']] };
  121. totalNumAdd += parseFloat(datalist[i].totalnum);
  122. }
  123. madePie(legendData, totalItemAmount, 'stockcur_amount', '库存重量', '库存总重量' + totalAmount.toFixed(2) + '千克');
  124. madePie(legendData, totalNum, 'stockcur_num', '库存总件数', '库存共' + totalNumAdd + '件');
  125. }
  126. });
  127. function madePie(legendData, seriesData, elementId, titleText, titleSubText) {
  128. var myChart = Echarts.init(document.getElementById(elementId), 'walden');
  129. var option = {
  130. title: {
  131. text: titleText,
  132. subtext: titleSubText,
  133. x: 'center'
  134. },
  135. tooltip: {
  136. trigger: 'item',
  137. formatter: "{b} : {c} ({d}%)"
  138. },
  139. legend: {
  140. orient: 'vertical',
  141. x: 'left',
  142. data: legendData,
  143. },
  144. toolbox: {
  145. show: true,
  146. feature: {
  147. mark: { show: true },
  148. dataView: { show: true, readOnly: false },
  149. magicType: {
  150. show: true,
  151. type: ['pie', 'funnel'],
  152. option: {
  153. funnel: {
  154. x: '25%',
  155. width: '50%',
  156. funnelAlign: 'left',
  157. max: 1548
  158. }
  159. }
  160. },
  161. restore: { show: true },
  162. saveAsImage: { show: true }
  163. }
  164. },
  165. calculable: true,
  166. series: [{
  167. type: 'pie',
  168. radius: '55%',
  169. center: ['50%', '60%'],
  170. data: seriesData,
  171. }]
  172. };
  173. myChart.setOption(option);
  174. };
  175. //折线图
  176. $.ajax({
  177. url: 'stock/stockin/countData',
  178. type: 'POST', //GET
  179. async: true, //或false,是否异步
  180. timeout: 5000, //超时时间
  181. dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text
  182. success: function (data) {
  183. linechartdata=data;
  184. var myChart = Echarts.init(document.getElementById('linechart'), 'walden');
  185. var option = {
  186. title: {
  187. text: '出入库重量折线图',
  188. subtext: ''
  189. },
  190. legend: {
  191. data: ["入库重量", "出库重量"]
  192. },
  193. xAxis: {
  194. type: 'category',
  195. boundaryGap: false,
  196. data: linechartdata.month,
  197. axisLabel:{
  198. interval:0,
  199. rotate:45
  200. }
  201. },
  202. yAxis: {
  203. type: 'value'
  204. },
  205. series: [{
  206. name: "入库重量",
  207. type: 'line',
  208. smooth: true,
  209. data: linechartdata.indata
  210. },
  211. {
  212. name: "出库重量",
  213. type: 'line',
  214. smooth: true,
  215. data: linechartdata.outdata
  216. }]
  217. };
  218. myChart.setOption(option);
  219. }
  220. });
  221. },
  222. add: function () {
  223. Controller.api.bindevent();
  224. },
  225. edit: function () {
  226. Controller.api.bindevent();
  227. },
  228. api: {
  229. bindevent: function () {
  230. Form.api.bindevent($("form[role=form]"));
  231. }
  232. }
  233. };
  234. return Controller;
  235. });