app.js 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508
  1. define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'service/Make', 'service/Account', 'service/Alert', 'ui.router', 'ui.bootstrap' , 'file-upload', 'ngSanitize'], function() {
  2. 'use strict';
  3. var app = angular.module('myApp', [ 'toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'PurcServices', 'MakeServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize']);
  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. 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. controller: function($scope) {
  40. $scope.truck = [];
  41. $scope.dataChanged = false;
  42. }
  43. }).state('sale.index', {
  44. url : "",
  45. templateUrl : "static/tpl/index/sale/index.html"
  46. }).state('sale.home', {
  47. url : "/",
  48. templateUrl : "static/tpl/index/sale/index.html"
  49. }).state('sale.todo', {
  50. url : "/todo",
  51. templateUrl : "static/tpl/index/sale/todo.html"
  52. }).state('sale.todo.inquiry', {
  53. url : "/inquiry",
  54. templateUrl : "static/tpl/index/sale/inquiry.html",
  55. controller: 'SaleInquiryCtrl'
  56. }).state('sale.todo.order', {
  57. url : "/order",
  58. templateUrl : "static/tpl/index/sale/order.html",
  59. controller: 'SaleOrderCtrl'
  60. }).state('sale.todo.change', {
  61. url : "/change",
  62. templateUrl : "static/tpl/index/sale/change.html",
  63. controller: 'SaleChangeCtrl'
  64. }).state('sale.todo.notice', {
  65. url : "/notice",
  66. templateUrl : "static/tpl/index/sale/notice.html",
  67. controller: 'SaleNoticeCtrl'
  68. }).state('sale.customer', {
  69. url : "/customer",
  70. templateUrl : "static/tpl/index/sale/customer.html",
  71. controller: 'CustomerCtrl'
  72. }).state('sale.customerProduct', {
  73. url : "/customerProduct",
  74. templateUrl : "static/tpl/index/sale/customer.html",
  75. controller: 'CustomerCtrl'
  76. }).state('sale.inquiry', {
  77. url : "/inquiry",
  78. templateUrl : "static/tpl/index/sale/inquiry.html",
  79. controller: 'SaleInquiryCtrl'
  80. }).state('sale.inquiry_detail', {
  81. url : "/inquiry/:id",
  82. templateUrl : "static/tpl/index/sale/inquiry_detail.html",
  83. controller: 'SaleInquiryDetailCtrl'
  84. }).state('sale.quotation', {
  85. url : "/quotation",
  86. templateUrl : "static/tpl/index/sale/quotation.html"
  87. }).state('sale.quotation.new', {
  88. url : "/new",
  89. templateUrl : "static/tpl/index/sale/quotation_new.html",
  90. controller: 'SaleQuotationNewCtrl'
  91. }).state('sale.quotation.list', {
  92. url : "/list",
  93. templateUrl : "static/tpl/index/sale/quotation_list.html",
  94. controller: 'SaleQuotationListCtrl'
  95. }).state('sale.quotation.item', {
  96. url : "/:id",
  97. templateUrl : "static/tpl/index/sale/quotation_new.html",
  98. controller: 'SaleQuotationNewCtrl'
  99. }).state('sale.order', {
  100. url : "/order",
  101. templateUrl : "static/tpl/index/sale/order.html",
  102. controller: 'SaleOrderCtrl'
  103. }).state('sale.order_detail', {
  104. url : "/order/:id",
  105. templateUrl : "static/tpl/index/sale/order_detail.html",
  106. controller: 'SaleOrderDetailCtrl'
  107. }).state('sale.change', {
  108. url : "/change",
  109. templateUrl : "static/tpl/index/sale/change.html",
  110. controller: 'SaleChangeCtrl'
  111. }).state('sale.change_detail', {
  112. url : "/change/:id",
  113. templateUrl : "static/tpl/index/sale/change_detail.html",
  114. controller: 'SaleChangeDetailCtrl'
  115. }).state('sale.notice', {
  116. url : "/notice",
  117. templateUrl : "static/tpl/index/sale/notice.html",
  118. controller: 'SaleNoticeCtrl'
  119. }).state('sale.send', {
  120. url : "/send",
  121. templateUrl : "static/tpl/index/sale/send.html",
  122. controller: 'SaleSendCtrl'
  123. }).state('sale.forecast', {
  124. url : "/forecast",
  125. templateUrl : "static/tpl/index/sale/forecast.html",
  126. controller: 'SaleForecastCtrl'
  127. }).state('sale.accept', {
  128. url : "/accept",
  129. templateUrl : "static/tpl/index/sale/accept.html",
  130. controller: 'SaleAcceptCtrl'
  131. }).state('sale.returns', {
  132. url : "/returns",
  133. templateUrl : "static/tpl/index/sale/returns.html",
  134. controller: 'SaleReturnsCtrl'
  135. }).state('sale.sample', {
  136. url : "/sample",
  137. templateUrl : "static/tpl/index/sale/sample.html",
  138. controller: 'SaleSampleCtrl'
  139. }).state('sale.approval', {
  140. url : "/approval",
  141. templateUrl : "static/tpl/index/sale/approval.html",
  142. controller: 'SaleApprovalCtrl'
  143. }).state('account', {
  144. url : "/account",
  145. views : {
  146. "left-view" : {
  147. templateUrl : "static/tpl/index/account/left.html"
  148. },
  149. "right-view" : {
  150. templateUrl : "static/tpl/index/account/right.html"
  151. }
  152. }
  153. }).state('account.index', {
  154. url : "",
  155. templateUrl : "static/tpl/index/account/index.html"
  156. }).state('account.home', {
  157. url : "/",
  158. templateUrl : "static/tpl/index/account/index.html"
  159. }).state('account.enterprise', {
  160. url : "/enterprise",
  161. templateUrl : "static/tpl/index/account/enterprise.html",
  162. controller: 'EnterpriseCtrl'
  163. }).state('account.user', {
  164. url : "/user",
  165. templateUrl : "static/tpl/index/account/user.html",
  166. controller: 'UserCtrl'
  167. }).state('account.log', {
  168. url : "/log",
  169. templateUrl : "static/tpl/index/account/log.html",
  170. controller: 'LogCtrl'
  171. }).state('account.resource', {
  172. url : "/resource",
  173. templateUrl : "static/tpl/index/account/resource.html",
  174. controller: 'ResourceCtrl'
  175. }).state('account.role', {
  176. url : "/role",
  177. templateUrl : "static/tpl/index/account/role.html",
  178. controller: 'RoleCtrl'
  179. }).state('qc', {
  180. url : "/qc",
  181. views : {
  182. "left-view" : {
  183. templateUrl : "static/tpl/index/qc/left.html"
  184. },
  185. "right-view" : {
  186. templateUrl : "static/tpl/index/qc/right.html"
  187. }
  188. }
  189. }).state('qc.badIn', {
  190. url : "/badIn",
  191. templateUrl : "static/tpl/index/qc/badIn.html",
  192. controller: 'SaleBadInCtrl'
  193. }).state('qc.badOut', {
  194. url : "/badOut",
  195. templateUrl : "static/tpl/index/qc/badOut.html",
  196. controller: 'SaleBadOutCtrl'
  197. }).state('qc.MRB', {
  198. url : "/MRB",
  199. templateUrl : "static/tpl/index/qc/MRB.html",
  200. controller: 'SaleMRBCtrl'
  201. }).state('fa', {
  202. url : "/fa",
  203. views : {
  204. "left-view" : {
  205. templateUrl : "static/tpl/index/fa/left.html"
  206. },
  207. "right-view" : {
  208. templateUrl : "static/tpl/index/fa/right.html"
  209. }
  210. }
  211. }).state('fa.apBill', {
  212. url : "/apBill",
  213. templateUrl : "static/tpl/index/fa/apBill.html",
  214. controller: 'SaleApBillCtrl'
  215. }).state('make', {
  216. url : "/make",
  217. views : {
  218. "left-view" : {
  219. templateUrl : "static/tpl/index/make/left.html"
  220. },
  221. "right-view" : {
  222. templateUrl : "static/tpl/index/make/right.html"
  223. }
  224. }
  225. }).state('make.index', {
  226. url : "",
  227. templateUrl : "static/tpl/index/make/index.html"
  228. }).state('make.order', {
  229. url : "/order",
  230. templateUrl : "static/tpl/index/make/order.html",
  231. controller: 'MakeOrderCtrl'
  232. }).state('make.order_detail', {
  233. url : "/order/:id",
  234. templateUrl : "static/tpl/index/make/order_detail.html",
  235. controller: 'SaleOrderDetailCtrl'
  236. });
  237. }]);
  238. /**
  239. * 表示符号
  240. */
  241. app.factory('Symbol', function(){
  242. return {
  243. currency: function(cur) {
  244. if(cur == 'RMB') return '¥';
  245. else if(cur == 'USD') return '$';
  246. else if(cur == 'EUR') return '€';
  247. else if(cur == null || cur == '') return '¥';
  248. else return cur;
  249. }
  250. };
  251. });
  252. app.controller('MyCtrl', ['$scope', '$rootScope', function($scope, $rootScope) {
  253. $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
  254. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  255. if (routeState.indexOf('/') > -1)
  256. routeState = routeState.substring(0, routeState.indexOf('/'));
  257. if (routeState.indexOf('.') > -1)
  258. routeState = routeState.substring(0, routeState.indexOf('.'));
  259. $scope.routeState = routeState || 'home';
  260. });
  261. }]);
  262. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', function($scope, $window, AuthenticationService, toaster) {
  263. $scope.isAuthed = AuthenticationService.isAuthed();
  264. $scope.userInfo = {};
  265. AuthenticationService.getAuthentication().success(function(data) {
  266. if(data.enterprises) {
  267. data.enterprise = data.enterprises[data.enterprises.length - 1];
  268. if(data.enterprises.length > 1) {
  269. var enSelect = [];
  270. angular.forEach(data.enterprises, function(e){
  271. if(e.current)
  272. data.enterprise = e;
  273. else
  274. enSelect.push(e);
  275. });
  276. data.enSelect = enSelect;
  277. }
  278. }
  279. $scope.userInfo = data;
  280. if (data == null || !data.uu)
  281. $scope.isAuthed = false;
  282. });
  283. $scope.logout = function() {
  284. AuthenticationService.logout().success(function() {
  285. $window.location.reload();
  286. });
  287. };
  288. $scope.switchto = function(enUU) {// 切换企业
  289. AuthenticationService.reSignin(enUU).success(function(){
  290. $window.location.reload();
  291. });
  292. };
  293. $scope.addFavorite = function(){
  294. var url = encodeURI(window.location.href);
  295. try{
  296. //ie浏览器收藏方式
  297. window.external.addFavorite(url, "优软商务平台");
  298. }catch(e) {
  299. try{
  300. //火狐浏览器收藏方式
  301. window.sidebar.addPanel("优软商务平台", url);
  302. }catch (e) {
  303. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
  304. "或手动在浏览器里进行设置。");
  305. }
  306. }
  307. };
  308. }]);
  309. app.controller('TodoCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  310. SnapshotService.getTodo(function(data){
  311. $scope.todo = data;
  312. });
  313. }]);
  314. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
  315. SaleTruck.query({}, function(data){
  316. $rootScope.truck = data;
  317. $scope.truckCount = data ? data.length : 0;
  318. });
  319. $scope.$watch(function(){
  320. return $rootScope.truck;
  321. }, function(data) {
  322. $scope.truckCount = data ? data.length : 0;
  323. }, true);
  324. $scope.clearAll = function() {
  325. SaleTruck.remove({}, function(){
  326. $rootScope.truck = [];
  327. });
  328. };
  329. $scope.openTrack = function() {
  330. $modal.open({
  331. templateUrl: 'static/tpl/index/sale/track.html',
  332. controller: 'TruckModalCtrl',
  333. size: 'lg'
  334. }).result.then(function(s){
  335. if(s) {
  336. $scope.clearAll();
  337. $rootScope.dataChanged = true;
  338. }
  339. });
  340. };
  341. }]);
  342. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster){
  343. $scope.saleSend = {sendItems: []};
  344. SaleTruck.detail({}, function(data){
  345. $scope.notices = data;
  346. });
  347. $scope.remove = function(index, notice) {
  348. SaleTruck.remove({noticeId: notice.id}, function(data){
  349. $rootScope.truck = data;
  350. $scope.notices.splice(index, 1);
  351. });
  352. };
  353. $scope.$watch(function(){
  354. return $scope.notices;
  355. }, function(data) {
  356. var q = 0, t = 0;
  357. if(data) {
  358. angular.forEach(data,function(d){
  359. q += d.thisSendQty;
  360. t += d.thisSendQty * d.orderItem.price;
  361. });
  362. }
  363. $scope.totalQty = q;
  364. $scope.total = t;
  365. }, true);
  366. $scope.cancel = function() {
  367. $modalInstance.close();
  368. };
  369. $scope.send = function() {// 发货
  370. if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  371. toaster.pop('error', '错误', '请输入送货单号');
  372. return;
  373. }
  374. var currency = $scope.notices[0].orderItem.order.currency,
  375. custUU = $scope.notices[0].enUU,
  376. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  377. for(var i in $scope.notices) {
  378. var item = $scope.notices[i];
  379. if(item.id) {
  380. if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  381. valid = false;
  382. break;
  383. }
  384. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price};
  385. }
  386. }
  387. if(!valid) {
  388. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  389. } else {
  390. var send = angular.extend(angular.copy($scope.saleSend), {
  391. currency: currency,
  392. custUU: custUU,
  393. payments: payments,
  394. sendItems: items
  395. });
  396. PurcNotice.sendByBatch({}, send, function(data){
  397. toaster.pop('success', '提示', '发货成功。');
  398. $modalInstance.close(true);
  399. }, function(response){
  400. toaster.pop('error', '错误', response.data);
  401. });
  402. }
  403. };
  404. }]);
  405. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
  406. SaleStat.cust({}, function(data){
  407. var p = [], q = [];
  408. angular.forEach(data.month, function(d){
  409. p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  410. });
  411. angular.forEach(data.year, function(d){
  412. q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
  413. });
  414. $scope.custCharts = {
  415. month : {
  416. chartType : 'pie',
  417. datas : {
  418. data : p
  419. },
  420. config : {
  421. labels : false,
  422. title : "客户月采购量排行榜",
  423. legend : {
  424. display : true,
  425. position : 'right'
  426. },
  427. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  428. click : function(d) {
  429. },
  430. mouseover : function(d) {
  431. },
  432. mouseout : function(d) {
  433. },
  434. innerRadius : 0,
  435. lineLegend : 'lineEnd'
  436. }
  437. },
  438. year : {
  439. chartType : 'pie',
  440. datas : {
  441. data : q
  442. },
  443. config : {
  444. labels : false,
  445. title : "客户年采购量排行榜",
  446. legend : {
  447. display : true,
  448. position : 'right'
  449. },
  450. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  451. click : function(d) {
  452. },
  453. mouseover : function(d) {
  454. },
  455. mouseout : function(d) {
  456. },
  457. innerRadius : 0,
  458. lineLegend : 'lineEnd'
  459. }
  460. }
  461. };
  462. });
  463. SaleStat.seller({}, function(data){
  464. var p = [], q = [];
  465. angular.forEach(data.month, function(d){
  466. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  467. });
  468. angular.forEach(data.year, function(d){
  469. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  470. });
  471. $scope.sellerCharts = {
  472. month : {
  473. chartType : 'pie',
  474. datas : {
  475. data : p
  476. },
  477. config : {
  478. labels : false,
  479. title : "业务员月销量排行榜",
  480. legend : {
  481. display : true,
  482. position : 'right'
  483. },
  484. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  485. click : function(d) {
  486. },
  487. mouseover : function(d) {
  488. },
  489. mouseout : function(d) {
  490. },
  491. innerRadius : 0,
  492. lineLegend : 'lineEnd'
  493. }
  494. },
  495. year : {
  496. chartType : 'pie',
  497. datas : {
  498. data : q
  499. },
  500. config : {
  501. labels : false,
  502. title : "业务员年销量排行榜",
  503. legend : {
  504. display : true,
  505. position : 'right'
  506. },
  507. colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
  508. click : function(d) {
  509. },
  510. mouseover : function(d) {
  511. },
  512. mouseout : function(d) {
  513. },
  514. innerRadius : 0,
  515. lineLegend : 'lineEnd'
  516. }
  517. }
  518. };
  519. });
  520. }]);
  521. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
  522. SaleStat.get({}, function(data){
  523. var p = [], q = [], r = [];
  524. angular.forEach(data.day, function(d){
  525. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  526. });
  527. angular.forEach(data.month, function(d){
  528. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  529. });
  530. angular.forEach(data.year, function(d){
  531. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  532. });
  533. $scope.charts = {
  534. day : {
  535. chartType : "line",
  536. datas: {
  537. series: ['销售额'],
  538. data: p
  539. },
  540. config : {
  541. "labels": false,
  542. "title": "销售额统计(近15日线)",
  543. "legend": {
  544. "display": true,
  545. "position": "right"
  546. },
  547. colors : [ '#4D9934'],
  548. "innerRadius": 0,
  549. "lineLegend": "lineEnd"
  550. }
  551. },
  552. month: {
  553. chartType : "line",
  554. datas: {
  555. series: ['销售额'],
  556. data: q
  557. },
  558. config : {
  559. "labels": false,
  560. "title": "销售额统计(近12月线)",
  561. "legend": {
  562. "display": true,
  563. "position": "right"
  564. },
  565. colors : [ '#4D9934'],
  566. "innerRadius": 0,
  567. "lineLegend": "lineEnd"
  568. }
  569. },
  570. year: {
  571. chartType : "line",
  572. datas: {
  573. series: ['销售额'],
  574. data: r
  575. },
  576. config : {
  577. "labels": false,
  578. "title": "销售额统计(近10年线)",
  579. "legend": {
  580. "display": true,
  581. "position": "right"
  582. },
  583. colors : [ '#4D9934'],
  584. "innerRadius": 0,
  585. "lineLegend": "lineEnd"
  586. }
  587. }
  588. };
  589. });
  590. }]);
  591. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
  592. SnapshotService.getNotice(5, function(data){
  593. $scope.notices = data;
  594. });
  595. $scope.dateTime = new Date();
  596. }]);
  597. app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
  598. VendorService.getCount(function(date){
  599. $scope.count = date;
  600. });
  601. }]);
  602. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService', 'ngTableParams', 'toaster', function($scope, VendorService, BaseService, ngTableParams, toaster){
  603. $scope.customerParams = new ngTableParams({
  604. page : 1,
  605. count : 10
  606. }, {
  607. total : 0,
  608. counts: [5, 10, 25, 50],
  609. getData : function($defer, params) {
  610. $scope.loading = true;
  611. VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
  612. $scope.loading = false;
  613. if(page) {
  614. params.total(page.totalElements);
  615. $defer.resolve(page.content);
  616. }
  617. $scope.totalCount = page.totalElements;
  618. }, function(response){
  619. $scope.loading = false;
  620. toaster.pop('error', '数据加载失败', response.data);
  621. });
  622. }
  623. });
  624. }]);
  625. var getState = function(active) {
  626. var fn = 'get';
  627. switch(active) {
  628. case 'done':
  629. fn = 'getDone';break;
  630. case 'todo':
  631. fn = 'getTodo';break;
  632. case 'end':
  633. fn = 'getEnd';break;
  634. case 'waiting':
  635. fn = 'getWaiting';break;
  636. }
  637. return fn;
  638. };
  639. var getDateCondition = function(zone, condition) {
  640. var date = new Date();
  641. if(zone == 1) {
  642. date.setMonth(date.getMonth() - 1);
  643. condition.dateFrom = date;
  644. condition.dateTo = new Date();
  645. } else if (zone == 6) {
  646. date.setMonth(date.getMonth() - 6);
  647. condition.dateFrom = date;
  648. condition.dateTo = new Date();
  649. } else {
  650. date.setMonth(date.getMonth() - 6);
  651. condition.dateFrom = null;
  652. condition.dateTo = date;
  653. }
  654. };
  655. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
  656. function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
  657. $scope.active = 'todo';
  658. $scope.dateZoneText = '一个月内';
  659. $scope.condition = {dateZone: 1};
  660. $scope.changeDateZone = function(zone) {
  661. $scope.condition.dateZone = zone;
  662. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  663. $scope.condition.$dateZoneOpen = false;
  664. getDateCondition(zone, $scope.condition);
  665. $scope.tableParams.reload();
  666. };
  667. $scope.setActive = function(state) {
  668. if($scope.active != state) {
  669. $scope.active = state;
  670. if($scope.tableParams.page() == 1)
  671. $scope.tableParams.reload();
  672. else
  673. $scope.tableParams.page(1);
  674. }
  675. };
  676. var getService = function() {
  677. return $scope.condition.dateZone ? PurcOrderItem : PurcOrderItemHis;
  678. };
  679. $scope.tableParams = new ngTableParams({
  680. page : 1,
  681. count : 5,
  682. sorting: {
  683. display: 'desc',
  684. date: 'desc'
  685. }
  686. }, {
  687. total : 0,
  688. counts: [5, 10, 25, 50],
  689. getData : function($defer, params) {
  690. $scope.loading = true;
  691. var pageParams = params.url();
  692. pageParams.keyword = $scope.keyword;
  693. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  694. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  695. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  696. $scope.loading = false;
  697. if(page) {
  698. params.total(page.totalElements);
  699. $defer.resolve(page.content);
  700. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  701. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  702. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  703. }
  704. }, function(response){
  705. $scope.loading = false;
  706. toaster.pop('error', '数据加载失败', response.data);
  707. });
  708. }
  709. });
  710. $scope.getOrderTotal = function(items) {
  711. var sum = 0;
  712. angular.forEach(items, function(item){
  713. sum += item.qty * item.price;
  714. });
  715. return sum;
  716. };
  717. $scope.openDatePicker = function($event, item, openParam) {
  718. $event.preventDefault();
  719. $event.stopPropagation();
  720. item[openParam] = !item[openParam];
  721. };
  722. $scope.parseDate = function(dateStr) {
  723. if(dateStr)
  724. return Date.parse(dateStr, 'yyyy-MM-dd');
  725. return new Date();
  726. };
  727. $scope.onReplyClick = function(item, inverse) {
  728. if(item.reply) {
  729. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  730. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  731. return;
  732. }
  733. var reply = angular.copy(item.reply);
  734. if(reply.delivery) {
  735. if(typeof reply.delivery == 'object')
  736. reply.delivery = reply.delivery.getTime();
  737. } else {
  738. reply.delivery = item.delivery;
  739. }
  740. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  741. $scope.loading = true;
  742. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  743. $scope.loading = false;
  744. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  745. $scope.tableParams.reload();
  746. }, function(response){
  747. $scope.loading = false;
  748. toaster.pop('error', '回复失败', response.data);
  749. });
  750. }
  751. };
  752. //打印
  753. $scope.print = function(order) {
  754. PurcOrder.printCount({id: order.id},{});//增加打印此次
  755. if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  756. ReportService.print(order.enUU, 'purchase', '{purc_orders.pu_id}=' + order.id, '销售订单-' + order.code);
  757. };
  758. $scope.getReply = function(item) {
  759. if(!item.replies) {
  760. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  761. item.replies = replies;
  762. });
  763. }
  764. };
  765. $scope.checkboxes = {
  766. checked : false
  767. };
  768. // 点击勾选全部的复选框
  769. $scope.checkAll = function(){
  770. angular.forEach($scope.tableParams.data, function(item) {
  771. item.$selected = $scope.checkboxes.checked;
  772. });
  773. };
  774. // 点击其中一个明细的复选框
  775. $scope.checkOne = function(order){
  776. var result = true;
  777. angular.forEach($scope.tableParams.data, function(item) {
  778. if(item.$selected != true){
  779. result = false;
  780. return;
  781. }
  782. });
  783. $scope.checkboxes.checked = result;
  784. };
  785. //批量回复采购订单
  786. $scope.replyByBatch = function() {
  787. $scope.loading = true;
  788. var str = '';
  789. angular.forEach($scope.tableParams.data, function(order) {
  790. if(order.$selected == true) {
  791. angular.forEach(order.orderItems, function(item){
  792. str += item.id;
  793. str += ',';
  794. });
  795. }
  796. });
  797. if(!(str == '')) {
  798. str = str.substr(0, str.length-1);
  799. PurcOrderItem.replyByBatch(str, function(){
  800. $scope.loading = false;
  801. $scope.tableParams.reload();
  802. toaster.pop('success', '提示', '批量回复成功');
  803. }, function(data){
  804. $scope.loading = false;
  805. toaster.pop('error', '批量回复失败', data);
  806. });
  807. } else {//没有勾选其中的明细
  808. $scope.loading = false;
  809. }
  810. };
  811. // 搜索框回车
  812. $scope.onSearch = function() {
  813. $scope.tableParams.page(1);
  814. $scope.tableParams.reload();
  815. };
  816. // 选择查找日期
  817. $scope.onDateCondition = function(){
  818. $scope.tableParams.page(1);
  819. $scope.tableParams.reload();
  820. };
  821. //设置为已查看
  822. $scope.setDisplay = function(state, orderId) {
  823. if(orderId) {//设置单个
  824. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  825. $scope.tableParams.reload();
  826. }, function() {
  827. toaster.pop('error', '错误', "设置失败");
  828. });
  829. } else {//设置已勾选的
  830. var str = null;
  831. angular.forEach($scope.tableParams.data, function(order) {
  832. if(order.$selected == true) {
  833. if(str != null && str != '') str += ',';
  834. str += order.id;
  835. }
  836. });
  837. if(str != null && str != '') {
  838. PurcOrder[state].call({}, {ids: '' + str}, function(){
  839. $scope.tableParams.reload();
  840. }, function() {
  841. toaster.pop('error', '错误', "设置失败");
  842. });
  843. }
  844. }
  845. };
  846. }]);
  847. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
  848. var loadData = function() {
  849. PurcOrder.get({id: $stateParams.id}, function(data){
  850. $scope.order = data;
  851. var sum = 0;
  852. angular.forEach($scope.order.orderItems, function(item){
  853. sum += item.qty * item.price;
  854. });
  855. $scope.order.total = sum;
  856. if($scope.order.display == 1) {//未查看的设为已查看
  857. $scope.setDisplay('setRead', $scope.order.id);
  858. }
  859. $scope.loading = false;
  860. });
  861. };
  862. loadData();
  863. $scope.getReply = function(item) {
  864. if(!item.replies) {
  865. PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
  866. item.replies = replies;
  867. });
  868. }
  869. };
  870. $scope.openDatePicker = function($event, item, openParam) {
  871. $event.preventDefault();
  872. $event.stopPropagation();
  873. item[openParam] = !item[openParam];
  874. };
  875. $scope.onReplyClick = function(item, inverse) {
  876. if(item.reply) {
  877. if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  878. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  879. return;
  880. }
  881. var reply = angular.copy(item.reply);
  882. if(reply.delivery) {
  883. if(typeof reply.delivery == 'object')
  884. reply.delivery = reply.delivery.getTime();
  885. } else {
  886. reply.delivery = item.delivery;
  887. }
  888. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  889. $scope.loading = true;
  890. PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
  891. $scope.loading = false;
  892. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  893. loadData();
  894. }, function(response){
  895. $scope.loading = false;
  896. toaster.pop('error', '回复失败', response.data);
  897. });
  898. }
  899. };
  900. $scope.print = function(order) {
  901. PurcOrder.printCount({id: order.id},{});//增加打印此次
  902. ReportService.print(order.enUU, 'purchase', '{purc_orders.pu_id}=' + order.id, '销售订单-' + order.code);
  903. };
  904. //设置为已查看
  905. $scope.setDisplay = function(state, orderId) {
  906. console.log(PurcOrder);
  907. if(orderId) {//设置单个
  908. PurcOrder[state].call({}, {ids: '' + orderId}, function(){
  909. $scope.tableParams.reload();
  910. }, function() {
  911. toaster.pop('error', '错误', "设置失败");
  912. });
  913. } else {//设置已勾选的
  914. var str = null;
  915. angular.forEach($scope.tableParams.data, function(order) {
  916. if(order.$selected == true) {
  917. if(str != null && str != '') str += ',';
  918. str += order.id;
  919. }
  920. });
  921. if(str != null && str != '') {
  922. PurcOrder[state].call({}, {ids: '' + str}, function(){
  923. $scope.tableParams.reload();
  924. }, function() {
  925. toaster.pop('error', '错误', "设置失败");
  926. });
  927. }
  928. }
  929. };
  930. }]);
  931. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, ngTableParams, toaster, BaseService, PurcChangeHis){
  932. $scope.active = 'todo';
  933. $scope.agreedText = '全部';
  934. $scope.dateZoneText = '一个月内';
  935. $scope.condition = {dateZone: 1};
  936. $scope.changeAgreed = function(agreed) {
  937. $scope.condition.agreed = agreed;
  938. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  939. $scope.condition.$agreedOpen = false;
  940. };
  941. $scope.changeDateZone = function(zone) {
  942. $scope.condition.dateZone = zone;
  943. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  944. $scope.condition.$dateZoneOpen = false;
  945. };
  946. $scope.setActive = function(state) {
  947. if($scope.active != state) {
  948. $scope.active = state;
  949. if($scope.tableParams.page() == 1)
  950. $scope.tableParams.reload();
  951. else
  952. $scope.tableParams.page(1);
  953. }
  954. };
  955. var getService = function() {
  956. return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
  957. };
  958. $scope.tableParams = new ngTableParams({
  959. page : 1,
  960. count : 5,
  961. sorting: {
  962. date: 'desc'
  963. }
  964. }, {
  965. total : 0,
  966. counts: [5, 10, 25, 50],
  967. getData : function($defer, params) {
  968. $scope.loading = true;
  969. var pageParams = params.url();
  970. pageParams.keyword = $scope.keyword;
  971. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  972. $scope.loading = false;
  973. if(page) {
  974. params.total(page.totalElements);
  975. $defer.resolve(page.content);
  976. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  977. }
  978. }, function(response){
  979. $scope.loading = false;
  980. toaster.pop('error', '数据加载失败', response.data);
  981. });
  982. }
  983. });
  984. $scope.openDatePicker = function($event, item, openParam) {
  985. $event.preventDefault();
  986. $event.stopPropagation();
  987. item[openParam] = !item[openParam];
  988. };
  989. $scope.onReplyClick = function(change) {
  990. if(change.$agreed) {
  991. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  992. $scope.loading = true;
  993. PurcChange.reply({changeId: change.id}, reply, function(){
  994. $scope.loading = false;
  995. toaster.pop('info', '提示', '回复成功');
  996. $scope.tableParams.reload();
  997. }, function(response){
  998. $scope.loading = false;
  999. toaster.pop('error', '回复失败', response.data);
  1000. });
  1001. }
  1002. };
  1003. // 搜索框回车
  1004. $scope.onSearch = function() {
  1005. $scope.tableParams.page(1);
  1006. $scope.tableParams.reload();
  1007. };
  1008. }]);
  1009. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
  1010. var loadData = function() {
  1011. PurcChange.get({id: $stateParams.id}, function(data){
  1012. $scope.change = data;
  1013. });
  1014. };
  1015. loadData();
  1016. $scope.openDatePicker = function($event, item, openParam) {
  1017. $event.preventDefault();
  1018. $event.stopPropagation();
  1019. item[openParam] = !item[openParam];
  1020. };
  1021. $scope.onReplyClick = function(change) {
  1022. if(change.$agreed) {
  1023. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  1024. PurcChange.reply({changeId: change.id}, reply, function(){
  1025. toaster.pop('info', '提示', '回复成功');
  1026. loadData();
  1027. }, function(response){
  1028. toaster.pop('error', '回复失败', response.data);
  1029. });
  1030. }
  1031. };
  1032. }]);
  1033. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis){
  1034. $scope.active = 'todo';
  1035. $scope.agreedText = '全部';
  1036. $scope.dateZoneText = '一个月内';
  1037. $scope.condition = {dateZone: 1};
  1038. $scope.changeAgreed = function(agreed) {
  1039. $scope.condition.agreed = agreed;
  1040. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  1041. $scope.condition.$agreedOpen = false;
  1042. };
  1043. $scope.changeDateZone = function(zone) {
  1044. $scope.condition.dateZone = zone;
  1045. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1046. $scope.condition.$dateZoneOpen = false;
  1047. };
  1048. $scope.setActive = function(state) {
  1049. if($scope.active != state) {
  1050. $scope.active = state;
  1051. if($scope.tableParams.page() == 1)
  1052. $scope.tableParams.reload();
  1053. else
  1054. $scope.tableParams.page(1);
  1055. }
  1056. };
  1057. var getService = function() {
  1058. return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
  1059. };
  1060. $scope.tableParams = new ngTableParams({
  1061. page : 1,
  1062. count : 5,
  1063. sorting: {
  1064. 'inquiry.date': 'desc',
  1065. 'inquiry.enterprise.enName': 'asc',
  1066. 'inquiry.code': 'asc'
  1067. }
  1068. }, {
  1069. total : 0,
  1070. counts: [5, 10, 25, 50],
  1071. getData : function($defer, params) {
  1072. $scope.loading = true;
  1073. var pageParams = params.url();
  1074. pageParams.keyword = $scope.keyword;
  1075. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1076. $scope.loading = false;
  1077. if(page) {
  1078. params.total(page.totalElements);
  1079. $defer.resolve(page.content);
  1080. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1081. }
  1082. }, function(response){
  1083. $scope.loading = false;
  1084. toaster.pop('error', '数据加载失败', response.data);
  1085. });
  1086. }
  1087. });
  1088. $scope.getMinDate = function(item) {
  1089. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  1090. };
  1091. $scope.addStep = function(inquiryItem) {
  1092. if(inquiryItem.replies.length >= 10) {
  1093. toaster.pop('warning', '提示', '最多支持10个分段!');
  1094. } else
  1095. inquiryItem.replies.push({});
  1096. };
  1097. $scope.removeStep = function(inquiryItem, stepIndex) {
  1098. inquiryItem.replies.splice(stepIndex, 1);
  1099. };
  1100. $scope.openDatePicker = function($event, item, openParam) {
  1101. $event.preventDefault();
  1102. $event.stopPropagation();
  1103. item[openParam] = !item[openParam];
  1104. };
  1105. $scope.getHistory = function(item) {
  1106. if(!item.history) {
  1107. PurcInquiry.getHistory({itemId: item.id}, function(data){
  1108. item.history = data;
  1109. });
  1110. }
  1111. };
  1112. $scope.isValid = function(item, withSteps) {
  1113. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  1114. if(!withSteps || !bool)
  1115. return bool;
  1116. angular.forEach(item.replies, function(r, i){
  1117. bool = (i > 0 ? r.lapQty : 1) && r.price;
  1118. });
  1119. return bool;
  1120. };
  1121. $scope.onReplyClick = function(item, withSteps) {
  1122. if(item.vendFromDate instanceof Date) {
  1123. item.vendFromDate = item.vendFromDate.getTime();
  1124. }
  1125. if(item.vendToDate instanceof Date) {
  1126. item.vendToDate = item.vendToDate.getTime();
  1127. }
  1128. if(item.vendFromDate > item.vendToDate) {
  1129. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  1130. return;
  1131. }
  1132. var replies = [];
  1133. angular.forEach(item.replies, function(r, i){
  1134. if((i > 0 ? r.lapQty : 1) || r.price)
  1135. replies.push(r);
  1136. });
  1137. item.replies = replies;
  1138. $scope.loading = true;
  1139. if(withSteps) {
  1140. PurcInquiry.reply({itemId: item.id}, item, function(){
  1141. $scope.loading = false;
  1142. toaster.pop('info', '提示', '报价成功');
  1143. $scope.tableParams.reload();
  1144. }, function(response){
  1145. $scope.loading = false;
  1146. toaster.pop('error', '报价失败', response.data);
  1147. });
  1148. } else {
  1149. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  1150. $scope.loading = false;
  1151. toaster.pop('info', '提示', '保存成功');
  1152. $scope.tableParams.reload();
  1153. }, function(response){
  1154. $scope.loading = false;
  1155. toaster.pop('error', '保存失败', response.data);
  1156. });
  1157. }
  1158. };
  1159. // 搜索框回车
  1160. $scope.onSearch = function() {
  1161. $scope.tableParams.page(1);
  1162. $scope.tableParams.reload();
  1163. };
  1164. }]);
  1165. // 询价单明细
  1166. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', 'toaster', function($scope, $stateParams, PurcInquiry, toaster){
  1167. var loadData = function() {
  1168. PurcInquiry.getAll({id: $stateParams.id}, function(data){
  1169. var inquiry = data[0].inquiry;
  1170. inquiry.inquiryItems = data;
  1171. angular.forEach(inquiry.attachs, function(attach){
  1172. attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
  1173. });
  1174. $scope.inquiry = inquiry;
  1175. });
  1176. };
  1177. loadData();
  1178. $scope.getMinDate = function(item) {
  1179. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  1180. };
  1181. $scope.addStep = function(inquiryItem) {
  1182. if(inquiryItem.replies.length >= 10) {
  1183. toaster.pop('warning', '提示', '最多支持10个分段!');
  1184. } else
  1185. inquiryItem.replies.push({});
  1186. };
  1187. $scope.removeStep = function(inquiryItem, stepIndex) {
  1188. inquiryItem.replies.splice(stepIndex, 1);
  1189. };
  1190. $scope.openDatePicker = function($event, item, openParam) {
  1191. $event.preventDefault();
  1192. $event.stopPropagation();
  1193. item[openParam] = !item[openParam];
  1194. };
  1195. $scope.getHistory = function(item) {
  1196. if(!item.history) {
  1197. PurcInquiry.getHistory({itemId: item.id}, function(data){
  1198. item.history = data;
  1199. });
  1200. }
  1201. };
  1202. $scope.isValid = function(item, withSteps) {
  1203. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  1204. if(!withSteps || !bool)
  1205. return bool;
  1206. angular.forEach(item.replies, function(r, i){
  1207. bool = (i > 0 ? r.lapQty : 1) && r.price;
  1208. });
  1209. return bool;
  1210. };
  1211. $scope.onReplyClick = function(item, withSteps) {
  1212. if(item.vendFromDate instanceof Date) {
  1213. item.vendFromDate = item.vendFromDate.getTime();
  1214. }
  1215. if(item.vendToDate instanceof Date) {
  1216. item.vendToDate = item.vendToDate.getTime();
  1217. }
  1218. if(item.vendFromDate > item.vendToDate) {
  1219. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  1220. return;
  1221. }
  1222. var replies = [];
  1223. angular.forEach(item.replies, function(r, i){
  1224. if((i > 0 ? r.lapQty : 1) || r.price)
  1225. replies.push(r);
  1226. });
  1227. item.replies = replies;
  1228. if(withSteps) {
  1229. PurcInquiry.reply({itemId: item.id}, item, function(){
  1230. toaster.pop('info', '提示', '报价成功');
  1231. loadData();
  1232. }, function(response){
  1233. toaster.pop('error', '报价失败', response.data);
  1234. });
  1235. } else {
  1236. PurcInquiry.saveItem({itemId: item.id}, item, function(){
  1237. toaster.pop('info', '提示', '保存成功');
  1238. loadData();
  1239. }, function(response){
  1240. toaster.pop('error', '保存失败', response.data);
  1241. });
  1242. }
  1243. };
  1244. }]);
  1245. // 主动报价 - 列表
  1246. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService){
  1247. $scope.active = 'todo';
  1248. $scope.agreedText = '全部';
  1249. $scope.dateZoneText = '一个月内';
  1250. $scope.condition = {dateZone: 1};
  1251. $scope.changeDateZone = function(zone) {
  1252. $scope.condition.dateZone = zone;
  1253. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1254. $scope.condition.$dateZoneOpen = false;
  1255. };
  1256. $scope.setActive = function(state) {
  1257. if($scope.active != state) {
  1258. $scope.active = state;
  1259. if($scope.tableParams.page() == 1)
  1260. $scope.tableParams.reload();
  1261. else
  1262. $scope.tableParams.page(1);
  1263. }
  1264. };
  1265. var getService = function() {
  1266. return Quotation;
  1267. };
  1268. $scope.tableParams = new ngTableParams({
  1269. page : 1,
  1270. count : 5,
  1271. sorting: {
  1272. 'quotation.date': 'desc'
  1273. }
  1274. }, {
  1275. total : 0,
  1276. counts: [5, 10, 25, 50],
  1277. getData : function($defer, params) {
  1278. $scope.loading = true;
  1279. var pageParams = params.url();
  1280. pageParams.keyword = $scope.keyword;
  1281. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1282. $scope.loading = false;
  1283. if(page) {
  1284. params.total(page.totalElements);
  1285. $defer.resolve(page.content);
  1286. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1287. }
  1288. }, function(response){
  1289. $scope.loading = false;
  1290. toaster.pop('error', '数据加载失败', response.data);
  1291. });
  1292. }
  1293. });
  1294. $scope.getHistory = function(item) {
  1295. if(!item.history) {
  1296. PurcInquiry.getHistory({itemId: item.id}, function(data){
  1297. item.history = data;
  1298. });
  1299. }
  1300. };
  1301. $scope.isValid = function(item, withSteps) {
  1302. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  1303. if(!withSteps || !bool)
  1304. return bool;
  1305. angular.forEach(item.replies, function(r, i){
  1306. bool = (i > 0 ? r.lapQty : 1) && r.price;
  1307. });
  1308. return bool;
  1309. };
  1310. // 搜索框回车
  1311. $scope.onSearch = function() {
  1312. $scope.tableParams.page(1);
  1313. $scope.tableParams.reload();
  1314. };
  1315. }]);
  1316. // Controller 主动报价 - 新增
  1317. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation){
  1318. var staticItem = null;
  1319. if( ! angular.isUndefined($stateParams.id)) {// 查看模式
  1320. $scope.loading = true;
  1321. Quotation.getItem({id: $stateParams.id}, function(data){
  1322. data.$editing = false;
  1323. $scope.item = data;
  1324. staticItem = angular.copy(data);
  1325. $scope.loading = false;
  1326. }, function(response){
  1327. $scope.loading = false;
  1328. toaster.pop('error', '数据加载失败', response.data);
  1329. });
  1330. } else {// 新增模式
  1331. $scope.item = {
  1332. quotation: {
  1333. currency: 'RMB',
  1334. taxrate: 17,
  1335. date: new Date()
  1336. },
  1337. product: {},
  1338. prices: [{lapQty: 0}],
  1339. minOrderQty: 1,
  1340. minPackQty: 1,
  1341. $endDateOpen: false,
  1342. $editing: true
  1343. };
  1344. }
  1345. $scope.getMinDate = function(item) {
  1346. return $filter('date')(new Date, 'yyyy-MM-dd');
  1347. };
  1348. $scope.openDatePicker = function($event, openParam) {
  1349. $event.preventDefault();
  1350. $event.stopPropagation();
  1351. $scope.item.$endDateOpen = !openParam;
  1352. };
  1353. // 增加一个分段
  1354. $scope.addPrice = function(){
  1355. if($scope.item.prices.length >= 10) {
  1356. toaster.pop('warning', '提示', '最多支持10个分段!');
  1357. } else
  1358. $scope.item.prices.push({});
  1359. };
  1360. // 删除一个分段
  1361. $scope.removePrice = function(index) {
  1362. $scope.item.prices.splice(index, 1);
  1363. };
  1364. // 查找客户
  1365. $scope.dbfindCust = function(){
  1366. if($scope.item.$editing) {
  1367. var modalInstance = $modal.open({
  1368. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  1369. controller: 'DbfindCustCtrl',
  1370. size: 'lg',
  1371. resolve: {
  1372. }
  1373. });
  1374. modalInstance.result.then(function(data){
  1375. $scope.item.quotation.cust = data.myEnterprise;
  1376. $scope.item.quotation.custUser = data.myUser;
  1377. $scope.item.product = null;
  1378. }, function(){
  1379. });
  1380. }
  1381. };
  1382. // 查找客户物料
  1383. $scope.dbfindCustProd = function(){
  1384. if($scope.item.$editing) {
  1385. if($scope.item.quotation.cust.uu) {
  1386. var modalInstance = $modal.open({
  1387. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  1388. controller: 'DbfindCustProdCtrl',
  1389. size: 'lg',
  1390. resolve: {
  1391. custUU: function(){return $scope.item.quotation.cust.uu}
  1392. }
  1393. });
  1394. modalInstance.result.then(function(data){
  1395. $scope.item.product = data;
  1396. }, function(){
  1397. });
  1398. } else {
  1399. toaster.pop('error', '错误', '请先选择客户');
  1400. }
  1401. }
  1402. };
  1403. // 保存
  1404. $scope.save = function(){
  1405. $scope.loading = true;
  1406. if(!$scope.item.quotation.code) //新增,设单号
  1407. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  1408. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  1409. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  1410. $scope.item.productId = $scope.item.product.id;
  1411. $scope.item.quotation.status = 100;//在录入
  1412. if($scope.item.quotation.date instanceof Date) {
  1413. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  1414. }
  1415. if($scope.item.quotation.endDate instanceof Date) {
  1416. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  1417. }
  1418. Quotation.save({}, $scope.item, function(data){
  1419. $scope.loading = false;
  1420. toaster.pop('success', '成功', '保存成功');
  1421. if($stateParams.id)
  1422. window.location.reload();
  1423. else
  1424. window.location.hash = '#/sale/quotation/' + data.id;
  1425. }, function(response){
  1426. $scope.loading = false;
  1427. toaster.pop('error', '保存失败', response.data);
  1428. });
  1429. };
  1430. // 更新
  1431. $scope.update = function(){
  1432. $scope.item.$editing = true;
  1433. };
  1434. // 取消
  1435. $scope.cancel = function(){
  1436. $scope.item.$editing = false;
  1437. $scope.item = angular.copy(staticItem);
  1438. };
  1439. // 提交
  1440. $scope.submit = function(){
  1441. $scope.loading = true;
  1442. $scope.item.quotation.status = 101;//在录入
  1443. Quotation.save({}, $scope.item, function(data){
  1444. $scope.loading = false;
  1445. toaster.pop('success', '成功', '提交成功');
  1446. window.location.hash = '#/sale/quotation/' + data.id;
  1447. }, function(response){
  1448. $scope.loading = false;
  1449. toaster.pop('error', '保存失败', response.data);
  1450. });
  1451. };
  1452. }]);
  1453. // 查找客户
  1454. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
  1455. $scope.customerParams = new ngTableParams({
  1456. page : 1,
  1457. count : 10
  1458. }, {
  1459. total : 0,
  1460. counts: [5, 10, 25, 50],
  1461. getData : function($defer, params) {
  1462. $scope.loading = true;
  1463. Customer.get(BaseService.parseParams(params.url()), function(page){
  1464. $scope.loading = false;
  1465. if(page) {
  1466. params.total(page.totalElements);
  1467. $defer.resolve(page.content);
  1468. }
  1469. $scope.totalCount = page.totalElements;
  1470. }, function(response){
  1471. $scope.loading = false;
  1472. toaster.pop('error', '数据加载失败', response.data);
  1473. });
  1474. }
  1475. });
  1476. $scope.cancel = function() {
  1477. $modalInstance.dismiss();
  1478. };
  1479. $scope.check = function(cust){
  1480. $modalInstance.close(cust);
  1481. };
  1482. }]);
  1483. // 查找客户物料
  1484. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
  1485. $scope.customerParams = new ngTableParams({
  1486. page : 1,
  1487. count : 10
  1488. }, {
  1489. total : 0,
  1490. counts: [5, 10, 25, 50],
  1491. getData : function($defer, params) {
  1492. $scope.loading = true;
  1493. var pageParams = params.url();
  1494. pageParams.keyword = $scope.keyword;
  1495. pageParams.custUU = custUU;
  1496. Product.get.call(null, BaseService.parseParams(pageParams), function(page){
  1497. $scope.loading = false;
  1498. if(page) {
  1499. params.total(page.totalElements);
  1500. $defer.resolve(page.content);
  1501. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1502. }
  1503. }, function(response){
  1504. $scope.loading = false;
  1505. toaster.pop('error', '数据加载失败', response.data);
  1506. });
  1507. }
  1508. });
  1509. // 取消
  1510. $scope.cancel = function() {
  1511. $modalInstance.dismiss();
  1512. };
  1513. // 选择
  1514. $scope.check = function(cust){
  1515. $modalInstance.close(cust);
  1516. };
  1517. // 搜索框回车
  1518. $scope.onSearch = function() {
  1519. $scope.tableParams.page(1);
  1520. $scope.customerParams.reload();
  1521. };
  1522. }]);
  1523. // 发货提醒
  1524. app.controller('SaleNoticeCtrl', ['$scope', '$rootScope', '$filter', 'PurcNotice', 'ngTableParams', 'toaster', 'BaseService', 'PurcNoticeHis', '$modal', 'SaleTruck', 'Symbol', function($scope, $rootScope, $filter, PurcNotice, ngTableParams, toaster, BaseService, PurcNoticeHis, $modal, SaleTruck, Symbol){
  1525. $scope.active = 'todo';
  1526. $scope.dateZoneText = '一个月内';
  1527. $scope.condition = {dateZone: 1};
  1528. $scope.currency = Symbol.currency;
  1529. $scope.changeDateZone = function(zone) {
  1530. $scope.condition.dateZone = zone;
  1531. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1532. $scope.condition.$dateZoneOpen = false;
  1533. getDateCondition(zone, $scope.condition);
  1534. $scope.tableParams.reload();
  1535. };
  1536. $scope.setActive = function(state) {
  1537. if($scope.active != state) {
  1538. $scope.active = state;
  1539. if($scope.tableParams.page() == 1)
  1540. $scope.tableParams.reload();
  1541. else
  1542. $scope.tableParams.page(1);
  1543. }
  1544. };
  1545. var getService = function() {
  1546. return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
  1547. };
  1548. $scope.tableParams = new ngTableParams({
  1549. page : 1,
  1550. count : 5,
  1551. sorting: {
  1552. 'delivery': 'asc',
  1553. 'orderItemOrderCode': 'asc',
  1554. 'orderItemNumber': 'asc'
  1555. }
  1556. }, {
  1557. total : 0,
  1558. counts: [5, 10, 25, 50],
  1559. getData : function($defer, params) {
  1560. $scope.loading = true;
  1561. var pageParams = params.url();
  1562. pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  1563. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  1564. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1565. $scope.loading = false;
  1566. if(page) {
  1567. params.total(page.totalElements);
  1568. $defer.resolve(page.content);
  1569. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1570. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  1571. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  1572. }
  1573. }, function(response){
  1574. $scope.loading = false;
  1575. toaster.pop('error', '数据加载失败', response.data);
  1576. });
  1577. }
  1578. });
  1579. $scope.openDatePicker = function($event, item, openParam) {
  1580. $event.preventDefault();
  1581. $event.stopPropagation();
  1582. item[openParam] = !item[openParam];
  1583. };
  1584. //生成随机单号
  1585. $scope.autoCode = function(notice){
  1586. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  1587. };
  1588. //可送货日期
  1589. $scope.sendDate = function(notice) {
  1590. var stock = notice.orderItem.product.ltinstock || 0;
  1591. var de = new Date(notice.delivery);
  1592. if(stock == -1) {
  1593. de.setMonth(de.getMonth() -1);
  1594. de.setDate(25);
  1595. } else if(stock >= 0) {
  1596. de.setDate(de.getDate() - stock -1);
  1597. }
  1598. return de;
  1599. };
  1600. $scope.onReplyClick = function(notice) {
  1601. if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  1602. toaster.pop('warning', '警告', '数量填写错误!');
  1603. } else if(!notice.send.code) {
  1604. toaster.pop('warning', '警告', '请填写发货单号!');
  1605. } else {
  1606. var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
  1607. $scope.loading = true;
  1608. PurcNotice.save({id: notice.id}, send, function(){
  1609. $scope.loading = false;
  1610. toaster.pop('success', '提示', '发货成功');
  1611. $scope.tableParams.reload();
  1612. }, function(response){
  1613. $scope.loading = false;
  1614. toaster.pop('error', '失败', response.data);
  1615. });
  1616. }
  1617. };
  1618. $scope.checkboxes = {
  1619. checked : false
  1620. };
  1621. // 点击勾选全部的复选框
  1622. $scope.checkAll = function(){
  1623. angular.forEach($scope.tableParams.data, function(item) {
  1624. if(!item.waiting)
  1625. item.$selected = $scope.checkboxes.checked;
  1626. });
  1627. };
  1628. // 点击其中一个明细的复选框
  1629. $scope.checkOne = function(order){
  1630. var result = true;
  1631. angular.forEach($scope.tableParams.data, function(item) {
  1632. if(item.$selected != true){
  1633. result = false;
  1634. return;
  1635. }
  1636. });
  1637. $scope.checkboxes.checked = result;
  1638. };
  1639. $scope.sendByBatch = function(){
  1640. var modalInstance = $modal.open({
  1641. animation: true,
  1642. templateUrl: 'sendByBatch.html',
  1643. controller: 'SaleNoticeSendByBatchCtrl',
  1644. size: 'lg',
  1645. resolve: {
  1646. selectedNotices: function(){return $scope.tableParams.data;}
  1647. }
  1648. });
  1649. modalInstance.result.then(function(){
  1650. $scope.tableParams.reload();
  1651. }, function(){
  1652. });
  1653. };
  1654. $scope.getSends = function(notice){
  1655. if( ! notice.sends && notice.endQty > 0){
  1656. notice.getSendsing = true;
  1657. notice.getSendsError = false;
  1658. PurcNotice.getSends({id: notice.id}, function(data){
  1659. notice.getSendsing = false;
  1660. notice.getSendsError = false;
  1661. notice.sends = data;
  1662. }, function(response){
  1663. notice.getSendsing = false;
  1664. notice.getSendsError = true;
  1665. });
  1666. }
  1667. };
  1668. // 搜索框回车
  1669. $scope.onSearch = function() {
  1670. $scope.tableParams.page(1);
  1671. $scope.tableParams.reload();
  1672. };
  1673. // 选择查找日期
  1674. $scope.onDateCondition = function(){
  1675. $scope.tableParams.page(1);
  1676. $scope.tableParams.reload();
  1677. };
  1678. //货车功能
  1679. var truck = $rootScope.truck;
  1680. if(!truck) {
  1681. SaleTruck.query({}, function(data){
  1682. $rootScope.truck = data;
  1683. });
  1684. }
  1685. $scope.isInTruck = function(noticeId) {
  1686. return truck.indexOf(noticeId) > -1;
  1687. };
  1688. $scope.addtoTruck = function(notice) {
  1689. SaleTruck.save({noticeId: notice.id}, {}, function(data){
  1690. $rootScope.truck = data;
  1691. });
  1692. };
  1693. $scope.delFromTruck = function(notice) {
  1694. SaleTruck.remove({noticeId: notice.id}, {}, function(data){
  1695. $rootScope.truck = data;
  1696. });
  1697. };
  1698. $scope.$watch(function(){
  1699. return $rootScope.truck;
  1700. }, function(data) {
  1701. truck = $rootScope.truck;
  1702. }, true);
  1703. $scope.$watch(function(){
  1704. return $rootScope.dataChanged;
  1705. }, function(data) {
  1706. data && ($scope.tableParams.reload());
  1707. }, true);
  1708. }]);
  1709. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster){
  1710. $scope.notices = angular.copy(selectedNotices);
  1711. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  1712. $scope.saleSend = {
  1713. code: '',
  1714. payments: '',
  1715. currency: '',
  1716. custUU: null,
  1717. custUserUU: null,
  1718. remark: '批量发货',
  1719. sendItems: []
  1720. };
  1721. /**
  1722. * 删除一个已选中的送货提醒
  1723. */
  1724. $scope.removeOne = function(index) {
  1725. $scope.notices.splice(index, 1);
  1726. };
  1727. //确认送货
  1728. $scope.sendByBatch = function () {
  1729. $scope.saleSend.sendItems = [];
  1730. if($scope.saleSend.code == '') {//送货单号为空
  1731. toaster.pop('error', '错误', '请输入送货单号');
  1732. return;
  1733. }
  1734. var a = 0;
  1735. var valid = true;
  1736. angular.forEach($scope.notices, function(item){
  1737. if(item.$selected) {
  1738. if(a == 0) {//第一次
  1739. $scope.saleSend.currency = item.orderItem.order.currency;
  1740. $scope.saleSend.custUU = item.enUU;
  1741. $scope.saleSend.payments = item.orderItem.order.payments;
  1742. a = 1;
  1743. } else {//其他
  1744. if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  1745. if($scope.saleSend.custUU != item.enUU) valid = false;
  1746. if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  1747. }
  1748. $scope.saleSend.sendItems[$scope.saleSend.sendItems.length] = {
  1749. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price
  1750. };
  1751. }
  1752. });
  1753. if(!valid) {
  1754. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  1755. } else {
  1756. PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
  1757. toaster.pop('success', '提示', '批量发货成功。');
  1758. $modalInstance.close('success');
  1759. }, function(response){
  1760. toaster.pop('error', '错误', response.data);
  1761. });
  1762. }
  1763. };
  1764. $scope.cancel = function () {
  1765. $modalInstance.dismiss();
  1766. };
  1767. }]);
  1768. /**
  1769. * 发货单
  1770. */
  1771. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol){
  1772. $scope.active = 'all';
  1773. $scope.agreedText = '全部';
  1774. $scope.dateZoneText = '一个月内';
  1775. $scope.condition = {dateZone: 1};
  1776. $scope.currency = Symbol.currency;
  1777. $scope.changeAgreed = function(agreed) {
  1778. $scope.condition.agreed = agreed;
  1779. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  1780. $scope.condition.$agreedOpen = false;
  1781. };
  1782. $scope.changeDateZone = function(zone) {
  1783. $scope.condition.dateZone = zone;
  1784. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1785. $scope.condition.$dateZoneOpen = false;
  1786. getDateCondition(zone, $scope.condition);
  1787. $scope.tableParams.reload();
  1788. };
  1789. $scope.setActive = function(state) {
  1790. if($scope.active != state) {
  1791. $scope.active = state;
  1792. if($scope.tableParams.page() == 1)
  1793. $scope.tableParams.reload();
  1794. else
  1795. $scope.tableParams.page(1);
  1796. }
  1797. };
  1798. var getService = function() {
  1799. return SaleSend;
  1800. };
  1801. $scope.tableParams = new ngTableParams({
  1802. page : 1,
  1803. count : 5,
  1804. sorting: {
  1805. date: 'desc'
  1806. }
  1807. }, {
  1808. total : 0,
  1809. counts: [5, 10, 25, 50],
  1810. getData : function($defer, params) {
  1811. $scope.loading = true;
  1812. var pageParams = params.url();
  1813. pageParams.keyword = $scope.keyword;
  1814. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  1815. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  1816. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1817. $scope.loading = false;
  1818. if(page) {
  1819. params.total(page.totalElements);
  1820. $defer.resolve(page.content);
  1821. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1822. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  1823. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  1824. }
  1825. }, function(response){
  1826. $scope.loading = false;
  1827. toaster.pop('error', '数据加载失败', response.data);
  1828. });
  1829. }
  1830. });
  1831. $scope.openDatePicker = function($event, item, openParam) {
  1832. $event.preventDefault();
  1833. $event.stopPropagation();
  1834. item[openParam] = !item[openParam];
  1835. };
  1836. // 搜索框回车
  1837. $scope.onSearch = function() {
  1838. $scope.tableParams.page(1);
  1839. $scope.tableParams.reload();
  1840. };
  1841. // 选择查找日期
  1842. $scope.onDateCondition = function(){
  1843. $scope.tableParams.page(1);
  1844. $scope.tableParams.reload();
  1845. };
  1846. }]);
  1847. /**
  1848. * 客户打样申请
  1849. */
  1850. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService', 'Symbol', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService, Symbol){
  1851. $scope.active = 'todo';
  1852. $scope.agreedText = '全部';
  1853. $scope.dateZoneText = '一个月内';
  1854. $scope.condition = {dateZone: 1};
  1855. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  1856. $scope.changeAgreed = function(agreed) {
  1857. $scope.condition.agreed = agreed;
  1858. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  1859. $scope.condition.$agreedOpen = false;
  1860. };
  1861. $scope.changeDateZone = function(zone) {
  1862. $scope.condition.dateZone = zone;
  1863. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1864. $scope.condition.$dateZoneOpen = false;
  1865. };
  1866. $scope.setActive = function(state) {
  1867. if($scope.active != state) {
  1868. $scope.active = state;
  1869. if($scope.tableParams.page() == 1)
  1870. $scope.tableParams.reload();
  1871. else
  1872. $scope.tableParams.page(1);
  1873. }
  1874. };
  1875. var getService = function() {
  1876. return PurcSample;
  1877. };
  1878. $scope.tableParams = new ngTableParams({
  1879. page : 1,
  1880. count : 5,
  1881. sorting: {
  1882. proofingDate: 'desc'
  1883. }
  1884. }, {
  1885. total : 0,
  1886. counts: [5, 10, 25, 50],
  1887. getData : function($defer, params) {
  1888. $scope.loading = true;
  1889. var pageParams = params.url();
  1890. pageParams.keyword = $scope.keyword;
  1891. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  1892. $scope.loading = false;
  1893. if(page) {
  1894. params.total(page.totalElements);
  1895. $defer.resolve(page.content);
  1896. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  1897. }
  1898. }, function(response){
  1899. $scope.loading = false;
  1900. toaster.pop('error', '数据加载失败', response.data);
  1901. });
  1902. }
  1903. });
  1904. $scope.openDatePicker = function($event, item, openParam) {
  1905. $event.preventDefault();
  1906. $event.stopPropagation();
  1907. item[openParam] = !item[openParam];
  1908. };
  1909. $scope.openSend = function(index, sample) {
  1910. var modalInstance = $modal.open({
  1911. animation: true,
  1912. templateUrl: 'sendModal.html',
  1913. controller: 'SampleSendCtrl',
  1914. resolve: {
  1915. sampleItem: function(){return sample;}
  1916. }
  1917. });
  1918. modalInstance.result.then(function(){
  1919. toaster.pop('info', '提示', '送样成功');
  1920. $scope.tableParams.reload();
  1921. }, function(){
  1922. });
  1923. };
  1924. $scope.getSend = function(proofing){
  1925. if( !proofing.send) {
  1926. proofing.getSendInfo = '加载中...';
  1927. PurcSample.getSend({id: proofing.id}, function(data){
  1928. if(data) {
  1929. proofing.getSendInfo = null;
  1930. proofing.send = data;
  1931. } else {
  1932. proofing.getSendInfo = '无送样信息';
  1933. proofing.send = '无送样信息';
  1934. }
  1935. }, function(response){
  1936. proofing.getSendInfo = '加载失败!';
  1937. });
  1938. }
  1939. };
  1940. // 搜索框回车
  1941. $scope.onSearch = function() {
  1942. $scope.tableParams.page(1);
  1943. $scope.tableParams.reload();
  1944. };
  1945. }]);
  1946. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
  1947. $scope.sampleItem = sampleItem;
  1948. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  1949. //确认送样
  1950. $scope.ok = function (form) {
  1951. $scope.loading = true;
  1952. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  1953. $upload.upload({
  1954. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  1955. method: 'POST',
  1956. file: file,
  1957. data: {
  1958. json: $scope.sampleItem.sampleSend
  1959. }
  1960. }).success(function(data){
  1961. $scope.loading = false;
  1962. $modalInstance.close('success');
  1963. }).error(function(data){
  1964. $scope.loading = false;
  1965. toaster.pop('danger', '错误', data);
  1966. });
  1967. };
  1968. $scope.cancel = function () {
  1969. $modalInstance.dismiss(sampleItem);
  1970. };
  1971. }]);
  1972. /**
  1973. * 客户认定单
  1974. */
  1975. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
  1976. $scope.active = 'all';
  1977. $scope.agreedText = '全部';
  1978. $scope.dateZoneText = '一个月内';
  1979. $scope.condition = {dateZone: 1};
  1980. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  1981. $scope.changeDateZone = function(zone) {
  1982. $scope.condition.dateZone = zone;
  1983. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  1984. $scope.condition.$dateZoneOpen = false;
  1985. getDateCondition(zone, $scope.condition);
  1986. $scope.tableParams.reload();
  1987. };
  1988. $scope.setActive = function(state) {
  1989. if($scope.active != state) {
  1990. $scope.active = state;
  1991. if($scope.tableParams.page() == 1)
  1992. $scope.tableParams.reload();
  1993. else
  1994. $scope.tableParams.page(1);
  1995. }
  1996. };
  1997. var getService = function() {
  1998. return PurcApproval;
  1999. };
  2000. $scope.tableParams = new ngTableParams({
  2001. page : 1,
  2002. count : 5,
  2003. sorting: {
  2004. inDate: 'desc'
  2005. }
  2006. }, {
  2007. total : 0,
  2008. counts: [5, 10, 25, 50],
  2009. getData : function($defer, params) {
  2010. $scope.loading = true;
  2011. var pageParams = params.url();
  2012. pageParams.keyword = $scope.keyword;
  2013. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  2014. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  2015. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2016. $scope.loading = false;
  2017. if(page) {
  2018. params.total(page.totalElements);
  2019. $defer.resolve(page.content);
  2020. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2021. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  2022. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  2023. }
  2024. }, function(response){
  2025. $scope.loading = false;
  2026. toaster.pop('error', '数据加载失败', response.data);
  2027. });
  2028. }
  2029. });
  2030. $scope.openDatePicker = function($event, item, openParam) {
  2031. $event.preventDefault();
  2032. $event.stopPropagation();
  2033. item[openParam] = !item[openParam];
  2034. };
  2035. $scope.parseDate = function(dateStr) {
  2036. if(dateStr)
  2037. return Date.parse(dateStr, 'yyyy-MM-dd');
  2038. return new Date();
  2039. };
  2040. // 搜索框回车
  2041. $scope.onSearch = function() {
  2042. $scope.tableParams.page(1);
  2043. $scope.tableParams.reload();
  2044. };
  2045. // 选择查找日期
  2046. $scope.onDateCondition = function(){
  2047. $scope.tableParams.page(1);
  2048. $scope.tableParams.reload();
  2049. };
  2050. }]);
  2051. /**
  2052. * 客户采购预测
  2053. */
  2054. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
  2055. $scope.active = 'all';
  2056. $scope.agreedText = '全部';
  2057. $scope.dateZoneText = '一个月内';
  2058. $scope.condition = {dateZone: 1};
  2059. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  2060. $scope.changeAgreed = function(agreed) {
  2061. $scope.condition.agreed = agreed;
  2062. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2063. $scope.condition.$agreedOpen = false;
  2064. };
  2065. $scope.changeDateZone = function(zone) {
  2066. $scope.condition.dateZone = zone;
  2067. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2068. $scope.condition.$dateZoneOpen = false;
  2069. };
  2070. $scope.setActive = function(state) {
  2071. if($scope.active != state) {
  2072. $scope.active = state;
  2073. if($scope.tableParams.page() == 1)
  2074. $scope.tableParams.reload();
  2075. else
  2076. $scope.tableParams.page(1);
  2077. }
  2078. };
  2079. var getService = function() {
  2080. return PurcForecast;
  2081. };
  2082. $scope.tableParams = new ngTableParams({
  2083. page : 1,
  2084. count : 5,
  2085. sorting: {
  2086. orderDate: 'desc'
  2087. }
  2088. }, {
  2089. total : 0,
  2090. counts: [5, 10, 25, 50],
  2091. getData : function($defer, params) {
  2092. $scope.loading = true;
  2093. var pageParams = params.url();
  2094. pageParams.keyword = $scope.keyword;
  2095. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2096. $scope.loading = false;
  2097. if(page) {
  2098. params.total(page.totalElements);
  2099. $defer.resolve(page.content);
  2100. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2101. }
  2102. }, function(response){
  2103. $scope.loading = false;
  2104. toaster.pop('error', '数据加载失败', response.data);
  2105. });
  2106. }
  2107. });
  2108. $scope.openDatePicker = function($event, item, openParam) {
  2109. $event.preventDefault();
  2110. $event.stopPropagation();
  2111. item[openParam] = !item[openParam];
  2112. };
  2113. // 搜索框回车
  2114. $scope.onSearch = function() {
  2115. $scope.tableParams.page(1);
  2116. $scope.tableParams.reload();
  2117. };
  2118. }]);
  2119. /**
  2120. * 客户采购验收
  2121. */
  2122. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
  2123. $scope.active = 'all';
  2124. $scope.agreedText = '全部';
  2125. $scope.dateZoneText = '一个月内';
  2126. $scope.condition = {dateZone: 1};
  2127. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  2128. $scope.changeAgreed = function(agreed) {
  2129. $scope.condition.agreed = agreed;
  2130. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2131. $scope.condition.$agreedOpen = false;
  2132. };
  2133. $scope.changeDateZone = function(zone) {
  2134. $scope.condition.dateZone = zone;
  2135. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2136. $scope.condition.$dateZoneOpen = false;
  2137. };
  2138. $scope.setActive = function(state) {
  2139. if($scope.active != state) {
  2140. $scope.active = state;
  2141. if($scope.tableParams.page() == 1)
  2142. $scope.tableParams.reload();
  2143. else
  2144. $scope.tableParams.page(1);
  2145. }
  2146. };
  2147. var getService = function() {
  2148. return PurcAccept;
  2149. };
  2150. $scope.tableParams = new ngTableParams({
  2151. page : 1,
  2152. count : 5,
  2153. sorting: {
  2154. date: 'desc'
  2155. }
  2156. }, {
  2157. total : 0,
  2158. counts: [5, 10, 25, 50],
  2159. getData : function($defer, params) {
  2160. $scope.loading = true;
  2161. var pageParams = params.url();
  2162. pageParams.keyword = $scope.keyword;
  2163. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2164. $scope.loading = false;
  2165. if(page) {
  2166. params.total(page.totalElements);
  2167. $defer.resolve(page.content);
  2168. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2169. }
  2170. }, function(response){
  2171. $scope.loading = false;
  2172. toaster.pop('error', '数据加载失败', response.data);
  2173. });
  2174. }
  2175. });
  2176. $scope.openDatePicker = function($event, item, openParam) {
  2177. $event.preventDefault();
  2178. $event.stopPropagation();
  2179. item[openParam] = !item[openParam];
  2180. };
  2181. // 搜索框回车
  2182. $scope.onSearch = function() {
  2183. $scope.tableParams.page(1);
  2184. $scope.tableParams.reload();
  2185. };
  2186. }]);
  2187. /**
  2188. * 客户采购验退
  2189. */
  2190. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
  2191. $scope.active = 'all';
  2192. $scope.agreedText = '全部';
  2193. $scope.dateZoneText = '一个月内';
  2194. $scope.condition = {dateZone: 1};
  2195. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  2196. $scope.changeAgreed = function(agreed) {
  2197. $scope.condition.agreed = agreed;
  2198. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2199. $scope.condition.$agreedOpen = false;
  2200. };
  2201. $scope.changeDateZone = function(zone) {
  2202. $scope.condition.dateZone = zone;
  2203. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2204. $scope.condition.$dateZoneOpen = false;
  2205. };
  2206. $scope.setActive = function(state) {
  2207. if($scope.active != state) {
  2208. $scope.active = state;
  2209. if($scope.tableParams.page() == 1)
  2210. $scope.tableParams.reload();
  2211. else
  2212. $scope.tableParams.page(1);
  2213. }
  2214. };
  2215. var getService = function() {
  2216. return PurcReturn;
  2217. };
  2218. $scope.tableParams = new ngTableParams({
  2219. page : 1,
  2220. count : 5,
  2221. sorting: {
  2222. date: 'desc'
  2223. }
  2224. }, {
  2225. total : 0,
  2226. counts: [5, 10, 25, 50],
  2227. getData : function($defer, params) {
  2228. $scope.loading = true;
  2229. var pageParams = params.url();
  2230. pageParams.keyword = $scope.keyword;
  2231. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2232. $scope.loading = false;
  2233. if(page) {
  2234. params.total(page.totalElements);
  2235. $defer.resolve(page.content);
  2236. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2237. }
  2238. }, function(response){
  2239. $scope.loading = false;
  2240. toaster.pop('error', '数据加载失败', response.data);
  2241. });
  2242. }
  2243. });
  2244. $scope.openDatePicker = function($event, item, openParam) {
  2245. $event.preventDefault();
  2246. $event.stopPropagation();
  2247. item[openParam] = !item[openParam];
  2248. };
  2249. // 搜索框回车
  2250. $scope.onSearch = function() {
  2251. $scope.tableParams.page(1);
  2252. $scope.tableParams.reload();
  2253. };
  2254. }]);
  2255. /**
  2256. * 客户不良品入库
  2257. */
  2258. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
  2259. $scope.active = 'all';
  2260. $scope.agreedText = '全部';
  2261. $scope.dateZoneText = '一个月内';
  2262. $scope.condition = {dateZone: 1};
  2263. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  2264. $scope.changeAgreed = function(agreed) {
  2265. $scope.condition.agreed = agreed;
  2266. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2267. $scope.condition.$agreedOpen = false;
  2268. };
  2269. $scope.changeDateZone = function(zone) {
  2270. $scope.condition.dateZone = zone;
  2271. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2272. $scope.condition.$dateZoneOpen = false;
  2273. };
  2274. $scope.setActive = function(state) {
  2275. if($scope.active != state) {
  2276. $scope.active = state;
  2277. if($scope.tableParams.page() == 1)
  2278. $scope.tableParams.reload();
  2279. else
  2280. $scope.tableParams.page(1);
  2281. }
  2282. };
  2283. var getService = function() {
  2284. return PurcBadIn;
  2285. };
  2286. $scope.tableParams = new ngTableParams({
  2287. page : 1,
  2288. count : 5,
  2289. sorting: {
  2290. date: 'desc'
  2291. }
  2292. }, {
  2293. total : 0,
  2294. counts: [5, 10, 25, 50],
  2295. getData : function($defer, params) {
  2296. $scope.loading = true;
  2297. var pageParams = params.url();
  2298. pageParams.keyword = $scope.keyword;
  2299. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2300. $scope.loading = false;
  2301. if(page) {
  2302. params.total(page.totalElements);
  2303. $defer.resolve(page.content);
  2304. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2305. }
  2306. }, function(response){
  2307. $scope.loading = false;
  2308. toaster.pop('error', '数据加载失败', response.data);
  2309. });
  2310. }
  2311. });
  2312. $scope.openDatePicker = function($event, item, openParam) {
  2313. $event.preventDefault();
  2314. $event.stopPropagation();
  2315. item[openParam] = !item[openParam];
  2316. };
  2317. // 搜索框回车
  2318. $scope.onSearch = function() {
  2319. $scope.tableParams.page(1);
  2320. $scope.tableParams.reload();
  2321. };
  2322. }]);
  2323. /**
  2324. * 客户不良品出库
  2325. */
  2326. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
  2327. $scope.active = 'all';
  2328. $scope.agreedText = '全部';
  2329. $scope.dateZoneText = '一个月内';
  2330. $scope.condition = {dateZone: 1};
  2331. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  2332. $scope.changeAgreed = function(agreed) {
  2333. $scope.condition.agreed = agreed;
  2334. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2335. $scope.condition.$agreedOpen = false;
  2336. };
  2337. $scope.changeDateZone = function(zone) {
  2338. $scope.condition.dateZone = zone;
  2339. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2340. $scope.condition.$dateZoneOpen = false;
  2341. };
  2342. $scope.setActive = function(state) {
  2343. if($scope.active != state) {
  2344. $scope.active = state;
  2345. if($scope.tableParams.page() == 1)
  2346. $scope.tableParams.reload();
  2347. else
  2348. $scope.tableParams.page(1);
  2349. }
  2350. };
  2351. var getService = function() {
  2352. return PurcBadOut;
  2353. };
  2354. $scope.tableParams = new ngTableParams({
  2355. page : 1,
  2356. count : 5,
  2357. sorting: {
  2358. date: 'desc'
  2359. }
  2360. }, {
  2361. total : 0,
  2362. counts: [5, 10, 25, 50],
  2363. getData : function($defer, params) {
  2364. $scope.loading = true;
  2365. var pageParams = params.url();
  2366. pageParams.keyword = $scope.keyword;
  2367. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2368. $scope.loading = false;
  2369. if(page) {
  2370. params.total(page.totalElements);
  2371. $defer.resolve(page.content);
  2372. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2373. }
  2374. }, function(response){
  2375. $scope.loading = false;
  2376. toaster.pop('error', '数据加载失败', response.data);
  2377. });
  2378. }
  2379. });
  2380. $scope.openDatePicker = function($event, item, openParam) {
  2381. $event.preventDefault();
  2382. $event.stopPropagation();
  2383. item[openParam] = !item[openParam];
  2384. };
  2385. // 搜索框回车
  2386. $scope.onSearch = function() {
  2387. $scope.tableParams.page(1);
  2388. $scope.tableParams.reload();
  2389. };
  2390. }]);
  2391. /**
  2392. * 客户MRB
  2393. */
  2394. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
  2395. $scope.active = 'all';
  2396. $scope.agreedText = '全部';
  2397. $scope.dateZoneText = '一个月内';
  2398. $scope.condition = {dateZone: 1};
  2399. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  2400. $scope.changeAgreed = function(agreed) {
  2401. $scope.condition.agreed = agreed;
  2402. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2403. $scope.condition.$agreedOpen = false;
  2404. };
  2405. $scope.changeDateZone = function(zone) {
  2406. $scope.condition.dateZone = zone;
  2407. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2408. $scope.condition.$dateZoneOpen = false;
  2409. };
  2410. $scope.setActive = function(state) {
  2411. if($scope.active != state) {
  2412. $scope.active = state;
  2413. if($scope.tableParams.page() == 1)
  2414. $scope.tableParams.reload();
  2415. else
  2416. $scope.tableParams.page(1);
  2417. }
  2418. };
  2419. var getService = function() {
  2420. return PurcMRB;
  2421. };
  2422. $scope.tableParams = new ngTableParams({
  2423. page : 1,
  2424. count : 5,
  2425. sorting: {
  2426. date: 'desc'
  2427. }
  2428. }, {
  2429. total : 0,
  2430. counts: [5, 10, 25, 50],
  2431. getData : function($defer, params) {
  2432. $scope.loading = true;
  2433. var pageParams = params.url();
  2434. pageParams.keyword = $scope.keyword;
  2435. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2436. $scope.loading = false;
  2437. if(page) {
  2438. params.total(page.totalElements);
  2439. $defer.resolve(page.content);
  2440. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2441. }
  2442. }, function(response){
  2443. $scope.loading = false;
  2444. toaster.pop('error', '数据加载失败', response.data);
  2445. });
  2446. }
  2447. });
  2448. $scope.openDatePicker = function($event, item, openParam) {
  2449. $event.preventDefault();
  2450. $event.stopPropagation();
  2451. item[openParam] = !item[openParam];
  2452. };
  2453. // 搜索框回车
  2454. $scope.onSearch = function() {
  2455. $scope.tableParams.page(1);
  2456. $scope.tableParams.reload();
  2457. };
  2458. }]);
  2459. /**
  2460. * 客户应付发票
  2461. */
  2462. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'PurcApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApBill, ngTableParams, toaster, BaseService, Symbol){
  2463. $scope.active = 'all';
  2464. $scope.agreedText = '全部';
  2465. $scope.dateZoneText = '一个月内';
  2466. $scope.condition = {dateZone: 1};
  2467. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  2468. $scope.changeAgreed = function(agreed) {
  2469. $scope.condition.agreed = agreed;
  2470. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  2471. $scope.condition.$agreedOpen = false;
  2472. };
  2473. $scope.changeDateZone = function(zone) {
  2474. $scope.condition.dateZone = zone;
  2475. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  2476. $scope.condition.$dateZoneOpen = false;
  2477. getDateCondition(zone, $scope.condition);
  2478. $scope.tableParams.reload();
  2479. };
  2480. $scope.setActive = function(state) {
  2481. if($scope.active != state) {
  2482. $scope.active = state;
  2483. if($scope.tableParams.page() == 1)
  2484. $scope.tableParams.reload();
  2485. else
  2486. $scope.tableParams.page(1);
  2487. }
  2488. };
  2489. var getService = function() {
  2490. return PurcApBill;
  2491. };
  2492. $scope.tableParams = new ngTableParams({
  2493. page : 1,
  2494. count : 5,
  2495. sorting: {
  2496. date: 'desc'
  2497. }
  2498. }, {
  2499. total : 0,
  2500. counts: [5, 10, 25, 50],
  2501. getData : function($defer, params) {
  2502. $scope.loading = true;
  2503. var pageParams = params.url();
  2504. pageParams.keyword = $scope.keyword;
  2505. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  2506. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  2507. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  2508. $scope.loading = false;
  2509. if(page) {
  2510. params.total(page.totalElements);
  2511. $defer.resolve(page.content);
  2512. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2513. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  2514. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  2515. }
  2516. }, function(response){
  2517. $scope.loading = false;
  2518. toaster.pop('error', '数据加载失败', response.data);
  2519. });
  2520. }
  2521. });
  2522. $scope.openDatePicker = function($event, item, openParam) {
  2523. $event.preventDefault();
  2524. $event.stopPropagation();
  2525. item[openParam] = !item[openParam];
  2526. };
  2527. // 搜索框回车
  2528. $scope.onSearch = function() {
  2529. $scope.tableParams.page(1);
  2530. $scope.tableParams.reload();
  2531. };
  2532. // 选择查找日期
  2533. $scope.onDateCondition = function(){
  2534. $scope.tableParams.page(1);
  2535. $scope.tableParams.reload();
  2536. };
  2537. }]);
  2538. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', function($scope, AccountEnterprise, toaster, $state, $modal){
  2539. $scope.loading = true;
  2540. AccountEnterprise.get({}, function(data){
  2541. $scope.loading = false;
  2542. $scope.enterprise = data;
  2543. });
  2544. AccountEnterprise.growth({}, function(data){
  2545. if(data != null && data.length > 0) {
  2546. var growth = [], years = [];
  2547. angular.forEach(data, function(d){
  2548. var date = new Date(d.date), year = date.getFullYear();
  2549. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  2550. if(years.indexOf(year) == -1) {
  2551. years.push(year);
  2552. growth.push({year: year});
  2553. }
  2554. growth.push(d);
  2555. });
  2556. $scope.growth = growth;
  2557. }
  2558. });
  2559. // 更新企业信息
  2560. $scope.updateDetailInfo = function(){
  2561. $scope.loading = true;
  2562. AccountEnterprise.save($scope.enterprise, function(){
  2563. $scope.loading = false;
  2564. $scope.connectionEditing = false;
  2565. toaster.pop('success', '提示', '修改企业信息成功');
  2566. $state.reload();
  2567. }, function(response){
  2568. $scope.loading = false;
  2569. toaster.pop('error', '修改信息失败', response.data);
  2570. });
  2571. };
  2572. // 申请Saas
  2573. $scope.applySaas = function(){
  2574. if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  2575. var modalInstance = $modal.open({
  2576. animation: true,
  2577. templateUrl: 'static/tpl/index/account/applySaas.html',
  2578. controller: 'ApplySaasCtrl',
  2579. resolve: {
  2580. enterprise: function(){return angular.copy($scope.enterprise);}
  2581. }
  2582. });
  2583. modalInstance.result.then(function(){
  2584. $state.reload();
  2585. }, function(){
  2586. });
  2587. } else {
  2588. toaster.pop('info', '请完善信息', '申请SAAS服务请先完善企业详细信息');
  2589. }
  2590. };
  2591. }]);
  2592. // 申请Saas Controller
  2593. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
  2594. $scope.enterprise = enterprise;
  2595. $scope.checking = false;
  2596. $scope.$watch('enterprise.enSaasUrl', function(){
  2597. if($scope.enterprise.enSaasUrl) {
  2598. $http.get('signup/saasUrlEnable', {
  2599. params: {
  2600. enSaasUrl: $scope.enterprise.enSaasUrl
  2601. }
  2602. }).success(function(data){
  2603. if(data && data == 'true') {
  2604. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  2605. } else {
  2606. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  2607. $scope.enSaasUrlErrorInfo = 'SAAS域名已被使用';
  2608. }
  2609. }).error(function(){
  2610. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  2611. $scope.enSaasUrlErrorInfo = '验证出错';
  2612. });
  2613. } else {
  2614. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  2615. }
  2616. });
  2617. var setSaasUrl = function(url) {
  2618. var index = url.indexOf('www.');
  2619. if(index != -1) {//包含www.
  2620. var substr = url.substring(index+4, url.length);
  2621. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  2622. } else {
  2623. $scope.enterprise.enSaasUrl = getHost(url);
  2624. }
  2625. };
  2626. // 解析获取网址的一级域名
  2627. var getHost = function(host){
  2628. var newhost;
  2629. var domain;
  2630. var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
  2631. for(var k in ArrDomain){
  2632. var re = eval('/\\' + ArrDomain[k] + '$/g');
  2633. newhost = host.replace(re, '');
  2634. if(newhost != host){
  2635. domain = ArrDomain[k];
  2636. break;
  2637. }
  2638. }
  2639. var hostar = newhost.split('.');
  2640. var s = hostar[hostar.length-1];
  2641. return s;
  2642. };
  2643. // 设置Saas域名为官网网址一级域名
  2644. if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  2645. $scope.apply = function(){
  2646. $scope.loading = true;
  2647. AccountEnterprise.applySaas({
  2648. enUU: $scope.enterprise.uu,
  2649. enSaasUrl: $scope.enterprise.enSaasUrl,
  2650. enAdminPassword: $scope.enterprise.enAdminPassword
  2651. }, {}, function(){
  2652. $scope.loading = false;
  2653. toaster.pop('success', '申请成功', '已提交系统开通SAAS服务,开通后将会发送邮件至管理员邮箱');
  2654. $modalInstance.close();
  2655. }, function(response){
  2656. $scope.loading = false;
  2657. toaster.pop('error', '申请失败', response.data);
  2658. });
  2659. };
  2660. $scope.cancel = function () {
  2661. $modalInstance.dismiss();
  2662. };
  2663. }]);
  2664. app.controller('UserCtrl', ['$scope', '$filter', 'AuthenticationService', 'AccountUser', 'BaseService', 'ngTableParams', 'toaster', '$modal', '$http', 'ngAlert', function($scope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http, ngAlert){
  2665. $scope.editing = false;
  2666. $scope.loading = true;
  2667. AuthenticationService.getAuthentication().success(function(data) {
  2668. $scope.loading = false;
  2669. $scope.user = data;
  2670. });
  2671. var users = [];
  2672. $scope.tableParams = new ngTableParams({
  2673. page : 1,
  2674. count : 5,
  2675. sorting: {
  2676. userName: 'asc'
  2677. }
  2678. }, {
  2679. total : 0,
  2680. counts: [15, 25, 50, 100],
  2681. getData : function($defer, params) {
  2682. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  2683. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  2684. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  2685. params.total(orderedData.length);
  2686. $defer.resolve($scope.users);
  2687. }
  2688. });
  2689. var loadUsers = function() {
  2690. AccountUser.query({}, function(data){
  2691. users = data;
  2692. $scope.tableParams.reload();
  2693. $scope.loading = false;
  2694. });
  2695. };
  2696. loadUsers();
  2697. $scope.saveUser = function(){
  2698. $scope.loading = true;
  2699. AccountUser.update({}, $scope.user, function(data){
  2700. $scope.loading = false;
  2701. toaster.pop('success', '提示', '修改用户信息成功');
  2702. AuthenticationService.getAuthentication().success(function(data) {
  2703. $scope.user = data;
  2704. });
  2705. loadUsers();
  2706. $scope.editing = false;
  2707. }, function(reponse){
  2708. $scope.loading = false;
  2709. toaster.pop('error', '失败', reponse.data);
  2710. });
  2711. };
  2712. $scope.updatePassword = function(){
  2713. var modalInstance = $modal.open({
  2714. animation: true,
  2715. templateUrl: 'updatePassword.html',
  2716. controller: 'PasswordCtrl',
  2717. resolve: {
  2718. user: function(){return $scope.user;}
  2719. }
  2720. });
  2721. modalInstance.result.then(function(){
  2722. }, function(){
  2723. });
  2724. };
  2725. $scope.newUser = {};
  2726. /**
  2727. * 添加用户
  2728. */
  2729. $scope.addUser = function() {
  2730. $scope.adding = true;
  2731. AccountUser.save({}, $scope.newUser, function(){
  2732. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  2733. $scope.newUser = {userSex: 'M'};
  2734. loadUsers();
  2735. $scope.adding = false;
  2736. $scope.newUserForm.newUserTel.$setValidity('available', false);
  2737. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  2738. $scope.userTelSuccess = false;
  2739. $scope.userTelError = false;
  2740. $scope.userEmailSuccess = false;
  2741. $scope.userEmailError = false;
  2742. }, function(response){
  2743. toaster.pop('error', '错误', response.data);
  2744. });
  2745. };
  2746. /**
  2747. * 验证手机号是否可用
  2748. */
  2749. $scope.telValid = function(tel) {
  2750. if(tel) {
  2751. $http.get('account/user/telEnable', {
  2752. params: {
  2753. tel: tel
  2754. }
  2755. }).success(function(data){
  2756. data = eval(data);
  2757. if(data == true) {
  2758. $scope.newUserForm.newUserTel.$setValidity('available', true);
  2759. $scope.userTelSuccess = true;
  2760. $scope.userTelError = false;
  2761. } else {
  2762. $scope.newUserForm.newUserTel.$setValidity('available', false);
  2763. $scope.userTelError = true;
  2764. $scope.userTelSuccess = false;
  2765. }
  2766. }).error(function(){
  2767. $scope.userTelSuccess = false;
  2768. $scope.userTelError = true;
  2769. });
  2770. } else {
  2771. $scope.userTelSuccess = false;
  2772. $scope.userTelError = false;
  2773. }
  2774. };
  2775. /**
  2776. * 验证邮箱是否可用
  2777. */
  2778. $scope.emailValid = function(email) {
  2779. if(email) {
  2780. $http.get('account/user/emailEnable', {
  2781. params: {
  2782. email: email
  2783. }
  2784. }).success(function(data){
  2785. data = eval(data);
  2786. if(data == true) {
  2787. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  2788. $scope.userEmailSuccess = true;
  2789. $scope.userEmailError = false;
  2790. } else {
  2791. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  2792. $scope.userEmailError = true;
  2793. $scope.userEmailSuccess = false;
  2794. }
  2795. }).error(function(){
  2796. $scope.userEmailError = true;
  2797. $scope.userEmailSuccess = false;
  2798. });
  2799. } else {
  2800. $scope.userEmailError = false;
  2801. $scope.userEmailSuccess = false;
  2802. }
  2803. };
  2804. /**
  2805. * 删除用户
  2806. */
  2807. $scope.removeUser = function(user) {
  2808. new ngAlert({
  2809. title: '提示',
  2810. content: '确定删除用户(' + user.userName + ')吗?'
  2811. }, function(){
  2812. AccountUser.remove({uu: user.userUU}, function(){
  2813. toaster.pop('success', '提示', '用户删除成功。');
  2814. loadUsers();
  2815. }, function(response){
  2816. toaster.pop('error', '删除失败', response.data);
  2817. });
  2818. });
  2819. };
  2820. // 编辑用户的角色
  2821. $scope.editUserRole = function(user) {
  2822. var modalInstance = $modal.open({
  2823. animation: true,
  2824. templateUrl: 'static/tpl/index/account/user_role.html',
  2825. controller: 'UserRoleCtrl',
  2826. resolve: {
  2827. user: function() {
  2828. return user;
  2829. }
  2830. }
  2831. });
  2832. modalInstance.result.then(function(changed, checked){
  2833. if(changed) {
  2834. if(checked)
  2835. $scope.newUser.roles = checked;
  2836. else
  2837. loadUsers();
  2838. }
  2839. });
  2840. };
  2841. }]);
  2842. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
  2843. $scope.checked = [];
  2844. $scope.master = [];
  2845. AccountRole.query({}, function(data){
  2846. if(user && data) {
  2847. var rs = [], checked = [];
  2848. angular.forEach(user.roles, function(r){
  2849. rs.push(r.id);
  2850. });
  2851. angular.forEach(data, function(d){
  2852. if(rs.indexOf(d.id) > -1) {
  2853. d.$checked = true;
  2854. checked.push(d);
  2855. }
  2856. });
  2857. }
  2858. $scope.roles = data;
  2859. $scope.checked = checked;
  2860. $scope.master = angular.copy($scope.checked);
  2861. });
  2862. $scope.select = function(role) {
  2863. role.$checked = !role.$checked;
  2864. if(role.$checked) {
  2865. $scope.checked.push(role);
  2866. } else {
  2867. angular.forEach($scope.checked, function(c, i){
  2868. if(c.id == role.id)
  2869. $scope.checked.splice(i, 1);
  2870. });
  2871. }
  2872. };
  2873. $scope.isChanged = function() {
  2874. return !angular.equals($scope.master, $scope.checked);
  2875. };
  2876. $scope.close = function(save) {
  2877. if(save) {
  2878. if(user.userUU) {
  2879. user.roles = $scope.checked;
  2880. AccountUser.update({}, user, function(){
  2881. toaster.pop('success', '提示', '保存成功');
  2882. $modalInstance.close(true);
  2883. }, function(response){
  2884. toaster.pop('error', '保存失败', response.data);
  2885. });
  2886. } else {
  2887. $modalInstance.close(true, $scope.checked);
  2888. }
  2889. } else {
  2890. $modalInstance.close(false);
  2891. }
  2892. };
  2893. }]);
  2894. // 修改密码Controller
  2895. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
  2896. $scope.user = user;
  2897. $scope.checking = false;
  2898. //输入原密码后验证原密码是否正确
  2899. $scope.checkPassword = function(password) {
  2900. $scope.checking = true;
  2901. $scope.checkSuccess = false;
  2902. $scope.checkFailed = false;
  2903. AccountUser.checkPassword({password: password}, function(data){
  2904. $scope.checkSuccess = true;
  2905. $scope.checking = false;
  2906. $scope.checkFailed = false;
  2907. }, function(response){
  2908. $scope.checkFailed = true;
  2909. $scope.checking = false;
  2910. $scope.checkSuccess = false;
  2911. });
  2912. };
  2913. //修改密码
  2914. $scope.ok = function () {
  2915. if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  2916. AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
  2917. toaster.pop('success', '成功', '修改密码成功,请牢记您的新密码。');
  2918. $scope.user.password = null;
  2919. $scope.user.newPassword = null;
  2920. $scope.user.newPassword1 = null;
  2921. $scope.checking = false;
  2922. $scope.checkSuccess = false;
  2923. $scope.checkFailed = false;
  2924. }, function(response){
  2925. toaster.pop('error', '错误', response.data);
  2926. });
  2927. } else {
  2928. toaster.pop('error', '错误', '重复密码不一致');
  2929. }
  2930. };
  2931. $scope.cancel = function () {
  2932. $modalInstance.dismiss();
  2933. };
  2934. }]);
  2935. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
  2936. $scope.erpParams = new ngTableParams({
  2937. page : 1,
  2938. count : 5,
  2939. sorting: {
  2940. time: 'desc'
  2941. }
  2942. }, {
  2943. total : 0,
  2944. counts: [5, 10, 25, 50],
  2945. getData : function($defer, params) {
  2946. $scope.loading = true;
  2947. ErpLog.get(BaseService.parseParams(params.url()), function(page){
  2948. $scope.loading = false;
  2949. if(page) {
  2950. params.total(page.totalElements);
  2951. $defer.resolve(page.content);
  2952. }
  2953. }, function(response){
  2954. $scope.loading = false;
  2955. toaster.pop('error', '数据加载失败', response.data);
  2956. });
  2957. }
  2958. });
  2959. $scope.usageParams = new ngTableParams({
  2960. page : 1,
  2961. count : 5,
  2962. sorting: {
  2963. time: 'desc'
  2964. }
  2965. }, {
  2966. total : 0,
  2967. counts: [5, 10, 25, 50],
  2968. getData : function($defer, params) {
  2969. $scope.loading = true;
  2970. UsageLog.get(BaseService.parseParams(params.url()), function(page){
  2971. $scope.loading = false;
  2972. if(page) {
  2973. params.total(page.totalElements);
  2974. $defer.resolve(page.content);
  2975. }
  2976. }, function(response){
  2977. $scope.loading = false;
  2978. toaster.pop('error', '数据加载失败', response.data);
  2979. });
  2980. }
  2981. });
  2982. }]);
  2983. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
  2984. AccountResource.query({}, function(data){
  2985. if(data && data.length > 0) {
  2986. data[0].$open = true;
  2987. }
  2988. $scope.resources = data;
  2989. });
  2990. }]);
  2991. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
  2992. $scope.roles = {};
  2993. var getData = function() {
  2994. AccountRole.query({}, function(data){
  2995. var defaults = [], custom = [];
  2996. angular.forEach(data, function(d){
  2997. if(d.isdefault == 1)
  2998. defaults.push(d);
  2999. else
  3000. custom.push(d);
  3001. });
  3002. $scope.roles = {defaults: defaults, custom: custom};
  3003. });
  3004. };
  3005. getData();
  3006. $scope.editRole = function(role){
  3007. var modalInstance = $modal.open({
  3008. animation: true,
  3009. templateUrl: 'static/tpl/index/account/role_detail.html',
  3010. controller: 'RoleEditCtrl',
  3011. resolve: {
  3012. role: function() {
  3013. return role;
  3014. }
  3015. }
  3016. });
  3017. modalInstance.result.then(function(added){
  3018. added && (getData());
  3019. });
  3020. };
  3021. }]);
  3022. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert){
  3023. $scope.role = role;
  3024. $scope.master = angular.copy($scope.role);
  3025. var isNew = role == null;
  3026. $scope.cancel = function() {
  3027. $modalInstance.close(false);
  3028. };
  3029. AccountResource.query({}, function(data){
  3030. if(data && data.length > 0) {
  3031. if(role && role.resourceItems) {
  3032. var rs = [];// 已分配的资源的id
  3033. angular.forEach(role.resourceItems, function(item){
  3034. rs.push(item.id);
  3035. });
  3036. angular.forEach(data, function(resource){
  3037. var c = 0;
  3038. angular.forEach(resource.items, function(item){
  3039. if(rs.indexOf(item.id) > -1) {
  3040. item.$checked = true;
  3041. c += 1;
  3042. }
  3043. });
  3044. resource.$checked = c == resource.items.length;
  3045. });
  3046. }
  3047. $scope.resourceItems = data[0].items;
  3048. data[0].$active = true;
  3049. }
  3050. $scope.resources = data;
  3051. $timeout(function(){
  3052. angular.forEach($scope.resources, function(resource){
  3053. var c = 0;
  3054. angular.forEach(resource.items, function(item){
  3055. item.$checked && (c+=1);
  3056. });
  3057. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  3058. });
  3059. }, 100);
  3060. });
  3061. $scope.onItemClick = function(resource) {
  3062. $scope.resourceItems = resource.items;
  3063. angular.forEach($scope.resources, function(r){
  3064. r.$active = false;
  3065. });
  3066. resource.$active = true;
  3067. };
  3068. var getChecked = function() {
  3069. var items = [];
  3070. angular.forEach($scope.resources, function(resource){
  3071. angular.forEach(resource.items, function(item){
  3072. item.$checked && (items.push(item));
  3073. });
  3074. });
  3075. $scope.role.resourceItems = items;
  3076. };
  3077. $scope.onResourceChange = function(resource) {
  3078. angular.forEach(resource.items, function(item){
  3079. item.$checked = resource.$checked;
  3080. });
  3081. getChecked();
  3082. };
  3083. $scope.onItemChange = function() {
  3084. angular.forEach($scope.resources, function(resource){
  3085. if(resource.$active) {
  3086. var c = 0;
  3087. angular.forEach(resource.items, function(item){
  3088. item.$checked && (c+=1);
  3089. });
  3090. resource.$checked = (c == resource.items.length);
  3091. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  3092. }
  3093. });
  3094. getChecked();
  3095. };
  3096. $scope.isChanged = function(formData) {
  3097. if(!$scope.master)
  3098. return true;
  3099. return !angular.equals(formData, $scope.master);
  3100. };
  3101. $scope.save = function() {
  3102. $scope.master = angular.copy($scope.role);
  3103. AccountRole.save($scope.master, function(){
  3104. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
  3105. $modalInstance.close(true);
  3106. }, function(response){
  3107. toaster.pop('error', '错误', response.data);
  3108. });
  3109. };
  3110. $scope.del = function() {
  3111. new ngAlert({
  3112. title: '提示',
  3113. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  3114. }, function(){
  3115. AccountRole.remove({id: role.id}, function(){
  3116. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  3117. $modalInstance.close(true);
  3118. }, function(response){
  3119. toaster.pop('error', '错误', response.data);
  3120. });
  3121. })
  3122. };
  3123. }]);
  3124. /**
  3125. * 委外订单
  3126. */
  3127. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster', 'BaseService',
  3128. function($scope, $filter, MakeOrder, ngTableParams, toaster, BaseService){
  3129. $scope.active = 'all';
  3130. $scope.dateZoneText = '一个月内';
  3131. $scope.condition = {dateZone: 1};
  3132. $scope.changeDateZone = function(zone) {
  3133. $scope.condition.dateZone = zone;
  3134. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  3135. $scope.condition.$dateZoneOpen = false;
  3136. getDateCondition(zone, $scope.condition);
  3137. $scope.tableParams.reload();
  3138. };
  3139. $scope.setActive = function(state) {
  3140. if($scope.active != state) {
  3141. $scope.active = state;
  3142. if($scope.tableParams.page() == 1)
  3143. $scope.tableParams.reload();
  3144. else
  3145. $scope.tableParams.page(1);
  3146. }
  3147. };
  3148. var getService = function() {
  3149. return MakeOrder;
  3150. };
  3151. $scope.tableParams = new ngTableParams({
  3152. page : 1,
  3153. count : 5,
  3154. sorting: {
  3155. date: 'desc'
  3156. }
  3157. }, {
  3158. total : 0,
  3159. counts: [5, 10, 25, 50],
  3160. getData : function($defer, params) {
  3161. $scope.loading = true;
  3162. var pageParams = params.url();
  3163. pageParams.keyword = $scope.keyword;
  3164. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
  3165. $scope.loading = false;
  3166. if(page) {
  3167. params.total(page.totalElements);
  3168. $defer.resolve(page.content);
  3169. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  3170. }
  3171. }, function(response){
  3172. $scope.loading = false;
  3173. toaster.pop('error', '数据加载失败', response.data);
  3174. });
  3175. }
  3176. });
  3177. $scope.getOrderTotal = function(items) {
  3178. var sum = 0;
  3179. angular.forEach(items, function(item){
  3180. sum += item.qty * item.price;
  3181. });
  3182. return sum;
  3183. };
  3184. $scope.openDatePicker = function($event, item, openParam) {
  3185. $event.preventDefault();
  3186. $event.stopPropagation();
  3187. item[openParam] = !item[openParam];
  3188. };
  3189. $scope.parseDate = function(dateStr) {
  3190. if(dateStr)
  3191. return Date.parse(dateStr, 'yyyy-MM-dd');
  3192. return new Date();
  3193. };
  3194. // 打开回复
  3195. $scope.openReply = function(order) {
  3196. if(!order.reply) {
  3197. order.reply = {
  3198. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  3199. delivery: order.delivery
  3200. }
  3201. }
  3202. order.$editing = true;
  3203. };
  3204. // 关闭回复
  3205. $scope.closeReply = function(order) {
  3206. order.$editing = false;
  3207. }
  3208. // 搜索框回车
  3209. $scope.onSearch = function() {
  3210. $scope.tableParams.page(1);
  3211. $scope.tableParams.reload();
  3212. };
  3213. // 点击回复
  3214. $scope.onReplyClick = function(order, inverse) {
  3215. if(order.reply) {
  3216. if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  3217. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  3218. return;
  3219. }
  3220. var reply = angular.copy(order.reply);
  3221. if(reply.delivery) {
  3222. if(typeof reply.delivery == 'object')
  3223. reply.delivery = reply.delivery.getTime();
  3224. } else {
  3225. reply.delivery = order.delivery;
  3226. }
  3227. if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  3228. $scope.loading = true;
  3229. MakeOrder.reply({orderId: order.id}, reply, function(){
  3230. $scope.loading = false;
  3231. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
  3232. $scope.tableParams.reload();
  3233. }, function(response){
  3234. $scope.loading = false;
  3235. toaster.pop('error', '回复失败', response.data);
  3236. });
  3237. }
  3238. };
  3239. // 获取回复记录
  3240. $scope.getReply = function(order) {
  3241. if(!order.replies) {
  3242. MakeOrder.getReply({orderId: order.id}, function(replies){
  3243. order.replies = replies;
  3244. });
  3245. }
  3246. };
  3247. }]);
  3248. /**
  3249. * 计算时间差
  3250. */
  3251. app.filter('timespan', function(){
  3252. return function(time) {
  3253. if(time == null)
  3254. return '9999年';
  3255. var now = new Date().getTime(), span = time - now,
  3256. d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
  3257. m = Math.ceil(span/60000);
  3258. if(span < 0)
  3259. return '0天';
  3260. if(d > 0)
  3261. return d + '天';
  3262. if(h > 0)
  3263. return h + '小时';
  3264. if(m > 0)
  3265. return m + '分钟';
  3266. return '0天';
  3267. };
  3268. });
  3269. app.filter('firstchar', function(){
  3270. return function(str) {
  3271. if(str == null)
  3272. return null;
  3273. return str.substring(0, 1);
  3274. };
  3275. });
  3276. /**
  3277. * 搜索框,回车触发
  3278. */
  3279. app.directive('ngSearch', ['$parse', function($parse) {
  3280. return {
  3281. require : '?ngModel',
  3282. restrict : 'A',
  3283. link : function(scope, element, attrs, ngModel) {
  3284. var searchFn = $parse(attrs.ngSearch);
  3285. element.bind('keypress', function(event) {
  3286. if (event.keyCode == '13') {
  3287. event.preventDefault();
  3288. event.stopPropagation();
  3289. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  3290. }
  3291. });
  3292. }
  3293. };
  3294. }]);
  3295. /**
  3296. * 状态码 -> 描述
  3297. */
  3298. app.filter('status', function(){
  3299. return function(data) {
  3300. var statusConfig = {
  3301. '101': '已提交',
  3302. '102': '已审核',
  3303. '103': '未通过',
  3304. '200': '未回复',
  3305. '201': '已回复',
  3306. '313': '已激活',
  3307. '316': '已过账',
  3308. '311': '申请中',
  3309. '312': '未激活'
  3310. };
  3311. return statusConfig[data];
  3312. }
  3313. });
  3314. return app;
  3315. });