commonCtrls.js 51 KB

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