commonCtrls.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903
  1. define([ 'app/app' ], function(app) {
  2. 'use strict';
  3. app.config(['$httpProvider', function($httpProvider) {
  4. // 设置http拦截器
  5. $httpProvider.interceptors.push('httpInterceptor');
  6. }]);
  7. // http拦截器,设置请求自定打开和关闭Loading框
  8. app.factory('httpInterceptor', ['Loading', '$q', function(Loading, $q) {
  9. var i = 0;
  10. var startLoading = function() {
  11. if(i++ == 0) Loading.show();
  12. };
  13. var endLoading = function() {
  14. if(--i < 1) Loading.hide();
  15. };
  16. var im_api_url = 'api/chat/message';
  17. return {
  18. request: function(cfg){
  19. if(cfg.url && cfg.url.indexOf(im_api_url) < 0) {
  20. startLoading();
  21. }
  22. return cfg;
  23. },
  24. requestError: function(rejection) {
  25. if(rejection.config.url && rejection.config.url.indexOf(im_api_url) < 0) {
  26. endLoading();
  27. }
  28. return $q.reject(rejection);
  29. },
  30. response: function(res) {
  31. if(res.config.url && res.config.url.indexOf(im_api_url) < 0) {
  32. endLoading();
  33. }
  34. return res;
  35. },
  36. responseError: function(rejection) {
  37. if(rejection.config.url && rejection.config.url.indexOf(im_api_url) < 0) {
  38. endLoading();
  39. }
  40. if(rejection.status == 401) {
  41. window.location.href = rejection.data.loginUrl || 'index';
  42. }
  43. return $q.reject(rejection);
  44. }
  45. }
  46. }]);
  47. // 修改页面标题
  48. app.controller('TitleCtrl', ['$scope', '$rootScope', '$window', function($scope, $rootScope, $window) {
  49. $rootScope.$on('$routeChangeSuccess', function(event, current, previous) {
  50. if(current.$$route) {
  51. $scope.pageTitle = current.$$route.title || '商品管理';
  52. document.title = $scope.pageTitle + '-优软商城';
  53. }
  54. });
  55. }]);
  56. // 身份认证
  57. app.controller('AuthenticationCtrl', ['$scope', '$window', 'AuthenticationService', '$rootScope', 'SessionService', 'collectionService', '$modal', 'toaster','$q', 'Cart',
  58. function($scope, $window, AuthenticationService, $rootScope, SessionService, collectionService, $modal, toaster, $q, Cart) {
  59. $scope.user = {
  60. j_username : "",
  61. j_password : "",
  62. loginType : 'uu'
  63. };
  64. // 登录
  65. $scope.login = function(user) {
  66. AuthenticationService.login(user).success(function(responseText, status) {
  67. if (status == 200) {
  68. }
  69. }).error(function(response) {
  70. toaster.pop('error', response);
  71. });
  72. };
  73. // 退出
  74. $scope.logout = function() {
  75. /*AuthenticationService.logout().success(function() {
  76. SessionService.removeCookie($rootScope.userInfo.userUU);
  77. });*/
  78. AuthenticationService.logoutWithoutProxy();
  79. };
  80. // 企业换企业开关
  81. $scope.toggleSwitch = function () {
  82. $scope.switching = !$scope.switching;
  83. };
  84. // 企业换企业开关
  85. $scope.toggleSwitchFalse = function () {
  86. $scope.switching = false;
  87. };
  88. // 切换企业
  89. $scope.switchto = function(enUU) {
  90. AuthenticationService.reSignin(enUU).success(function(){
  91. //$window.location.reload();
  92. /*if (!enUU || enUU == '0'){
  93. var now = window.location.href.toString();
  94. if (now.indexOf('vendor') > -1){
  95. location.href = './register-saler';
  96. return;
  97. }
  98. }*/
  99. location.href = './';
  100. });
  101. };
  102. // 是否已经登录
  103. $scope.isAuthed = AuthenticationService.isAuthed();
  104. $scope.userInfo = {};
  105. // 获取已登录的用户信息
  106. var getAuthentication = function() {
  107. return AuthenticationService.getAuthentication().success(function(data) {
  108. if(data && data.enterprises) {
  109. //data.enterprise = data.enterprises[data.enterprises.length - 1];
  110. if(data.enterprises.length > 0) {
  111. var enSelect = [];
  112. angular.forEach(data.enterprises, function(e){
  113. if(e.current)
  114. data.enterprise = e;
  115. else
  116. enSelect.push(e);
  117. });
  118. data.enSelect = enSelect;
  119. }
  120. }
  121. $scope.userInfo = data;
  122. $scope.sortEnterprises = $scope.userInfo.enterprises || [];
  123. if ($scope.sortEnterprises.length) {
  124. $scope.sortEnterprises.sort(function (a, b) {
  125. return b.lastLoginTime - a.lastLoginTime;
  126. })
  127. }
  128. // 增加收藏功能的代码
  129. $rootScope.userInfo = data;
  130. $rootScope.brandCount = 0;
  131. $rootScope.componentCount = 0;
  132. // 以用户的身份进入系统
  133. if(SessionService.get('authenticated')) {
  134. collectionService.getStoreByUU({}, function(data) {
  135. var store = [];
  136. var brandCount = 0;
  137. var componentCount = 0;
  138. for(var i = 0; i < data.length; i++) {
  139. if(data[i].kind == 1) {
  140. brandCount++;
  141. }else if (data[i].kind == 2){
  142. componentCount++;
  143. }
  144. store.push(data[i]);
  145. }
  146. $rootScope.brandCount = brandCount;
  147. $rootScope.componentCount = componentCount;
  148. SessionService.setCookie($rootScope.userInfo.enterprise ? $rootScope.userInfo.userUU +"-"+ $rootScope.userInfo.enterprise.uu : $rootScope.userInfo.userUU, angular.toJson(store));
  149. // 默认在登录界面游客收藏的数据已传输成功,删除游客的数据
  150. SessionService.removeCookie('visitor');
  151. }, function(response) {
  152. });
  153. }else { // 以游客身份登录系统
  154. // 获取本地的数据
  155. var arrs = angular.fromJson(SessionService.getCookie('visitor'));
  156. angular.forEach(arrs, function(store) {
  157. if(store.kind == 2) {
  158. $rootScope.componentCount++;
  159. }else {
  160. $rootScope.brandCount++;
  161. }
  162. });
  163. }
  164. $scope.isAuthed = data != null && data.userUU;
  165. });
  166. };
  167. //根据用户的信息
  168. $q.all([getAuthentication()]).then(function () {
  169. if(AuthenticationService.isAuthed()) {
  170. Cart.getCount({}, function(data){
  171. $rootScope.countCart = data.count;
  172. }, function(res){
  173. toaster.pop('error', '系统错误', '获取购物车失败');
  174. });
  175. }
  176. }, function () {
  177. });
  178. // 打开登录模态框
  179. $scope.signinModal = function() {
  180. // var modalInstance = $modal.open({
  181. // templateUrl : 'static/view/common/modal/signin.html',// 指向上面创建的视图
  182. // controller : 'SigninModalCtrl'// 初始化模态范围
  183. // });
  184. // modalInstance.result.then(function(orderid){
  185. // $window.location.reload();
  186. // }, function(reason){
  187. //
  188. // });
  189. // 跳转账户中心
  190. AuthenticationService.redirectSignin();
  191. };
  192. // 注册
  193. $scope.registerModal = function() {
  194. // 跳转账户中心
  195. AuthenticationService.redirectRegister();
  196. };
  197. //安全中心:
  198. }]);
  199. // 登录模态框
  200. app.controller('SigninModalCtrl', ['$scope', '$modalInstance', 'AuthenticationService', 'toaster', function($scope, $modalInstance, AuthenticationService, toaster) {
  201. $scope.user = {
  202. j_username : "",
  203. j_password : "",
  204. loginType : 'uu'
  205. };
  206. // 关闭
  207. $scope.cancel = function(){
  208. $modalInstance.dismiss('');
  209. };
  210. // 登录
  211. $scope.login = function(user) {
  212. AuthenticationService.login(user).success(function(responseText, status) {
  213. if (status == 200) {
  214. $modalInstance.close();
  215. } else if(status == 207 && responseText instanceof Array) {// multi
  216. $scope.$enSelect = true;// 输入框此时readOnly,不可输入
  217. $scope.enterprises = responseText;
  218. angular.forEach($scope.enterprises, function(e){
  219. if(e.isLast)
  220. $scope.user.t_enuu = e.uu;
  221. });
  222. }
  223. }).error(function(response) {
  224. toaster.pop('error', response);
  225. });
  226. };
  227. // 取消选择企业,可以重新输入账号
  228. $scope.cancelSelect = function() {
  229. $scope.$enSelect = false;
  230. $scope.enterprises = null;
  231. $scope.user.t_enuu = null;
  232. };
  233. }]);
  234. // 搜索框Ctrl
  235. app.controller('SearchCtrl', ['$scope', '$http', '$rootScope', 'SessionService', function($scope, $http, $rootScope, SessionService) {
  236. $scope.searchType = 'original';// 搜索类型
  237. $scope.searchType = {
  238. original: false,
  239. inaction: false,
  240. proffing: false,
  241. brand: false,
  242. isCmp: function() {
  243. var me = this;
  244. return me.original || me.inaction || me.proffing;
  245. }
  246. };
  247. if(SessionService.get('brand')) {
  248. $scope.searchType.brand = true;
  249. }
  250. var componentSearchType = SessionService.get('component');
  251. if(componentSearchType) {
  252. $scope.searchType = angular.fromJson(componentSearchType);
  253. $scope.searchType.isCmp = function() {
  254. var me = this;
  255. return me.original || me.inaction || me.proffing;
  256. }
  257. }
  258. // 点击搜索库存、样品、呆滞
  259. $scope.cmpTypeClick = function() {
  260. if($scope.searchType.isCmp()) {
  261. $scope.searchType.brand = false;
  262. }
  263. };
  264. // 点击搜索品牌
  265. $scope.brandTypeClick = function() {
  266. if($scope.searchType.brand) {
  267. $scope.searchType.original = false;
  268. $scope.searchType.inaction = false;
  269. $scope.searchType.proffing = false;
  270. }
  271. };
  272. // 选搜索类型
  273. $scope.setSearchType = function(t) {
  274. $scope.searchType = t;
  275. };
  276. // 搜索
  277. $scope.search = function() {
  278. if($scope.keyword) {
  279. if($scope.searchType.brand) {
  280. SessionService.set('brand', true);
  281. SessionService.unset('component');
  282. window.location.href = 'search?w=' + encodeURI($scope.keyword) + '&type=brand';
  283. }else if($scope.searchType.isCmp()){
  284. SessionService.set('component', angular.toJson($scope.searchType));
  285. SessionService.unset('brand');
  286. window.location.href = 'search?w=' + encodeURI($scope.keyword) + '&type=component';
  287. }else {
  288. SessionService.unset('component');
  289. SessionService.unset('brand');
  290. window.location.href = 'search?w=' + encodeURI($scope.keyword) + '&type=all';
  291. }
  292. }
  293. };
  294. // 搜索框获得焦点,显示联想框
  295. $scope.onFocus = function() {
  296. $scope.associate = true;
  297. $scope.selectIndex = -1;
  298. if(!$scope.keyword) $scope.keyword = '';
  299. };
  300. // 搜索框失去焦点,关闭联想框
  301. $scope.onBlur = function() {
  302. $scope.associate = false;
  303. };
  304. // 搜索框通过按键选取想要的联想词
  305. $scope.onKeyup = function() {
  306. if($scope.associates && $scope.associates.length) {
  307. if(event.keyCode == 40) { //监听到按下键
  308. $scope.selectIndex ++;
  309. if($scope.selectIndex >= $scope.associates.length) $scope.selectIndex = 0;
  310. $scope.keyword = $scope.associates[$scope.selectIndex];
  311. } else if(event.keyCode == 38) { //监听到按上键
  312. $scope.selectIndex --;
  313. if($scope.selectIndex < 0) $scope.selectIndex = $scope.associates.length - 1;
  314. $scope.keyword = $scope.keyword = $scope.associates[$scope.selectIndex];
  315. } else if(event.keyCode == 13) { //确定键
  316. $scope.search();
  317. }
  318. }
  319. };
  320. // 输入框内容变化,获取新的联想词
  321. $scope.onChange = function() {
  322. if ($scope.keyword) {
  323. var params = {
  324. keyword: $scope.keyword
  325. };
  326. if($rootScope.userInfo) {
  327. params.userUU = $rootScope.userInfo.userUU;
  328. }
  329. $http.get('search/similarKeywords', {
  330. params : params
  331. }).success(function(data){
  332. $scope.associates = data;// 联想词数组
  333. }).error(function(response) {
  334. });
  335. } else {
  336. $scope.associates = [];// 联想词数组
  337. }
  338. };
  339. // 点击联想词
  340. $scope.onAssociateClick = function(component) {
  341. $scope.keyword = component;
  342. $scope.search();
  343. };
  344. // 鼠标进入联想词框,不能关闭联想词框
  345. $scope.onAssociateEnter = function() {
  346. $scope.associateEnter = true;
  347. };
  348. // 鼠标离开联想词框,可以关闭联想词框
  349. $scope.onAssociateLeave = function() {
  350. $scope.associateEnter = false;
  351. };
  352. // 热词
  353. $scope.hotwords = [{name : 'SCT2080KEC', url :'product#/component/1100400300009990/'},
  354. {name : '电池组', url : 'product#/kinds/346'},
  355. {name : 'Vishay',url : 'product#/brand/30327265e42a871be050007f01003d96/'},
  356. {name : 'Panasonic Battery', url : 'product#/brand/30327265e4e7871be050007f01003d96/'}];
  357. }]);
  358. // 商品类目菜单导航
  359. app.controller('CategoryMenuCtrl', ['$scope', 'KindAPI', '$rootScope', function($scope, KindAPI, $rootScope) {
  360. // 展开、收起类目菜单
  361. $scope.showMenu = function(b) {
  362. $scope.isMenuShow = b;
  363. };
  364. // 获取类目数据
  365. KindAPI.getAllChildren({parentId: 0}, function(data) {
  366. $scope.categories = data;
  367. }, function(response) {
  368. });
  369. }]);
  370. // 首页计数器
  371. app.controller('CommonCountCtrl', [ '$scope', 'CommonCountAPI', function ($scope, CommonCountAPI) {
  372. $scope.opreatedCounts = [];
  373. CommonCountAPI.getActived({}, function (data) {
  374. $scope.counts = data;
  375. angular.forEach($scope.counts, function (count) {
  376. count.countStr = count.count.toString();
  377. while (count.countStr.length < 9) {
  378. count.countStr = '0' + count.countStr;
  379. }
  380. count.nums = [];
  381. for(var i = 0; i < count.countStr.length; i++) {
  382. if (i%3 == 0) {
  383. var num = [];
  384. }
  385. var str = count.countStr.substring(i, i+1);
  386. num.push({value : str});
  387. if (i%3 == 0) {
  388. count.nums.push(num);
  389. }
  390. }
  391. });
  392. for(var i = 0; i < $scope.counts.length; i++) {
  393. if (i % 2 == 0) {
  394. var countList = [];
  395. }
  396. countList.push($scope.counts[i]);
  397. if (i % 2 == 0) {
  398. $scope.opreatedCounts.push(countList);
  399. }
  400. }
  401. }, function (response) {
  402. })
  403. }]);
  404. //器件的上架货物选择模态框的controller
  405. app.controller('GoodChooseCtrl', ['$scope', '$rootScope', 'toaster', 'NgTableParams', '$modalInstance', 'uuid', 'isBuy', 'Goods', 'Cart' , 'Order', '$filter', '$modal' ,'$location', 'Currency', 'SessionService', 'ngTableParams', function($scope, $rootScope, toaster, NgTableParams, $modalInstance, uuid, isBuy, Goods, Cart, Order, $filter, $modal, $location, Currency, SessionService, ngTableParams) {
  406. var enIdFilter = $filter('EncryptionFilter');
  407. $scope.uuid = uuid;
  408. $scope.isBuy = isBuy;
  409. $scope.choosedGoods = [];
  410. $scope.sort = {field: 'minPrice', desc: 'asc'};
  411. // 是否已加入购物车判断
  412. $scope.flag = {};
  413. $scope.orderType= 'prices[0].rMBPrice';
  414. // 设置每个批次的最低价格,用于排序
  415. var setMinPrice = function(data) {
  416. for(var i = 0; i < data.length; i ++) {
  417. var g = data[i];
  418. if(g.prices && g.prices.length) {
  419. g.minPrice = g.prices[g.prices.length - 1].price;
  420. }
  421. g.minPackQty = g.minPackQty || 1;
  422. g.minBuyQty = g.minBuyQty || 1;
  423. }
  424. };
  425. // 获取商品是否加入购物车状态信息
  426. var getCarts = function() {
  427. $scope.flag = {};
  428. if($rootScope.userInfo) {
  429. Cart.getCarts({}, function(data) {
  430. angular.forEach(data,function(cart){
  431. $scope.flag[cart.batchCode] = true;
  432. });
  433. });
  434. }
  435. };
  436. // 展开或隐藏分段价格
  437. $scope.showPrices = function(goods, currency) {
  438. if(currency === 'RMB') {
  439. goods.$pricesShowRmb = !goods.$pricesShowRmb;
  440. }else if(currency === 'USD') {
  441. goods.$pricesShowUsd = !goods.$pricesShowUsd;
  442. }
  443. };
  444. // 获取初始数据
  445. var getData = function() {
  446. $scope.productTableParams = new ngTableParams({
  447. page : 1,
  448. count : 10
  449. }, {
  450. total : 0,
  451. getData : function($defer, params) {
  452. $scope.paginationParams = params;
  453. var pageParams = params.url();
  454. pageParams.filter = {};
  455. getCarts();
  456. pageParams.filter.kindid = $scope.kindId;
  457. if($scope.filters.brandid) {// 品牌筛选
  458. pageParams.filter.brandid = $scope.filters.brandid;
  459. }
  460. // 属性值筛选
  461. if($scope.filters.properties && Object.keys($scope.filters.properties).length) {
  462. pageParams.filter.properties = angular.toJson($scope.filters.properties);
  463. }
  464. KindAPI.getCompGoodsByKindid(BaseService.parseParams(pageParams), function(data) {
  465. init(data.content);
  466. $defer.resolve(data.content);
  467. params.total(data.totalElements);
  468. // 初始化一下是否有送样
  469. $scope.hasSample = [];
  470. angular.forEach(data.content, function(compGoods) {
  471. compGoods.$pricesShowRmb = false;
  472. compGoods.$pricesShowUsd = false;
  473. if(compGoods.sampleQty > 0) {
  474. $scope.hasSample.push(false);
  475. }
  476. });
  477. }, function(response) {
  478. toaster.pop('error', '获取信息失败');
  479. });
  480. }
  481. });
  482. }
  483. getData();
  484. // 检测是否给定产品只有一种类型,同时标记同种类型的批次,便于在HTML中年使之具备相同的背景色。约定:content的数据是按型号已经分组好的。
  485. var init = function(content) {
  486. $scope.onlyOneType = false;
  487. if(content.length > 0) {
  488. $scope.onlyOneType = true;
  489. var obj0 = content[0];
  490. obj0.isOdd = true;
  491. var previousObj = obj0;
  492. var currentObj;
  493. for(var i = 0; i < content.length; i++) {
  494. currentObj = content[i];
  495. if(currentObj.code !== obj0.code) {
  496. $scope.onlyOneType = false;
  497. }
  498. if(currentObj.code !== previousObj.code) {
  499. //console.log('curr.code'+content[i].code);
  500. currentObj.isOdd = !previousObj.isOdd;
  501. //console.log('prev.code'+content[i].code);
  502. }else {
  503. currentObj.isOdd = previousObj.isOdd;
  504. }
  505. previousObj = currentObj;
  506. }
  507. }
  508. if($scope.onlyOneType) {
  509. $scope.orderType = 'reserve';
  510. $scope.dir = '-';
  511. }
  512. }
  513. // 改变排序顺序
  514. $scope.changeOrder = function(type){
  515. $scope.orderType = type;
  516. if(!$scope.dir || $scope.dir === '') {
  517. $scope.dir = '-';
  518. }else {
  519. $scope.dir = '';
  520. }
  521. }
  522. // 加入购物车或直接购买
  523. $scope.addToCart = function(goods, isBuy, value){
  524. if(!$rootScope.userInfo || !$rootScope.userInfo.userUU) {
  525. AuthenticationService.redirectSignin();
  526. return;
  527. }
  528. var a = {};
  529. a.uuid = goods.uuid;
  530. //TODO 先设置为点击加入购物车加入最小起订量,方便修改页面
  531. a.number = goods.minBuyQty;
  532. a.batchCode = goods.batchCode;
  533. a.taxes = goods.taxes;
  534. ///a.storeuuid = goods.s
  535. var goodsList = [];
  536. goodsList.push(a);
  537. SessionService.set("buyNow", false);
  538. if(isBuy){// 1、如果是立即购买,跳转订单确认页面
  539. if(a.number > 0) {
  540. var newWindow = window.open('product#/cart');
  541. Order.saveByGroup({}, goodsList, function(data){
  542. // 控制订单确认页,直接购买不显示进度条
  543. SessionService.set("buyNow", true);
  544. newWindow.location.href = 'products#/orderEnsure/'+ enIdFilter(data.data.orderid);
  545. }, function(res){
  546. newWindow.close();
  547. toaster.pop('error', '警告', res.data);
  548. });
  549. }else {
  550. toaster.pop('warning', '提示', '该商品库存为0,请等待上货或咨询客服');
  551. }
  552. } else {// 2、如果是加入购物车,组装cart对象,提交
  553. if (a.number > 0) {
  554. Cart.save({uuid: a.uuid}, a, function(data){
  555. toaster.pop('success', '保存成功', '添加购物车成功');
  556. Cart.getCount({}, function(data){
  557. $rootScope.countCart = data.count;
  558. }, function(res){
  559. });
  560. // 每次修改购物车信息之后,都获取当前状态
  561. getCarts();
  562. }, function(res){
  563. toaster.pop('error', '警告', res.data);
  564. getCarts();
  565. });
  566. } else {
  567. toaster.pop('warning', '提示', '该商品库存为0,请等待上货或咨询客服');
  568. }
  569. }
  570. };
  571. // 删除购物车对应商品
  572. $scope.deleteFromCart = function(batchCode) {
  573. var arr = [];
  574. arr.push(batchCode);
  575. var batchCodes = angular.toJson(arr);
  576. Cart.deleteByBatchCode(batchCodes,function(data){
  577. toaster.pop('info', '取消成功', '撤销商品成功');
  578. Cart.getCount({}, function(data){
  579. $rootScope.countCart = data.count;
  580. }, function(res){
  581. });
  582. // 每次修改购物车信息之后,都获取当前状态
  583. getCarts();
  584. }, function(res){
  585. toaster.pop('error', '取消失败', '商品已从购物车删除,请重新选择');
  586. getCarts();
  587. });
  588. };
  589. Currency.getAllName({}, {}, function(data) {
  590. $scope.currencyNames = data;
  591. }, function(res) {
  592. toaster.pop('error', '币别信息加载失败,请刷新页面')
  593. })
  594. // 选择币别
  595. $scope.setCurrency = function(c){
  596. $scope.goodsTableParams.filter({'currencyName': c});
  597. }
  598. // 设置已添加购物车数
  599. var setAddedCart = function(carts) {
  600. if(carts && carts.length > 0) {
  601. for(var i = 0; i < carts.length; i ++) {
  602. var cart = carts[i];
  603. for(var j = 0; j < $scope.goodes.length; j ++) {
  604. var goods = $scope.goodes[j];
  605. if(goods.batchCode == cart.batchCode) {
  606. goods.addedQty = (goods.addedQty || 0) + cart.number;
  607. goods.qty = goods.addedQty;
  608. $scope.checkQty(goods);
  609. }
  610. }
  611. }
  612. }
  613. };
  614. var loadData = function(){
  615. // 请求商品批次信息
  616. Goods.findSimpleAvailableByUuid({uuid: uuid}, {}, function(data){
  617. setMinPrice(data);// 设置每个批次的最低价格
  618. $scope.goodes = data;
  619. $scope.goodsTableParams = new NgTableParams({}, { dataset: data});
  620. $scope.goodsTableParams.sorting($scope.sort.field, $scope.sort.desc);
  621. getCarts();
  622. Cart.getByUuid({uuid: uuid}, function(data) {
  623. setAddedCart(data);
  624. }, function(response) {
  625. toaster.pop('error', '获取购物车信息失败', response.data);
  626. });
  627. }, function(res){
  628. toaster.pop('error', '系统异常', '产品现货批次数据加载失败');
  629. });
  630. };
  631. // 设置排序方式
  632. $scope.setSort = function(field, desc) {
  633. if(field == 'minPrice' && $scope.sort.field != 'minPrice') {// 切换到价格排序时先升序排序
  634. desc = 'asc';
  635. } else if( ! desc) {// 不指定升降序时,进行升降序切换
  636. if($scope.sort.desc == 'asc') {
  637. desc = 'desc';
  638. } else {
  639. desc = 'asc';
  640. }
  641. }
  642. $scope.sort = {field: field, desc: desc};
  643. $scope.goodsTableParams.sorting($scope.sort.field, $scope.sort.desc);
  644. };
  645. // 根据批次已输入购买数量获取对应的分段价格
  646. $scope.currentPrice = function(goods) {
  647. var r;
  648. if(goods.qty && goods.prices) {
  649. angular.forEach(goods.prices, function(v, k) {
  650. if(v.start <= goods.qty && v.end >= goods.qty) {
  651. r = v.taxPrice;
  652. v.$checked = true;
  653. } else {
  654. v.$checked = false;
  655. }
  656. if(k == (goods.prices.length - 1) && goods.qty > v.end) {
  657. r = v.taxPrice;
  658. }
  659. });
  660. }
  661. return r;
  662. };
  663. // 验证批次购买数量是否有效
  664. $scope.qtyInvalid = function(goods) {
  665. return goods.qty && (goods.qty % goods.minPackQty);
  666. };
  667. // 检验购买数量,合理则加入已加入购物清单
  668. $scope.checkQty = function(goods) {
  669. if(! $scope.qtyInvalid(goods) && goods.qty) {
  670. var p = $scope.currentPrice(goods);
  671. var taxes = goods.qty*(p*goods.tax/(100+goods.tax)); // 税率是相对于未含税的价格,而此处的价格已含税
  672. var unContained = true;
  673. angular.forEach($scope.choosedGoods, function(v, k) {
  674. if(v.batchCode == goods.batchCode) {
  675. unContained = false;
  676. v.taxPrice = p;
  677. v.qty = goods.qty;
  678. v.taxes = taxes;
  679. }
  680. });
  681. if(unContained) {
  682. $scope.choosedGoods.push(angular.extend({taxPrice: p, taxes: taxes}, goods));
  683. }
  684. goods.$choosed = true;// 此批次已选购
  685. } else {
  686. angular.forEach($scope.choosedGoods, function(v, k) {
  687. if(v.batchCode == goods.batchCode) {
  688. $scope.choosedGoods.splice(k, 1);
  689. }
  690. });
  691. goods.$choosed = false;// 此批次未选购
  692. }
  693. };
  694. // 移除已选择的批次
  695. $scope.removeChoosed = function(index) {
  696. var cg = $scope.choosedGoods[index];
  697. if(cg) {
  698. $scope.choosedGoods.splice(index, 1);
  699. angular.forEach($scope.goodes, function(v, k) {
  700. if(cg.batchCode == v.batchCode) {
  701. v.qty = null;
  702. v.$choosed = false;
  703. }
  704. });
  705. }
  706. };
  707. // 获取已选购的总数量
  708. $scope.getTotalQty = function() {
  709. var qty = 0;
  710. angular.forEach($scope.choosedGoods, function(v, k) {
  711. qty += Number(v.qty);
  712. });
  713. return qty;
  714. };
  715. // 获取已选购的总额
  716. $scope.getTotal = function() {
  717. var total = {};
  718. angular.forEach($scope.choosedGoods, function(v, k) {
  719. total[v.currencyName] = total[v.currencyName] || 0;
  720. total[v.currencyName] += v.taxPrice * v.qty;
  721. });
  722. return total;
  723. };
  724. // 提交前转换一下已选购的商品
  725. var convertGoods = function() {
  726. var r = [];
  727. angular.forEach($scope.choosedGoods, function(v, k) {
  728. r.push({
  729. uuid: v.uuid,
  730. batchCode: v.batchCode,
  731. number: v.qty,
  732. taxes: v.taxes
  733. });
  734. });
  735. return r;
  736. };
  737. loadData();
  738. /*// 自动分配选购数量
  739. $scope.allocate = function(num) {
  740. if(num) {
  741. if (!$scope.currency) {
  742. $scope.currency = 'RMB';
  743. $scope.goodsTableParams.filter({'currencyName': 'RMB'});
  744. }
  745. $scope.choosedGoods = [];
  746. var datas = $filter('orderBy')($scope.goodes, $scope.sort.field, $scope.sort.desc == 'desc');
  747. for(var i = 0; i < datas.length; i ++) {
  748. var d = datas[i];
  749. // 只对指定的币别 && 要分配数量大于最小订购量 的商品批次分配
  750. if(d.currencyName == $scope.currency && num >= d.minBuyQty) {
  751. if(d.reserve >= num) {
  752. if(num % d.minPackQty > 0) {
  753. d.qty = num - (num % d.minPackQty) + d.minPackQty;
  754. } else {
  755. d.qty = num;
  756. }
  757. } else {
  758. d.qty = d.reserve - (d.reserve % d.minPackQty);
  759. }
  760. num -= d.qty;
  761. } else {
  762. d.qty = null;
  763. }
  764. $scope.checkQty(d);
  765. }
  766. }
  767. };*/
  768. /*// 确认
  769. $scope.ok = function(){
  770. angular.forEach($scope.goodes, function(v, k) {
  771. $scope.checkQty(v);
  772. });
  773. var g = convertGoods();
  774. if(!g || g.length == 0) return;// 没选择批次就不提交
  775. if($scope.isBuy){// 1、如果是立即购买,直接生成订单,返回订单
  776. Order.saveByGroup({}, g, function(data){
  777. var orderids = [];
  778. angular.forEach(data, function(order) {
  779. orderids.push(order.orderid );
  780. })
  781. toaster.pop('success', '成功', '订单生成成功,订单号为【' + orderids.join(',') + '】。请您确认订单并付款');
  782. $modalInstance.close(enIdFilter(orderids.join('-')));
  783. }, function(res){
  784. toaster.pop('error', '警告', res.data);
  785. });
  786. } else {// 2、如果是加入购物车,组装cart对象,提交
  787. Cart.save({uuid: $scope.uuid}, g, function(data){
  788. toaster.pop('success', '保存成功', '添加购物车成功');
  789. Cart.getCount({}, function(data){
  790. $rootScope.countCart = data.count;
  791. }, function(res){
  792. });
  793. $modalInstance.close(); //关闭并返回当前选项
  794. window.open('user#/cart');
  795. }, function(res){
  796. toaster.pop('error', '警告', res.data);
  797. });
  798. }
  799. };*/
  800. $scope.applysample = function(goods) {
  801. //首先判断是否已送样
  802. Goods.isSample({id: goods.id}, {}, function(data){
  803. if(data.id) {
  804. window.open("product#/proofings/" + enIdFilter(goods.batchCode));
  805. }else {
  806. toaster.pop('info', '该批次已申请样品', '请勿重复申请');
  807. loadData();
  808. }
  809. }, function(res){
  810. loadData();
  811. toaster.pop('error', '系统异常', '产品现货批次数据加载失败');
  812. });
  813. }
  814. // 退出
  815. $scope.cancel = function(){
  816. $modalInstance.dismiss('');
  817. };
  818. }]);
  819. // 对比框侧边栏的Controller
  820. app.controller('CompareBarCtrl', ['$scope', '$rootScope', 'Compare', 'toaster', function($scope, $rootScope, Compare, toaster) {
  821. if(!$rootScope.compares) {
  822. Compare.get({}, function(data){
  823. $rootScope.compares = data;
  824. }, function(response) {
  825. toaster.pop('error', '获取对比列表失败', response.data);
  826. });
  827. }
  828. // 移除对比
  829. $scope.remove = function(uuid) {
  830. Compare.remove({uuid: uuid}, {}, function(data) {
  831. $rootScope.compares = data;
  832. }, function(response) {
  833. toaster.pop('error', '移除对比失败', response.data);
  834. });
  835. };
  836. // 清空对比
  837. $scope.removeAll = function() {
  838. Compare.removeAll({}, {}, function(data) {
  839. $rootScope.compares = data;
  840. }, function(response) {
  841. toaster.pop('error', '清空对比失败', response.data);
  842. });
  843. };
  844. // 开始对比
  845. $scope.compare = function() {
  846. $rootScope.$content_open = false;
  847. var uuids = [];
  848. if($rootScope.compares.length<2) {
  849. toaster.pop('info', "少于两个产品,不能对比");
  850. return ;
  851. }
  852. for(var i=0; i<$rootScope.compares.length; i ++) {
  853. uuids.push($rootScope.compares[i].uuid);
  854. }
  855. var uuidStr = uuids.join(',');
  856. window.location.href = 'product#/compare/' + uuidStr;
  857. };
  858. }]);
  859. // 留言板侧边栏的Controller
  860. app.controller('MessageBarCtrl', ['$scope', '$modal', 'BaseService', function($scope, $modal, BaseService) {
  861. var rootPath = BaseService.getRootPath();
  862. $scope.openMessagePanel = function() {
  863. var modalInstance = $modal.open({
  864. templateUrl : rootPath + '/static/view/common/modal/messageBoard.html', //指向上面创建的视图
  865. controller : 'MessageBoardModalCtrl',// 初始化模态范围
  866. size : 'md',
  867. backdrop : 'static'
  868. });
  869. modalInstance.opened.then(function(){
  870. });
  871. modalInstance.result.then(function(brand){
  872. }, function(reason){
  873. });
  874. }
  875. }]);
  876. // 我的店铺侧边栏的Controller
  877. app.controller('goCartCtrl', ['$scope', 'StoreInfo', 'AuthenticationService', function($scope, StoreInfo, AuthenticationService) {
  878. $scope.uuid = false;
  879. if(AuthenticationService.isAuthed()) {
  880. StoreInfo.existStore({}, {}, function (result) {
  881. $scope.uuid = result.uuid;
  882. })
  883. }
  884. $scope.openMystore = function(){
  885. var uuid = $scope.uuid;
  886. window.open('store/' + uuid, '_self');
  887. }
  888. }])
  889. // Web Chat侧边栏的Controller
  890. app.controller('WebChatCtrl', ['$scope', '$interval', 'AuthenticationService', 'ChatBusinessLayer', 'toaster','$rootScope', function($scope, $interval, AuthenticationService, ChatBusinessLayer, toaster ,$rootScope) {
  891. $scope.userInfo = null;
  892. $scope.countData = 0;
  893. $scope.goWebChat = goWebChat;
  894. activate();
  895. function activate() {
  896. AuthenticationService.getAuthentication().then(function (data) {
  897. if (data && data.data) {
  898. $scope.userInfo = data.data;
  899. $scope.param = ChatBusinessLayer.getParamsFromUserInfo(data.data);
  900. // accessRealTimeData($scope.param);
  901. }
  902. }, function () {
  903. });
  904. }
  905. function accessRealTimeData(param) {
  906. //先调一次
  907. ChatBusinessLayer.accessUnreadMessageCount(param).then(function (count) {
  908. $scope.countData = count;
  909. }, function () {
  910. $scope.countData = 0;
  911. });
  912. $interval(function () {
  913. ChatBusinessLayer.accessUnreadMessageCount(param).then(function (count) {
  914. $scope.countData = count;
  915. }, function () {
  916. $scope.countData = 0;
  917. });
  918. }, 10000);
  919. }
  920. function goWebChat() {
  921. if (!$scope.userInfo) {
  922. toaster.pop('error', '请先登录优软商城!');
  923. return ;
  924. }
  925. if (!$scope.userInfo.userTel || $scope.userInfo.userTel === '') {
  926. toaster.pop('error', '请先注册优软互联!');
  927. return ;
  928. }
  929. //获得窗口的垂直位置
  930. var iTop = (window.screen.availHeight - 30 - 780) / 2;
  931. //获得窗口的水平位置
  932. var iLeft = (window.screen.availWidth - 10 - 1030) / 2;
  933. var newTab = window.open('', '即时对话框', 'height=750, width=1000, top=' + iTop + ', left=' + iLeft + ', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
  934. newTab.close();
  935. var newTab = window.open('', '即时对话框', 'height=750, width=1000, top=' + iTop + ', left=' + iLeft + ', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
  936. var chatInfoDto = { userPhone: $scope.param.phone, enUU: $scope.param.enUU };
  937. if (!chatInfoDto.enUU){
  938. chatInfoDto = {userPhone: $scope.param.phone};
  939. }
  940. ChatBusinessLayer.visitWebChat(chatInfoDto, 'LIST').then(function (gid) {
  941. console.log(gid);
  942. //newTab.location.href = 'http://192.168.253.31:20220/chat/visit?gid=' + gid;
  943. newTab.location.href = 'https://im.ubtob.com/chat/visit?gid=' + gid;
  944. }, function (error) {
  945. console.log(error);
  946. newTab.close();
  947. toaster.pop('warning', '您还没有开通客服系统,请开通客服系统!');
  948. });
  949. }
  950. }]);
  951. // 跳至顶部
  952. app.controller('ScrollToTopCtrl', ['$scope', 'SmoothScroll', 'toaster', 'CommonGoodsBrowsingHistory', 'AuthenticationService', function($scope, SmoothScroll, toaster, CommonGoodsBrowsingHistory, AuthenticationService){
  953. $scope.scrollToTop = function(){
  954. SmoothScroll.scrollTo(null, 'site-nav');
  955. };
  956. AuthenticationService.getAuthentication().success(function(data){
  957. $scope.userInfo = data;
  958. if(data){
  959. loadData();
  960. }
  961. });
  962. // 获取浏览历史
  963. var loadData = function(){
  964. CommonGoodsBrowsingHistory.getAllHistory({ }, { }, function (response) {
  965. $scope.inithistory = response;
  966. $scope.history = [];
  967. angular.forEach($scope.inithistory, function(data){
  968. if(data.isDelete == 1){
  969. $scope.history.push(data);
  970. }
  971. })
  972. })
  973. }
  974. // 删除足迹历史
  975. $scope.deleteHistory = function (id) {
  976. CommonGoodsBrowsingHistory.setDelete({id : id}, { }, function(response){
  977. if(response.data = "success"){
  978. toaster.pop("success", "删除足迹成功");
  979. loadData();
  980. }
  981. })
  982. }
  983. }]);
  984. // 留言板模态框
  985. app.controller('MessageBoardModalCtrl', ['$scope', '$modalInstance', 'AuthenticationService', 'MessageBoardAPI', 'MessageBoard', 'toaster', 'ngTableParams', 'BaseService', function($scope, $modalInstance, AuthenticationService, MessageBoardAPI, MessageBoard, toaster, ngTableParams, BaseService) {
  986. $scope.messageBoard = {};
  987. $scope.showHistory = false;
  988. $scope.params = {
  989. page : 1,
  990. count : 3,
  991. sorting : {
  992. createDate: 'DESC'
  993. }
  994. };
  995. AuthenticationService.getAuthentication().success(function(data){
  996. $scope.user = data;
  997. });
  998. document.onkeydown = function (ev) {
  999. var onEvent = ev || event;
  1000. if (onEvent.keyCode == 27)
  1001. $('#image-box').hide();
  1002. };
  1003. /**
  1004. * 上传图片
  1005. */
  1006. $scope.onUpload = function ($data, index) {
  1007. if (!$scope.imgs) {
  1008. $scope.imgs = [{}, {}, {}, {}, {}];
  1009. }
  1010. if (!$data || !$data.path) {
  1011. toaster.pop('error', '图片上传失败');
  1012. return ;
  1013. }
  1014. $scope.imgs[index] = {'img' : $data.path};
  1015. };
  1016. // 删除图片
  1017. $scope.deleteImg = function (index) {
  1018. $scope.imgs[index] = {};
  1019. };
  1020. // 查看范例
  1021. $scope.showImg = function(imgUrl) {
  1022. var src = imgUrl, box = $('#image-box'), modal = $('.modal-content');
  1023. box.show();
  1024. box.find('img').attr('src', src);
  1025. box.find('a').click(function(){
  1026. box.hide();
  1027. });
  1028. box.dblclick(function(){
  1029. box.hide();
  1030. });
  1031. };
  1032. //初始化页数信息
  1033. $scope.initPages = function (totalElementPages) {
  1034. var pageNum = [];
  1035. if(totalElementPages == 1) {
  1036. return ;
  1037. }else if(totalElementPages < 10) {
  1038. for(var i = 0; i < totalElementPages + 2; i++) {
  1039. pageNum.push(i);
  1040. }
  1041. }else {
  1042. pageNum = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  1043. }
  1044. angular.forEach(pageNum, function (number) {
  1045. var page = {active : true, type : 'page', number : number};
  1046. if(number == 0) {
  1047. page.type = 'prev';
  1048. }else if(number == 1) {
  1049. page.type = 'first';
  1050. }else if(number == pageNum.length - 2) {
  1051. page.type = 'last';
  1052. page.number = totalElementPages;
  1053. }else if(number == pageNum.length - 1){
  1054. page.type = 'next';
  1055. }
  1056. $scope.pages.push(page);
  1057. });
  1058. };
  1059. //当前页在后端计算方式
  1060. $scope.endSegment = function (currentPage, totalElementPages) {
  1061. if (totalElementPages > 8) {
  1062. angular.forEach($scope.pages, function (page) {
  1063. switch (page.number) {
  1064. case 2:
  1065. page.active = false;
  1066. page.type = 'more';
  1067. break;
  1068. case 10:
  1069. if(currentPage == totalElementPages) {
  1070. page.active = false;
  1071. }
  1072. break;
  1073. case 0:
  1074. case 1:
  1075. break;
  1076. default:
  1077. if(page.number != totalElementPages) {
  1078. page.number = totalElementPages - 9 + page.number;
  1079. }
  1080. page.current = (currentPage == page.number);
  1081. break;
  1082. }
  1083. });
  1084. }
  1085. };
  1086. //当前页在中间计算方式
  1087. $scope.middleSegment = function (currentPage) {
  1088. angular.forEach($scope.pages, function (page) {
  1089. switch (page.number) {
  1090. case 2:
  1091. case 8:
  1092. page.type ='more';
  1093. page.active = false;
  1094. break;
  1095. case 3:
  1096. page.number = currentPage - 2;
  1097. break;
  1098. case 4:
  1099. page.number = currentPage - 1;
  1100. break;
  1101. case 5:
  1102. page.number = currentPage;
  1103. page.current = true;
  1104. break;
  1105. case 6:
  1106. page.number = currentPage + 1;
  1107. break;
  1108. case 7:
  1109. page.number = currentPage + 2;
  1110. break;
  1111. }
  1112. });
  1113. };
  1114. //当前页在前段的计算方式
  1115. $scope.frontSegment = function (currentPage, totalElementPages) {
  1116. if (totalElementPages > 8) {
  1117. angular.forEach($scope.pages, function (page) {
  1118. switch (page.number) {
  1119. case 8:
  1120. page.type = 'more';
  1121. page.active = false;
  1122. break;
  1123. case 0:
  1124. if(currentPage == 1) {
  1125. page.active = false;
  1126. }
  1127. default : {
  1128. page.current = (currentPage == page.number);
  1129. }
  1130. }
  1131. });
  1132. }
  1133. };
  1134. //输入框监听Enter事件
  1135. $scope.listenEnter = function () {
  1136. if(event.keyCode == 13) {
  1137. var rnum = /^\d*$/;
  1138. if (rnum.test($scope.params.currentPage)) {
  1139. $scope.setPage("page", $scope.params.currentPage);
  1140. } else {
  1141. toaster.pop('info', '请输入合法数字');
  1142. }
  1143. }
  1144. };
  1145. $scope.setPage = function(type, number) {
  1146. if(type != 'prev' && type != 'page' && type != 'next' && type != 'last' && type != 'first') {
  1147. return ;
  1148. };
  1149. var page = -1;
  1150. switch (type) {
  1151. case "page":
  1152. if(number < 1) {
  1153. page = 1;
  1154. }else if(number > $scope.messageBoardAllData.totalPages) {
  1155. page = $scope.messageBoardAllData.totalPages;
  1156. }else {
  1157. page = number;
  1158. };
  1159. break;
  1160. case "prev":
  1161. if($scope.params.page <= 1) {
  1162. page = 1;
  1163. }else {
  1164. page =$scope.params.page - 1;
  1165. };
  1166. break;
  1167. case "next":
  1168. if($scope.params.page >= $scope.messageBoardAllData.totalPages) {
  1169. page = $scope.messageBoardAllData.totalPages
  1170. }else {
  1171. page =$scope.params.page + 1;
  1172. }
  1173. break;
  1174. case "first":
  1175. page = 1;
  1176. break;
  1177. case "last":
  1178. page = $scope.messageBoardAllData.totalPages;
  1179. break;
  1180. }
  1181. if(page == $scope.params.page || page < 1 || page > $scope.messageBoardAllData.totalPages) {
  1182. $scope.params.currentPage = $scope.params.page;
  1183. return ;
  1184. }
  1185. var rnum = /^\d*$/;
  1186. if (rnum.test(page)) {
  1187. $scope.params.page = page;
  1188. loadData();
  1189. } else {
  1190. toaster.pop('info', '请输入合法数字');
  1191. }
  1192. };
  1193. //计算页数的方式。
  1194. $scope.acculatePages = function(currentPage, totalElementPages) {
  1195. $scope.pages = [];
  1196. if(totalElementPages < 1) {
  1197. return ;
  1198. }
  1199. //初始化页面数据
  1200. $scope.initPages(totalElementPages);
  1201. if(currentPage < 6) {//当期页小于6
  1202. $scope.frontSegment(currentPage, totalElementPages);
  1203. }else if(currentPage > totalElementPages - 5) { //当期页在后面
  1204. $scope.endSegment(currentPage, totalElementPages);
  1205. }else { //当期页在中间
  1206. $scope.middleSegment(currentPage);
  1207. }
  1208. };
  1209. var loadData = function() {
  1210. MessageBoard.getPageInfoByUser($scope.params, function(page) {
  1211. if (page) {
  1212. $scope.messageBoardAllData = page;
  1213. $scope.messageBoardCurrent = page.content;
  1214. $scope.params.currentPage = page.number;
  1215. $scope.acculatePages(page.number, page.totalPages);
  1216. }
  1217. }, function(){
  1218. });
  1219. };
  1220. // 提交留言
  1221. $scope.confirm = function(){
  1222. $scope.messageBoard.imgs = [];
  1223. angular.forEach($scope.imgs, function(img){
  1224. if (img.img) {
  1225. $scope.messageBoard.imgs.push(img);
  1226. }
  1227. });
  1228. if (!$scope.messageBoard.question) {
  1229. toaster.pop('info', '您还没有填写反馈内容');
  1230. return;
  1231. }
  1232. if (!$scope.messageBoard.role) {
  1233. toaster.pop('info', '请选择您的身份信息');
  1234. return;
  1235. }
  1236. if (!$scope.messageBoard.type) {
  1237. toaster.pop('info', '请选择一种反馈类型');
  1238. return;
  1239. }
  1240. if (!$scope.user) {
  1241. if (!$scope.messageBoard.userTel && !$scope.messageBoard.email) {
  1242. toaster.pop('info', '请填写任意一种联系方式');
  1243. return;
  1244. }
  1245. var regTel = /^[\d]{8,11}$/;
  1246. if ($scope.messageBoard.userTel && ($scope.messageBoard.userTel.length > 11 || $scope.messageBoard.userTel.length < 8)) {
  1247. toaster.pop('info', '请填写8~11位手机号码');
  1248. return;
  1249. }
  1250. if ($scope.messageBoard.userTel && $scope.messageBoard.userTel.match(regTel) == null) {
  1251. toaster.pop('info', '请填写正确的联系方式');
  1252. return;
  1253. }
  1254. var regEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  1255. if ($scope.messageBoard.email && $scope.messageBoard.email.length > 125) {
  1256. toaster.pop('info', '邮箱地址不得超过125个字符');
  1257. return;
  1258. }
  1259. if ($scope.messageBoard.email && messageBoardForm.email.$invalid) {
  1260. toaster.pop('info', '请填写正确的联系方式');
  1261. return;
  1262. }
  1263. if (!$scope.messageBoard.userTel && !$scope.messageBoard.email) {
  1264. toaster.pop('info', '请填写任意一种联系方式');
  1265. return;
  1266. }
  1267. }
  1268. $scope.messageBoard.submitUrl = window.location.href;
  1269. $scope.messageBoard.submitTitle = document.title;
  1270. MessageBoardAPI.save({}, $scope.messageBoard, function(data) {
  1271. toaster.pop('info', '提示', '感谢您的宝贵意见');
  1272. $modalInstance.close();
  1273. }, function(res) {
  1274. toaster.pop('error', '提示', '留言失败,请重新提交' + res.data);
  1275. });
  1276. };
  1277. // 关闭
  1278. $scope.cancel = function() {
  1279. $modalInstance.dismiss();
  1280. };
  1281. // 打开记录
  1282. $scope.openHistory = function() {
  1283. $scope.showHistory = true;
  1284. loadData();
  1285. };
  1286. // 关闭记录
  1287. $scope.hideHistory = function() {
  1288. $scope.showHistory = false;
  1289. };
  1290. }]);
  1291. // 留言记录模态框
  1292. app.controller('MessageBoardListModalCtrl', ['$scope', function($scope) {
  1293. // 关闭
  1294. $scope.cancel = function() {
  1295. $modalInstance.dismiss();
  1296. };
  1297. }]);
  1298. // 线下支付模态框
  1299. app.controller('OfflinePayCtrl', ['$scope', '$modalInstance', 'order', 'totalAmount', 'bankInfoService', 'toaster', '$modal', '$filter', 'ImgUrl', 'bankTransferService', function ($scope, $modalInstance, order, totalAmount, bankInfoService, toaster, $modal, $filter, ImgUrl, bankTransferService) {
  1300. var hideBankFilter = $filter("hideBankFilter");
  1301. $scope.order = order;
  1302. $scope.totalAmount = totalAmount;
  1303. $scope.isBuyerAccountPersonal = false; // 默认买家账户是企业账户
  1304. $scope.isMallAccountPersonal = false; // 默认商城账户是企业账户
  1305. // 为买家设置账户类型
  1306. $scope.setAccountTypeForBuyer = function(isPersonal) {
  1307. if(!angular.equals($scope.isBuyerAccountPersonal, isPersonal)) {
  1308. $scope.isBuyerAccountPersonal = isPersonal;
  1309. getBuyAccount();
  1310. }
  1311. };
  1312. // 为商城设置账户类型
  1313. $scope.setAccountTypeForMall = function(isPersonal) {
  1314. if(!angular.equals($scope.isMallAccountPersonal, isPersonal)) {
  1315. $scope.isMallAccountPersonal = isPersonal;
  1316. getSellerAccount();
  1317. }
  1318. };
  1319. // 下拉买家账户
  1320. $scope.dropDownBuyerAccount = function(dropdown) {
  1321. $scope.isBuyerAccountDropDown = dropdown
  1322. }
  1323. // 选择买家账户
  1324. $scope.selectBuyerAccount = function (account) {
  1325. $scope.buyAccount = account;
  1326. $scope.isBuyerAccountDropDown = false;
  1327. }
  1328. // 下拉商城账户
  1329. $scope.dropDownMallAccount = function(dropdown) {
  1330. $scope.isMallAccountDropDown = dropdown
  1331. }
  1332. // 选择商城账户
  1333. $scope.selectMallAccount = function (account) {
  1334. $scope.saleAccount = account;
  1335. $scope.isMallAccountDropDown = false;
  1336. }
  1337. // 获取数据
  1338. //根据单选框的状态,提取不同的数据
  1339. var getBuyAccount = function() {
  1340. if(!$scope.isBuyerAccountPersonal) {
  1341. bankInfoService.getBuyEnterpriseBank('', function(data) {
  1342. $scope.buyAccountInfos = resolveData(data);
  1343. angular.forEach($scope.buyAccountInfos, function(buyAccountInfo) {
  1344. buyAccountInfo.filterAccount = hideBankFilter(buyAccountInfo.number);
  1345. });
  1346. $scope.buyAccount = getOriginalData($scope.buyAccountInfos);
  1347. }, function(error) {
  1348. toaster.pop('error', '错误', '提取企业账户信息失败');
  1349. });
  1350. }else {
  1351. bankInfoService.getBuyPersonalBank('', function(data) {
  1352. $scope.buyAccountInfos = resolveData(data);
  1353. angular.forEach($scope.buyAccountInfos, function(buyAccountInfo) {
  1354. buyAccountInfo.filterAccount = hideBankFilter(buyAccountInfo.number);
  1355. });
  1356. $scope.buyAccount = getOriginalData($scope.buyAccountInfos);
  1357. }, function(error) {
  1358. toaster.pop('error', '错误', '提取个人账户信息失败');
  1359. });
  1360. }
  1361. };
  1362. getBuyAccount();
  1363. //获取管理平台账户信息
  1364. var getSellerAccount = function() {
  1365. if(!$scope.isMallAccountPersonal) {
  1366. bankInfoService.getAdminEnterAccount('', function(data) {
  1367. $scope.saleAccountInfos = resolveData(data);
  1368. angular.forEach($scope.saleAccountInfos, function(saleAccountInfo) {
  1369. saleAccountInfo.filterAccount = hideBankFilter(saleAccountInfo.number);
  1370. });
  1371. $scope.saleAccount = getOriginalData($scope.saleAccountInfos);
  1372. }, function(res) {
  1373. toaster.pop('error', '错误', '获取卖家企业账户信息失败');
  1374. });
  1375. }else {
  1376. bankInfoService.getAdminPersAccount('', function(data) {
  1377. $scope.saleAccountInfos = resolveData(data);
  1378. angular.forEach($scope.saleAccountInfos, function(saleAccountInfo) {
  1379. saleAccountInfo.filterAccount = hideBankFilter(saleAccountInfo.number);
  1380. });
  1381. $scope.saleAccount = getOriginalData($scope.saleAccountInfos);
  1382. }, function(res) {
  1383. toaster.pop('error', '错误', '获取卖家个人账户信息失败');
  1384. });
  1385. }
  1386. }
  1387. getSellerAccount();
  1388. // 买家新增账户
  1389. $scope.newAccount = function(data) {
  1390. var modalInstance = $modal.open({
  1391. templateUrl : 'static/view/common/bankInfoModal.html',
  1392. controller : 'BankInfoCtrl',
  1393. resolve : {
  1394. kind : function() {
  1395. //深拷贝一份
  1396. return angular.copy($scope.isBuyerAccountPersonal);
  1397. },
  1398. account : function() {
  1399. //深拷贝一份
  1400. return angular.copy(data);
  1401. }
  1402. }
  1403. });
  1404. modalInstance.result.then(function(account) {
  1405. if(account.kind) {
  1406. bankInfoService.saveBuyPersonalBank({}, account, function(data) {
  1407. toaster.pop('success', '成功','信息已添加');
  1408. $scope.purKind = account.kind;
  1409. getBuyAccount(); //这个方法不能提取到外面,因为存在异步。
  1410. }, function(res) {
  1411. toaster.pop('error', '错误', res.data);
  1412. });
  1413. }else {
  1414. //企业账户
  1415. bankInfoService.saveBuyEnterpriseBank({}, account, function(data) {
  1416. toaster.pop('success', '保存成功','信息已添加');
  1417. $scope.purKind = account.kind;
  1418. getBuyAccount();
  1419. }, function(res) {
  1420. toaster.pop('error', '错误', res.data);
  1421. });
  1422. }
  1423. }, function() {
  1424. });
  1425. };
  1426. // 买家删除账户
  1427. $scope.deleteAccount = function(buyAccount) {
  1428. var isSure = confirm('确认删除本银行账户?删除后无法恢复,请谨慎操作');
  1429. if(isSure){
  1430. bankInfoService.deleteBank({id: buyAccount.id}, function(data) {
  1431. toaster.pop('success', '删除成功');
  1432. getBuyAccount();
  1433. }, function(response) {
  1434. toaster.pop('error', '删除失败');
  1435. })
  1436. }
  1437. }
  1438. // 选择日期相关逻辑
  1439. $scope.maxDate = new Date();
  1440. $scope.image = {src: null};
  1441. // 图片上传成功之后
  1442. $scope.onUploadSuccess = function(data){
  1443. var path = data.path;
  1444. path = ImgUrl.handelByWidthHeigth(path, 65, 66);
  1445. $scope.$apply(function(){
  1446. $scope.image.src = data.path;
  1447. $scope.image.thumb = path;
  1448. });
  1449. };
  1450. $scope.pay = function(order) {
  1451. if(order.availabletime < new Date().getTime()) {
  1452. toaster.pop("error", '错误', '此订单已过期,已失效');
  1453. }
  1454. };
  1455. $scope.confirm = function() {
  1456. if(angular.isUndefined($scope.order.orderid) || angular.equals($scope.order.orderid,'') || angular.equals($scope.total, 0)) {
  1457. toaster.pop('info', '提示', '没有选择要付款的订单,或付款总额为0');
  1458. return ;
  1459. }
  1460. if(angular.isUndefined($scope.buyAccount)||angular.equals("{}", angular.toJson($scope.buyAccount))) {
  1461. toaster.pop('info', '提示', '请选择买家账户');
  1462. return ;
  1463. }
  1464. if(angular.isUndefined($scope.saleAccount)||angular.equals("{}", angular.toJson($scope.saleAccount))) {
  1465. toaster.pop('info', '提示', '请选择卖家账户');
  1466. return ;
  1467. }
  1468. if(!$scope.transferTime) {
  1469. toaster.pop('info', '提示', '请选择付款日期');
  1470. return ;
  1471. }
  1472. if(!$scope.image.src) {
  1473. toaster.pop('info', '提示', '请选择付款截图');
  1474. return ;
  1475. }
  1476. var buyAccount = angular.copy($scope.buyAccount);
  1477. var saleAccount = angular.copy($scope.saleAccount);
  1478. delete saleAccount.filterAccount;
  1479. delete buyAccount.filterAccount;
  1480. var jsonPament = angular.toJson(buyAccount);
  1481. var jsonReceive = angular.toJson(saleAccount);
  1482. var transfer = {};
  1483. transfer.jsonPament = jsonPament;
  1484. transfer.jsonReceive = jsonReceive;
  1485. transfer.imgUrl = $scope.logoUrl;
  1486. transfer.transferTime = $scope.transferTime.getTime();
  1487. transfer.total = $scope.total;
  1488. bankTransferService.saveTransfer({order: $scope.order.orderid}, transfer, function(data) {
  1489. $modalInstance.close();
  1490. }, function(response) {
  1491. toaster.pop("error", '失败', '信息保存失败:' + response.data);
  1492. });
  1493. }
  1494. // 取消
  1495. $scope.cancel = function () {
  1496. $modalInstance.dismiss();
  1497. }
  1498. // 确认提醒
  1499. $scope.ensureWarning = function (isWarning) {
  1500. if(isWarning) {
  1501. if(!$scope.transferTime) $scope.transferWaring = true;
  1502. if(!$scope.image.src) $scope.imgWarning = true;
  1503. }else {
  1504. $scope.transferWaring = false;
  1505. $scope.imgWarning = false;
  1506. }
  1507. }
  1508. }]);
  1509. // 新建/修改银行账户
  1510. app.controller('BankInfoCtrl', ['$scope', '$modalInstance', 'account', 'kind', function($scope, $modalInstance, account, kind){
  1511. $scope.account = account;
  1512. if($scope.account) {
  1513. $scope.eidt = true;
  1514. } else {
  1515. delete $scope.eidt;
  1516. }
  1517. $scope.kind = kind;
  1518. if($scope.account) {
  1519. $scope.title = "修改账户";
  1520. }else {
  1521. $scope.title = "新增账户";
  1522. $scope.account = {};
  1523. $scope.account.currency = 'RMB'; // 默认银行卡币别是人民币
  1524. }
  1525. $scope.set = function(kind) {
  1526. $scope.kind = kind;
  1527. }
  1528. $scope.confirm = function() {
  1529. $scope.account.kind = $scope.kind;
  1530. $modalInstance.close($scope.account);
  1531. }
  1532. $scope.cancel = function() {
  1533. $modalInstance.dismiss();
  1534. }
  1535. }]);
  1536. /**
  1537. * 店铺首页header控制器
  1538. */
  1539. app.controller('StoreHeaderCtrl', ['$scope', '$rootScope', '$modal', 'toaster', 'StoreFocusService', 'AuthenticationService', function ($scope, $rootScope, $modal, toaster, StoreFocusService, AuthenticationService) {
  1540. /**
  1541. * 店铺首页下拉信息是否展开
  1542. */
  1543. $scope.isOpen = false;
  1544. /**
  1545. * 展示下拉信息
  1546. */
  1547. $scope.openDropDown = function () {
  1548. $scope.isOpen = true;
  1549. };
  1550. /**
  1551. * 收起下拉信息
  1552. */
  1553. $scope.closeDropDown = function () {
  1554. $scope.isOpen = false;
  1555. };
  1556. $scope.isFocus = false; // 是否关注标识
  1557. // 用户已登陆状态,初始加载页面时,判断店铺是否已经关注
  1558. AuthenticationService.getAuthentication().success(function(data){
  1559. $scope.userInfo = data;
  1560. if(data) {
  1561. StoreFocusService.storeIfFocus({storeid : $rootScope.storeInfo.id}, {}, function(response){
  1562. var result = response.data;
  1563. if(result == "true"){
  1564. $scope.isFocus = true;
  1565. }
  1566. });
  1567. }
  1568. });
  1569. // 店铺关注
  1570. $scope.focus = function(id, storeName){
  1571. $scope.storeFocus = {};
  1572. $scope.storeFocus.storeName = storeName;
  1573. $scope.storeFocus.storeid = id;
  1574. StoreFocusService.saveStoreFocus({}, $scope.storeFocus, function(response){
  1575. var result = response.data;
  1576. if(result == "success"){
  1577. $scope.isFocus = true;
  1578. $modal.open({
  1579. templateUrl : $rootScope.rootPath + "/static/view/store/modal/storeFocus_modal.html",
  1580. controller : "storeFocusModalCtrl",
  1581. size : 'sm'
  1582. });
  1583. }else{
  1584. toaster.pop("error", "店铺关注失败");
  1585. }
  1586. })
  1587. }
  1588. }]);
  1589. app.controller('storeFocusModalCtrl', ["$scope", "$modalInstance", function($scope, $modalInstance){
  1590. $scope.cancel = function() {
  1591. $modalInstance.dismiss();
  1592. };
  1593. }]);
  1594. /**
  1595. * 左侧导航栏控制器
  1596. */
  1597. app.controller('leftNavCtrl', ["$scope", "toaster", '$modal', '$rootScope', function($scope, toaster, $modal, $rootScope) {
  1598. //安全设置提醒框
  1599. $scope.openHomeCenterModel = function () {
  1600. var modalInstance = $modal.open({
  1601. animation: true,
  1602. templateUrl: $rootScope.rootPath + '/static/view/usercenter/modal/homeCenter_modal.html',
  1603. controller: 'homeModalCtrl'
  1604. });
  1605. modalInstance.result.then(function () {
  1606. }, function () {
  1607. });
  1608. };
  1609. }]);
  1610. /**
  1611. * 左侧导航栏控制器
  1612. */
  1613. app.controller('leftNavCtrl', ["$scope", "toaster", '$modal', '$rootScope', function($scope, toaster, $modal, $rootScope){
  1614. //安全设置提醒框
  1615. // $scope.openHomeCenterModel = function() {
  1616. // var modalInstance = $modal.open({
  1617. // animation: true,
  1618. // templateUrl: $rootScope.rootPath + '/static/view/usercenter/modal/homeCenter_modal.html',
  1619. // controller:'homeModalCtrl'
  1620. // });
  1621. // modalInstance.result.then(function(){
  1622. // }, function(){
  1623. // });
  1624. // };
  1625. // $scope.promptUpdate = function() {
  1626. // if (!$scope.userInfo.pwdEnable || !$scope.userInfo.userEmail || !$scope.userInfo.haveUserQuestion) {
  1627. // $scope.openHomeCenterModel();
  1628. // }
  1629. // };
  1630. }]);
  1631. app.controller('homeModalCtrl', ['$rootScope', '$scope', '$modalInstance', 'toaster', '$http', 'ShippingAddress','$state', function($rootScope, $scope, $modalInstance, toaster, $http, ShippingAddress,$state) {
  1632. $rootScope.$on('$stateChangeStart',
  1633. function (event, toState, toParams, fromState, fromParams) {
  1634. $modalInstance.dismiss();
  1635. })
  1636. $scope.goLink = function (op) {
  1637. $state.go('vendor_account_management', {op: op});
  1638. $modalInstance.dismiss('cancel');
  1639. }
  1640. $scope.cancel = function () {
  1641. $modalInstance.dismiss('cancel');
  1642. }
  1643. }])
  1644. // 手续费控制器
  1645. app.controller('poundageCtrl', ["$scope", "NumberService", function($scope, NumberService){
  1646. // 手续费介绍提示框
  1647. $scope.showRemindTagIntro = false;
  1648. // 手续费减免提示框
  1649. $scope.showRemindTagActivity = false;
  1650. $scope.getMul = function (val1, val2) {
  1651. return NumberService.mul(Number(val1), Number(val2)) < 0.01 ? 0.01 : NumberService.mul(Number(val1), Number(val2));
  1652. }
  1653. $scope.getAdd = function (val1, val2) {
  1654. return NumberService.add(Number(val1), Number(val2));
  1655. }
  1656. }]);
  1657. /**
  1658. * 左侧导航栏控制器
  1659. */
  1660. app.controller('leftNavCtrl', ["$scope", "toaster", "$modal", "$rootScope", '$q', function($scope, toaster, $modal, $rootScope, $q){
  1661. //安全设置提醒框
  1662. // $scope.openHomeCenterModel = function() {
  1663. // var modalInstance = $modal.open({
  1664. // animation: true,
  1665. // templateUrl: $rootScope.rootPath + '/static/view/usercenter/modal/homeCenter_modal.html',
  1666. // controller:'homeModalCtrl'
  1667. // });
  1668. // modalInstance.result.then(function(){
  1669. // }, function(){
  1670. // });
  1671. // };
  1672. // $scope.promptUpdate = function() {
  1673. // if (!$scope.userInfo.pwdEnable || !$scope.userInfo.haveUserQuestion||!$scope.userInfo.emailValidCode || $scope.userInfo.emailValidCode != 2) {
  1674. // $scope.openHomeCenterModel();
  1675. // }
  1676. /*if (!$scope.userInfo.pwdEnable || !$scope.userInfo.userEmail || !$scope.userInfo.haveUserQuestion) {
  1677. $scope.openHomeCenterModel();
  1678. }*/
  1679. // };
  1680. // $q.all[$rootScope.pcbPromise].then(function (res) {
  1681. // $rootScope.isPcbStore = res == 1;
  1682. // })
  1683. // console.log($scope.pcbPromise);
  1684. }]);
  1685. function checkNullStr (str) {
  1686. var NULL_ARR = ['空', '没', '无', '-', '—', 'null', '#N/A'];
  1687. var flag = true;
  1688. NULL_ARR.map(function (s) { flag = str === s ? false : flag; });
  1689. return flag;
  1690. }
  1691. app.filter('nullStrFilter', function () {
  1692. return function (str) {
  1693. return checkNullStr(str) ? str : '-'
  1694. }
  1695. });
  1696. app.controller('homeModalCtrl', ['$rootScope', '$scope', '$modalInstance', 'toaster', '$http', 'ShippingAddress','$state', function($rootScope, $scope, $modalInstance, toaster, $http, ShippingAddress,$state){
  1697. $rootScope.$on('$stateChangeStart',
  1698. function(event, toState, toParams, fromState, fromParams){
  1699. $modalInstance.dismiss();
  1700. })
  1701. $scope.goLink = function(op) {
  1702. $state.go('vendor_account_management',{op:op});
  1703. $modalInstance.dismiss('cancel');
  1704. }
  1705. $scope.cancel = function () {
  1706. $modalInstance.dismiss('cancel');
  1707. }
  1708. }]);
  1709. var getOriginalData = function(data) {
  1710. var result = {};
  1711. if(data&&data.length) {
  1712. result = data[0];
  1713. }else {
  1714. result = null;
  1715. }
  1716. return result;
  1717. };
  1718. //解析数据,从返回的数据中找到要解析的数据
  1719. var resolveData = function(data) {
  1720. var arr = new Array();
  1721. for(var key in data) {
  1722. var numb= Number(key);
  1723. if(angular.isNumber(numb)&&(!isNaN(numb))) {
  1724. arr.push(data[key]);
  1725. }
  1726. }
  1727. return arr;
  1728. };
  1729. });