| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508 |
- define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'service/Make', 'service/Account', 'service/Alert', 'ui.router', 'ui.bootstrap' , 'file-upload', 'ngSanitize'], function() {
- 'use strict';
- var app = angular.module('myApp', [ 'toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'PurcServices', 'MakeServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize']);
- app.init = function() {
- angular.bootstrap(document, [ 'myApp' ]);
- };
- app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
- $urlRouterProvider.otherwise('/index');
- $stateProvider.state('index', {
- url : "/index",
- views : {
- "left-view" : {
- templateUrl : "static/tpl/index/home/left.html"
- },
- "right-view" : {
- templateUrl : "static/tpl/index/home/right.html"
- }
- }
- }).state('home', {
- url : "/",
- views : {
- "left-view" : {
- templateUrl : "static/tpl/index/home/left.html"
- },
- "right-view" : {
- templateUrl : "static/tpl/index/home/right.html"
- }
- }
- }).state('sale', {
- url : "/sale",
- views : {
- "left-view" : {
- templateUrl : "static/tpl/index/sale/left.html"
- },
- "right-view" : {
- templateUrl : "static/tpl/index/sale/right.html"
- }
- },
- controller: function($scope) {
- $scope.truck = [];
- $scope.dataChanged = false;
- }
- }).state('sale.index', {
- url : "",
- templateUrl : "static/tpl/index/sale/index.html"
- }).state('sale.home', {
- url : "/",
- templateUrl : "static/tpl/index/sale/index.html"
- }).state('sale.todo', {
- url : "/todo",
- templateUrl : "static/tpl/index/sale/todo.html"
- }).state('sale.todo.inquiry', {
- url : "/inquiry",
- templateUrl : "static/tpl/index/sale/inquiry.html",
- controller: 'SaleInquiryCtrl'
- }).state('sale.todo.order', {
- url : "/order",
- templateUrl : "static/tpl/index/sale/order.html",
- controller: 'SaleOrderCtrl'
- }).state('sale.todo.change', {
- url : "/change",
- templateUrl : "static/tpl/index/sale/change.html",
- controller: 'SaleChangeCtrl'
- }).state('sale.todo.notice', {
- url : "/notice",
- templateUrl : "static/tpl/index/sale/notice.html",
- controller: 'SaleNoticeCtrl'
- }).state('sale.customer', {
- url : "/customer",
- templateUrl : "static/tpl/index/sale/customer.html",
- controller: 'CustomerCtrl'
- }).state('sale.customerProduct', {
- url : "/customerProduct",
- templateUrl : "static/tpl/index/sale/customer.html",
- controller: 'CustomerCtrl'
- }).state('sale.inquiry', {
- url : "/inquiry",
- templateUrl : "static/tpl/index/sale/inquiry.html",
- controller: 'SaleInquiryCtrl'
- }).state('sale.inquiry_detail', {
- url : "/inquiry/:id",
- templateUrl : "static/tpl/index/sale/inquiry_detail.html",
- controller: 'SaleInquiryDetailCtrl'
- }).state('sale.quotation', {
- url : "/quotation",
- templateUrl : "static/tpl/index/sale/quotation.html"
- }).state('sale.quotation.new', {
- url : "/new",
- templateUrl : "static/tpl/index/sale/quotation_new.html",
- controller: 'SaleQuotationNewCtrl'
- }).state('sale.quotation.list', {
- url : "/list",
- templateUrl : "static/tpl/index/sale/quotation_list.html",
- controller: 'SaleQuotationListCtrl'
- }).state('sale.quotation.item', {
- url : "/:id",
- templateUrl : "static/tpl/index/sale/quotation_new.html",
- controller: 'SaleQuotationNewCtrl'
- }).state('sale.order', {
- url : "/order",
- templateUrl : "static/tpl/index/sale/order.html",
- controller: 'SaleOrderCtrl'
- }).state('sale.order_detail', {
- url : "/order/:id",
- templateUrl : "static/tpl/index/sale/order_detail.html",
- controller: 'SaleOrderDetailCtrl'
- }).state('sale.change', {
- url : "/change",
- templateUrl : "static/tpl/index/sale/change.html",
- controller: 'SaleChangeCtrl'
- }).state('sale.change_detail', {
- url : "/change/:id",
- templateUrl : "static/tpl/index/sale/change_detail.html",
- controller: 'SaleChangeDetailCtrl'
- }).state('sale.notice', {
- url : "/notice",
- templateUrl : "static/tpl/index/sale/notice.html",
- controller: 'SaleNoticeCtrl'
- }).state('sale.send', {
- url : "/send",
- templateUrl : "static/tpl/index/sale/send.html",
- controller: 'SaleSendCtrl'
- }).state('sale.forecast', {
- url : "/forecast",
- templateUrl : "static/tpl/index/sale/forecast.html",
- controller: 'SaleForecastCtrl'
- }).state('sale.accept', {
- url : "/accept",
- templateUrl : "static/tpl/index/sale/accept.html",
- controller: 'SaleAcceptCtrl'
- }).state('sale.returns', {
- url : "/returns",
- templateUrl : "static/tpl/index/sale/returns.html",
- controller: 'SaleReturnsCtrl'
- }).state('sale.sample', {
- url : "/sample",
- templateUrl : "static/tpl/index/sale/sample.html",
- controller: 'SaleSampleCtrl'
- }).state('sale.approval', {
- url : "/approval",
- templateUrl : "static/tpl/index/sale/approval.html",
- controller: 'SaleApprovalCtrl'
- }).state('account', {
- url : "/account",
- views : {
- "left-view" : {
- templateUrl : "static/tpl/index/account/left.html"
- },
- "right-view" : {
- templateUrl : "static/tpl/index/account/right.html"
- }
- }
- }).state('account.index', {
- url : "",
- templateUrl : "static/tpl/index/account/index.html"
- }).state('account.home', {
- url : "/",
- templateUrl : "static/tpl/index/account/index.html"
- }).state('account.enterprise', {
- url : "/enterprise",
- templateUrl : "static/tpl/index/account/enterprise.html",
- controller: 'EnterpriseCtrl'
- }).state('account.user', {
- url : "/user",
- templateUrl : "static/tpl/index/account/user.html",
- controller: 'UserCtrl'
- }).state('account.log', {
- url : "/log",
- templateUrl : "static/tpl/index/account/log.html",
- controller: 'LogCtrl'
- }).state('account.resource', {
- url : "/resource",
- templateUrl : "static/tpl/index/account/resource.html",
- controller: 'ResourceCtrl'
- }).state('account.role', {
- url : "/role",
- templateUrl : "static/tpl/index/account/role.html",
- controller: 'RoleCtrl'
- }).state('qc', {
- url : "/qc",
- views : {
- "left-view" : {
- templateUrl : "static/tpl/index/qc/left.html"
- },
- "right-view" : {
- templateUrl : "static/tpl/index/qc/right.html"
- }
- }
- }).state('qc.badIn', {
- url : "/badIn",
- templateUrl : "static/tpl/index/qc/badIn.html",
- controller: 'SaleBadInCtrl'
- }).state('qc.badOut', {
- url : "/badOut",
- templateUrl : "static/tpl/index/qc/badOut.html",
- controller: 'SaleBadOutCtrl'
- }).state('qc.MRB', {
- url : "/MRB",
- templateUrl : "static/tpl/index/qc/MRB.html",
- controller: 'SaleMRBCtrl'
- }).state('fa', {
- url : "/fa",
- views : {
- "left-view" : {
- templateUrl : "static/tpl/index/fa/left.html"
- },
- "right-view" : {
- templateUrl : "static/tpl/index/fa/right.html"
- }
- }
- }).state('fa.apBill', {
- url : "/apBill",
- templateUrl : "static/tpl/index/fa/apBill.html",
- controller: 'SaleApBillCtrl'
- }).state('make', {
- url : "/make",
- views : {
- "left-view" : {
- templateUrl : "static/tpl/index/make/left.html"
- },
- "right-view" : {
- templateUrl : "static/tpl/index/make/right.html"
- }
- }
- }).state('make.index', {
- url : "",
- templateUrl : "static/tpl/index/make/index.html"
- }).state('make.order', {
- url : "/order",
- templateUrl : "static/tpl/index/make/order.html",
- controller: 'MakeOrderCtrl'
- }).state('make.order_detail', {
- url : "/order/:id",
- templateUrl : "static/tpl/index/make/order_detail.html",
- controller: 'SaleOrderDetailCtrl'
- });
- }]);
-
- /**
- * 表示符号
- */
- app.factory('Symbol', function(){
- return {
- currency: function(cur) {
- if(cur == 'RMB') return '¥';
- else if(cur == 'USD') return '$';
- else if(cur == 'EUR') return '€';
- else if(cur == null || cur == '') return '¥';
- else return cur;
- }
- };
- });
-
- app.controller('MyCtrl', ['$scope', '$rootScope', function($scope, $rootScope) {
- $rootScope.$on('$locationChangeSuccess', function(evt, newUrl) {
- var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
- if (routeState.indexOf('/') > -1)
- routeState = routeState.substring(0, routeState.indexOf('/'));
- if (routeState.indexOf('.') > -1)
- routeState = routeState.substring(0, routeState.indexOf('.'));
- $scope.routeState = routeState || 'home';
- });
- }]);
- app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', function($scope, $window, AuthenticationService, toaster) {
- $scope.isAuthed = AuthenticationService.isAuthed();
- $scope.userInfo = {};
- AuthenticationService.getAuthentication().success(function(data) {
- if(data.enterprises) {
- data.enterprise = data.enterprises[data.enterprises.length - 1];
- if(data.enterprises.length > 1) {
- var enSelect = [];
- angular.forEach(data.enterprises, function(e){
- if(e.current)
- data.enterprise = e;
- else
- enSelect.push(e);
- });
- data.enSelect = enSelect;
- }
- }
- $scope.userInfo = data;
- if (data == null || !data.uu)
- $scope.isAuthed = false;
- });
- $scope.logout = function() {
- AuthenticationService.logout().success(function() {
- $window.location.reload();
- });
- };
- $scope.switchto = function(enUU) {// 切换企业
- AuthenticationService.reSignin(enUU).success(function(){
- $window.location.reload();
- });
- };
-
- $scope.addFavorite = function(){
- var url = encodeURI(window.location.href);
- try{
- //ie浏览器收藏方式
- window.external.addFavorite(url, "优软商务平台");
- }catch(e) {
- try{
- //火狐浏览器收藏方式
- window.sidebar.addPanel("优软商务平台", url);
- }catch (e) {
- toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加,"+
- "或手动在浏览器里进行设置。");
- }
- }
- };
- }]);
- app.controller('TodoCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
- SnapshotService.getTodo(function(data){
- $scope.todo = data;
- });
- }]);
- app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function($scope, $rootScope, $modal, SaleTruck){
- SaleTruck.query({}, function(data){
- $rootScope.truck = data;
- $scope.truckCount = data ? data.length : 0;
- });
- $scope.$watch(function(){
- return $rootScope.truck;
- }, function(data) {
- $scope.truckCount = data ? data.length : 0;
- }, true);
- $scope.clearAll = function() {
- SaleTruck.remove({}, function(){
- $rootScope.truck = [];
- });
- };
- $scope.openTrack = function() {
- $modal.open({
- templateUrl: 'static/tpl/index/sale/track.html',
- controller: 'TruckModalCtrl',
- size: 'lg'
- }).result.then(function(s){
- if(s) {
- $scope.clearAll();
- $rootScope.dataChanged = true;
- }
- });
- };
- }]);
- app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', function($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster){
- $scope.saleSend = {sendItems: []};
- SaleTruck.detail({}, function(data){
- $scope.notices = data;
- });
- $scope.remove = function(index, notice) {
- SaleTruck.remove({noticeId: notice.id}, function(data){
- $rootScope.truck = data;
- $scope.notices.splice(index, 1);
- });
- };
- $scope.$watch(function(){
- return $scope.notices;
- }, function(data) {
- var q = 0, t = 0;
- if(data) {
- angular.forEach(data,function(d){
- q += d.thisSendQty;
- t += d.thisSendQty * d.orderItem.price;
- });
- }
- $scope.totalQty = q;
- $scope.total = t;
- }, true);
- $scope.cancel = function() {
- $modalInstance.close();
- };
- $scope.send = function() {// 发货
- if(!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
- toaster.pop('error', '错误', '请输入送货单号');
- return;
- }
- var currency = $scope.notices[0].orderItem.order.currency,
- custUU = $scope.notices[0].enUU,
- payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
- for(var i in $scope.notices) {
- var item = $scope.notices[i];
- if(item.id) {
- if(item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
- valid = false;
- break;
- }
- items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price};
- }
- }
- if(!valid) {
- toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
- } else {
- var send = angular.extend(angular.copy($scope.saleSend), {
- currency: currency,
- custUU: custUU,
- payments: payments,
- sendItems: items
- });
- PurcNotice.sendByBatch({}, send, function(data){
- toaster.pop('success', '提示', '发货成功。');
- $modalInstance.close(true);
- }, function(response){
- toaster.pop('error', '错误', response.data);
- });
- }
- };
- }]);
- app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat) {
- SaleStat.cust({}, function(data){
- var p = [], q = [];
- angular.forEach(data.month, function(d){
- p.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
- });
- angular.forEach(data.year, function(d){
- q.push({x: (d.enterprise.enShortname || d.enterprise.enName), y: [(d.total || 0)], tooltip: (d.total || 0)});
- });
- $scope.custCharts = {
- month : {
- chartType : 'pie',
- datas : {
- data : p
- },
- config : {
- labels : false,
- title : "客户月采购量排行榜",
- legend : {
- display : true,
- position : 'right'
- },
- colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
- click : function(d) {
- },
- mouseover : function(d) {
- },
- mouseout : function(d) {
- },
- innerRadius : 0,
- lineLegend : 'lineEnd'
- }
- },
- year : {
- chartType : 'pie',
- datas : {
- data : q
- },
- config : {
- labels : false,
- title : "客户年采购量排行榜",
- legend : {
- display : true,
- position : 'right'
- },
- colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
- click : function(d) {
- },
- mouseover : function(d) {
- },
- mouseout : function(d) {
- },
- innerRadius : 0,
- lineLegend : 'lineEnd'
- }
- }
- };
- });
- SaleStat.seller({}, function(data){
- var p = [], q = [];
- angular.forEach(data.month, function(d){
- p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
- });
- angular.forEach(data.year, function(d){
- q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
- });
- $scope.sellerCharts = {
- month : {
- chartType : 'pie',
- datas : {
- data : p
- },
- config : {
- labels : false,
- title : "业务员月销量排行榜",
- legend : {
- display : true,
- position : 'right'
- },
- colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
- click : function(d) {
- },
- mouseover : function(d) {
- },
- mouseout : function(d) {
- },
- innerRadius : 0,
- lineLegend : 'lineEnd'
- }
- },
- year : {
- chartType : 'pie',
- datas : {
- data : q
- },
- config : {
- labels : false,
- title : "业务员年销量排行榜",
- legend : {
- display : true,
- position : 'right'
- },
- colors : [ '#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC' ],
- click : function(d) {
- },
- mouseover : function(d) {
- },
- mouseout : function(d) {
- },
- innerRadius : 0,
- lineLegend : 'lineEnd'
- }
- }
- };
- });
- }]);
- app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function($scope, SaleStat){
- SaleStat.get({}, function(data){
- var p = [], q = [], r = [];
- angular.forEach(data.day, function(d){
- p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
- });
- angular.forEach(data.month, function(d){
- q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
- });
- angular.forEach(data.year, function(d){
- r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
- });
- $scope.charts = {
- day : {
- chartType : "line",
- datas: {
- series: ['销售额'],
- data: p
- },
- config : {
- "labels": false,
- "title": "销售额统计(近15日线)",
- "legend": {
- "display": true,
- "position": "right"
- },
- colors : [ '#4D9934'],
- "innerRadius": 0,
- "lineLegend": "lineEnd"
- }
- },
- month: {
- chartType : "line",
- datas: {
- series: ['销售额'],
- data: q
- },
- config : {
- "labels": false,
- "title": "销售额统计(近12月线)",
- "legend": {
- "display": true,
- "position": "right"
- },
- colors : [ '#4D9934'],
- "innerRadius": 0,
- "lineLegend": "lineEnd"
- }
- },
- year: {
- chartType : "line",
- datas: {
- series: ['销售额'],
- data: r
- },
- config : {
- "labels": false,
- "title": "销售额统计(近10年线)",
- "legend": {
- "display": true,
- "position": "right"
- },
- colors : [ '#4D9934'],
- "innerRadius": 0,
- "lineLegend": "lineEnd"
- }
- }
- };
- });
- }]);
- app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function($scope, SnapshotService){
- SnapshotService.getNotice(5, function(data){
- $scope.notices = data;
- });
-
- $scope.dateTime = new Date();
- }]);
- app.controller('VendCountCtrl', ['$scope', 'VendorService', function($scope, VendorService){
- VendorService.getCount(function(date){
- $scope.count = date;
- });
- }]);
- app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService', 'ngTableParams', 'toaster', function($scope, VendorService, BaseService, ngTableParams, toaster){
- $scope.customerParams = new ngTableParams({
- page : 1,
- count : 10
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- VendorService.customer.get(BaseService.parseParams(params.url()), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- }
- $scope.totalCount = page.totalElements;
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
- }]);
- var getState = function(active) {
- var fn = 'get';
- switch(active) {
- case 'done':
- fn = 'getDone';break;
- case 'todo':
- fn = 'getTodo';break;
- case 'end':
- fn = 'getEnd';break;
- case 'waiting':
- fn = 'getWaiting';break;
- }
- return fn;
- };
-
- var getDateCondition = function(zone, condition) {
- var date = new Date();
- if(zone == 1) {
- date.setMonth(date.getMonth() - 1);
- condition.dateFrom = date;
- condition.dateTo = new Date();
- } else if (zone == 6) {
- date.setMonth(date.getMonth() - 6);
- condition.dateFrom = date;
- condition.dateTo = new Date();
- } else {
- date.setMonth(date.getMonth() - 6);
- condition.dateFrom = null;
- condition.dateTo = date;
- }
- };
-
- app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis',
- function($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis){
- $scope.active = 'todo';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- getDateCondition(zone, $scope.condition);
- $scope.tableParams.reload();
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return $scope.condition.dateZone ? PurcOrderItem : PurcOrderItemHis;
- };
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- display: 'desc',
- date: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
- pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
- $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.getOrderTotal = function(items) {
- var sum = 0;
- angular.forEach(items, function(item){
- sum += item.qty * item.price;
- });
- return sum;
- };
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- $scope.parseDate = function(dateStr) {
- if(dateStr)
- return Date.parse(dateStr, 'yyyy-MM-dd');
- return new Date();
- };
-
- $scope.onReplyClick = function(item, inverse) {
- if(item.reply) {
- if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
- toaster.pop('warning', '提示', '请填写有效的回复数量!');
- return;
- }
- var reply = angular.copy(item.reply);
- if(reply.delivery) {
- if(typeof reply.delivery == 'object')
- reply.delivery = reply.delivery.getTime();
- } else {
- reply.delivery = item.delivery;
- }
- if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
- $scope.loading = true;
- PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
- $scope.loading = false;
- toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
- $scope.tableParams.reload();
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '回复失败', response.data);
- });
- }
- };
-
- //打印
- $scope.print = function(order) {
- PurcOrder.printCount({id: order.id},{});//增加打印此次
- if(order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
- ReportService.print(order.enUU, 'purchase', '{purc_orders.pu_id}=' + order.id, '销售订单-' + order.code);
- };
-
- $scope.getReply = function(item) {
- if(!item.replies) {
- PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
- item.replies = replies;
- });
- }
- };
-
- $scope.checkboxes = {
- checked : false
- };
- // 点击勾选全部的复选框
- $scope.checkAll = function(){
- angular.forEach($scope.tableParams.data, function(item) {
- item.$selected = $scope.checkboxes.checked;
- });
- };
-
- // 点击其中一个明细的复选框
- $scope.checkOne = function(order){
- var result = true;
- angular.forEach($scope.tableParams.data, function(item) {
- if(item.$selected != true){
- result = false;
- return;
- }
- });
- $scope.checkboxes.checked = result;
- };
-
- //批量回复采购订单
- $scope.replyByBatch = function() {
- $scope.loading = true;
- var str = '';
- angular.forEach($scope.tableParams.data, function(order) {
- if(order.$selected == true) {
- angular.forEach(order.orderItems, function(item){
- str += item.id;
- str += ',';
- });
- }
- });
- if(!(str == '')) {
- str = str.substr(0, str.length-1);
- PurcOrderItem.replyByBatch(str, function(){
- $scope.loading = false;
- $scope.tableParams.reload();
- toaster.pop('success', '提示', '批量回复成功');
- }, function(data){
- $scope.loading = false;
- toaster.pop('error', '批量回复失败', data);
- });
- } else {//没有勾选其中的明细
- $scope.loading = false;
- }
- };
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
- // 选择查找日期
- $scope.onDateCondition = function(){
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
- //设置为已查看
- $scope.setDisplay = function(state, orderId) {
- if(orderId) {//设置单个
- PurcOrder[state].call({}, {ids: '' + orderId}, function(){
- $scope.tableParams.reload();
- }, function() {
- toaster.pop('error', '错误', "设置失败");
- });
- } else {//设置已勾选的
- var str = null;
- angular.forEach($scope.tableParams.data, function(order) {
- if(order.$selected == true) {
- if(str != null && str != '') str += ',';
- str += order.id;
- }
- });
- if(str != null && str != '') {
- PurcOrder[state].call({}, {ids: '' + str}, function(){
- $scope.tableParams.reload();
- }, function() {
- toaster.pop('error', '错误', "设置失败");
- });
- }
- }
- };
- }]);
- app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', function($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService){
- var loadData = function() {
- PurcOrder.get({id: $stateParams.id}, function(data){
- $scope.order = data;
- var sum = 0;
- angular.forEach($scope.order.orderItems, function(item){
- sum += item.qty * item.price;
- });
- $scope.order.total = sum;
- if($scope.order.display == 1) {//未查看的设为已查看
- $scope.setDisplay('setRead', $scope.order.id);
- }
- $scope.loading = false;
- });
- };
- loadData();
- $scope.getReply = function(item) {
- if(!item.replies) {
- PurcOrderItem.getReply({orderItemId: item.id}, function(replies){
- item.replies = replies;
- });
- }
- };
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- $scope.onReplyClick = function(item, inverse) {
- if(item.reply) {
- if(!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
- toaster.pop('warning', '提示', '请填写有效的回复数量!');
- return;
- }
- var reply = angular.copy(item.reply);
- if(reply.delivery) {
- if(typeof reply.delivery == 'object')
- reply.delivery = reply.delivery.getTime();
- } else {
- reply.delivery = item.delivery;
- }
- if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
- $scope.loading = true;
- PurcOrderItem.reply({orderItemId: item.id}, reply, function(){
- $scope.loading = false;
- toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
- loadData();
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '回复失败', response.data);
- });
- }
- };
-
- $scope.print = function(order) {
- PurcOrder.printCount({id: order.id},{});//增加打印此次
- ReportService.print(order.enUU, 'purchase', '{purc_orders.pu_id}=' + order.id, '销售订单-' + order.code);
- };
-
- //设置为已查看
- $scope.setDisplay = function(state, orderId) {
- console.log(PurcOrder);
- if(orderId) {//设置单个
- PurcOrder[state].call({}, {ids: '' + orderId}, function(){
- $scope.tableParams.reload();
- }, function() {
- toaster.pop('error', '错误', "设置失败");
- });
- } else {//设置已勾选的
- var str = null;
- angular.forEach($scope.tableParams.data, function(order) {
- if(order.$selected == true) {
- if(str != null && str != '') str += ',';
- str += order.id;
- }
- });
- if(str != null && str != '') {
- PurcOrder[state].call({}, {ids: '' + str}, function(){
- $scope.tableParams.reload();
- }, function() {
- toaster.pop('error', '错误', "设置失败");
- });
- }
- }
- };
- }]);
- app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', function($scope, $filter, PurcChange, ngTableParams, toaster, BaseService, PurcChangeHis){
- $scope.active = 'todo';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.changeAgreed = function(agreed) {
- $scope.condition.agreed = agreed;
- $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
- $scope.condition.$agreedOpen = false;
- };
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return $scope.condition.dateZone ? PurcChange : PurcChangeHis;
- };
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- date: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- $scope.onReplyClick = function(change) {
- if(change.$agreed) {
- var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
- $scope.loading = true;
- PurcChange.reply({changeId: change.id}, reply, function(){
- $scope.loading = false;
- toaster.pop('info', '提示', '回复成功');
- $scope.tableParams.reload();
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '回复失败', response.data);
- });
- }
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
- }]);
- app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', function($scope, $stateParams, PurcChange, toaster){
- var loadData = function() {
- PurcChange.get({id: $stateParams.id}, function(data){
- $scope.change = data;
- });
- };
- loadData();
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- $scope.onReplyClick = function(change) {
- if(change.$agreed) {
- var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
- PurcChange.reply({changeId: change.id}, reply, function(){
- toaster.pop('info', '提示', '回复成功');
- loadData();
- }, function(response){
- toaster.pop('error', '回复失败', response.data);
- });
- }
- };
- }]);
- app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryHis', function($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryHis){
- $scope.active = 'todo';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.changeAgreed = function(agreed) {
- $scope.condition.agreed = agreed;
- $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
- $scope.condition.$agreedOpen = false;
- };
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return $scope.condition.dateZone ? PurcInquiry : PurcInquiryHis;
- };
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- 'inquiry.date': 'desc',
- 'inquiry.enterprise.enName': 'asc',
- 'inquiry.code': 'asc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.getMinDate = function(item) {
- return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
- };
-
- $scope.addStep = function(inquiryItem) {
- if(inquiryItem.replies.length >= 10) {
- toaster.pop('warning', '提示', '最多支持10个分段!');
- } else
- inquiryItem.replies.push({});
- };
-
- $scope.removeStep = function(inquiryItem, stepIndex) {
- inquiryItem.replies.splice(stepIndex, 1);
- };
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- $scope.getHistory = function(item) {
- if(!item.history) {
- PurcInquiry.getHistory({itemId: item.id}, function(data){
- item.history = data;
- });
- }
- };
-
- $scope.isValid = function(item, withSteps) {
- var bool = item.leadtime && item.replies && item.replies[0].price > 0;
- if(!withSteps || !bool)
- return bool;
- angular.forEach(item.replies, function(r, i){
- bool = (i > 0 ? r.lapQty : 1) && r.price;
- });
- return bool;
- };
-
- $scope.onReplyClick = function(item, withSteps) {
- if(item.vendFromDate instanceof Date) {
- item.vendFromDate = item.vendFromDate.getTime();
- }
- if(item.vendToDate instanceof Date) {
- item.vendToDate = item.vendToDate.getTime();
- }
- if(item.vendFromDate > item.vendToDate) {
- toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
- return;
- }
- var replies = [];
- angular.forEach(item.replies, function(r, i){
- if((i > 0 ? r.lapQty : 1) || r.price)
- replies.push(r);
- });
- item.replies = replies;
- $scope.loading = true;
- if(withSteps) {
- PurcInquiry.reply({itemId: item.id}, item, function(){
- $scope.loading = false;
- toaster.pop('info', '提示', '报价成功');
- $scope.tableParams.reload();
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '报价失败', response.data);
- });
- } else {
- PurcInquiry.saveItem({itemId: item.id}, item, function(){
- $scope.loading = false;
- toaster.pop('info', '提示', '保存成功');
- $scope.tableParams.reload();
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '保存失败', response.data);
- });
- }
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
- }]);
-
- // 询价单明细
- app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', 'toaster', function($scope, $stateParams, PurcInquiry, toaster){
- var loadData = function() {
- PurcInquiry.getAll({id: $stateParams.id}, function(data){
- var inquiry = data[0].inquiry;
- inquiry.inquiryItems = data;
- angular.forEach(inquiry.attachs, function(attach){
- attach.type = attach.name.substr(attach.name.lastIndexOf('.')+1);
- });
- $scope.inquiry = inquiry;
- });
- };
- loadData();
- $scope.getMinDate = function(item) {
- return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
- };
-
- $scope.addStep = function(inquiryItem) {
- if(inquiryItem.replies.length >= 10) {
- toaster.pop('warning', '提示', '最多支持10个分段!');
- } else
- inquiryItem.replies.push({});
- };
-
- $scope.removeStep = function(inquiryItem, stepIndex) {
- inquiryItem.replies.splice(stepIndex, 1);
- };
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- $scope.getHistory = function(item) {
- if(!item.history) {
- PurcInquiry.getHistory({itemId: item.id}, function(data){
- item.history = data;
- });
- }
- };
-
- $scope.isValid = function(item, withSteps) {
- var bool = item.leadtime && item.replies && item.replies[0].price > 0;
- if(!withSteps || !bool)
- return bool;
- angular.forEach(item.replies, function(r, i){
- bool = (i > 0 ? r.lapQty : 1) && r.price;
- });
- return bool;
- };
-
- $scope.onReplyClick = function(item, withSteps) {
- if(item.vendFromDate instanceof Date) {
- item.vendFromDate = item.vendFromDate.getTime();
- }
- if(item.vendToDate instanceof Date) {
- item.vendToDate = item.vendToDate.getTime();
- }
- if(item.vendFromDate > item.vendToDate) {
- toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
- return;
- }
- var replies = [];
- angular.forEach(item.replies, function(r, i){
- if((i > 0 ? r.lapQty : 1) || r.price)
- replies.push(r);
- });
- item.replies = replies;
- if(withSteps) {
- PurcInquiry.reply({itemId: item.id}, item, function(){
- toaster.pop('info', '提示', '报价成功');
- loadData();
- }, function(response){
- toaster.pop('error', '报价失败', response.data);
- });
- } else {
- PurcInquiry.saveItem({itemId: item.id}, item, function(){
- toaster.pop('info', '提示', '保存成功');
- loadData();
- }, function(response){
- toaster.pop('error', '保存失败', response.data);
- });
- }
- };
- }]);
-
- // 主动报价 - 列表
- app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', function($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService){
- $scope.active = 'todo';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return Quotation;
- };
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- 'quotation.date': 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.getHistory = function(item) {
- if(!item.history) {
- PurcInquiry.getHistory({itemId: item.id}, function(data){
- item.history = data;
- });
- }
- };
-
- $scope.isValid = function(item, withSteps) {
- var bool = item.leadtime && item.replies && item.replies[0].price > 0;
- if(!withSteps || !bool)
- return bool;
- angular.forEach(item.replies, function(r, i){
- bool = (i > 0 ? r.lapQty : 1) && r.price;
- });
- return bool;
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
- }]);
-
- // Controller 主动报价 - 新增
- app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', function($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation){
- var staticItem = null;
-
- if( ! angular.isUndefined($stateParams.id)) {// 查看模式
- $scope.loading = true;
- Quotation.getItem({id: $stateParams.id}, function(data){
- data.$editing = false;
- $scope.item = data;
- staticItem = angular.copy(data);
- $scope.loading = false;
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- } else {// 新增模式
- $scope.item = {
- quotation: {
- currency: 'RMB',
- taxrate: 17,
- date: new Date()
- },
- product: {},
- prices: [{lapQty: 0}],
- minOrderQty: 1,
- minPackQty: 1,
- $endDateOpen: false,
- $editing: true
- };
- }
-
- $scope.getMinDate = function(item) {
- return $filter('date')(new Date, 'yyyy-MM-dd');
- };
-
- $scope.openDatePicker = function($event, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- $scope.item.$endDateOpen = !openParam;
- };
-
- // 增加一个分段
- $scope.addPrice = function(){
- if($scope.item.prices.length >= 10) {
- toaster.pop('warning', '提示', '最多支持10个分段!');
- } else
- $scope.item.prices.push({});
- };
-
- // 删除一个分段
- $scope.removePrice = function(index) {
- $scope.item.prices.splice(index, 1);
- };
-
- // 查找客户
- $scope.dbfindCust = function(){
- if($scope.item.$editing) {
- var modalInstance = $modal.open({
- templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
- controller: 'DbfindCustCtrl',
- size: 'lg',
- resolve: {
-
- }
- });
-
- modalInstance.result.then(function(data){
- $scope.item.quotation.cust = data.myEnterprise;
- $scope.item.quotation.custUser = data.myUser;
- $scope.item.product = null;
- }, function(){
-
- });
- }
- };
-
- // 查找客户物料
- $scope.dbfindCustProd = function(){
- if($scope.item.$editing) {
- if($scope.item.quotation.cust.uu) {
- var modalInstance = $modal.open({
- templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
- controller: 'DbfindCustProdCtrl',
- size: 'lg',
- resolve: {
- custUU: function(){return $scope.item.quotation.cust.uu}
- }
- });
-
- modalInstance.result.then(function(data){
- $scope.item.product = data;
- }, function(){
-
- });
- } else {
- toaster.pop('error', '错误', '请先选择客户');
- }
- }
- };
-
- // 保存
- $scope.save = function(){
- $scope.loading = true;
- if(!$scope.item.quotation.code) //新增,设单号
- $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
- $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
- $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
- $scope.item.productId = $scope.item.product.id;
- $scope.item.quotation.status = 100;//在录入
- if($scope.item.quotation.date instanceof Date) {
- $scope.item.quotation.date = $scope.item.quotation.date.getTime();
- }
- if($scope.item.quotation.endDate instanceof Date) {
- $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
- }
- Quotation.save({}, $scope.item, function(data){
- $scope.loading = false;
- toaster.pop('success', '成功', '保存成功');
- if($stateParams.id)
- window.location.reload();
- else
- window.location.hash = '#/sale/quotation/' + data.id;
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '保存失败', response.data);
- });
- };
-
- // 更新
- $scope.update = function(){
- $scope.item.$editing = true;
- };
-
- // 取消
- $scope.cancel = function(){
- $scope.item.$editing = false;
- $scope.item = angular.copy(staticItem);
- };
-
- // 提交
- $scope.submit = function(){
- $scope.loading = true;
- $scope.item.quotation.status = 101;//在录入
- Quotation.save({}, $scope.item, function(data){
- $scope.loading = false;
- toaster.pop('success', '成功', '提交成功');
- window.location.hash = '#/sale/quotation/' + data.id;
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '保存失败', response.data);
- });
- };
- }]);
-
- // 查找客户
- app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance){
- $scope.customerParams = new ngTableParams({
- page : 1,
- count : 10
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- Customer.get(BaseService.parseParams(params.url()), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- }
- $scope.totalCount = page.totalElements;
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.cancel = function() {
- $modalInstance.dismiss();
- };
-
- $scope.check = function(cust){
- $modalInstance.close(cust);
- };
- }]);
-
- // 查找客户物料
- app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU){
- $scope.customerParams = new ngTableParams({
- page : 1,
- count : 10
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- pageParams.custUU = custUU;
- Product.get.call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- // 取消
- $scope.cancel = function() {
- $modalInstance.dismiss();
- };
-
- // 选择
- $scope.check = function(cust){
- $modalInstance.close(cust);
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.customerParams.reload();
- };
- }]);
-
- // 发货提醒
- 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){
- $scope.active = 'todo';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.currency = Symbol.currency;
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- getDateCondition(zone, $scope.condition);
- $scope.tableParams.reload();
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return $scope.condition.dateZone ? PurcNotice : PurcNoticeHis;
- };
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- 'delivery': 'asc',
- 'orderItemOrderCode': 'asc',
- 'orderItemNumber': 'asc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
- pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
- $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- //生成随机单号
- $scope.autoCode = function(notice){
- notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
- };
-
- //可送货日期
- $scope.sendDate = function(notice) {
- var stock = notice.orderItem.product.ltinstock || 0;
- var de = new Date(notice.delivery);
- if(stock == -1) {
- de.setMonth(de.getMonth() -1);
- de.setDate(25);
- } else if(stock >= 0) {
- de.setDate(de.getDate() - stock -1);
- }
- return de;
- };
-
- $scope.onReplyClick = function(notice) {
- if(!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
- toaster.pop('warning', '警告', '数量填写错误!');
- } else if(!notice.send.code) {
- toaster.pop('warning', '警告', '请填写发货单号!');
- } else {
- var send = {code: notice.send.code, remark: notice.send.remark, sendItems: [{qty: notice.send.qty}]};
- $scope.loading = true;
- PurcNotice.save({id: notice.id}, send, function(){
- $scope.loading = false;
- toaster.pop('success', '提示', '发货成功');
- $scope.tableParams.reload();
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '失败', response.data);
- });
- }
- };
-
- $scope.checkboxes = {
- checked : false
- };
- // 点击勾选全部的复选框
- $scope.checkAll = function(){
- angular.forEach($scope.tableParams.data, function(item) {
- if(!item.waiting)
- item.$selected = $scope.checkboxes.checked;
- });
- };
-
- // 点击其中一个明细的复选框
- $scope.checkOne = function(order){
- var result = true;
- angular.forEach($scope.tableParams.data, function(item) {
- if(item.$selected != true){
- result = false;
- return;
- }
- });
- $scope.checkboxes.checked = result;
- };
-
- $scope.sendByBatch = function(){
- var modalInstance = $modal.open({
- animation: true,
- templateUrl: 'sendByBatch.html',
- controller: 'SaleNoticeSendByBatchCtrl',
- size: 'lg',
- resolve: {
- selectedNotices: function(){return $scope.tableParams.data;}
- }
- });
-
- modalInstance.result.then(function(){
- $scope.tableParams.reload();
- }, function(){
-
- });
- };
-
- $scope.getSends = function(notice){
- if( ! notice.sends && notice.endQty > 0){
- notice.getSendsing = true;
- notice.getSendsError = false;
- PurcNotice.getSends({id: notice.id}, function(data){
- notice.getSendsing = false;
- notice.getSendsError = false;
- notice.sends = data;
- }, function(response){
- notice.getSendsing = false;
- notice.getSendsError = true;
- });
- }
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- // 选择查找日期
- $scope.onDateCondition = function(){
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- //货车功能
- var truck = $rootScope.truck;
- if(!truck) {
- SaleTruck.query({}, function(data){
- $rootScope.truck = data;
- });
- }
- $scope.isInTruck = function(noticeId) {
- return truck.indexOf(noticeId) > -1;
- };
- $scope.addtoTruck = function(notice) {
- SaleTruck.save({noticeId: notice.id}, {}, function(data){
- $rootScope.truck = data;
- });
- };
- $scope.delFromTruck = function(notice) {
- SaleTruck.remove({noticeId: notice.id}, {}, function(data){
- $rootScope.truck = data;
- });
- };
- $scope.$watch(function(){
- return $rootScope.truck;
- }, function(data) {
- truck = $rootScope.truck;
- }, true);
- $scope.$watch(function(){
- return $rootScope.dataChanged;
- }, function(data) {
- data && ($scope.tableParams.reload());
- }, true);
- }]);
- app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', function($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster){
- $scope.notices = angular.copy(selectedNotices);
- $scope.currency = Symbol.currency;//将币别转化为对应的符号
- $scope.saleSend = {
- code: '',
- payments: '',
- currency: '',
- custUU: null,
- custUserUU: null,
- remark: '批量发货',
- sendItems: []
-
- };
-
- /**
- * 删除一个已选中的送货提醒
- */
- $scope.removeOne = function(index) {
- $scope.notices.splice(index, 1);
- };
-
- //确认送货
- $scope.sendByBatch = function () {
- $scope.saleSend.sendItems = [];
- if($scope.saleSend.code == '') {//送货单号为空
- toaster.pop('error', '错误', '请输入送货单号');
- return;
- }
- var a = 0;
- var valid = true;
- angular.forEach($scope.notices, function(item){
- if(item.$selected) {
- if(a == 0) {//第一次
- $scope.saleSend.currency = item.orderItem.order.currency;
- $scope.saleSend.custUU = item.enUU;
- $scope.saleSend.payments = item.orderItem.order.payments;
- a = 1;
- } else {//其他
- if($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
- if($scope.saleSend.custUU != item.enUU) valid = false;
- if($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
- }
- $scope.saleSend.sendItems[$scope.saleSend.sendItems.length] = {
- noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price
- };
- }
- });
- if(!valid) {
- toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
- } else {
- PurcNotice.sendByBatch({}, $scope.saleSend, function(data){
- toaster.pop('success', '提示', '批量发货成功。');
- $modalInstance.close('success');
- }, function(response){
- toaster.pop('error', '错误', response.data);
- });
- }
- };
- $scope.cancel = function () {
- $modalInstance.dismiss();
- };
- }]);
-
- /**
- * 发货单
- */
- app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol){
- $scope.active = 'all';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.currency = Symbol.currency;
-
- $scope.changeAgreed = function(agreed) {
- $scope.condition.agreed = agreed;
- $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
- $scope.condition.$agreedOpen = false;
- };
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- getDateCondition(zone, $scope.condition);
- $scope.tableParams.reload();
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return SaleSend;
- };
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- date: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
- pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
- $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- // 选择查找日期
- $scope.onDateCondition = function(){
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- }]);
-
- /**
- * 客户打样申请
- */
- app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService', 'Symbol', function($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService, Symbol){
- $scope.active = 'todo';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.currency = Symbol.currency;//将币别转化为对应的符号
- $scope.changeAgreed = function(agreed) {
- $scope.condition.agreed = agreed;
- $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
- $scope.condition.$agreedOpen = false;
- };
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return PurcSample;
- };
-
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- proofingDate: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- $scope.openSend = function(index, sample) {
- var modalInstance = $modal.open({
- animation: true,
- templateUrl: 'sendModal.html',
- controller: 'SampleSendCtrl',
- resolve: {
- sampleItem: function(){return sample;}
- }
- });
-
- modalInstance.result.then(function(){
- toaster.pop('info', '提示', '送样成功');
- $scope.tableParams.reload();
- }, function(){
-
- });
- };
-
- $scope.getSend = function(proofing){
- if( !proofing.send) {
- proofing.getSendInfo = '加载中...';
- PurcSample.getSend({id: proofing.id}, function(data){
- if(data) {
- proofing.getSendInfo = null;
- proofing.send = data;
- } else {
- proofing.getSendInfo = '无送样信息';
- proofing.send = '无送样信息';
- }
- }, function(response){
- proofing.getSendInfo = '加载失败!';
- });
- }
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
- }]);
-
- app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster){
- $scope.sampleItem = sampleItem;
- $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
-
- //确认送样
- $scope.ok = function (form) {
- $scope.loading = true;
- var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
- $upload.upload({
- url: 'sale/sample/' + $scope.sampleItem.id + '/send',
- method: 'POST',
- file: file,
- data: {
- json: $scope.sampleItem.sampleSend
- }
- }).success(function(data){
- $scope.loading = false;
- $modalInstance.close('success');
- }).error(function(data){
- $scope.loading = false;
- toaster.pop('danger', '错误', data);
- });
- };
- $scope.cancel = function () {
- $modalInstance.dismiss(sampleItem);
- };
- }]);
-
- /**
- * 客户认定单
- */
- app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol){
- $scope.active = 'all';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.currency = Symbol.currency;//将币别转化为对应的符号
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- getDateCondition(zone, $scope.condition);
- $scope.tableParams.reload();
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return PurcApproval;
- };
-
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- inDate: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
- pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
- $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- $scope.parseDate = function(dateStr) {
- if(dateStr)
- return Date.parse(dateStr, 'yyyy-MM-dd');
- return new Date();
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- // 选择查找日期
- $scope.onDateCondition = function(){
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
- }]);
-
- /**
- * 客户采购预测
- */
- app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol){
- $scope.active = 'all';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.currency = Symbol.currency;//将币别转化为对应的符号
- $scope.changeAgreed = function(agreed) {
- $scope.condition.agreed = agreed;
- $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
- $scope.condition.$agreedOpen = false;
- };
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return PurcForecast;
- };
-
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- orderDate: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- }]);
-
- /**
- * 客户采购验收
- */
- app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
- $scope.active = 'all';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.currency = Symbol.currency;//将币别转化为对应的符号
- $scope.changeAgreed = function(agreed) {
- $scope.condition.agreed = agreed;
- $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
- $scope.condition.$agreedOpen = false;
- };
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return PurcAccept;
- };
-
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- date: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- }]);
-
- /**
- * 客户采购验退
- */
- app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol){
- $scope.active = 'all';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.currency = Symbol.currency;//将币别转化为对应的符号
- $scope.changeAgreed = function(agreed) {
- $scope.condition.agreed = agreed;
- $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
- $scope.condition.$agreedOpen = false;
- };
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return PurcReturn;
- };
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- date: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- }]);
-
- /**
- * 客户不良品入库
- */
- app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol){
- $scope.active = 'all';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.currency = Symbol.currency;//将币别转化为对应的符号
- $scope.changeAgreed = function(agreed) {
- $scope.condition.agreed = agreed;
- $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
- $scope.condition.$agreedOpen = false;
- };
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return PurcBadIn;
- };
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- date: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- }]);
-
- /**
- * 客户不良品出库
- */
- app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol){
- $scope.active = 'all';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.currency = Symbol.currency;//将币别转化为对应的符号
- $scope.changeAgreed = function(agreed) {
- $scope.condition.agreed = agreed;
- $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
- $scope.condition.$agreedOpen = false;
- };
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return PurcBadOut;
- };
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- date: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- }]);
-
- /**
- * 客户MRB
- */
- app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol){
- $scope.active = 'all';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.currency = Symbol.currency;//将币别转化为对应的符号
- $scope.changeAgreed = function(agreed) {
- $scope.condition.agreed = agreed;
- $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
- $scope.condition.$agreedOpen = false;
- };
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return PurcMRB;
- };
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- date: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- }]);
-
- /**
- * 客户应付发票
- */
- app.controller('SaleApBillCtrl', ['$scope', '$filter', 'PurcApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcApBill, ngTableParams, toaster, BaseService, Symbol){
- $scope.active = 'all';
- $scope.agreedText = '全部';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.currency = Symbol.currency;//将币别转化为对应的符号
- $scope.changeAgreed = function(agreed) {
- $scope.condition.agreed = agreed;
- $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
- $scope.condition.$agreedOpen = false;
- };
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- getDateCondition(zone, $scope.condition);
- $scope.tableParams.reload();
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return PurcApBill;
- };
-
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- date: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
- pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
- $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- // 选择查找日期
- $scope.onDateCondition = function(){
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- }]);
-
- app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', function($scope, AccountEnterprise, toaster, $state, $modal){
- $scope.loading = true;
- AccountEnterprise.get({}, function(data){
- $scope.loading = false;
- $scope.enterprise = data;
- });
- AccountEnterprise.growth({}, function(data){
- if(data != null && data.length > 0) {
- var growth = [], years = [];
- angular.forEach(data, function(d){
- var date = new Date(d.date), year = date.getFullYear();
- d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
- if(years.indexOf(year) == -1) {
- years.push(year);
- growth.push({year: year});
- }
- growth.push(d);
- });
- $scope.growth = growth;
- }
- });
-
- // 更新企业信息
- $scope.updateDetailInfo = function(){
- $scope.loading = true;
- AccountEnterprise.save($scope.enterprise, function(){
- $scope.loading = false;
- $scope.connectionEditing = false;
- toaster.pop('success', '提示', '修改企业信息成功');
- $state.reload();
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '修改信息失败', response.data);
- });
- };
-
- // 申请Saas
- $scope.applySaas = function(){
- if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
- var modalInstance = $modal.open({
- animation: true,
- templateUrl: 'static/tpl/index/account/applySaas.html',
- controller: 'ApplySaasCtrl',
- resolve: {
- enterprise: function(){return angular.copy($scope.enterprise);}
- }
- });
-
- modalInstance.result.then(function(){
- $state.reload();
- }, function(){
- });
- } else {
- toaster.pop('info', '请完善信息', '申请SAAS服务请先完善企业详细信息');
- }
- };
- }]);
-
- // 申请Saas Controller
- app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
- $scope.enterprise = enterprise;
- $scope.checking = false;
-
- $scope.$watch('enterprise.enSaasUrl', function(){
- if($scope.enterprise.enSaasUrl) {
- $http.get('signup/saasUrlEnable', {
- params: {
- enSaasUrl: $scope.enterprise.enSaasUrl
- }
- }).success(function(data){
- if(data && data == 'true') {
- $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
- } else {
- $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
- $scope.enSaasUrlErrorInfo = 'SAAS域名已被使用';
- }
- }).error(function(){
- $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
- $scope.enSaasUrlErrorInfo = '验证出错';
- });
- } else {
- $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
- }
- });
-
- var setSaasUrl = function(url) {
- var index = url.indexOf('www.');
- if(index != -1) {//包含www.
- var substr = url.substring(index+4, url.length);
- $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
- } else {
- $scope.enterprise.enSaasUrl = getHost(url);
- }
- };
-
- // 解析获取网址的一级域名
- var getHost = function(host){
- var newhost;
- var domain;
- var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
- for(var k in ArrDomain){
- var re = eval('/\\' + ArrDomain[k] + '$/g');
- newhost = host.replace(re, '');
- if(newhost != host){
- domain = ArrDomain[k];
- break;
- }
- }
- var hostar = newhost.split('.');
- var s = hostar[hostar.length-1];
- return s;
- };
-
- // 设置Saas域名为官网网址一级域名
- if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
-
- $scope.apply = function(){
- $scope.loading = true;
- AccountEnterprise.applySaas({
- enUU: $scope.enterprise.uu,
- enSaasUrl: $scope.enterprise.enSaasUrl,
- enAdminPassword: $scope.enterprise.enAdminPassword
- }, {}, function(){
- $scope.loading = false;
- toaster.pop('success', '申请成功', '已提交系统开通SAAS服务,开通后将会发送邮件至管理员邮箱');
- $modalInstance.close();
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '申请失败', response.data);
- });
- };
- $scope.cancel = function () {
- $modalInstance.dismiss();
- };
- }]);
-
- app.controller('UserCtrl', ['$scope', '$filter', 'AuthenticationService', 'AccountUser', 'BaseService', 'ngTableParams', 'toaster', '$modal', '$http', 'ngAlert', function($scope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http, ngAlert){
- $scope.editing = false;
- $scope.loading = true;
- AuthenticationService.getAuthentication().success(function(data) {
- $scope.loading = false;
- $scope.user = data;
- });
- var users = [];
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- userName: 'asc'
- }
- }, {
- total : 0,
- counts: [15, 25, 50, 100],
- getData : function($defer, params) {
- var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
- orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
- $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
- params.total(orderedData.length);
- $defer.resolve($scope.users);
- }
- });
- var loadUsers = function() {
- AccountUser.query({}, function(data){
- users = data;
- $scope.tableParams.reload();
- $scope.loading = false;
- });
- };
- loadUsers();
- $scope.saveUser = function(){
- $scope.loading = true;
- AccountUser.update({}, $scope.user, function(data){
- $scope.loading = false;
- toaster.pop('success', '提示', '修改用户信息成功');
- AuthenticationService.getAuthentication().success(function(data) {
- $scope.user = data;
- });
- loadUsers();
- $scope.editing = false;
- }, function(reponse){
- $scope.loading = false;
- toaster.pop('error', '失败', reponse.data);
- });
- };
-
- $scope.updatePassword = function(){
- var modalInstance = $modal.open({
- animation: true,
- templateUrl: 'updatePassword.html',
- controller: 'PasswordCtrl',
- resolve: {
- user: function(){return $scope.user;}
- }
- });
-
- modalInstance.result.then(function(){
- }, function(){
- });
- };
-
- $scope.newUser = {};
-
- /**
- * 添加用户
- */
- $scope.addUser = function() {
- $scope.adding = true;
- AccountUser.save({}, $scope.newUser, function(){
- toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
- $scope.newUser = {userSex: 'M'};
- loadUsers();
- $scope.adding = false;
- $scope.newUserForm.newUserTel.$setValidity('available', false);
- $scope.newUserForm.newUserEmail.$setValidity('available', false);
- $scope.userTelSuccess = false;
- $scope.userTelError = false;
- $scope.userEmailSuccess = false;
- $scope.userEmailError = false;
- }, function(response){
- toaster.pop('error', '错误', response.data);
- });
- };
-
- /**
- * 验证手机号是否可用
- */
- $scope.telValid = function(tel) {
- if(tel) {
- $http.get('account/user/telEnable', {
- params: {
- tel: tel
- }
- }).success(function(data){
- data = eval(data);
- if(data == true) {
- $scope.newUserForm.newUserTel.$setValidity('available', true);
- $scope.userTelSuccess = true;
- $scope.userTelError = false;
- } else {
- $scope.newUserForm.newUserTel.$setValidity('available', false);
- $scope.userTelError = true;
- $scope.userTelSuccess = false;
- }
- }).error(function(){
- $scope.userTelSuccess = false;
- $scope.userTelError = true;
- });
- } else {
- $scope.userTelSuccess = false;
- $scope.userTelError = false;
- }
- };
-
- /**
- * 验证邮箱是否可用
- */
- $scope.emailValid = function(email) {
- if(email) {
- $http.get('account/user/emailEnable', {
- params: {
- email: email
- }
- }).success(function(data){
- data = eval(data);
- if(data == true) {
- $scope.newUserForm.newUserEmail.$setValidity('available', true);
- $scope.userEmailSuccess = true;
- $scope.userEmailError = false;
- } else {
- $scope.newUserForm.newUserEmail.$setValidity('available', false);
- $scope.userEmailError = true;
- $scope.userEmailSuccess = false;
- }
- }).error(function(){
- $scope.userEmailError = true;
- $scope.userEmailSuccess = false;
- });
- } else {
- $scope.userEmailError = false;
- $scope.userEmailSuccess = false;
- }
- };
-
- /**
- * 删除用户
- */
- $scope.removeUser = function(user) {
- new ngAlert({
- title: '提示',
- content: '确定删除用户(' + user.userName + ')吗?'
- }, function(){
- AccountUser.remove({uu: user.userUU}, function(){
- toaster.pop('success', '提示', '用户删除成功。');
- loadUsers();
- }, function(response){
- toaster.pop('error', '删除失败', response.data);
- });
- });
- };
- // 编辑用户的角色
- $scope.editUserRole = function(user) {
- var modalInstance = $modal.open({
- animation: true,
- templateUrl: 'static/tpl/index/account/user_role.html',
- controller: 'UserRoleCtrl',
- resolve: {
- user: function() {
- return user;
- }
- }
- });
- modalInstance.result.then(function(changed, checked){
- if(changed) {
- if(checked)
- $scope.newUser.roles = checked;
- else
- loadUsers();
- }
- });
- };
- }]);
-
- app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountRole, AccountUser, toaster){
- $scope.checked = [];
- $scope.master = [];
- AccountRole.query({}, function(data){
- if(user && data) {
- var rs = [], checked = [];
- angular.forEach(user.roles, function(r){
- rs.push(r.id);
- });
- angular.forEach(data, function(d){
- if(rs.indexOf(d.id) > -1) {
- d.$checked = true;
- checked.push(d);
- }
- });
- }
- $scope.roles = data;
- $scope.checked = checked;
- $scope.master = angular.copy($scope.checked);
- });
- $scope.select = function(role) {
- role.$checked = !role.$checked;
- if(role.$checked) {
- $scope.checked.push(role);
- } else {
- angular.forEach($scope.checked, function(c, i){
- if(c.id == role.id)
- $scope.checked.splice(i, 1);
- });
- }
- };
- $scope.isChanged = function() {
- return !angular.equals($scope.master, $scope.checked);
- };
- $scope.close = function(save) {
- if(save) {
- if(user.userUU) {
- user.roles = $scope.checked;
- AccountUser.update({}, user, function(){
- toaster.pop('success', '提示', '保存成功');
- $modalInstance.close(true);
- }, function(response){
- toaster.pop('error', '保存失败', response.data);
- });
- } else {
- $modalInstance.close(true, $scope.checked);
- }
- } else {
- $modalInstance.close(false);
- }
- };
- }]);
-
- // 修改密码Controller
- app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
- $scope.user = user;
- $scope.checking = false;
- //输入原密码后验证原密码是否正确
- $scope.checkPassword = function(password) {
- $scope.checking = true;
- $scope.checkSuccess = false;
- $scope.checkFailed = false;
- AccountUser.checkPassword({password: password}, function(data){
- $scope.checkSuccess = true;
- $scope.checking = false;
- $scope.checkFailed = false;
- }, function(response){
- $scope.checkFailed = true;
- $scope.checking = false;
- $scope.checkSuccess = false;
- });
- };
-
- //修改密码
- $scope.ok = function () {
- if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
- AccountUser.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(data){
- toaster.pop('success', '成功', '修改密码成功,请牢记您的新密码。');
- $scope.user.password = null;
- $scope.user.newPassword = null;
- $scope.user.newPassword1 = null;
- $scope.checking = false;
- $scope.checkSuccess = false;
- $scope.checkFailed = false;
- }, function(response){
- toaster.pop('error', '错误', response.data);
- });
- } else {
- toaster.pop('error', '错误', '重复密码不一致');
- }
- };
- $scope.cancel = function () {
- $modalInstance.dismiss();
- };
- }]);
-
- app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function($scope, BaseService, ngTableParams, ErpLog, UsageLog){
- $scope.erpParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- time: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- ErpLog.get(BaseService.parseParams(params.url()), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
- $scope.usageParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- time: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- UsageLog.get(BaseService.parseParams(params.url()), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
- }]);
-
- app.controller('ResourceCtrl', ['$scope', 'AccountResource', function($scope, AccountResource){
- AccountResource.query({}, function(data){
- if(data && data.length > 0) {
- data[0].$open = true;
- }
- $scope.resources = data;
- });
- }]);
-
- app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function($scope, $modal, AccountRole){
- $scope.roles = {};
- var getData = function() {
- AccountRole.query({}, function(data){
- var defaults = [], custom = [];
- angular.forEach(data, function(d){
- if(d.isdefault == 1)
- defaults.push(d);
- else
- custom.push(d);
- });
- $scope.roles = {defaults: defaults, custom: custom};
- });
- };
- getData();
- $scope.editRole = function(role){
- var modalInstance = $modal.open({
- animation: true,
- templateUrl: 'static/tpl/index/account/role_detail.html',
- controller: 'RoleEditCtrl',
- resolve: {
- role: function() {
- return role;
- }
- }
- });
- modalInstance.result.then(function(added){
- added && (getData());
- });
- };
- }]);
-
- app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert){
- $scope.role = role;
- $scope.master = angular.copy($scope.role);
- var isNew = role == null;
- $scope.cancel = function() {
- $modalInstance.close(false);
- };
- AccountResource.query({}, function(data){
- if(data && data.length > 0) {
- if(role && role.resourceItems) {
- var rs = [];// 已分配的资源的id
- angular.forEach(role.resourceItems, function(item){
- rs.push(item.id);
- });
- angular.forEach(data, function(resource){
- var c = 0;
- angular.forEach(resource.items, function(item){
- if(rs.indexOf(item.id) > -1) {
- item.$checked = true;
- c += 1;
- }
- });
- resource.$checked = c == resource.items.length;
- });
- }
- $scope.resourceItems = data[0].items;
- data[0].$active = true;
- }
- $scope.resources = data;
- $timeout(function(){
- angular.forEach($scope.resources, function(resource){
- var c = 0;
- angular.forEach(resource.items, function(item){
- item.$checked && (c+=1);
- });
- angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
- });
- }, 100);
- });
- $scope.onItemClick = function(resource) {
- $scope.resourceItems = resource.items;
- angular.forEach($scope.resources, function(r){
- r.$active = false;
- });
- resource.$active = true;
- };
- var getChecked = function() {
- var items = [];
- angular.forEach($scope.resources, function(resource){
- angular.forEach(resource.items, function(item){
- item.$checked && (items.push(item));
- });
- });
- $scope.role.resourceItems = items;
- };
- $scope.onResourceChange = function(resource) {
- angular.forEach(resource.items, function(item){
- item.$checked = resource.$checked;
- });
- getChecked();
- };
- $scope.onItemChange = function() {
- angular.forEach($scope.resources, function(resource){
- if(resource.$active) {
- var c = 0;
- angular.forEach(resource.items, function(item){
- item.$checked && (c+=1);
- });
- resource.$checked = (c == resource.items.length);
- angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
- }
- });
- getChecked();
- };
- $scope.isChanged = function(formData) {
- if(!$scope.master)
- return true;
- return !angular.equals(formData, $scope.master);
- };
- $scope.save = function() {
- $scope.master = angular.copy($scope.role);
- AccountRole.save($scope.master, function(){
- toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
- $modalInstance.close(true);
- }, function(response){
- toaster.pop('error', '错误', response.data);
- });
- };
- $scope.del = function() {
- new ngAlert({
- title: '提示',
- content: '确定删除角色(' + $scope.role.desc + ')吗?'
- }, function(){
- AccountRole.remove({id: role.id}, function(){
- toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
- $modalInstance.close(true);
- }, function(response){
- toaster.pop('error', '错误', response.data);
- });
- })
- };
- }]);
-
- /**
- * 委外订单
- */
- app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster', 'BaseService',
- function($scope, $filter, MakeOrder, ngTableParams, toaster, BaseService){
- $scope.active = 'all';
- $scope.dateZoneText = '一个月内';
- $scope.condition = {dateZone: 1};
- $scope.changeDateZone = function(zone) {
- $scope.condition.dateZone = zone;
- $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
- $scope.condition.$dateZoneOpen = false;
- getDateCondition(zone, $scope.condition);
- $scope.tableParams.reload();
- };
- $scope.setActive = function(state) {
- if($scope.active != state) {
- $scope.active = state;
- if($scope.tableParams.page() == 1)
- $scope.tableParams.reload();
- else
- $scope.tableParams.page(1);
- }
- };
- var getService = function() {
- return MakeOrder;
- };
- $scope.tableParams = new ngTableParams({
- page : 1,
- count : 5,
- sorting: {
- date: 'desc'
- }
- }, {
- total : 0,
- counts: [5, 10, 25, 50],
- getData : function($defer, params) {
- $scope.loading = true;
- var pageParams = params.url();
- pageParams.keyword = $scope.keyword;
- getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
- $scope.loading = false;
- if(page) {
- params.total(page.totalElements);
- $defer.resolve(page.content);
- $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
- }
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '数据加载失败', response.data);
- });
- }
- });
-
- $scope.getOrderTotal = function(items) {
- var sum = 0;
- angular.forEach(items, function(item){
- sum += item.qty * item.price;
- });
- return sum;
- };
-
- $scope.openDatePicker = function($event, item, openParam) {
- $event.preventDefault();
- $event.stopPropagation();
- item[openParam] = !item[openParam];
- };
-
- $scope.parseDate = function(dateStr) {
- if(dateStr)
- return Date.parse(dateStr, 'yyyy-MM-dd');
- return new Date();
- };
-
- // 打开回复
- $scope.openReply = function(order) {
- if(!order.reply) {
- order.reply = {
- qty: order.qty - (order.replyQty ? order.replyQty : 0),
- delivery: order.delivery
- }
- }
- order.$editing = true;
- };
-
- // 关闭回复
- $scope.closeReply = function(order) {
- order.$editing = false;
- }
-
- // 搜索框回车
- $scope.onSearch = function() {
- $scope.tableParams.page(1);
- $scope.tableParams.reload();
- };
-
- // 点击回复
- $scope.onReplyClick = function(order, inverse) {
- if(order.reply) {
- if(!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
- toaster.pop('warning', '提示', '请填写有效的回复数量!');
- return;
- }
- var reply = angular.copy(order.reply);
- if(reply.delivery) {
- if(typeof reply.delivery == 'object')
- reply.delivery = reply.delivery.getTime();
- } else {
- reply.delivery = order.delivery;
- }
- if(inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
- $scope.loading = true;
- MakeOrder.reply({orderId: order.id}, reply, function(){
- $scope.loading = false;
- toaster.pop('info', '提示', (inverse == -1 ? '撤销成功':'回复成功'));
- $scope.tableParams.reload();
- }, function(response){
- $scope.loading = false;
- toaster.pop('error', '回复失败', response.data);
- });
- }
- };
-
- // 获取回复记录
- $scope.getReply = function(order) {
- if(!order.replies) {
- MakeOrder.getReply({orderId: order.id}, function(replies){
- order.replies = replies;
- });
- }
- };
- }]);
-
- /**
- * 计算时间差
- */
- app.filter('timespan', function(){
- return function(time) {
- if(time == null)
- return '9999年';
- var now = new Date().getTime(), span = time - now,
- d = Math.ceil(span/86400000), h = Math.ceil(span/3600000),
- m = Math.ceil(span/60000);
- if(span < 0)
- return '0天';
- if(d > 0)
- return d + '天';
- if(h > 0)
- return h + '小时';
- if(m > 0)
- return m + '分钟';
- return '0天';
- };
- });
- app.filter('firstchar', function(){
- return function(str) {
- if(str == null)
- return null;
- return str.substring(0, 1);
- };
- });
- /**
- * 搜索框,回车触发
- */
- app.directive('ngSearch', ['$parse', function($parse) {
- return {
- require : '?ngModel',
- restrict : 'A',
- link : function(scope, element, attrs, ngModel) {
- var searchFn = $parse(attrs.ngSearch);
- element.bind('keypress', function(event) {
- if (event.keyCode == '13') {
- event.preventDefault();
- event.stopPropagation();
- searchFn(scope, {$data: ngModel.$modelValue, $event: event});
- }
- });
- }
- };
- }]);
-
-
- /**
- * 状态码 -> 描述
- */
- app.filter('status', function(){
- return function(data) {
- var statusConfig = {
- '101': '已提交',
- '102': '已审核',
- '103': '未通过',
- '200': '未回复',
- '201': '已回复',
- '313': '已激活',
- '316': '已过账',
- '311': '申请中',
- '312': '未激活'
- };
- return statusConfig[data];
- }
- });
-
-
- return app;
- });
|