app.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/PurcOrder', 'ui.router', 'ui.bootstrap' ], function() {
  2. 'use strict';
  3. var app = angular.module('myApp', [ 'toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'PurcOrderServices', 'ui.bootstrap']);
  4. app.init = function() {
  5. angular.bootstrap(document, [ 'myApp' ]);
  6. };
  7. app.config(function($stateProvider, $urlRouterProvider) {
  8. $urlRouterProvider.otherwise('/index');
  9. $stateProvider.state('index', {
  10. url : "",
  11. views : {
  12. "left-view" : {
  13. templateUrl : "static/tpl/index/home/left.html"
  14. },
  15. "right-view" : {
  16. templateUrl : "static/tpl/index/home/right.html"
  17. }
  18. }
  19. }).state('home', {
  20. url : "/",
  21. views : {
  22. "left-view" : {
  23. templateUrl : "static/tpl/index/home/left.html"
  24. },
  25. "right-view" : {
  26. templateUrl : "static/tpl/index/home/right.html"
  27. }
  28. }
  29. }).state('sale', {
  30. url : "/sale",
  31. views : {
  32. "left-view" : {
  33. templateUrl : "static/tpl/index/sale/left.html"
  34. },
  35. "right-view" : {
  36. templateUrl : "static/tpl/index/sale/right.html"
  37. }
  38. }
  39. }).state('sale.index', {
  40. url : "",
  41. views : {
  42. "sale-view" : {
  43. templateUrl : "static/tpl/index/sale/index.html"
  44. }
  45. }
  46. }).state('sale.home', {
  47. url : "/",
  48. views : {
  49. "sale-view" : {
  50. templateUrl : "static/tpl/index/sale/index.html"
  51. }
  52. }
  53. }).state('sale.order', {
  54. url : "/order",
  55. views : {
  56. "sale-view" : {
  57. templateUrl : "static/tpl/index/sale/order.html"
  58. }
  59. }
  60. }).state('sale.order.reply', {
  61. url : "/reply",
  62. views : {
  63. "sale-view" : {
  64. templateUrl : "static/tpl/index/sale/order.html"
  65. }
  66. }
  67. }).state('sale.change', {
  68. url : "/change",
  69. views : {
  70. "sale-view" : {
  71. templateUrl : "static/tpl/index/sale/change.html"
  72. }
  73. }
  74. }).state('user', {
  75. url : "/user",
  76. views : {
  77. "left-view" : {
  78. templateUrl : "static/tpl/index/user/left.html"
  79. },
  80. "right-view" : {
  81. templateUrl : "static/tpl/index/user/right.html"
  82. }
  83. }
  84. }).state('qc', {
  85. url : "/qc",
  86. views : {
  87. "left-view" : {
  88. templateUrl : "static/tpl/index/qc/left.html"
  89. },
  90. "right-view" : {
  91. templateUrl : "static/tpl/index/qc/right.html"
  92. }
  93. }
  94. }).state('fa', {
  95. url : "/fa",
  96. views : {
  97. "left-view" : {
  98. templateUrl : "static/tpl/index/fa/left.html"
  99. },
  100. "right-view" : {
  101. templateUrl : "static/tpl/index/fa/right.html"
  102. }
  103. }
  104. });
  105. });
  106. app.controller('MyCtrl', function($scope, $rootScope) {
  107. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  108. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  109. if (routeState.indexOf('/') > -1)
  110. routeState = routeState.substring(0, routeState.indexOf('/'));
  111. if (routeState.indexOf('.') > -1)
  112. routeState = routeState.substring(0, routeState.indexOf('.'));
  113. $scope.routeState = routeState || 'home';
  114. });
  115. });
  116. app.controller('AuthCtrl', function($scope, $window, AuthenticationService) {
  117. $scope.isAuthed = AuthenticationService.isAuthed();
  118. $scope.userInfo = {};
  119. AuthenticationService.getAuthentication().success(function(data) {
  120. $scope.userInfo = data;
  121. if (data == null || !data.uu)
  122. $scope.isAuthed = false;
  123. });
  124. $scope.logout = function() {
  125. AuthenticationService.logout().success(function() {
  126. $window.location.reload();
  127. });
  128. };
  129. });
  130. app.controller('DataCtrl', function($scope) {
  131. $scope.charts = {
  132. product : {
  133. chartType : 'pie',
  134. datas : {
  135. data : [ {
  136. x : "JDI 5寸液晶玻璃",
  137. y : [ 100000 ],
  138. tooltip : "JDI 5寸液晶玻璃: ¥100000"
  139. }, {
  140. x : "液晶显示屏",
  141. y : [ 60000 ],
  142. tooltip : "液晶显示屏: ¥60000"
  143. }, {
  144. x : "触摸屏",
  145. y : [ 48000 ],
  146. tooltip : "触摸屏: ¥48000"
  147. }, {
  148. x : "松下连接器",
  149. y : [ 36000 ],
  150. tooltip : "松下连接器: ¥36000"
  151. }, {
  152. x : "罗姆IC",
  153. y : [ 18000 ],
  154. tooltip : "罗姆IC: ¥18000"
  155. } ]
  156. },
  157. config : {
  158. labels : false,
  159. title : "产品月销量排行榜",
  160. legend : {
  161. display : true,
  162. position : 'right'
  163. },
  164. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  165. click : function(d) {
  166. },
  167. mouseover : function(d) {
  168. },
  169. mouseout : function(d) {
  170. },
  171. innerRadius : 0,
  172. lineLegend : 'lineEnd'
  173. }
  174. },
  175. sale : {
  176. chartType : 'pie',
  177. datas : {
  178. data : [ {
  179. x : "通达电子",
  180. y : [ 1800000 ],
  181. tooltip : "通达电子: ¥1800000"
  182. }, {
  183. x : "天派科技",
  184. y : [ 1600000 ],
  185. tooltip : "天派科技: ¥1600000"
  186. }, {
  187. x : "凯瑞德",
  188. y : [ 900000 ],
  189. tooltip : "凯瑞德: ¥900000"
  190. }, {
  191. x : "松下电器",
  192. y : [ 360000 ],
  193. tooltip : "松下电器: ¥360000"
  194. }, {
  195. x : "易商电子",
  196. y : [ 180000 ],
  197. tooltip : "易商电子: ¥180000"
  198. } ]
  199. },
  200. config : {
  201. labels : false,
  202. title : "客户月采购量排行榜",
  203. legend : {
  204. display : true,
  205. position : 'right'
  206. },
  207. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  208. click : function(d) {
  209. },
  210. mouseover : function(d) {
  211. },
  212. mouseout : function(d) {
  213. },
  214. innerRadius : 0,
  215. lineLegend : 'lineEnd'
  216. }
  217. },
  218. seller : {
  219. chartType : 'pie',
  220. datas : {
  221. data : [ {
  222. x : "刘青松",
  223. y : [ 5000000 ],
  224. tooltip : "刘青松: ¥5000000"
  225. }, {
  226. x : "凌海洋",
  227. y : [ 2000000 ],
  228. tooltip : "凌海洋: ¥2000000"
  229. }, {
  230. x : "聂洋",
  231. y : [ 980000 ],
  232. tooltip : "聂洋: ¥980000"
  233. }, {
  234. x : "李小敏",
  235. y : [ 900000 ],
  236. tooltip : "李小敏: ¥900000"
  237. }, {
  238. x : "张韶刚",
  239. y : [ 800000 ],
  240. tooltip : "张韶刚: ¥800000"
  241. } ]
  242. },
  243. config : {
  244. labels : false,
  245. title : "业务员月销量排行榜",
  246. legend : {
  247. display : true,
  248. position : 'right'
  249. },
  250. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  251. click : function(d) {
  252. },
  253. mouseover : function(d) {
  254. },
  255. mouseout : function(d) {
  256. },
  257. innerRadius : 0,
  258. lineLegend : 'lineEnd'
  259. }
  260. }
  261. };
  262. });
  263. var isNumber = function(n) {
  264. return !isNaN(parseFloat(n)) && isFinite(n);
  265. };
  266. var parseParams = function(requestParams) {
  267. // parse url params
  268. for (var key in requestParams) {
  269. if (key.indexOf('[') >= 0) {
  270. var params = key.split(/\[(.*)\]/), value = requestParams[key], lastKey = '';
  271. angular.forEach(params.reverse(), function(name) {
  272. if (name != '') {
  273. var v = value;
  274. value = {};
  275. value[lastKey = name] = isNumber(v) ? parseFloat(v) : v;
  276. }
  277. });
  278. requestParams[lastKey] = angular.extend(requestParams[lastKey] || {}, value[lastKey]);
  279. delete requestParams[key];
  280. } else {
  281. requestParams[key] = isNumber(requestParams[key]) ? parseFloat(requestParams[key]) : requestParams[key];
  282. }
  283. }
  284. return requestParams;
  285. };
  286. app.controller('SaleOrderCtrl', function($scope, $filter, PurcOrderItem, ngTableParams,
  287. toaster, ReportService){
  288. $scope.tableParams = new ngTableParams({
  289. page : 1, // show first page
  290. count : 5, // count per page
  291. sorting: {
  292. date: 'desc'
  293. },
  294. filter: {
  295. 'status' : 200
  296. }
  297. }, {
  298. total : 0,
  299. counts: [5, 10, 25, 50],
  300. getData : function($defer, params) {
  301. PurcOrderItem.get(parseParams(params.url()), function(page){
  302. if(page) {
  303. params.total(page.totalElements);
  304. $defer.resolve(page.content);
  305. }
  306. });
  307. }
  308. });
  309. $scope.getOrderTotal = function(items) {
  310. var sum = 0;
  311. angular.forEach(items, function(item){
  312. sum += item.qty * item.price;
  313. });
  314. return sum;
  315. };
  316. $scope.openDatePicker = function($event, item) {
  317. $event.preventDefault();
  318. $event.stopPropagation();
  319. item.$opened = !item.$opened;
  320. };
  321. $scope.parseDate = function(dateStr) {
  322. if(dateStr)
  323. return Date.parse(dateStr, 'yyyy-MM-dd');
  324. return new Date();
  325. };
  326. $scope.onReplyClick = function(item) {
  327. if(item.reply) {
  328. var reply = angular.copy(item.reply);
  329. if(reply.delivery && typeof reply.delivery == 'object') {
  330. reply.delivery = reply.delivery.getTime();
  331. }
  332. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  333. toaster.pop('info', '提示', '回复成功');
  334. $scope.tableParams.reload();
  335. }, function(response){
  336. toaster.pop('error', '回复失败', response.data);
  337. });
  338. }
  339. };
  340. $scope.print = function(order) {
  341. ReportService.print(order.vendUU, 'purchase', '{purc_orders.pu_id}=' + order.id, '销售订单-' + order.code);
  342. };
  343. });
  344. app.controller('SaleChangeCtrl', function($scope, $filter, PurcChange, ngTableParams, toaster){
  345. $scope.tableParams = new ngTableParams({
  346. page : 1,
  347. count : 5,
  348. sorting: {
  349. date: 'desc'
  350. },
  351. filter: {
  352. 'status' : 200
  353. }
  354. }, {
  355. total : 0,
  356. counts: [5, 10, 25, 50],
  357. getData : function($defer, params) {
  358. PurcChange.get(parseParams(params.url()), function(page){
  359. if(page) {
  360. params.total(page.totalElements);
  361. $defer.resolve(page.content);
  362. }
  363. });
  364. }
  365. });
  366. $scope.getOrderTotal = function(items) {
  367. var sum = 0;
  368. angular.forEach(items, function(item){
  369. sum += item.newQty * item.newPrice;
  370. });
  371. return sum;
  372. };
  373. $scope.onReplyClick = function(change) {
  374. if(change.agreed) {
  375. var reply = {id: change.id, agreed: Number(change.agreed), replyRemark: change.replyRemark};
  376. PurcChange.reply({changeId: change.id}, reply, function(){
  377. toaster.pop('info', '提示', '回复成功');
  378. $scope.tableParams.reload();
  379. }, function(response){
  380. toaster.pop('error', '回复失败', response.data);
  381. });
  382. }
  383. };
  384. });
  385. return app;
  386. });