mobile.index.app.js 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156
  1. define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'service/Make', 'ui.router','service/Fa','ui.bootstrap' ], function() {
  2. 'use strict';
  3. var app = angular.module('myApp', ['ngAnimate', 'toaster', 'ui.router', 'common.services', 'PurcServices', 'MakeServices', 'FaServices' , 'ui.bootstrap']);
  4. app.init = function() {
  5. angular.bootstrap(document, [ 'myApp' ]);
  6. };
  7. app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
  8. $urlRouterProvider.otherwise('/index');
  9. $stateProvider.state('index', {
  10. url : "/index",
  11. templateUrl : "static/tpl/index_mobile/home/index.html"
  12. }).state('sale', {// 销售
  13. url : "/sale",
  14. templateUrl : "static/tpl/index_mobile/sale/sale.html"
  15. }).state('make', {// 委外
  16. url : "/make",
  17. templateUrl : "static/tpl/index_mobile/make/make.html"
  18. }).state('sale.order', {// 销售,订单列表
  19. url : "/order",
  20. templateUrl : "static/tpl/index_mobile/sale/order_list.html",
  21. controller: 'SaleOrderListCtrl'
  22. }).state('sale.sample', {// 销售,送样申请列表
  23. url : "/sample",
  24. templateUrl : "static/tpl/index_mobile/sale/sample.html",
  25. controller: 'SaleSampleCtrl'
  26. }).state('sale.sample_detail', {
  27. url : "/sample/:id",
  28. templateUrl : "static/tpl/index_mobile/sale/sample_detail.html",
  29. controller: 'SaleSampleDetailCtrl'
  30. }).state('sale.approval', {// 销售,客户认定列表
  31. url : "/approval",
  32. templateUrl : "static/tpl/index_mobile/sale/approval.html",
  33. controller: 'SaleApprovalCtrl'
  34. }).state('sale.approval_detail', {
  35. url : "/approval/:id",
  36. templateUrl : "static/tpl/index_mobile/sale/approval_detail.html",
  37. controller: 'SaleApprovalDetailCtrl'
  38. }).state('sale.change', {// 销售,变更单列表
  39. url : "/change",
  40. templateUrl : "static/tpl/index_mobile/sale/change_list.html",
  41. controller: 'SaleChangeListCtrl'
  42. }).state('sale.inquiry', {// 销售,询价单列表
  43. url : "/inquiry",
  44. templateUrl : "static/tpl/index_mobile/sale/inquiry_list.html",
  45. controller: 'SaleInquiryListCtrl'
  46. }).state('sale.notice', {// 销售,发货提醒列表
  47. url : "/notice",
  48. templateUrl : "static/tpl/index_mobile/sale/notice_list.html",
  49. controller: 'SaleNoticeListCtrl'
  50. }).state('sale.accept', {// 销售,验收单列表
  51. url : "/accept",
  52. templateUrl : "static/tpl/index_mobile/sale/accept_list.html",
  53. controller: 'SaleAcceptListCtrl'
  54. }).state('sale.return', {// 销售,退货单列表
  55. url : "/return",
  56. templateUrl : "static/tpl/index_mobile/sale/return_list.html",
  57. controller: 'SaleReturnListCtrl'
  58. }).state('make.order', {// 委外,加工单列表
  59. url : "/order",
  60. templateUrl : "static/tpl/index_mobile/make/order_list.html",
  61. controller: 'MakeOrderListCtrl'
  62. }).state('make.change', {// 委外,变更单列表
  63. url : "/change",
  64. templateUrl : "static/tpl/index_mobile/make/change_list.html",
  65. controller: 'MakeChangeListCtrl'
  66. }).state('make.accept', {// 委外,验收单列表
  67. url : "/accept",
  68. templateUrl : "static/tpl/index_mobile/make/accept_list.html",
  69. controller: 'MakeAcceptListCtrl'
  70. }).state('make.return', {// 委外,退货单列表
  71. url : "/return",
  72. templateUrl : "static/tpl/index_mobile/make/return_list.html",
  73. controller: 'MakeReturnListCtrl'
  74. }).state('sale.send', {// 销售,客户发货单
  75. url : "/send",
  76. templateUrl : "static/tpl/index_mobile/sale/send.html",
  77. controller: 'SaleSendCtrl'
  78. }).state('sale.send_detail', {
  79. url : "/send/:id",
  80. templateUrl : "static/tpl/index_mobile/sale/send_detail.html",
  81. controller: 'SaleSendDetailCtrl'
  82. }).state('sale.order_detail', {// 销售,订单详情
  83. url : "/order/:id",
  84. templateUrl : "static/tpl/index_mobile/sale/order_detail.html",
  85. controller: 'SaleOrderCtrl'
  86. }).state('sale.change_detail', {// 销售,变更单详情
  87. url: '/change/:id',
  88. templateUrl: 'static/tpl/index_mobile/sale/change_detail.html',
  89. controller: 'SaleChangeCtrl'
  90. }).state('sale.inquiry_detail', {// 销售,询价单详情
  91. url: '/inquiry/:itemId',
  92. templateUrl: 'static/tpl/index_mobile/sale/inquiry_detail.html',
  93. controller: 'SaleInquiryCtrl'
  94. }).state('sale.notice_detail', {// 销售,发货提醒详情
  95. url: '/notice/:id',
  96. templateUrl: 'static/tpl/index_mobile/sale/notice_detail.html',
  97. controller: 'SaleNoticeCtrl'
  98. }).state('sale.accept_detail', {// 销售,验收单详情
  99. url: '/accept/:id',
  100. templateUrl: 'static/tpl/index_mobile/sale/accept_detail.html',
  101. controller: 'SaleAcceptCtrl'
  102. }).state('sale.return_detail', {// 销售,退货单详情
  103. url: '/return/:id',
  104. templateUrl: 'static/tpl/index_mobile/sale/return_detail.html',
  105. controller: 'SaleReturnCtrl'
  106. }).state('fa', {//财务
  107. url : "/fa",
  108. templateUrl : "static/tpl/index_mobile/financial/financial.html"
  109. }).state('fa.apBill', {//财务,客户应付发票
  110. url : "/apBill",
  111. templateUrl : "static/tpl/index_mobile/financial/apBill_list.html",
  112. controller : 'SaleApBillCtrl'
  113. }).state('fa.arCheck', {//财务,应付对账单
  114. url : "/arCheck",
  115. templateUrl : "static/tpl/index_mobile/financial/arCheck_list.html",
  116. controller: 'SaleArCheckCtrl'
  117. }).state('fa.receCheck', {//财务,应收对账单
  118. url : "/receCheck",
  119. templateUrl : "static/tpl/index_mobile/financial/receCheck_list.html",
  120. controller : "SaleReceCheckCtrl"
  121. }).state('fa.arCheck_detail', {// 财务,应付对账详情页
  122. url : "/arCheck/:id",
  123. templateUrl : "static/tpl/index_mobile/financial/arCheck_detail.html",
  124. controller: 'SaleArCheckDetailCtrl'
  125. }).state('fa.apBill_detail', {
  126. url : '/apBill/:id',
  127. templateUrl : "static/tpl/index_mobile/financial/apBill_detail.html",
  128. controller: 'FaApBillDetailCtrl'
  129. }).state('make.order_detail', {// 委外,加工单详情
  130. url: '/order/:id',
  131. templateUrl: 'static/tpl/index_mobile/make/order_detail.html',
  132. controller: 'MakeOrderCtrl'
  133. }).state('make.change_detail', {// 委外,变更单详情
  134. url: '/change/:id',
  135. templateUrl: 'static/tpl/index_mobile/make/change_detail.html',
  136. controller: 'MakeChangeCtrl'
  137. }).state('make.accept_detail', {// 委外,验收单详情
  138. url: '/accept/:id',
  139. templateUrl: 'static/tpl/index_mobile/make/accept_detail.html',
  140. controller: 'MakeAcceptCtrl'
  141. }).state('make.return_detail', {// 委外,退货单详情
  142. url: '/return/:id',
  143. templateUrl: 'static/tpl/index_mobile/make/return_detail.html',
  144. controller: 'MakeReturnCtrl'
  145. }).state('qc', {// 品质管理
  146. url : "/qc",
  147. templateUrl : "static/tpl/index_mobile/qc/qc.html"
  148. }).state('qc.badIn', {// 不良品入库
  149. url : "/badIn",
  150. templateUrl : "static/tpl/index_mobile/qc/badIn.html",
  151. controller: 'SaleBadInCtrl'
  152. }).state('qc.badIn_detail', {
  153. url : "/badIn/:id",
  154. templateUrl : "static/tpl/index_mobile/qc/badIn_detail.html",
  155. controller: 'SaleBadInDetailCtrl'
  156. }).state('qc.badOut', {// 不良品出库
  157. url : "/badOut",
  158. templateUrl : "static/tpl/index_mobile/qc/badOut.html",
  159. controller: 'SaleBadOutCtrl'
  160. }).state('qc.badOut_detail', {
  161. url : "/badOut/:id",
  162. templateUrl : "static/tpl/index_mobile/qc/badOut_detail.html",
  163. controller: 'SaleBadOutDetailCtrl'
  164. }).state('qc.MRB', {// MRB
  165. url : "/MRB",
  166. templateUrl : "static/tpl/index_mobile/qc/MRB.html",
  167. controller: 'SaleMRBCtrl'
  168. }).state('qc.MRB_detail', {
  169. url : "/MRB/:id",
  170. templateUrl : "static/tpl/index_mobile/qc/MRB_detail.html",
  171. controller: 'SaleMRBDetailCtrl'
  172. })
  173. }]);
  174. app.factory('StatusCode', function(){
  175. var statusConfig = {
  176. '101' : '已提交',
  177. '102' : '已审核',
  178. '103' : '未通过',
  179. '313' : '已激活',
  180. '316' : '已过账',
  181. '311' : '申请中',
  182. '312' : '未激活',
  183. '200' : '未回复',
  184. '203' : '已下载',
  185. '201' : '已回复'
  186. };
  187. return {
  188. get: function(code) {
  189. return statusConfig[code];
  190. }
  191. };
  192. }).filter('status', ['StatusCode', function(StatusCode){
  193. return function(data) {
  194. return StatusCode.get(data);
  195. }
  196. }]);
  197. app.factory('Symbol', function(){
  198. return {
  199. currency: function(cur) {
  200. if(cur == 'RMB') return '¥';
  201. else if(cur == 'USD') return '$';
  202. else if(cur == 'EUR') return '€';
  203. else return cur;
  204. }
  205. };
  206. });
  207. app.controller('MyCtrl', ['$scope', '$rootScope','$window', 'AuthenticationService', function($scope, $rootScope,$window,AuthenticationService) {
  208. $scope.logout = function() {
  209. AuthenticationService.logout().success(function() {
  210. $window.location.reload();
  211. });
  212. };
  213. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  214. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  215. if (routeState.indexOf('/') > -1)
  216. routeState = routeState.substring(0, routeState.indexOf('/'));
  217. if (routeState.indexOf('.') > -1)
  218. routeState = routeState.substring(0, routeState.indexOf('.'));
  219. $scope.routeState = routeState || 'home';
  220. });
  221. }]);
  222. //切换账套
  223. app.controller('ChooseEnterpriseCtrl', ['$scope', '$modalInstance', 'enterprises', 'enterprise', function($scope, $modalInstance, enterprises, enterprise){
  224. $scope.choose = enterprise.uu;
  225. $scope.enterprises = enterprises;
  226. $scope.cancel = function() {
  227. $modalInstance.close();
  228. };
  229. $scope.login = function(uu) {
  230. $modalInstance.close(uu);
  231. };
  232. }]);
  233. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', '$modal', 'BaseService', function($scope, $window, AuthenticationService, $modal, BaseService) {
  234. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  235. $scope.userInfo = {};
  236. AuthenticationService.getAuthentication().success(function(data) {
  237. if(data.enterprises) {
  238. data.enterprise = data.enterprises[data.enterprises.length - 1];
  239. if(data.enterprises.length > 1) {
  240. var enSelect = [];
  241. angular.forEach(data.enterprises, function(e){
  242. if(e.current)
  243. data.enterprise = e;
  244. else
  245. enSelect.push(e);
  246. });
  247. data.enSelect = enSelect;
  248. }
  249. }
  250. $scope.userInfo = data;
  251. if (data == null || !data.userUU) {
  252. $scope.isAuthed = false;
  253. $window.location.href = BaseService.getRootPath() + "/signin";
  254. }
  255. });
  256. $scope.logout = function() {
  257. AuthenticationService.logout().success(function() {
  258. $window.location.href = BaseService.getRootPath() + "/signin";
  259. });
  260. };
  261. $scope.switchto = function(enUU) {// 切换企业
  262. AuthenticationService.reSignin(enUU).success(function(){
  263. $window.location.reload();
  264. });
  265. };
  266. //切换帐套信息方法
  267. $scope.changeMaster = function() {
  268. $modal.open({
  269. templateUrl: 'chooseEnterprise.html',
  270. controller: 'ChooseEnterpriseCtrl',
  271. size: 'sm',
  272. resolve: {
  273. enterprises: function() {
  274. return $scope.userInfo.enterprises;
  275. },
  276. enterprise: function() {
  277. return $scope.userInfo.enterprise;
  278. }
  279. }
  280. }).result.then(function(enUU){
  281. $scope.switchto(enUU);
  282. });
  283. }
  284. }]);
  285. // 根据状态分类得到获取数据的方法
  286. var getState = function(active) {
  287. var fn = 'get';
  288. switch(active) {
  289. case 'done':
  290. fn = 'getDone';break;
  291. case 'todo':
  292. fn = 'getTodo';break;
  293. case 'end':
  294. fn = 'getEnd';break;
  295. case 'waiting':
  296. fn = 'getWaiting';break;
  297. }
  298. return fn;
  299. };
  300. /**
  301. * 待处理数据统计
  302. */
  303. app.controller('TodoCtrl', ['$rootScope', '$scope', 'SnapshotService', function($rootScope, $scope, SnapshotService){
  304. SnapshotService.getTodo(function(data){
  305. $scope.todo = data;
  306. });
  307. if(!$rootScope.active) {
  308. $rootScope.active = [true, false, false, false];
  309. };
  310. $scope.active =$rootScope.active;
  311. $scope.showMake = function(index) {
  312. for (var i=0;i<$scope.active.length;i++) {
  313. if($scope.active[i] == true) {
  314. $scope.active[i] = false;
  315. $rootScope.active[i] = false;
  316. }
  317. if(index == i) {
  318. $scope.active[i] = true;
  319. $rootScope.active[i] = true;
  320. }
  321. }
  322. }
  323. }]);
  324. /**
  325. * 客户采购订单列表
  326. */
  327. app.controller('SaleOrderListCtrl', ['$scope', 'BaseService', 'PurcOrderItem', 'toaster', function($scope, BaseService, PurcOrderItem, toaster) {
  328. $scope.data = {};// 列表数据
  329. var pageParams = { // 页面参数
  330. page : 1,
  331. count : 5,
  332. sorting: {
  333. date: 'desc'
  334. },
  335. searchFilter: { // 筛选条件
  336. keyword: null
  337. }
  338. };
  339. $scope._state = 'todo';
  340. // 切换单据类型
  341. $scope.setState = function(state) {
  342. if($scope._state != state) {
  343. $scope._state = state;
  344. if(pageParams.page == 1)
  345. getData();
  346. else {
  347. pageParams.page = 1;
  348. getData();
  349. }
  350. }
  351. };
  352. // 加载数据
  353. var getData = function(add) {
  354. $scope.loading = true;
  355. pageParams.searchFilter.keyword = $scope.keyword;
  356. PurcOrderItem[getState($scope._state)].call(null, BaseService.parseParams(pageParams), function(data){
  357. if(add) {
  358. data.content = $scope.data.content.concat(data.content);
  359. $scope.data = data;
  360. } else {
  361. $scope.data = data;
  362. }
  363. $scope.loading = false;
  364. }, function(response){
  365. $scope.loading = false;
  366. toaster.pop('error', '加载数据失败', response.data);
  367. });
  368. };
  369. getData();// 初始获取数据
  370. $scope.onSearch = function() {
  371. getData();
  372. }
  373. // 加载更多数据
  374. $scope.getMoreData = function() {
  375. pageParams.page ++;
  376. getData(true);
  377. };
  378. // 获取订单的总金额
  379. $scope.getTotal = function(order) {
  380. var total = 0;
  381. angular.forEach(order.orderItems, function(item){
  382. total += (item.qty||0) * (item.price||0);
  383. });
  384. return total;
  385. };
  386. // 获取物料总数
  387. $scope.getProdCount = function(order) {
  388. var count = 0;
  389. angular.forEach(order.orderItems, function(item){
  390. count += (item.qty || 0);
  391. });
  392. return count;
  393. };
  394. }]);
  395. /**
  396. * 客户采购订单详情
  397. */
  398. app.controller('SaleOrderCtrl', ['$scope', '$filter', '$stateParams', 'toaster', 'PurcOrder', 'PurcOrderItem', 'Symbol', function($scope, $filter, $stateParams, toaster, PurcOrder, PurcOrderItem, Symbol){
  399. $scope.loading = true;
  400. $scope.symbol = Symbol.currency;
  401. $scope.getOrderTotal = function(items) {
  402. var sum = 0;
  403. angular.forEach(items, function(item){
  404. sum += item.qty * item.price;
  405. });
  406. return parseFloat(sum).toFixed(2);//四舍五入取两位小数
  407. };
  408. PurcOrder.get({id: $stateParams.id}, function(data) {
  409. $scope.purcOrder = data;
  410. $scope.loading = false;
  411. });
  412. // 展开回复
  413. $scope.expandReply = function(orderItem) {
  414. if(!orderItem.replys) {
  415. PurcOrderItem.getReply({orderItemId: orderItem.id}, function(data){
  416. orderItem.replys = data;
  417. }, function(){
  418. orderItem.replysError = true;
  419. });
  420. }
  421. angular.forEach($scope.purcOrder.orderItems, function(item, index){
  422. if(item.number != orderItem.number) item.expand = false;
  423. });
  424. orderItem.expand = !orderItem.expand;
  425. };
  426. // 全选
  427. $scope.checkAll = function(value) {
  428. angular.forEach($scope.purcOrder.orderItems, function(item, index){
  429. item.checked = value;
  430. });
  431. };
  432. // 选中一个
  433. $scope.checkOne = function(value) {
  434. if(value) {
  435. // angular.forEach($scope.purcOrder.orderItems, function(item, index){
  436. // if(item.checked == false) {
  437. // $scope.check_all = false; return ;
  438. // }
  439. // });
  440. } else {
  441. $scope.check_all = false;
  442. }
  443. };
  444. $scope.open = function($event, orderItem) {
  445. $event.preventDefault();
  446. $event.stopPropagation();
  447. orderItem.opened = !orderItem.opened;
  448. };
  449. $scope.reply = function(item) {
  450. $scope.loading = true;
  451. if(item.reply && item.reply.qty && item.reply.delivery) {
  452. var reply = angular.copy(item.reply),
  453. dateFilter = $filter('date');
  454. if(reply.delivery) {
  455. reply.delivery = reply.delivery.getTime();
  456. }
  457. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  458. PurcOrder.get({id: $stateParams.id}, function(data) {
  459. $scope.purcOrder = data;
  460. $scope.loading = false;
  461. toaster.pop('success', '提示', '回复成功:' + reply.qty);
  462. });
  463. }, function(response){
  464. $scope.loading = false;
  465. toaster.pop('error', '回复失败', response.data);
  466. });
  467. } else {
  468. $scope.loading = false;
  469. toaster.pop('warning', '提示', '请填写回复的具体内容');
  470. }
  471. };
  472. $scope.replyByBatch = function() {
  473. $scope.loading = true;
  474. var str = '';
  475. angular.forEach($scope.purcOrder.orderItems, function(item) {
  476. if(item.checked == true) {
  477. str += item.id + ",";
  478. }
  479. });
  480. if(str) {
  481. str = str.substr(0, str.length-1);
  482. PurcOrderItem.replyByBatch(str, function(){
  483. $scope.loading = false;
  484. PurcOrder.get({id: $stateParams.id}, function(data) {
  485. $scope.purcOrder = data;
  486. $scope.loading = false;
  487. toaster.pop('success', '提示', '回复成功');
  488. });
  489. }, function(data){
  490. $scope.loading = false;
  491. toaster.pop('error', '回复失败', data);
  492. });
  493. } else {
  494. $scope.loading = false;
  495. toaster.pop('warning', '警告', '请勾选要回复的明细行');
  496. }
  497. };
  498. }]);
  499. /**
  500. * 客户采购变更列表
  501. */
  502. app.controller('SaleChangeListCtrl', ['$scope', 'PurcChange', 'toaster', 'BaseService', function($scope, PurcChange, toaster, BaseService) {
  503. $scope.data = {};// 列表数据
  504. var pageParams = { // 页面参数
  505. page : 1,
  506. count : 5,
  507. sorting: {
  508. date: 'desc'
  509. },
  510. searchFilter: { // 筛选条件
  511. keyword: null
  512. }
  513. };
  514. $scope._state = 'todo';
  515. // 切换单据类型
  516. $scope.setState = function(state) {
  517. if($scope._state != state) {
  518. $scope._state = state;
  519. if(pageParams.page == 1)
  520. getData();
  521. else {
  522. pageParams.page = 1;
  523. getData();
  524. }
  525. }
  526. };
  527. // 加载数据
  528. var getData = function(add) {
  529. $scope.loading = true;
  530. pageParams.keyword = $scope.keyword;
  531. PurcChange[getState($scope._state)].call(null, BaseService.parseParams(pageParams), function(data){
  532. if(add) {
  533. data.content = $scope.data.content.concat(data.content);
  534. $scope.data = data;
  535. } else {
  536. $scope.data = data;
  537. }
  538. $scope.loading = false;
  539. }, function(response){
  540. $scope.loading = false;
  541. toaster.pop('error', '加载数据失败', response.data);
  542. });
  543. };
  544. getData();// 初始获取数据
  545. // 加载更多数据
  546. $scope.getMoreData = function() {
  547. pageParams.page ++;
  548. getData(true);
  549. };
  550. $scope.onSearch = function() {
  551. getData();
  552. }
  553. }]);
  554. /**
  555. * 客户采购变更详情
  556. */
  557. app.controller('SaleChangeCtrl', ['$scope', '$stateParams', 'toaster', 'PurcChange', function($scope, $stateParams, toaster, PurcChange){
  558. $scope.loading = true;
  559. $scope.remark = '';
  560. //获取变更单
  561. PurcChange.get({id: $stateParams.id}, function(data){
  562. $scope.purcChange = data;
  563. $scope.remark = data.replyRemark;
  564. $scope.loading = false;
  565. }, function(response){
  566. toaster.pop('error', '数据加载失败', response.data);
  567. });
  568. $scope.onReplyClick = function(change) {
  569. $scope.loading = true;
  570. var reply = {id: change.id, agreed: Number(change.agreed), replyRemark: change.replyRemark};
  571. PurcChange.reply({changeId: change.id}, reply, function(){
  572. toaster.pop('info', '提示', '回复成功');
  573. PurcChange.get({id: $stateParams.id}, function(data){
  574. $scope.purcChange = data;
  575. $scope.remark = data.replyRemark;
  576. $scope.loading = false;
  577. }, function(response){
  578. console.log(response);
  579. });
  580. }, function(response){
  581. $scope.loading = false;
  582. toaster.pop('error', '回复失败', response.data);
  583. });
  584. };
  585. }]);
  586. /**
  587. * 客户询价单列表
  588. */
  589. app.controller('SaleInquiryListCtrl', ['$scope', 'BaseService', 'PurcInquiry', 'toaster', function($scope, BaseService, PurcInquiry, toaster) {
  590. $scope.data = {};// 列表数据
  591. var pageParams = {// 页面参数
  592. page : 1,
  593. count : 5,
  594. sorting: {
  595. 'inquiry.date': 'desc'
  596. },
  597. searchFilter: { // 筛选条件
  598. keyword: null
  599. }
  600. };
  601. $scope._state = 'todo';
  602. // 切换单据类型
  603. $scope.setState = function(state) {
  604. if($scope._state != state) {
  605. $scope._state = state;
  606. if(pageParams.page == 1)
  607. getData();
  608. else {
  609. pageParams.page = 1;
  610. getData();
  611. }
  612. }
  613. };
  614. // 加载数据
  615. var getData = function(add) {
  616. $scope.loading = true;
  617. pageParams.keyword = $scope.keyword;
  618. PurcInquiry[getState($scope._state)].call(null, BaseService.parseParams(pageParams), function(data){
  619. if(add) {
  620. data.content = $scope.data.content.concat(data.content);
  621. $scope.data = data;
  622. } else {
  623. $scope.data = data;
  624. }
  625. $scope.loading = false;
  626. }, function(response){
  627. $scope.loading = false;
  628. toaster.pop('error', '加载数据失败', response.data);
  629. });
  630. };
  631. getData();// 初始获取数据
  632. // 加载更多数据
  633. $scope.getMoreData = function() {
  634. pageParams.page ++;
  635. getData(true);
  636. };
  637. $scope.onSearch = function() {
  638. getData();
  639. }
  640. }]);
  641. /**
  642. * 客户询价单详情
  643. */
  644. app.controller('SaleInquiryCtrl', ['$scope', '$stateParams', 'toaster', 'PurcInquiry', 'Symbol', function($scope, $stateParams, toaster, PurcInquiry, Symbol){
  645. $scope.loading = true;
  646. $scope.vendFromDateOpen = false;
  647. $scope.vendToDateOpen = false;
  648. var inquiry = null;
  649. $scope.symbol = Symbol.currency;//把币别转化为符号
  650. PurcInquiry.getItem({itemId: $stateParams.itemId}, function(data){
  651. $scope.purcInquiry = data;
  652. inquiry = angular.copy(data);
  653. $scope.loading = false;
  654. }, function(response){
  655. toaster.pop('error', '加载失败', response.data);
  656. });
  657. $scope.openF = function($event) {
  658. $event.preventDefault();
  659. $event.stopPropagation();
  660. $scope.vendFromDateOpen = !$scope.vendFromDateOpen;
  661. };
  662. $scope.openT = function($event) {
  663. $event.preventDefault();
  664. $event.stopPropagation();
  665. $scope.vendToDateOpen = !$scope.vendToDateOpen;
  666. };
  667. $scope.addNewReply = function(reply) {
  668. $scope.purcInquiry.replies.push({price: null, lapQty: null, id: null, editing: true});
  669. reply.editing = false;
  670. };
  671. $scope.save = function(item) {
  672. $scope.loading = true;
  673. if(angular.equals($scope.purcInquiry, inquiry)) {
  674. $scope.loading = false;
  675. toaster.pop('warning', '提示', '没有修改,不需要保存');
  676. return;
  677. }
  678. if(angular.isDate(item.vendFromDate)) {
  679. item.vendFromDate = item.vendFromDate.getTime();
  680. }
  681. if(angular.isDate(item.vendToDate)) {
  682. item.vendToDate = item.vendToDate.getTime();
  683. }
  684. PurcInquiry.saveItem({itemId: item.id}, item, function(data) {
  685. toaster.pop('info', '提示', '保存成功');
  686. PurcInquiry.getItem({itemId: $stateParams.itemId}, function(data){
  687. $scope.purcInquiry = data;
  688. $scope.loading = false;
  689. }, function(response){
  690. $scope.loading = false;
  691. toaster.pop('error', '加载失败', response.data);
  692. });
  693. }, function(response){
  694. $scope.loading = false;
  695. toaster.pop('error', '保存失败', response.data);
  696. });
  697. };
  698. $scope.reply = function(item) {
  699. $scope.loading = true;
  700. if(item.vendFromDate instanceof Date) {
  701. item.vendFromDate = item.vendFromDate.getTime();
  702. }
  703. if(item.vendToDate instanceof Date) {
  704. item.vendToDate = item.vendToDate.getTime();
  705. }
  706. PurcInquiry.reply({itemId: item.id}, item, function(data) {
  707. toaster.pop('info', '提示', '回复成功');
  708. PurcInquiry.getItem({itemId: $stateParams.itemId}, function(data){
  709. $scope.purcInquiry = data;
  710. $scope.loading = false;
  711. }, function(data){
  712. $scope.loading = false;
  713. toaster.pop('error', '加载失败', response.data);
  714. });
  715. }, function(response){
  716. $scope.loading = false;
  717. toaster.pop('error', '回复失败', response.data);
  718. });
  719. };
  720. }]);
  721. /**
  722. * 客户发货提醒列表
  723. */
  724. app.controller('SaleNoticeListCtrl', ['$scope', 'PurcNotice', 'toaster', 'BaseService', 'SaleTruck', 'Symbol', '$state', function($scope, PurcNotice, toaster, BaseService, SaleTruck, Symbol, $state) {
  725. $scope.data = {};// 列表数据
  726. var pageParams = { // 页面参数
  727. page : 1,
  728. count : 5,
  729. sorting: {
  730. 'delivery': 'asc',
  731. 'orderItemOrderCode': 'asc',
  732. 'orderItemNumber': 'asc'
  733. },
  734. searchFilter: { // 筛选条件
  735. keyword: null
  736. }
  737. };
  738. $scope._state = 'todo';
  739. // 切换单据类型
  740. $scope.setState = function(state) {
  741. if($scope._state != state) {
  742. $scope._state = state;
  743. if(pageParams.page == 1)
  744. getData();
  745. else {
  746. pageParams.page = 1;
  747. getData();
  748. }
  749. }
  750. };
  751. // 加载数据
  752. var getData = function(add) {
  753. $scope.loading = true;
  754. pageParams.keyword = $scope.keyword;
  755. PurcNotice[getState($scope._state)].call(null, BaseService.parseParams(pageParams), function(data){
  756. if(add) {
  757. data.content = $scope.data.content.concat(data.content);
  758. $scope.data = data;
  759. } else {
  760. $scope.data = data;
  761. }
  762. $scope.loading = false;
  763. }, function(response){
  764. $scope.loading = false;
  765. toaster.pop('error', '加载数据失败', response.data);
  766. });
  767. };
  768. getData();// 初始获取数据
  769. // 加载更多数据
  770. $scope.getMoreData = function() {
  771. pageParams.page ++;
  772. getData(true);
  773. };
  774. $scope.onSearch = function() {
  775. getData();
  776. }
  777. }]);
  778. /**
  779. * 客户发货提醒详情
  780. */
  781. app.controller('SaleNoticeCtrl', ['$scope', '$stateParams', 'toaster', 'PurcNotice', 'Symbol', function($scope, $stateParams, toaster, PurcNotice, Symbol){
  782. $scope.loading = true;
  783. $scope.symbol = Symbol.currency;//把币别转化为符号
  784. $scope.logShow = false;
  785. $scope.notice = PurcNotice.get({id: $stateParams.id}, function(data){
  786. $scope.loading = false;
  787. }, function(response){
  788. toaster.pop('error', '加载失败', response.data);
  789. });
  790. $scope.getSends = function(){
  791. if(! $scope.notice.sendLogs) {
  792. $scope.loading = true;
  793. $scope.notice.sendLogs = PurcNotice.getSends({id: $stateParams.id}, function(data){
  794. $scope.loading = false;
  795. }, function(response){
  796. $scope.loading = false;
  797. toaster.pop('error', '加载失败', response.data);
  798. });
  799. }
  800. };
  801. $scope.onReplyClick = function(notice) {
  802. if(notice.send.qty > notice.qty - (notice.endQty || 0)) {
  803. toaster.pop('warning', '警告', '本次发货数量超出!');
  804. } else {
  805. var send = {code: notice.send.code, sendItems: [{qty: notice.send.qty}]};
  806. $scope.loading = true;
  807. PurcNotice.save({id: notice.id}, send, function(){
  808. $scope.loading = false;
  809. $scope.notice = PurcNotice.get({id: $stateParams.id}, function(data){
  810. }, function(response){
  811. toaster.pop('error', '加载失败', response.data);
  812. });
  813. toaster.pop('success', '提示', '发货成功');
  814. }, function(response){
  815. $scope.loading = false;
  816. toaster.pop('error', '失败', response);
  817. });
  818. $scope.logShow = false;
  819. }
  820. };
  821. }]);
  822. /**
  823. * 客户打样申请
  824. */
  825. app.controller('SaleSampleCtrl', ['$scope', 'PurcSample','BaseService' ,function($scope, PurcSample,BaseService){
  826. $scope.data = {};// 列表数据
  827. // 搜索框回车
  828. $scope.onSearch = function() {
  829. pageParams.keyword = $scope.keyword;
  830. getData();
  831. };
  832. var pageParams = { // 页面参数
  833. page : 1,
  834. count : 5,
  835. sorting: {
  836. proofingDate: 'desc'
  837. },
  838. keyword: null
  839. };
  840. $scope._state = 'done';
  841. // 切换单据类型
  842. $scope.setState = function(state) {
  843. if($scope._state != state) {
  844. $scope._state = state;
  845. if(pageParams.page == 1)
  846. getData();
  847. else {
  848. pageParams.page = 1;
  849. getData();
  850. }
  851. }
  852. };
  853. // 加载数据
  854. var getData = function(add) {
  855. $scope.loading = true;
  856. pageParams.keyword = $scope.keyword;
  857. PurcSample[getState($scope._state)].call(null, BaseService.parseParams(pageParams), function(data){
  858. if(add) {
  859. data.content = $scope.data.content.concat(data.content);
  860. $scope.data = data;
  861. } else {
  862. $scope.data = data;
  863. }
  864. $scope.loading = false;
  865. }, function(response){
  866. $scope.loading = false;
  867. toaster.pop('error', '加载数据失败', response.data);
  868. });
  869. };
  870. getData();// 初始获取数据
  871. // 加载更多数据
  872. $scope.getMoreData = function() {
  873. pageParams.page ++;
  874. getData(true);
  875. };
  876. $scope.onSearch = function() {
  877. getData();
  878. }
  879. }]);
  880. /**
  881. * 客户打样申请详情
  882. */
  883. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', function($scope, $stateParams, PurcSample){
  884. var loading = true;
  885. var loadData = function() {
  886. PurcSample.get({id: $stateParams.id}, function(data){
  887. $scope.sample = data;
  888. if(!$scope.sample.send){
  889. $scope.sample.getSendInfo = '加载中...';
  890. PurcSample.getSend({id: $stateParams.id}, function(sendData){
  891. if(sendData) {
  892. $scope.sample.getSendInfo = null;
  893. $scope.sample.send = sendData;
  894. } else {
  895. $scope.sample.getSendInfo = '无送样信息';
  896. $scope.sample.send = '无送样信息';
  897. }
  898. }, function(response){
  899. $scope.sample.getSendInfo = '加载失败!';
  900. });
  901. }
  902. $scope.loading = false;
  903. }, function(response){
  904. loading = false;
  905. toaster.pop('error', '获取数据失败', response.data);
  906. });
  907. };
  908. loadData();
  909. }]);
  910. /**
  911. * 客户发货单列表
  912. */
  913. app.controller('SaleSendCtrl', ['$scope', 'SaleSend', 'toaster', 'BaseService', 'SaleTruck', 'Symbol', '$state', function($scope, SaleSend, toaster, BaseService, SaleTruck, Symbol, $state) {
  914. $scope.data = {};// 列表数据
  915. // 搜索框回车
  916. $scope.onSearch = function() {
  917. pageParams.keyword = $scope.keyword;
  918. getData();
  919. };
  920. var pageParams = { // 页面参数
  921. page : 1,
  922. count : 5,
  923. sorting: {
  924. date: 'desc'
  925. },
  926. keyword : null
  927. };
  928. $scope._state = 'todo';
  929. // 切换单据类型
  930. $scope.setState = function(state) {
  931. if($scope._state != state) {
  932. $scope._state = state;
  933. if(pageParams.page == 1)
  934. getData();
  935. else {
  936. pageParams.page = 1;
  937. getData();
  938. }
  939. }
  940. };
  941. // 加载数据
  942. var getData = function(add) {
  943. $scope.loading = true;
  944. pageParams.keyword = $scope.keyword;
  945. SaleSend[getState($scope._state)].call(null, BaseService.parseParams(pageParams), function(data){
  946. if(add) {
  947. data.content = $scope.data.content.concat(data.content);
  948. $scope.data = data;
  949. } else {
  950. $scope.data = data;
  951. }
  952. $scope.loading = false;
  953. }, function(response){
  954. $scope.loading = false;
  955. toaster.pop('error', '加载数据失败', response.data);
  956. });
  957. };
  958. getData();// 初始获取数据
  959. $scope.onSearch = function() {
  960. getData();
  961. }
  962. // 获取物料总数
  963. $scope.getProdCount = function(send) {
  964. var count = 0;
  965. angular.forEach(send.sendItems, function(item){
  966. count += (item.qty || 0);
  967. });
  968. return count;
  969. };
  970. // 加载更多数据
  971. $scope.getMoreData = function() {
  972. pageParams.page ++;
  973. getData(true);
  974. };
  975. }]);
  976. /**
  977. * 客户发货单列表
  978. */
  979. app.controller('SaleSendDetailCtrl', ['$scope','$stateParams', 'SaleSend', 'toaster', 'Symbol', function($scope,$stateParams, SaleSend, toaster, Symbol) {
  980. $scope.symbol = Symbol.currency;
  981. // 加载数据
  982. $scope.loading = true;
  983. SaleSend.get({id: $stateParams.id}, function(data){
  984. $scope.send = data;
  985. $scope.loading = false;
  986. }, function(response){
  987. $scope.loading = false;
  988. toaster.pop('error', '加载数据失败', response.data);
  989. });
  990. }]);
  991. /**
  992. * 客户认定单
  993. */
  994. app.controller('SaleApprovalCtrl', ['$scope', 'PurcApproval','toaster', 'BaseService' ,function($scope, PurcApproval,toaster,BaseService){
  995. $scope.data = {};// 列表数据
  996. // 搜索框回车
  997. $scope.onSearch = function() {
  998. pageParams.keyword = $scope.keyword;
  999. getData();
  1000. };
  1001. var pageParams = { // 页面参数
  1002. page : 1,
  1003. count : 5,
  1004. sorting: {
  1005. inDate: 'desc'
  1006. },
  1007. keyword: null
  1008. };
  1009. // 加载数据
  1010. var getData = function(add) {
  1011. $scope.loading = true;
  1012. pageParams.keyword = $scope.keyword;
  1013. PurcApproval.get(BaseService.parseParams(pageParams), null, function(data){
  1014. if(add) {
  1015. data.content = $scope.data.content.concat(data.content);
  1016. $scope.data = data;
  1017. } else {
  1018. $scope.data = data;
  1019. }
  1020. $scope.loading = false;
  1021. }, function(response){
  1022. $scope.loading = false;
  1023. toaster.pop('error', '加载数据失败', response.data);
  1024. });
  1025. };
  1026. getData();// 初始获取数据
  1027. // 加载更多数据
  1028. $scope.getMoreData = function() {
  1029. pageParams.page ++;
  1030. getData(true);
  1031. };
  1032. $scope.onSearch = function() {
  1033. getData();
  1034. }
  1035. }]);
  1036. /**
  1037. * 客户认定单详情
  1038. */
  1039. app.controller('SaleApprovalDetailCtrl', ['$scope', '$stateParams','toaster', 'PurcApproval', function($scope, $stateParams,toaster, PurcApproval){
  1040. var loading = true;
  1041. var loadData = function() {
  1042. PurcApproval.getItem({id: $stateParams.id},function(data) {
  1043. $scope.approval = data;
  1044. }, function(response){
  1045. $scope.loading = false;
  1046. toaster.pop('error', '加载数据失败', response.data);
  1047. })
  1048. }
  1049. loadData();
  1050. }]);
  1051. /**
  1052. * 客户验收单列表*/
  1053. app.controller('SaleAcceptListCtrl',['$scope','BaseService','PurcAccept','toaster',function($scope,BaseService,PurcAccept,toaster){
  1054. $scope.data = {};// 列表数据
  1055. var pageParams = {// 页面参数
  1056. page : 1,
  1057. count : 5,
  1058. sorting: {
  1059. date: 'desc'
  1060. }
  1061. };
  1062. // 加载数据
  1063. var getData = function(add) {
  1064. PurcAccept.getAll(BaseService.parseParams(pageParams),null,function(data){
  1065. if(add) {
  1066. data.content = $scope.data.content.concat(data.content);
  1067. $scope.data = data;
  1068. } else {
  1069. $scope.data = data;
  1070. }
  1071. $scope.loading = false;
  1072. }, function(response){
  1073. $scope.loading = false;
  1074. toaster.pop('error', '加载数据失败', response.data);
  1075. });
  1076. };
  1077. getData();//初始获取数据
  1078. $scope.getMoreData = function() {
  1079. pageParams.page ++;
  1080. getData(true);
  1081. };
  1082. // 获取物料种类数
  1083. $scope.getProdKind = function(accept) {
  1084. var kind = 0;
  1085. angular.forEach(accept.acceptItems, function(item){
  1086. kind = item.number;
  1087. });
  1088. return kind;
  1089. };
  1090. // 获取物料总数
  1091. $scope.getProdCount = function(accept) {
  1092. var count = 0;
  1093. angular.forEach(accept.acceptItems, function(item){
  1094. count += (item.qty || 0);
  1095. });
  1096. return count;
  1097. };
  1098. $scope.onSearch = function() {
  1099. getData();
  1100. }
  1101. }]);
  1102. /**
  1103. * 客户应付发票
  1104. */
  1105. app.controller('SaleApBillCtrl', ['$scope', '$stateParams', 'Symbol', 'toaster', 'FaApBill', 'BaseService', function($scope, $stateParams, Symbol, toaster, FaApBill, BaseService){
  1106. $scope.active = 'all';
  1107. $scope.data = {};
  1108. var pageParam = {
  1109. count : 5,
  1110. page : 1,
  1111. sorting : {
  1112. date : 'DESC'
  1113. }
  1114. };
  1115. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  1116. var getData = function(add) {
  1117. $scope.loading = true;
  1118. pageParam.keyword = $scope.keyword;
  1119. FaApBill.get(BaseService.parseParams(pageParam), null, function(data){
  1120. if(add) {
  1121. data.content = $scope.data.content.concat(data.content);
  1122. }
  1123. $scope.data = data;
  1124. $scope.loading = false;
  1125. }, function(response) {
  1126. $scope.loading = false;
  1127. toaster.pop('error', '加载数据失败', response.data);
  1128. });
  1129. }
  1130. getData();
  1131. $scope.getMoreData = function() {
  1132. pageParam.page++;
  1133. getData(true);
  1134. }
  1135. // 搜索框回车
  1136. $scope.onSearch = function() {
  1137. getData();
  1138. };
  1139. }]);
  1140. /*
  1141. * 应付对账单列表
  1142. */
  1143. app.controller('SaleArCheckCtrl',['$scope', '$stateParams', 'Symbol', 'toaster', 'FaArCheck', 'BaseService', function($scope, $stateParams, Symbol, toaster, FaArCheck, BaseService) {
  1144. $scope.data = {};
  1145. $scope._state = "all";
  1146. var pageParam = {
  1147. page : 1,
  1148. count : 5,
  1149. sorting : {
  1150. date : 'DESC'
  1151. }
  1152. };
  1153. $scope.currency = Symbol.currency;
  1154. var getData = function(add) {
  1155. $scope.loading = true;
  1156. pageParam.keyword = $scope.keyword;
  1157. FaArCheck[getState($scope._state)](BaseService.parseParams(pageParam), null, function(data){
  1158. if(add) {
  1159. data.content = $scope.data.content.concat(data.content);
  1160. }
  1161. $scope.data = data;
  1162. $scope.loading = false;
  1163. }, function(response) {
  1164. $scope.loading = false;
  1165. toaster.pop('error', '数据加载失败', response.data);
  1166. })
  1167. };
  1168. getData();
  1169. $scope.getMoreData = function() {
  1170. pageParam.page++;
  1171. getData(true);
  1172. };
  1173. //计算商品的总数
  1174. $scope.getTotalProd = function(check) {
  1175. var total = 0;
  1176. if(check.items){
  1177. angular.forEach(check.items, function(value) {
  1178. total += value.qty;
  1179. });
  1180. }
  1181. return total;
  1182. };
  1183. $scope.onSearch = function() {
  1184. getData();
  1185. };
  1186. $scope.setState = function(state) {
  1187. if($scope._state !=state) {
  1188. $scope._state = state;
  1189. pageParam.page = 1;
  1190. getData();
  1191. }
  1192. }
  1193. }]);
  1194. /*
  1195. * 应收对账单
  1196. */
  1197. app.controller('SaleReceCheckCtrl', function() {
  1198. //TODO
  1199. });
  1200. /*
  1201. * 应付对账单详情页
  1202. */
  1203. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', function($scope, $stateParams, FaArCheck, toaster, $state) {
  1204. var loadData = function() {
  1205. FaArCheck.get({id: $stateParams.id}, function(data) {
  1206. $scope.check = data;
  1207. $scope.loading = false;
  1208. })
  1209. }
  1210. loadData(); //加载初始的信息
  1211. $scope.onReplyClick = function(item, isAgreed) {
  1212. if(isAgreed) {// 同意确认
  1213. FaArCheck.agree({itemId: item.id}, {}, function(data){
  1214. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  1215. }, function(response){
  1216. toaster.pop('danger', '确认失败', response.data);
  1217. });
  1218. } else {// 不同意回复
  1219. FaArCheck.disagree({itemId: item.id}, {qty: item.$replyQty, remark: item.$replyRemark}, function(data) {
  1220. item.$editing = false;
  1221. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  1222. loadData();
  1223. }, function(response) {
  1224. item.$editing = false;
  1225. toaster.pop('danger', '确认失败', response.data);
  1226. loadData();
  1227. });
  1228. }
  1229. };
  1230. // 获取明细的回复记录
  1231. $scope.getReplies = function(item) {
  1232. if(!item.replies) {
  1233. FaArCheck.getReplies({itemId: item.id}, function(data) {
  1234. item.replies = data;
  1235. }, function(response) {
  1236. toaster.pop('danger', '获取对账记录失败', response.data);
  1237. });
  1238. }
  1239. };
  1240. }]);
  1241. /*
  1242. * 客户应付发票详情页
  1243. */
  1244. app.controller('FaApBillDetailCtrl', ['$scope', '$stateParams', 'Symbol', 'toaster', 'FaApBill', 'BaseService', function($scope, $stateParams, Symbol, toaster, FaApBill, BaseService) {
  1245. $scope.apBill = {};
  1246. $scope.currency = Symbol.currency;
  1247. FaApBill.get({id: $stateParams.id}, function(data) {
  1248. $scope.apBill = data;
  1249. console.log($scope.apBill);
  1250. $scope.loading = false;
  1251. }, function(response) {
  1252. toaster.pop('error', '获取记录失败', response.data);
  1253. $scope.loading = false;
  1254. });
  1255. }]);
  1256. /**
  1257. * 客户验收单详情
  1258. */
  1259. app.controller('SaleAcceptCtrl',['$scope','$stateParams','PurcAccept','Symbol','toaster',function($scope,$stateParams,PurcAccept,Symbol,toaster){
  1260. $scope.loading = true;
  1261. $scope.symbol = Symbol.currency;//把币别转化为符号
  1262. PurcAccept.get({id:$stateParams.id}, function(data){
  1263. $scope.accept = data;
  1264. $scope.loading = false;
  1265. },function(response){
  1266. $scope.loading = false;
  1267. toaster.pop('error', '加载失败', response.data);
  1268. });
  1269. //查看更多
  1270. $scope.page = 1;
  1271. $scope.count = 4;
  1272. $scope.showMore = function(length){
  1273. length = $scope.accept.acceptItems.length;
  1274. $scope.page ++;
  1275. }
  1276. }]);
  1277. /**
  1278. * 客户验退单列表
  1279. */
  1280. app.controller('SaleReturnListCtrl',['$scope','BaseService','PurcReturn','toaster',function($scope,BaseService,PurcReturn,toaster){
  1281. $scope.data = {};// 列表数据
  1282. var pageParams = {// 页面参数
  1283. page : 1,
  1284. count : 5,
  1285. sorting: {
  1286. date: 'desc'
  1287. }
  1288. };
  1289. // 加载数据
  1290. var getData = function(add) {
  1291. $scope.loading = true;
  1292. pageParams.keyword = $scope.keyword;
  1293. PurcReturn.getAll(BaseService.parseParams(pageParams),null,function(data){
  1294. if(add) {
  1295. data.content = $scope.data.content.concat(data.content);
  1296. $scope.data = data;
  1297. } else {
  1298. $scope.data = data;
  1299. }
  1300. $scope.loading = false;
  1301. }, function(response){
  1302. $scope.loading = false;
  1303. toaster.pop('error', '加载数据失败', response.data);
  1304. });
  1305. };
  1306. getData();
  1307. $scope.getMoreData = function() {
  1308. pageParams.page ++;
  1309. getData(true);
  1310. };
  1311. // 获取物料种类数
  1312. $scope.getProdKind = function(returns) {
  1313. var kind = 0;
  1314. angular.forEach(returns.returnItems, function(item){
  1315. kind = item.number;
  1316. });
  1317. return kind;
  1318. };
  1319. // 获取物料总数
  1320. $scope.getProdCount = function(returns) {
  1321. var count = 0;
  1322. angular.forEach(returns.returnItems, function(item){
  1323. count += (item.qty || 0);
  1324. });
  1325. return count;
  1326. };
  1327. $scope.onSearch = function() {
  1328. getData();
  1329. }
  1330. }]);
  1331. /**
  1332. * 客户验退单详情
  1333. * */
  1334. app.controller('SaleReturnCtrl',['$scope','$stateParams','PurcReturn','Symbol','toaster',function($scope,$stateParams,PurcReturn,Symbol,toaster){
  1335. $scope.symbol = Symbol.currency;//把币别转化为符号
  1336. $scope.loading = true;
  1337. PurcReturn.get({id:$stateParams.id},function(data){
  1338. $scope.returns = data;
  1339. $scope.loading = false;
  1340. },function(response) {
  1341. $scope.loading = false;
  1342. toaster.pop('error', '加载失败', response.data);
  1343. });
  1344. //点击加载更多
  1345. $scope.page = 1;
  1346. $scope.count = 4;
  1347. $scope.showMore = function(length){
  1348. length = $scope.accept.acceptItems.length;
  1349. $scope.page ++;
  1350. }
  1351. }]);
  1352. /**
  1353. * 委外加工单列表
  1354. * */
  1355. app.controller("MakeOrderListCtrl",['$scope','BaseService','MakeOrder','toaster',function($scope,BaseService,MakeOrder,toaster){
  1356. $scope.data = {};// 列表数据
  1357. var pageParams = { // 页面参数
  1358. page : 1,
  1359. count : 5,
  1360. sorting: {
  1361. date: 'desc'
  1362. },
  1363. searchFilter: { // 筛选条件
  1364. }
  1365. };
  1366. $scope._state = 'todo';
  1367. // 切换单据类型
  1368. $scope.setState = function(state) {
  1369. if($scope._state != state) {
  1370. $scope._state = state;
  1371. if(pageParams.page == 1)
  1372. getData();
  1373. else {
  1374. pageParams.page = 1;
  1375. getData();
  1376. }
  1377. }
  1378. };
  1379. // 加载数据
  1380. var getData = function(add) {
  1381. $scope.loading = true;
  1382. pageParams.searchFilter = {};
  1383. pageParams.searchFilter.keyword = $scope.keyword;
  1384. MakeOrder[getState($scope._state)].call(null, BaseService.parseParams(pageParams), function(data){
  1385. if(add) {
  1386. data.content = $scope.data.content.concat(data.content);
  1387. $scope.data = data;
  1388. } else {
  1389. $scope.data = data;
  1390. }
  1391. $scope.loading = false;
  1392. }, function(response){
  1393. $scope.loading = false;
  1394. toaster.pop('error', '加载数据失败', response.data);
  1395. });
  1396. };
  1397. getData();// 初始获取数据
  1398. // 加载更多数据
  1399. $scope.getMoreData = function() {
  1400. pageParams.page ++;
  1401. getData(true);
  1402. };
  1403. // 按条件查询
  1404. $scope.onClick = function() {
  1405. getData();
  1406. };
  1407. }]);
  1408. /**
  1409. * 委外加工单详情
  1410. * */
  1411. app.controller("MakeOrderCtrl",['$scope' , '$filter' , '$stateParams' , 'MakeOrder' , 'toaster' , 'Symbol' , function($scope , $filter , $stateParams , MakeOrder , toaster , Symbol){
  1412. $scope.loading = true;
  1413. $scope.symbol = Symbol.currency;
  1414. var loadData = function(){
  1415. MakeOrder.get({id:$stateParams.id}, function(data){
  1416. $scope.order = data;
  1417. $scope.loading = false;
  1418. },function(response){
  1419. $scope.loading = false;
  1420. toaster.pop('error', '加载失败', response.data);
  1421. });
  1422. };
  1423. loadData();
  1424. $scope.open = function($event, order) {
  1425. $event.preventDefault();
  1426. $event.stopPropagation();
  1427. order.opened = !order.opened;
  1428. };
  1429. // 展开回复
  1430. $scope.expandReply = function(order) {
  1431. if(!order.replys) {
  1432. MakeOrder.getReply({orderId:order.id}, function(data){
  1433. order.replys = data;
  1434. }, function(){
  1435. order.replysError = true;
  1436. });
  1437. }
  1438. order.expand = !order.expand;
  1439. };
  1440. //点击回复
  1441. $scope.reply = function(order) {
  1442. $scope.loading = true;
  1443. if(order.reply && order.reply.qty && order.reply.delivery) {
  1444. var reply = angular.copy(order.reply),
  1445. dateFilter = $filter('date');
  1446. if(reply.delivery) {
  1447. reply.delivery = reply.delivery.getTime();
  1448. }
  1449. MakeOrder.reply({orderId: order.id}, reply, function(){
  1450. $scope.loading = false;
  1451. order.expand = false;
  1452. loadData();
  1453. toaster.pop('success', '提示', '回复成功:' + reply.qty);
  1454. }, function(response){
  1455. $scope.loading = false;
  1456. toaster.pop('error', '回复失败', response.data);
  1457. });
  1458. } else {
  1459. $scope.loading = false;
  1460. toaster.pop('warning', '提示', '请填写回复的具体内容');
  1461. }
  1462. };
  1463. }]);
  1464. /**
  1465. * 委外变更单列表
  1466. * */
  1467. app.controller("MakeChangeListCtrl",['$scope','BaseService','MakeChange','toaster',function($scope,BaseService,MakeChange,toaster){
  1468. // 列表数据
  1469. $scope.data = {};
  1470. // 页面参数
  1471. $scope.pageParams = {
  1472. page : 1,
  1473. count : 5,
  1474. sorting: {
  1475. orderChangeDate: 'desc'
  1476. }
  1477. };
  1478. // 加载数据
  1479. $scope.getData = function(add) {
  1480. $scope.loading = true;
  1481. $scope.pageParams.searchFilter = {};
  1482. $scope.pageParams.searchFilter.keyword = $scope.keyword;
  1483. MakeChange.getAll(BaseService.parseParams($scope.pageParams),null,function(data){
  1484. if(add) {
  1485. data.content = $scope.data.content.concat(data.content);
  1486. $scope.data = data;
  1487. } else {
  1488. $scope.data = data;
  1489. }
  1490. $scope.loading = false;
  1491. }, function(response){
  1492. $scope.loading = false;
  1493. toaster.pop('error', '加载数据失败', response.data);
  1494. });
  1495. };
  1496. //初始获取数据
  1497. $scope.getData();
  1498. //加载更多数据
  1499. $scope.getMoreData = function() {
  1500. $scope.pageParams.page ++;
  1501. $scope.getData(true);
  1502. };
  1503. // 按条件查询
  1504. $scope.onClick = function() {
  1505. $scope.getData();
  1506. };
  1507. }]);
  1508. /**
  1509. * 委外变更单详情
  1510. * */
  1511. app.controller("MakeChangeCtrl",['$scope','$stateParams','MakeChange','toaster',function($scope,$stateParams,MakeChange,toaster){
  1512. $scope.loading = true;
  1513. $scope.remark = '';
  1514. //获取变更单
  1515. MakeChange.get({id: $stateParams.id}, function(data){
  1516. $scope.makeChange = data;
  1517. $scope.remark = data.replyRemark;
  1518. $scope.loading = false;
  1519. }, function(response){
  1520. toaster.pop('error', '数据加载失败', response.data);
  1521. });
  1522. //点击回复
  1523. $scope.onReplyClick = function(change) {
  1524. $scope.loading = true;
  1525. var reply = {id: change.id, agreed: Number(change.agreed), replyRemark: change.replyRemark};
  1526. MakeChange.reply({itemId: change.id}, reply, function(){
  1527. toaster.pop('info', '提示', '回复成功');
  1528. MakeChange.get({id: $stateParams.id}, function(data){
  1529. $scope.makeChange = data;
  1530. $scope.remark = data.replyRemark;
  1531. $scope.loading = false;
  1532. }, function(response){
  1533. console.log(response);
  1534. });
  1535. }, function(response){
  1536. $scope.loading = false;
  1537. toaster.pop('error', '回复失败', response.data);
  1538. });
  1539. };
  1540. }]);
  1541. /**
  1542. * 委外验收单列表
  1543. * */
  1544. app.controller("MakeAcceptListCtrl",['$scope','BaseService','MakeAccept','toaster',function($scope,BaseService,MakeAccept,toaster){
  1545. // 列表数据
  1546. $scope.data = {};
  1547. // 页面参数
  1548. $scope.pageParams = {
  1549. page : 1,
  1550. count : 5,
  1551. sorting: {
  1552. date: 'desc'
  1553. }
  1554. };
  1555. // 加载数据
  1556. $scope.getData = function(add) {
  1557. $scope.loading = true;
  1558. $scope.pageParams.searchFilter = {};
  1559. $scope.pageParams.searchFilter.keyword = $scope.keyword;
  1560. MakeAccept.getAll(BaseService.parseParams($scope.pageParams),null,function(data){
  1561. if(add) {
  1562. data.content = $scope.data.content.concat(data.content);
  1563. $scope.data = data;
  1564. } else {
  1565. $scope.data = data;
  1566. }
  1567. $scope.loading = false;
  1568. }, function(response){
  1569. $scope.loading = false;
  1570. toaster.pop('error', '加载数据失败', response.data);
  1571. });
  1572. };
  1573. //初始获取数据
  1574. $scope.getData();
  1575. //加载更多数据
  1576. $scope.getMoreData = function() {
  1577. $scope.pageParams.page ++;
  1578. $scope.getData(true);
  1579. };
  1580. // 按条件查询
  1581. $scope.onClick = function() {
  1582. $scope.getData();
  1583. };
  1584. // 获取物料种类数
  1585. $scope.getProdKind = function(accept) {
  1586. var kind = 0;
  1587. angular.forEach(accept.acceptItems, function(item){
  1588. kind = item.number;
  1589. });
  1590. return kind;
  1591. };
  1592. // 获取物料总数
  1593. $scope.getProdCount = function(accept) {
  1594. var count = 0;
  1595. angular.forEach(accept.acceptItems, function(item){
  1596. count += (item.qty || 0);
  1597. });
  1598. return count;
  1599. };
  1600. }]);
  1601. /**
  1602. * 委外验收单详情
  1603. * */
  1604. app.controller('MakeAcceptCtrl',['$scope','$stateParams','MakeAccept','toaster',function($scope,$stateParams,MakeAccept,toaster){
  1605. $scope.loading = true;
  1606. MakeAccept.get({id:$stateParams.id}, function(data){
  1607. $scope.accept = data;
  1608. $scope.loading = false;
  1609. },function(response){
  1610. $scope.loading = false;
  1611. toaster.pop('error', '加载失败', response.data);
  1612. });
  1613. //查看更多
  1614. $scope.page = 1;
  1615. $scope.count = 4;
  1616. $scope.showMore = function(length){
  1617. length = $scope.accept.acceptItems.length;
  1618. $scope.page ++;
  1619. }
  1620. }]);
  1621. /**
  1622. * 委外退货单列表
  1623. * */
  1624. app.controller("MakeReturnListCtrl",['$scope','BaseService','MakeReturn','toaster',function($scope,BaseService,MakeReturn,toaster){
  1625. // 列表数据
  1626. $scope.data = {};
  1627. // 页面参数
  1628. $scope.pageParams = {
  1629. page : 1,
  1630. count : 5,
  1631. sorting: {
  1632. date: 'desc'
  1633. }
  1634. };
  1635. // 加载数据
  1636. $scope.getData = function(add) {
  1637. $scope.loading = true;
  1638. $scope.pageParams.searchFilter = {};
  1639. $scope.pageParams.searchFilter.keyword = $scope.keyword;
  1640. MakeReturn.getAll(BaseService.parseParams($scope.pageParams),null,function(data){
  1641. if(add) {
  1642. data.content = $scope.data.content.concat(data.content);
  1643. $scope.data = data;
  1644. } else {
  1645. $scope.data = data;
  1646. }
  1647. $scope.loading = false;
  1648. }, function(response){
  1649. $scope.loading = false;
  1650. toaster.pop('error', '加载数据失败', response.data);
  1651. });
  1652. };
  1653. //初始获取数据
  1654. $scope.getData();
  1655. //加载更多数据
  1656. $scope.getMoreData = function() {
  1657. $scope.pageParams.page ++;
  1658. $scope.getData(true);
  1659. };
  1660. // 按条件查询
  1661. $scope.onClick = function() {
  1662. $scope.getData();
  1663. };
  1664. // 获取物料种类数
  1665. $scope.getProdKind = function(returns) {
  1666. var kind = 0;
  1667. angular.forEach(returns.returnItems, function(item){
  1668. kind = item.number;
  1669. });
  1670. return kind;
  1671. };
  1672. // 获取物料总数
  1673. $scope.getProdCount = function(returns) {
  1674. var count = 0;
  1675. angular.forEach(returns.returnItems, function(item){
  1676. count += (item.qty || 0);
  1677. });
  1678. return count;
  1679. };
  1680. }]);
  1681. /**
  1682. * 委外退货单详情
  1683. * */
  1684. app.controller('MakeReturnCtrl',['$scope','$stateParams','MakeReturn','toaster',function($scope,$stateParams,MakeReturn,toaster){
  1685. $scope.loading = true;
  1686. MakeReturn.get({id:$stateParams.id}, function(data){
  1687. $scope.returns = data;
  1688. $scope.loading = false;
  1689. },function(response){
  1690. $scope.loading = false;
  1691. toaster.pop('error', '加载失败', response.data);
  1692. });
  1693. //查看更多
  1694. $scope.page = 1;
  1695. $scope.count = 4;
  1696. $scope.showMore = function(length){
  1697. length = $scope.returns.returnItems.length;
  1698. $scope.page ++;
  1699. }
  1700. }]);
  1701. /**
  1702. * 客户不良品入库
  1703. */
  1704. app.controller('SaleBadInCtrl', ['$scope', 'PurcBadIn','BaseService' ,function($scope, PurcBadIn,BaseService){
  1705. $scope.data = {};// 列表数据
  1706. //搜索功能
  1707. $scope.onSearch = function() {
  1708. pageParams.keyword = $scope.keyword;
  1709. getData();
  1710. }
  1711. var pageParams = { // 页面参数
  1712. page : 1,
  1713. count : 5,
  1714. sorting: {
  1715. date: 'desc'
  1716. },
  1717. keyword: null
  1718. };
  1719. $scope._state = 'all';
  1720. // 加载数据
  1721. var getData = function(add) {
  1722. $scope.loading = true;
  1723. PurcBadIn[getState($scope._state)].call(null, BaseService.parseParams(pageParams), function(data){
  1724. if(add) {
  1725. data.content = $scope.data.content.concat(data.content);
  1726. $scope.data = data;
  1727. } else {
  1728. $scope.data = data;
  1729. }
  1730. $scope.loading = false;
  1731. }, function(response){
  1732. $scope.loading = false;
  1733. toaster.pop('error', '加载数据失败', response.data);
  1734. });
  1735. };
  1736. getData();// 初始获取数据
  1737. // 获取物料总数
  1738. $scope.getProdCount = function(order) {
  1739. var count = 0;
  1740. angular.forEach(order.badInItems, function(item){
  1741. count += (item.qty || 0);
  1742. });
  1743. return count;
  1744. };
  1745. // 加载更多数据
  1746. $scope.getMoreData = function() {
  1747. pageParams.page ++;
  1748. getData(true);
  1749. };
  1750. }]);
  1751. /**
  1752. * 客户不良品入库详情
  1753. */
  1754. app.controller('SaleBadInDetailCtrl', ['$scope','$stateParams', 'toaster','Symbol', 'PurcBadIn' ,function($scope,$stateParams,toaster,Symbol, PurcBadIn){
  1755. $scope.symbol = Symbol.currency;
  1756. // 加载数据
  1757. $scope.loading = true;
  1758. PurcBadIn.get({id:$stateParams.id}, function(data){
  1759. $scope.badIn = data;
  1760. $scope.loading = false;
  1761. }, function(response){
  1762. $scope.loading = false;
  1763. toaster.pop('error', '加载数据失败', response.data);
  1764. });
  1765. }]);
  1766. /**
  1767. * 客户不良品出库
  1768. */
  1769. app.controller('SaleBadOutCtrl', ['$scope', 'PurcBadOut','BaseService' ,function($scope, PurcBadOut,BaseService){
  1770. $scope.data = {};// 列表数据
  1771. //搜索功能
  1772. $scope.onSearch = function() {
  1773. pageParams.keyword = $scope.keyword;
  1774. getData();
  1775. }
  1776. var pageParams = { // 页面参数
  1777. page : 1,
  1778. count : 5,
  1779. sorting: {
  1780. date: 'desc'
  1781. },
  1782. keyword: null
  1783. };
  1784. $scope._state = 'all';
  1785. // 加载数据
  1786. var getData = function(add) {
  1787. $scope.loading = true;
  1788. PurcBadOut[getState($scope._state)].call(null, BaseService.parseParams(pageParams), function(data){
  1789. if(add) {
  1790. data.content = $scope.data.content.concat(data.content);
  1791. $scope.data = data;
  1792. } else {
  1793. $scope.data = data;
  1794. }
  1795. $scope.loading = false;
  1796. }, function(response){
  1797. $scope.loading = false;
  1798. toaster.pop('error', '加载数据失败', response.data);
  1799. });
  1800. };
  1801. getData();// 初始获取数据
  1802. // 获取物料总数
  1803. $scope.getProdCount = function(order) {
  1804. var count = 0;
  1805. angular.forEach(order.badOutItems, function(item){
  1806. count += (item.qty || 0);
  1807. });
  1808. return count;
  1809. };
  1810. // 加载更多数据
  1811. $scope.getMoreData = function() {
  1812. pageParams.page ++;
  1813. getData(true);
  1814. };
  1815. }]);
  1816. /**
  1817. * 客户不良品出库详情
  1818. */
  1819. app.controller('SaleBadOutDetailCtrl', ['$scope','$stateParams', 'toaster', 'Symbol','PurcBadOut' ,function($scope,$stateParams, toaster, Symbol,PurcBadOut){
  1820. $scope.symbol = Symbol.currency;
  1821. // 加载数据
  1822. $scope.loading = true;
  1823. PurcBadOut.get({id:$stateParams.id}, function(data){
  1824. $scope.badOut = data;
  1825. $scope.loading = false;
  1826. }, function(response){
  1827. $scope.loading = false;
  1828. toaster.pop('error', '加载数据失败', response.data);
  1829. });
  1830. }]);
  1831. /**
  1832. * 客户MRB
  1833. */
  1834. app.controller('SaleMRBCtrl', ['$scope', 'PurcMRB','BaseService' ,function($scope, PurcMRB,BaseService){
  1835. $scope.data = {};// 列表数据
  1836. //搜索功能
  1837. $scope.onSearch = function() {
  1838. pageParams.keyword = $scope.keyword;
  1839. getData();
  1840. }
  1841. var pageParams = { // 页面参数
  1842. page : 1,
  1843. count : 5,
  1844. sorting: {
  1845. date: 'desc'
  1846. },
  1847. keyword: null
  1848. };
  1849. $scope._state = 'all';
  1850. // 加载数据
  1851. var getData = function(add) {
  1852. $scope.loading = true;
  1853. PurcMRB[getState($scope._state)].call(null, BaseService.parseParams(pageParams), function(data){
  1854. if(add) {
  1855. data.content = $scope.data.content.concat(data.content);
  1856. $scope.data = data;
  1857. } else {
  1858. $scope.data = data;
  1859. }
  1860. $scope.loading = false;
  1861. }, function(response){
  1862. $scope.loading = false;
  1863. toaster.pop('error', '加载数据失败', response.data);
  1864. });
  1865. };
  1866. getData();// 初始获取数据
  1867. // 获取物料总数
  1868. $scope.getProdCount = function(order) {
  1869. var count = 0;
  1870. angular.forEach(order.badOutItems, function(item){
  1871. count += (item.qty || 0);
  1872. });
  1873. return count;
  1874. };
  1875. // 加载更多数据
  1876. $scope.getMoreData = function() {
  1877. pageParams.page ++;
  1878. getData(true);
  1879. };
  1880. }]);
  1881. /**
  1882. * 客户不良品入库详情
  1883. */
  1884. app.controller('SaleMRBDetailCtrl', ['$scope','$stateParams', 'toaster', 'PurcMRB' ,function($scope,$stateParams,toaster, PurcMRB){
  1885. // 加载数据
  1886. $scope.loading = true;
  1887. PurcMRB.get({id:$stateParams.id}, function(data){
  1888. $scope.MRB = data;
  1889. $scope.loading = false;
  1890. }, function(response){
  1891. $scope.loading = false;
  1892. toaster.pop('error', '加载数据失败', response.data);
  1893. });
  1894. }]);
  1895. /**
  1896. * 搜索框,回车触发
  1897. */
  1898. app.directive('ngSearch', ['$parse', function($parse) {
  1899. return {
  1900. require : '?ngModel',
  1901. restrict : 'A',
  1902. link : function(scope, element, attrs, ngModel) {
  1903. var searchFn = $parse(attrs.ngSearch);
  1904. element.bind('keypress', function(event) {
  1905. if (event.keyCode == '13') {
  1906. event.preventDefault();
  1907. event.stopPropagation();
  1908. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  1909. }
  1910. });
  1911. }
  1912. };
  1913. }]);
  1914. return app;
  1915. });