staffManagementCtrl.js 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303
  1. /**
  2. * Created by yujia on 2017/3/24.
  3. * 原厂认证
  4. */
  5. define(['app/app'], function (app) {
  6. "use strict";
  7. app.register.controller('staffManagementCtrl', ['$scope', '$rootScope', 'Enterprise', 'User', 'toaster', '$modal', 'BaseService', 'ngTableParams', '$http', 'AuthenticationService', '$stateParams','AccountResource','AccountRole', 'Authority', function ($scope, $rootScope, Enterprise, User, toaster, $modal, BaseService, ngTableParams, $http, AuthenticationService, $stateParams, AccountResource, AccountRole, Authority) {
  8. $rootScope.active = 'sso_management';
  9. document.title = '员工管理-帐户中心';
  10. $scope.tab = 'base';
  11. $scope.addingUser = false;
  12. $scope.setAddingUser = function (status) {
  13. $scope.addingUser = status;
  14. $scope.adding = false;
  15. $scope.newUser = {};
  16. $scope.newUser.userTel = '';
  17. $scope.newUser.userEmail = '';
  18. };
  19. $scope.userInfo = $rootScope.userInfo;
  20. $scope.updateState = false;
  21. $scope.filterRole = 'all';
  22. $scope.searchParams = {
  23. keyword: ''
  24. };
  25. if ($rootScope.userInfo.enterprise) {
  26. $scope.isAdmin = $rootScope.userInfo.enterprise.enAdminuu === $rootScope.userInfo.userUU ? true : false;
  27. } else {
  28. $scope.isAdmin = false
  29. }
  30. // $scope.userInfo.pwdEnable = false;
  31. // $scope.userInfo.haveUserQuestion = false;
  32. // $scope.userInfo.userEmail = null;
  33. //table设置
  34. var applyToEnterpriseTableParams = function () {
  35. $scope.applyToEnterpriseTableParams = new ngTableParams({
  36. page : 1,
  37. count : 10
  38. }, {
  39. total : 0,
  40. getData : function ($defer, params) {
  41. var param = BaseService.parseParams(params.url());
  42. if ($scope.page.totalElements) {
  43. if (param.page < 1 || param.page > $scope.page.totalElements) {
  44. toaster.pop('error', '请输入正确的页数!');
  45. return;
  46. }
  47. }
  48. //param.page = param.page;
  49. param.size = param.count;
  50. param.speaceUU = $scope.userInfo.enterprise.uu;
  51. if (!($scope.searchParams.keyword.trim() == '')) {
  52. param.keyword = $scope.searchParams.keyword.trim();
  53. }
  54. // 状态为申请中
  55. param.status = 311;
  56. $http({
  57. method: 'get',
  58. dataType: 'json',
  59. url: $scope.urlPrex + '/api/userspace/apply/info/mall',
  60. params: {speaceUU: param.speaceUU, page: param.page, size: param.size, status: param.status, keyword: param.keyword}
  61. }).success(function (page) {
  62. params.total(page.content.totalElements);
  63. $scope.page = page.content;
  64. $scope.totalPages = page.content.totalPages;
  65. $scope.content = page.content.content;
  66. $scope.totalElements = page.content.totalElements;
  67. }).error(function (response) {
  68. toaster.pop('error', '获取未处理审批数据失败');
  69. });
  70. // Enterprise.findApplyToMall(param, {}, function (page) {
  71. // $defer.resolve(page.content || []);
  72. // params.total(page.totalElements);
  73. // $scope.page = page;
  74. // $scope.totalPages = page.totalPages;
  75. // $scope.content = page.content;
  76. // }, function (error) {
  77. // console.log(error);
  78. // $defer.resolve([]);
  79. // params.total(0);
  80. // $scope.totalPages = 0;
  81. // toaster.pop('error', '数据获取失败,请重新刷新页面!');
  82. // });
  83. }
  84. });
  85. };
  86. if ($scope.isAdmin) {
  87. User.isDevOrProd(null, function (data) {
  88. // $scope.isProd = data.data;
  89. $scope.urlPrex = data.data == 'success' ? 'https://sso.ubtob.com' : 'http://192.168.253.6:32323';
  90. applyToEnterpriseTableParams();
  91. }, function (response) {
  92. toaster.pop('error', '获取运行环境失败');
  93. });
  94. }
  95. // 申请
  96. $scope.auditApply = function (status, id, UU) {
  97. var param = {
  98. userUU: UU,
  99. id: id,
  100. status: status
  101. }
  102. Enterprise.auditApply(param, {}, function (data) {
  103. console.log(data);
  104. applyToEnterpriseTableParams();
  105. }, function (error) {
  106. console.log(error);
  107. $defer.resolve([]);
  108. params.total(0);
  109. $scope.totalPages = 0;
  110. toaster.pop('error', '数据获取失败,请重新刷新页面!');
  111. });
  112. }
  113. $scope.searchApply = function () {
  114. applyToEnterpriseTableParams();
  115. }
  116. var getEnterprise = function () {
  117. // 获取企业信息
  118. Enterprise.getEnterpriseInfo({enuu : $scope.userInfo.enterprise.uu}, function(data) {
  119. $scope.enterpriseInfo = data;
  120. $scope.enBusinessScope = $scope.enterpriseInfo.enBusinessScope ? angular.copy($scope.enterpriseInfo.enBusinessScope).split(',') : [];
  121. $scope.enterpriseInfoBackup = angular.copy($scope.enterpriseInfo);
  122. $scope.enAdminuu = $scope.enterpriseInfo.enAdminuu;
  123. User.getUserByUU({uu: $scope.enAdminuu}, {}, function(data){
  124. $scope.adminInfo = data;
  125. console.log($scope.adminInfo);
  126. }, function(){
  127. toaster.pop('error', '获取管理员信息失败');
  128. });
  129. },function() {
  130. toaster.pop('error', '获取企业信息失败');
  131. });
  132. }
  133. if (typeof $scope.userInfo != 'undefined' && typeof $scope.userInfo.enterprise != 'undefined') {
  134. getEnterprise();
  135. } else {
  136. AuthenticationService.getAuthentication().success(function (data) {
  137. $scope.userInfo = data;
  138. for (var i=0; i<$scope.userInfo.enterprises.length; i++) {
  139. if ($scope.userInfo.enterprises[i].current) {
  140. $scope.userInfo.enterprise = $scope.userInfo.enterprises[i];
  141. break;
  142. }
  143. }
  144. getEnterprise();
  145. }, function (error) {
  146. toaster.pop('error', '获取用户信息失败');
  147. })
  148. }
  149. $scope.pageParam = {};
  150. $scope.tableParams = new ngTableParams({
  151. page : 1, // show first page
  152. count : 10 // count per page
  153. }, {
  154. total : 0,
  155. getData : function($defer, params) {
  156. var param = BaseService.parseParams(params.url());
  157. param.enuu = $scope.userInfo.enterprise.uu;
  158. if(!$scope.searchMthod) {
  159. Enterprise.getAllUsersByEnuu(param, function (page) {
  160. if (page) {
  161. $scope.pageParam.start = (page.number-1)*page.size+1;
  162. $scope.pageParam.end = $scope.pageParam.start + page.numberOfElements - 1;
  163. $scope.pageParam.all = page.totalElements;
  164. params.total(page.totalElements);
  165. $defer.resolve(page.content);
  166. $scope.users = page.content;
  167. $scope.reloadUserCheck(false);
  168. }
  169. },function (error) {
  170. toaster.pop('error', '获取企业人员信息失败',error.data);
  171. });
  172. }
  173. else {
  174. param.keyword = $scope.keyword;
  175. if (filterRolejs !== 1){
  176. param.roleId = filterRolejs;
  177. }
  178. Enterprise.findUsersByKeyword(param,function (page) {
  179. if (page) {
  180. $scope.pageParam.start = (page.number-1)*page.size+1;
  181. $scope.pageParam.end = $scope.pageParam.start + page.numberOfElements - 1;
  182. $scope.pageParam.all = page.totalElements;
  183. params.total(page.totalElements);
  184. $defer.resolve(page.content);
  185. $scope.users = page.content;
  186. $scope.reloadUserCheck(false);
  187. }
  188. },function (error) {
  189. toaster.pop('error', '获取企业人员信息失败',error.data);
  190. })
  191. }
  192. }
  193. });
  194. var filterRolejs = 1;
  195. $scope.onSearch = function (keyword,filterRole) {
  196. filterRolejs = 1;
  197. if ((keyword != null && keyword != '') || filterRole !== 'all') {
  198. if (filterRole === 'all'){
  199. filterRolejs = 1;
  200. }else {
  201. filterRolejs = filterRole;
  202. }
  203. $scope.searchMthod = true;
  204. $scope.keyword = keyword;
  205. } else {
  206. $scope.searchMthod = false;
  207. }
  208. $scope.tableParams.page(1);
  209. $scope.tableParams.reload();
  210. };
  211. $scope.onKeyUpSearch = function (keyword, filterRole, event) {
  212. if (event && event.keyCode == 13) {
  213. $scope.onSearch(keyword, filterRole);
  214. }
  215. }
  216. $scope.newUser = {};
  217. //弹出添加用户模态框
  218. $scope.addExistUser = function () {
  219. $scope.adding = false;
  220. $scope.setAddingUser(false);
  221. $scope.newUser = {};
  222. var modalInstance = $modal.open({
  223. animation: true,
  224. templateUrl: $rootScope.rootPath + '/static/view/vendor/forstore/addExistUser.html',
  225. controller: 'AddExistUserCtrl'
  226. });
  227. modalInstance.result.then(function () {
  228. $scope.userTelSuccess = false;
  229. $scope.userTelError = false;
  230. $scope.tableParams.page(1);
  231. $scope.tableParams.reload();
  232. }, function () {
  233. });
  234. };
  235. /**
  236. * 添加未注册用户
  237. */
  238. $scope.addUser = function () {
  239. if (!$scope.userEmailSuccess || !$scope.userTelSuccess) {
  240. toaster.pop('error', '请输入正确的信息后提交');
  241. return;
  242. }
  243. $scope.adding = true;
  244. $scope.loading = true;
  245. Enterprise.saveUser({}, $scope.newUser, function () {
  246. $scope.loading = false;
  247. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  248. $scope.setAddingUser(false);
  249. $scope.newUser = {userSex: 'M'};
  250. $scope.tableParams.page(1);
  251. $scope.tableParams.reload();
  252. $scope.adding = false;
  253. // $scope.newUserForm.newUserTel.$setValidity('available', false);
  254. // $scope.newUserForm.newUserEmail.$setValidity('available', false);
  255. $scope.userTelSuccess = false;
  256. $scope.userTelError = false;
  257. $scope.userEmailSuccess = false;
  258. $scope.userEmailError = false;
  259. }, function (response) {
  260. $scope.loading = false;
  261. toaster.pop('error', '错误', response.data);
  262. });
  263. };
  264. $scope.adding = false;
  265. $scope.setAdding = function (status) {
  266. $scope.adding = status;
  267. }
  268. /**
  269. * 删除用户
  270. */
  271. $scope.removeUser = function (user) {
  272. // if (confirm('确定删除用户(' + user.userName + ')吗?')) {
  273. // }
  274. Enterprise.removeUser({uu: user.userUU}, function () {
  275. toaster.pop('success', '提示', '用户删除成功。');
  276. $scope.tableParams.page(1);
  277. $scope.tableParams.reload();
  278. $scope.showDelUserFlag = false;
  279. }, function (response) {
  280. toaster.pop('error', '删除失败', response.data);
  281. });
  282. };
  283. //用户删除确认框
  284. $scope.showDelUserFlag = false;
  285. $scope.setShowDelUserFlag = function (flag, user) {
  286. $scope.showDelUserFlag = flag;
  287. if (flag) {
  288. $scope.delUser = user;
  289. }
  290. }
  291. /***
  292. * 全选
  293. * */
  294. $scope.isCheckAll = false;
  295. $scope.doCheckAll = function () {
  296. $scope.isCheckAll = !$scope.isCheckAll;
  297. if ($scope.isCheckAll) {
  298. $scope.reloadUserCheck(true);
  299. } else {
  300. $scope.reloadUserCheck(false);
  301. }
  302. }
  303. $scope.checkUser = function (user) {
  304. user.checked = !user.checked;
  305. var allcheck = true
  306. angular.forEach($scope.users, function (item) {
  307. if (!item.checked) {
  308. allcheck = false;
  309. }
  310. });
  311. $scope.isCheckAll = allcheck;
  312. }
  313. $scope.reloadUserCheck = function (flag) {
  314. angular.forEach($scope.users, function (item) {
  315. item.checked = flag;
  316. });
  317. }
  318. /**
  319. * 验证手机号是否可用
  320. */
  321. $scope.telValid = function (tel) {
  322. if (tel) {
  323. $http.get('basic/user/telEnable', {
  324. params: {
  325. tel: tel
  326. }
  327. }).success(function (data) {
  328. data = eval(data);
  329. if (data == true) {
  330. // $scope.newUserForm.newUserTel.$setValidity('available', true);
  331. $scope.userTelSuccess = true;
  332. $scope.userTelError = false;
  333. } else {
  334. // $scope.newUserForm.newUserTel.$setValidity('available', false);
  335. $scope.userTelError = true;
  336. $scope.userTelSuccess = false;
  337. if (tel.length == 11)
  338. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  339. }
  340. }).error(function () {
  341. $scope.userTelSuccess = false;
  342. $scope.userTelError = true;
  343. });
  344. } else {
  345. $scope.userTelSuccess = false;
  346. $scope.userTelError = false;
  347. }
  348. };
  349. /**
  350. * 验证邮箱是否可用
  351. */
  352. $scope.emailValid = function (email) {
  353. if (email) {
  354. $http.get('basic/user/emailEnable', {
  355. params: {
  356. email: email
  357. }
  358. }).success(function (data) {
  359. data = eval(data);
  360. if (data == true) {
  361. // $scope.newUserForm.newUserEmail.$setValidity('available',
  362. // true);
  363. $scope.userEmailSuccess = true;
  364. $scope.userEmailError = false;
  365. } else {
  366. // $scope.newUserForm.newUserEmail.$setValidity('available',
  367. // false);
  368. $scope.userEmailError = true;
  369. $scope.userEmailSuccess = false;
  370. toaster.pop('error', '错误', '邮箱 ' + email + ' 已被注册');
  371. }
  372. }).error(function () {
  373. $scope.userEmailError = true;
  374. $scope.userEmailSuccess = false;
  375. });
  376. } else {
  377. $scope.userEmailError = false;
  378. $scope.userEmailSuccess = false;
  379. }
  380. };
  381. /**
  382. * 变更到更新状态
  383. */
  384. $scope.changeToUpdate = function (isUpdate) {
  385. // if ($rootScope.userInfo.userUU != $rootScope.userInfo.enterprise.enAdminuu) {
  386. // toaster.pop('error', '您无该模块的编辑权限,请联系企业管理员进行编辑维护!');
  387. // return;
  388. // }
  389. Authority.getAuthority({resUrl: '/basic/enterprise/*/updateInfo'}, function (data) {
  390. if (data.status == 'fail') {
  391. toaster.pop('error', data.msg || '系统错误');
  392. } else {
  393. $scope.updateState = isUpdate;
  394. if ($scope.updateState == false) {
  395. $scope.enterpriseInfo = angular.copy($scope.enterpriseInfoBackup);
  396. }
  397. }
  398. });
  399. };
  400. /**
  401. * 验证企业信息
  402. */
  403. function validateEnterpriseInfo() {
  404. var props = ['enName', 'enAddress', 'enUrl'];
  405. var flag = true;
  406. angular.forEach(props, function (prop) {
  407. if ($scope.enterpriseInfo.hasOwnProperty(prop)) {
  408. if (!$scope.enterpriseInfo[prop] || $scope.enterpriseInfo[prop]
  409. === '') {
  410. console.log(prop + '不能为空');
  411. // TODO 记录验证信息
  412. flag = false;
  413. }
  414. } else {
  415. console.log(prop + '不能为空');
  416. flag = false;
  417. }
  418. });
  419. return flag;
  420. }
  421. // 获取行业信息
  422. $http.get('static/data/profession.json').success(function (data) {
  423. $scope.list = data;
  424. });
  425. // 选择行业
  426. $scope.profession = new Array();
  427. $scope.showProfession = false;
  428. $scope.selectProfession = function () {
  429. $scope.professionArray = [];
  430. $scope.active = [];
  431. $scope.showProfession = !$scope.showProfession;
  432. $scope.profession[0] = $scope.list;
  433. };
  434. $scope.isInList = false;
  435. $scope.isInInput = false;
  436. $scope.hideList = function () {
  437. if (!$scope.isInList && !$scope.isInInput && $scope.showProfession) {
  438. $scope.showProfession = false;
  439. }
  440. };
  441. $scope.enterInput = function () {
  442. $scope.isInInput = true;
  443. };
  444. $scope.leaveInput = function () {
  445. $scope.isInInput = false;
  446. };
  447. $scope.enterList = function () {
  448. $scope.isInList = true;
  449. };
  450. $scope.leaveList = function () {
  451. $scope.isInList = false;
  452. };
  453. // 行业子菜单点击
  454. $scope.onItemClick = function (key, index, value) {
  455. $scope.active[index] = key;
  456. if (angular.isString(value)){ // 值为字符串说明点击的是最后一级
  457. $scope.enterpriseInfo.enIndustry = value;
  458. $scope.showProfession = false;
  459. return;
  460. }
  461. $scope.professionArray = [];
  462. $scope.profession.splice(index+1);
  463. if (angular.isArray(value)){ // 值为数组说明下一级是最后一级
  464. $scope.professionArray = value;
  465. } else if (angular.isObject(value)) {
  466. $scope.profession[index+1] = value;
  467. }
  468. };
  469. // 判断值是否为字符串
  470. $scope.isString = function (value) {
  471. return angular.isString(value);
  472. };
  473. // 增加经营范围内容标签
  474. $scope._scope = $scope
  475. $scope.addBusinessScope = function () {
  476. if(!$scope.businessScope) return false;
  477. if($scope.enBusinessScope.length > 20) {
  478. toaster.pop('error', '经营范围内容标签不能超过20个!');
  479. return false;
  480. }
  481. $scope.enBusinessScope.push($scope.businessScope);
  482. $scope.businessScope = '';
  483. }
  484. // 删除选择的内容标签
  485. $scope.clearBusinessScope = function (key) {
  486. $scope.enBusinessScope.splice(key, 1);
  487. }
  488. /**
  489. * 保存企业信息
  490. */
  491. $scope.saveUpdate = function () {
  492. $scope.enterpriseInfo.enBusinessScope = $scope.enBusinessScope.join(',');
  493. // 先检查信息是否为空
  494. if (angular.equals($scope.enterpriseInfo,
  495. $scope.enterpriseInfoBackup)) {
  496. toaster.pop('error', '未做任何修改');
  497. $scope.updateState = false;
  498. return;
  499. }
  500. var enterpriseInfoFlag = validateEnterpriseInfo();
  501. if (!enterpriseInfoFlag) {
  502. toaster.pop('error', '请补充完信息后再次提交');
  503. return;
  504. }
  505. Enterprise.updateEnterpriseInfo(
  506. {enuu: $scope.userInfo.enterprise.uu}, $scope.enterpriseInfo,
  507. function () {
  508. $scope.loading = false;
  509. toaster.pop('success', '提示', '企业信息修改成功');
  510. $scope.enterpriseInfoBackup = angular.copy(
  511. $scope.enterpriseInfo);
  512. $scope.updateState = false;
  513. }, function (response) {
  514. $scope.loading = false;
  515. toaster.pop('error', '修改失败', response.data);
  516. });
  517. };
  518. // 直接跳转到申请绑定
  519. if ($rootScope.tab) {
  520. $scope.tab = $rootScope.tab;
  521. // 删除$rootScope.tab属性
  522. delete $rootScope.tab;
  523. }
  524. // 切换tab
  525. $scope.checkTab = function (t) {
  526. $scope.tab = t;
  527. if (t === 'role' && $scope.rolesExcept) {
  528. toaster.pop('error', '获取企业角色信息失败',$scope.rolesExcept);
  529. }
  530. // if (t === 'auth') {
  531. // $scope.keyword = '';
  532. // $scope.onSearch($scope.keyword,'all');
  533. // }
  534. };
  535. /* 查询接口权限 */
  536. // AccountRole.findAuthority({resUrl: encodeURIComponent('/account/role'), method: 'GET'}, function (data) {
  537. //
  538. // }, function (error) {
  539. //
  540. // })
  541. $scope.updatePassword = function () {
  542. AuthenticationService.redirectPassword();
  543. };
  544. $scope.updateUserEmail = function(){
  545. AuthenticationService.redirectEmail();
  546. };
  547. $scope.updateUserTel = function(){
  548. AuthenticationService.redirectPhone();
  549. };
  550. $scope.updateUserPay = function(){
  551. var modalInstance = $modal.open({
  552. animation: true,
  553. templateUrl: $rootScope.rootPath + '/static/view/vendor/modal/updateUserPay.html',
  554. controller: 'UserPayCtrl',
  555. resolve: {
  556. user: function(){return angular.copy($rootScope.userInfo);}
  557. }
  558. });
  559. modalInstance.result.then(function(){
  560. }, function(){
  561. });
  562. };
  563. $scope.updateUserQuestion = function(){
  564. AuthenticationService.redirectSecQuestion();
  565. };
  566. $scope.updateRealAuth = function(){
  567. AuthenticationService.redirectRealNameAuth();
  568. };
  569. //卖家中心 等级提示跳转
  570. if($stateParams.op!=""){
  571. var op =$stateParams.op;
  572. $scope.checkTab('safe');
  573. switch(op)
  574. {
  575. case 'pwd':
  576. $scope.updatePassword();
  577. break;
  578. case 'question':
  579. $scope.updateUserQuestion();
  580. break;
  581. case 'email':
  582. $scope.updateUserEmail();
  583. break;
  584. }
  585. }
  586. //角色控制
  587. $scope.roles = {};
  588. AccountResource.query({}, function (data) {
  589. if (data && data.length > 0) {
  590. data[0].$open = true;
  591. }
  592. $scope.resources = data;
  593. });
  594. var getData = function () {
  595. AccountRole.findAll({}, function (data) {
  596. var defaults = [], custom = [];
  597. angular.forEach(data, function (d) {
  598. if (d.isdefault == 1)
  599. defaults.push(d);
  600. else
  601. custom.push(d);
  602. });
  603. $scope.roles = {defaults: defaults, custom: custom};
  604. },function (error) {
  605. $scope.rolesExcept = error.data;
  606. });
  607. AccountRole.getByExistRoleAndEnuu({}, function (data) {
  608. var defaults = [], custom = [];
  609. angular.forEach(data, function (d) {
  610. if (d.isdefault == 1)
  611. defaults.push(d);
  612. else
  613. custom.push(d);
  614. });
  615. $scope.existRoles = {defaults: defaults, custom: custom};
  616. });
  617. };
  618. getData();
  619. $scope.editRole = function (role) {
  620. var modalInstance = $modal.open({
  621. animation: true,
  622. templateUrl: $rootScope.rootPath + '/static/view/vendor/modal/role_detail.html',
  623. controller: 'RoleEditCtrl',
  624. resolve: {
  625. role: function () {
  626. return role;
  627. }
  628. }
  629. });
  630. modalInstance.result.then(function (added) {
  631. added && getData();
  632. });
  633. };
  634. $scope.editUserRole = function (user) {
  635. var modalInstance = $modal.open({
  636. animation: true,
  637. templateUrl: $rootScope.rootPath + '/static/view/vendor/modal/edit_user_role.html',
  638. controller: 'UserRoleEditCtrl',
  639. resolve: {
  640. user: function () {
  641. return user;
  642. }
  643. }
  644. });
  645. };
  646. $scope.inSelect = false;
  647. $scope.setInSelect = function (status) {
  648. $scope.inSelect = status;
  649. }
  650. $(document).on("click", function () {
  651. $scope.$apply(function () {
  652. if (!$scope.inSelect) {
  653. $scope.setAdding(false);
  654. }
  655. })
  656. })
  657. }]);
  658. /*
  659. * 绑定用户到企业
  660. */
  661. app.register.controller('AddExistUserCtrl',
  662. ['$scope', '$modalInstance', 'Enterprise', 'AuthenticationService',
  663. '$timeout', 'toaster',
  664. function ($scope, $modalInstance, Enterprise, AuthenticationService,
  665. $timeout, toaster) {
  666. $scope.searching = false;
  667. //根据输入的内容查找用户
  668. $scope.searchUser = function (keyWord) {
  669. $scope.searching = true;
  670. $scope.searchSuccess = false;
  671. $scope.searchFailed = false;
  672. $scope.illegalError = false;
  673. $scope.reBindError = false;
  674. $scope.okDisabled = false;
  675. Enterprise.searchUser({keyWord: keyWord}, function (data) {
  676. $scope.searchSuccess = true;
  677. $scope.searchFailed = false;
  678. $scope.user = data; //查询到的用户
  679. }, function (response) {
  680. $scope.searchSuccess = false;
  681. $scope.searchFailed = true;
  682. });
  683. };
  684. $scope.onKeyDown = function (e, key) {
  685. var keycode = window.event ? e.keyCode : e.which;
  686. if (keycode == 13) {
  687. $scope.searchUser(key);
  688. }
  689. }
  690. //确认绑定
  691. $scope.ok = function (keyWord) {
  692. AuthenticationService.getAuthentication().success(function (data) {
  693. $scope.currentUser = data; //当前登录的用户(管理员)
  694. //不可自己绑定自己
  695. if ($scope.currentUser.userUU == $scope.user.userUU) {
  696. $scope.illegalError = true;
  697. $scope.okDisabled = true;
  698. return false;
  699. }
  700. //用户未绑定到任何企业时
  701. if (!$scope.user.enterprises) {
  702. //正常绑定
  703. Enterprise.bindUserToMyEnterprise({userUU: $scope.user.userUU},
  704. function (data) {
  705. $scope.okDisabled = true;
  706. toaster.pop("success", "提示", "用户绑定成功");
  707. $modalInstance.close(true);
  708. }, function (response) {
  709. toaster.pop('error', response.data);
  710. });
  711. return true;
  712. }
  713. //用户已绑定到某些企业时
  714. for (var i = 0; i < $scope.currentUser.enterprises.length; i++) {
  715. if ($scope.currentUser.enterprises[i].current) {
  716. for (var j = 0; j < $scope.user.enterprises.length; j++) {
  717. //该用户已绑定到当前企业,不可重复绑定
  718. if ($scope.currentUser.enterprises[i].uu
  719. == $scope.user.enterprises[j].uu) {
  720. $scope.reBindError = true;
  721. $scope.okDisabled = true;
  722. return false;
  723. }
  724. }
  725. //该用户未绑定到当前企业,可以进行绑定
  726. Enterprise.bindUserToMyEnterprise(
  727. {userUU: $scope.user.userUU}, function (data) {
  728. $scope.okDisabled = true;
  729. toaster.pop("success", "提示", "用户绑定成功");
  730. $modalInstance.close(true);
  731. }, function (response) {
  732. toaster.pop('error', response.data);
  733. });
  734. }
  735. }
  736. });
  737. };
  738. $scope.cancel = function () {
  739. $modalInstance.dismiss();
  740. };
  741. }]);
  742. // 修改密码Controller
  743. app.register.controller('PasswordCtrl',
  744. ['$rootScope', '$scope', '$modalInstance', 'user', 'User', 'toaster','$state',
  745. function ($rootScope, $scope, $modalInstance, user, User, toaster,$state) {
  746. $rootScope.$on('$stateChangeStart',
  747. function(event, toState, toParams, fromState, fromParams){
  748. $modalInstance.dismiss();
  749. })
  750. $scope.user = user;
  751. $scope.checking = false;
  752. $scope.showPassword = false;
  753. $scope.showNewPassword = false;
  754. $scope.showPassword1 = false;
  755. $scope.reloadKeyboard = function (type, $event) {
  756. $event.stopPropagation();
  757. if (type === 'showPassword') {
  758. $scope.showPassword = !$scope.showPassword;
  759. if (!$scope.showPassword) {
  760. $scope.checkPassword($scope.user.password);
  761. } else {
  762. $scope.closeOtherKeyboard('showPassword');
  763. }
  764. } else if (type === 'showNewPassword') {
  765. $scope.showNewPassword = !$scope.showNewPassword;
  766. if (!$scope.showNewPassword) {
  767. $scope.checkNewPassword($scope.user.newPassword);
  768. } else {
  769. $scope.closeOtherKeyboard('showNewPassword');
  770. }
  771. } else if (type === 'showPassword1') {
  772. $scope.showPassword1 = !$scope.showPassword1;
  773. if (!$scope.showNewPassword1) {
  774. $scope.checkNewPassword1($scope.user.newPassword1);
  775. } else {
  776. $scope.closeOtherKeyboard('showPassword1');
  777. }
  778. }
  779. }
  780. function resetPassword() {
  781. $scope.showPassword = false;
  782. $scope.checkPassword($scope.user.password);
  783. }
  784. function resetNewPassword() {
  785. $scope.showNewPassword = false;
  786. $scope.checkNewPassword($scope.user.newPassword);
  787. }
  788. function resetPassword1() {
  789. $scope.showPassword1 = false;
  790. $scope.checkNewPassword1($scope.user.newPassword1);
  791. }
  792. $scope.closeOtherKeyboard = function (type) {
  793. if (type == 'showPassword') {
  794. if ($scope.showNewPassword) {
  795. resetNewPassword();
  796. } else if ($scope.showPassword1) {
  797. resetPassword1();
  798. }
  799. } else if (type == 'showNewPassword') {
  800. if ($scope.showPassword) {
  801. resetPassword();
  802. } else if ($scope.showPassword1) {
  803. resetPassword1();
  804. }
  805. } else if (type == 'showPassword1') {
  806. if ($scope.showPassword) {
  807. resetPassword();
  808. } else if ($scope.showNewPassword) {
  809. resetNewPassword();
  810. }
  811. }
  812. }
  813. $scope.closeKeyboard = function () {
  814. if ($scope.showPassword) {
  815. $scope.showPassword = false;
  816. $scope.checkPassword($scope.user.password);
  817. } else if ($scope.showNewPassword) {
  818. $scope.showNewPassword = false;
  819. $scope.checkNewPassword($scope.user.newPassword);
  820. } else if ($scope.showPassword1) {
  821. $scope.showPassword1 = false;
  822. $scope.checkNewPassword1($scope.user.newPassword1);
  823. }
  824. }
  825. //输入原密码后验证原密码是否正确
  826. $scope.checkSuccess = false;
  827. $scope.checkFailed = false;
  828. $scope.checkPassword = function (password) {
  829. $scope.checkSuccess = false;
  830. $scope.checkFailed = false;
  831. if(!password){
  832. $scope.checkFailed = true;
  833. $scope.checkSuccess = false;
  834. }
  835. User.checkPassword({password: password}, function () {
  836. $scope.checkSuccess = true;
  837. $scope.checkFailed = false;
  838. }, function () {
  839. $scope.checkFailed = true;
  840. $scope.checkSuccess = false;
  841. });
  842. };
  843. // 对新密码进行校验
  844. $scope.checkSuccess1 = false;
  845. $scope.checkFailed1 = false;
  846. $scope.checkNewPassword = function (newPassword) {
  847. var middlLevelReg = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/;
  848. if (newPassword == null || !middlLevelReg.test(newPassword)) {
  849. //toaster.pop('error', '错误', '密码为8-20字符的英文、数字混合');
  850. $scope.checkSuccess1 = false;
  851. $scope.checkFailed1 = true;
  852. return false;
  853. } else {
  854. $scope.checkSuccess1 = true;
  855. $scope.checkFailed1 = false;
  856. }
  857. }
  858. $scope.$watch('user.newPassword', function (newValue, oldValue) {
  859. $scope.checkPasswordLevel(newValue);
  860. });
  861. // 密码强度校验
  862. $scope.secLevel = 0;
  863. $scope.checkPasswordLevel = function (newPassword) {
  864. $scope.checkFailed1 = false;
  865. if (newPassword == null) {
  866. $scope.secLevel = 0;
  867. return false;
  868. }
  869. // 密码强度中的正则
  870. var middlLevelReg = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/;
  871. // 密码强度高的正则
  872. var heightLevelReg = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/;
  873. if(heightLevelReg.test(newPassword)){
  874. $scope.secLevel = 3;
  875. return true;
  876. }else if(middlLevelReg.test(newPassword)){
  877. $scope.secLevel = 2;
  878. return true;
  879. }else{
  880. $scope.secLevel = 1;
  881. return false;
  882. }
  883. }
  884. //校验确认密码是否与新密码相同
  885. $scope.checkSuccess2 = false;
  886. $scope.checkFailed2 = false;
  887. $scope.checkNewPassword1 = function () {
  888. if ($scope.checkSuccess1 == true && ($scope.user.newPassword
  889. == $scope.user.newPassword1)) {
  890. $scope.checkSuccess2 = true;
  891. $scope.checkFailed2 = false;
  892. return false;
  893. }
  894. $scope.checkSuccess2 = false;
  895. $scope.checkFailed2 = true;
  896. }
  897. // 修改密码
  898. $scope.ok = function () {
  899. // 原密码校验
  900. if(!$scope.checkSuccess){
  901. $scope.checkPassword($scope.user.password);
  902. }
  903. // 新密码校验
  904. $scope.checkNewPassword($scope.user.newPassword);
  905. // 再次输入密码校验
  906. $scope.checkNewPassword1();
  907. if(!$scope.checkSuccess || !$scope.checkSuccess1 || !$scope.checkSuccess2){
  908. return;
  909. }
  910. // 密码强度校验
  911. if(!$scope.checkPasswordLevel($scope.user.newPassword)){
  912. toaster.pop('error', '错误', '密码强度不够,请重新输入');
  913. return;
  914. }
  915. if ($scope.user.newPassword == $scope.user.password) {
  916. toaster.pop('error', '错误', '新密码与原密码相同');
  917. return;
  918. }
  919. if ($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  920. User.updatePassword({
  921. password: $scope.user.password,
  922. newPassword: $scope.user.newPassword,
  923. secLevel: $scope.secLevel
  924. }, {}, function () {
  925. toaster.pop('success', '成功', '修改密码成功,请牢记您的新密码。');
  926. $scope.user.password = null;
  927. $scope.user.newPassword = null;
  928. $scope.user.newPassword1 = null;
  929. $scope.checking = false;
  930. $scope.checkSuccess = false;
  931. $scope.checkFailed = false;
  932. $scope.checkSuccess1 = false;
  933. $scope.checkFailed1 = false;
  934. $scope.checkSuccess2 = false;
  935. $scope.checkFailed2 = false;
  936. window.location.href = "vendor#/account/management/sec";
  937. window.location.reload();
  938. $modalInstance.close();
  939. }, function (response) {
  940. toaster.pop('error', '错误', response.data);
  941. $modalInstance.close();
  942. });
  943. } else {
  944. toaster.pop('error', '错误', '重复密码不一致');
  945. }
  946. };
  947. $scope.cancel = function () {
  948. $modalInstance.close();
  949. };
  950. $scope.hideKeyboard = function () {
  951. $scope.closeKeyboard();
  952. console.log(1);
  953. }
  954. }]);
  955. // 修改邮箱Controller
  956. app.register.controller('UserEmailCtrl',
  957. ['$rootScope', '$scope', '$modalInstance', 'user', 'User', 'toaster', '$interval',
  958. function ($rootScope, $scope, $modalInstance, user, User, toaster, $interval) {
  959. $rootScope.$on('$stateChangeStart',
  960. function(event, toState, toParams, fromState, fromParams){
  961. $modalInstance.dismiss();
  962. })
  963. User.getPageToken();
  964. $scope.user = user;
  965. $scope.user.userEmail = null;
  966. $scope.user.newUserEmail = null;
  967. //验证用户输入的旧邮箱地址是否正确
  968. $scope.checkUserEmail = function (userEmail) {
  969. if (userEmail == null) {
  970. $scope.checkFailed = true;
  971. $scope.checkSuccess = false;
  972. return false;
  973. }
  974. $scope.checkSuccess = false;
  975. $scope.checkFailed = false;
  976. User.checkUserEmail({userEmail: userEmail}, function () {
  977. $scope.checkSuccess = true;
  978. $scope.checkFailed = false;
  979. }, function () {
  980. $scope.checkFailed = true;
  981. $scope.checkSuccess = false;
  982. });
  983. };
  984. //如果之前未绑定
  985. if($scope.userInfo.userEmail==null?true:false){
  986. $scope.checkSuccess = true;
  987. }
  988. //验证用户新输入的邮箱是否可用
  989. $scope.checkSuccess1 = false;
  990. $scope.checkFailed1 = false;
  991. $scope.checkFailed1_1 = false;
  992. $scope.emailEnable = function (newUserEmail) {
  993. //邮箱不可用
  994. if ((newUserEmail == null || newUserEmail.length > 30)
  995. || newUserEmail.indexOf("@") == -1 || newUserEmail.indexOf(".") == -1) {
  996. $scope.checkSuccess1 = false;
  997. $scope.checkFailed1 = true;
  998. $scope.checkFailed1_1 = false;
  999. return false;
  1000. }
  1001. User.emailEnable({email: newUserEmail}, function (data) {
  1002. if (data.data == "true") {//邮箱可用
  1003. $scope.checkSuccess1 = true;
  1004. $scope.checkFailed1 = false;
  1005. $scope.checkFailed1_1 = false;
  1006. } else {//邮箱不可用
  1007. $scope.checkSuccess1 = false;
  1008. $scope.checkFailed1 = false;
  1009. $scope.checkFailed1_1 = true;
  1010. }
  1011. }, function () {
  1012. $scope.checkSuccess1 = false;
  1013. $scope.checkFailed1 = true;
  1014. $scope.checkFailed1_1 = false;
  1015. });
  1016. };
  1017. $scope.codeSuccess = false;
  1018. $scope.sendSuccess = true;
  1019. //发送验证码
  1020. $scope.sendCheckCode = function (newUserEmail) {
  1021. if (!$scope.checkSuccess1 || ($scope.userInfo.userEmail!=null && !$scope.checkSuccess)) {
  1022. if ($scope.userInfo.userEmail!=null && !$scope.checkSuccess) {
  1023. $scope.checkFailed = true;
  1024. }
  1025. return;
  1026. }
  1027. $scope.sendSuccess = false;
  1028. User.sendCheckCode({newUserEmail: newUserEmail}, function () {
  1029. $scope.codeSuccess = true;
  1030. $interval.cancel(timePromise);
  1031. var second = 60,
  1032. timePromise = $interval(function () {
  1033. if (second <= 0) {
  1034. $interval.cancel(timePromise);
  1035. second = 60;
  1036. } else {
  1037. second--;
  1038. $scope.paracont = second + "秒后可重发";
  1039. if (second == 0) {
  1040. $scope.paracont = "重发验证码";
  1041. $scope.sendSuccess = true;
  1042. }
  1043. }
  1044. }, 1000, 60);
  1045. }, function (response) {
  1046. toaster.pop('error', '错误', response.data);
  1047. $scope.sendSuccess = true;
  1048. });
  1049. };
  1050. $scope.checkSuccess2 = false;
  1051. $scope.checkFailed2 = false;
  1052. //校验验证码
  1053. $scope.validCheckCode = function (checkCode) {
  1054. if(!checkCode){
  1055. $scope.checkSuccess2 = false;
  1056. $scope.checkFailed2 = true;
  1057. return false;
  1058. }
  1059. User.validCheckCode({checkCode: checkCode,newUserEmail:$scope.user.newUserEmail}, function (data) {
  1060. var status = data.status;
  1061. var message = data.message;
  1062. if (status == 1) {
  1063. $scope.checkSuccess2 = true;
  1064. $scope.checkFailed2 = false;
  1065. } else {
  1066. $scope.checkSuccess2 = false;
  1067. $scope.checkFailed2 = true;
  1068. }
  1069. });
  1070. };
  1071. //修改邮箱地址
  1072. $scope.ok = function () {
  1073. //原邮箱校验
  1074. if($scope.userInfo.userEmail && !$scope.checkSuccess ){
  1075. $scope.checkUserEmail($scope.user.userEmail);
  1076. }
  1077. //新邮箱校验
  1078. if(!$scope.checkSuccess1){
  1079. $scope.emailEnable($scope.user.newUserEmail);
  1080. }
  1081. //验证码
  1082. $scope.validCheckCode($scope.checkCode);
  1083. if((!$scope.checkSuccess && $scope.userInfo.userEmail)|| !$scope.checkSuccess1 || !$scope.checkSuccess2){
  1084. return;
  1085. }
  1086. var param = {
  1087. newUserEmail: $scope.user.newUserEmail,
  1088. checkCode:$scope.checkCode
  1089. };
  1090. if ($scope.user.userEmail!=null && $scope.user.newUserEmail == $scope.user.userEmail) {
  1091. toaster.pop('error', '错误', '新邮箱地址与旧邮箱地址相同');
  1092. return;
  1093. }else{
  1094. param["userEmail"]=$scope.user.userEmail;
  1095. }
  1096. User.updateUserEmail(param, {}, function () {
  1097. toaster.pop('success', '成功', '修改邮箱成功。');
  1098. //修改userInfo里面的userEmail
  1099. $scope.userInfo.userEmail =$scope.user.newUserEmail.substr(
  1100. 0,1) + "***"
  1101. + $scope.user.newUserEmail.substr($scope.user.newUserEmail.indexOf("@"));
  1102. $scope.user.userEmail = null;
  1103. $scope.user.newUserEmail = null;
  1104. $scope.checking = false;
  1105. $scope.checkSuccess = false;
  1106. $scope.checkFailed = false;
  1107. $scope.codeSuccess = false;
  1108. $scope.validSuccess = false;
  1109. $scope.checkSuccess1 = false;
  1110. $scope.checkFailed1 = false;
  1111. window.location.href = "vendor#/account/management/sec";
  1112. window.location.reload();
  1113. $modalInstance.close();
  1114. }, function (response) {
  1115. toaster.pop('error', '错误', response.data);
  1116. $modalInstance.close();
  1117. });
  1118. };
  1119. $scope.cancel = function () {
  1120. $modalInstance.close();
  1121. };
  1122. }]);
  1123. //手机验证Controller
  1124. app.register.controller('UserTelCtrl',
  1125. ['$rootScope', '$scope', '$modalInstance', 'user', 'User', 'toaster', '$interval',
  1126. function ($rootScope, $scope, $modalInstance, user, User, toaster, $interval) {
  1127. $rootScope.$on('$stateChangeStart',
  1128. function(event, toState, toParams, fromState, fromParams){
  1129. $modalInstance.dismiss();
  1130. })
  1131. User.getPageToken();
  1132. $scope.user = user;
  1133. $scope.user.userTel = null;
  1134. //原手机号校验
  1135. $scope.checking = false;
  1136. //验证用户输入的旧邮箱地址是否正确
  1137. $scope.checkUserTel = function (userTel) {
  1138. $scope.checking = true;
  1139. $scope.checkSuccess = false;
  1140. $scope.checkFailed = false;
  1141. User.checkUserTel({userTel: userTel}, function () {
  1142. $scope.checkSuccess = true;
  1143. $scope.checking = false;
  1144. $scope.checkFailed = false;
  1145. }, function () {
  1146. $scope.checkFailed = true;
  1147. $scope.checking = false;
  1148. $scope.checkSuccess = false;
  1149. });
  1150. };
  1151. //新手机号是否可用
  1152. $scope.checkFailed1 = false;
  1153. $scope.checkFailed1_1 = false;
  1154. $scope.checkSuccess1 = false;
  1155. $scope.telEnable = function (newUserTel) {
  1156. if (newUserTel == null || !/^[0-9]{8,11}$/.test(newUserTel)) {
  1157. $scope.checkFailed1 = true;
  1158. $scope.checkSuccess1 = false;
  1159. $scope.checkFailed1_1 = false;
  1160. return false;
  1161. }
  1162. $scope.checking1 = true;
  1163. $scope.checkSuccess1 = false;
  1164. $scope.checkFailed1 = false;
  1165. User.telEnable({tel: newUserTel}, function (data) {
  1166. if (data.data == "true") {//手机可用
  1167. $scope.checkSuccess1 = true;
  1168. $scope.checkFailed1 = false;
  1169. $scope.checkFailed1_1 = false;
  1170. } else {//手机不可用
  1171. $scope.checkFailed1_1 = true;
  1172. $scope.checking1 = false;
  1173. $scope.checkSuccess1 = false;
  1174. }
  1175. }, function () {
  1176. $scope.checkFailed1 = true;
  1177. $scope.checking1 = false;
  1178. $scope.checkSuccess1 = false;
  1179. $scope.checkFailed1_1 = false;
  1180. });
  1181. };
  1182. //发送验证码
  1183. $scope.codeSuccess = false;
  1184. $scope.sendSuccess = true;
  1185. //发送验证码
  1186. $scope.sendTelCheckCode = function (newUserTel) {
  1187. if (!$scope.checkSuccess1 || ($scope.userInfo.userTel!=null && !$scope.checkSuccess)) {
  1188. if ($scope.userInfo.userTel!=null && !$scope.checkSuccess) {
  1189. $scope.checkFailed = true;
  1190. }
  1191. return;
  1192. }
  1193. $scope.sendSuccess = false;
  1194. User.sendTelCheckCode({newUserTel: newUserTel}, function () {
  1195. $scope.codeSuccess = true;
  1196. $interval.cancel(timePromise);
  1197. var second = 60,
  1198. timePromise = $interval(function () {
  1199. if (second <= 0) {
  1200. $interval.cancel(timePromise);
  1201. second = 60;
  1202. } else {
  1203. second--;
  1204. $scope.paracont = second + "秒后可重发";
  1205. if (second == 0) {
  1206. $scope.paracont = "重发验证码";
  1207. $scope.sendSuccess = true;
  1208. }
  1209. }
  1210. }, 1000, 60);
  1211. }, function (response) {
  1212. toaster.pop('error', '错误', response.data);
  1213. $scope.sendSuccess = true;
  1214. });
  1215. };
  1216. $scope.checkSuccess2 = false;
  1217. $scope.checkFailed2 = false;
  1218. //校验验证码
  1219. $scope.validTelCheckCode = function (telCheckCode) {
  1220. if(!telCheckCode){
  1221. $scope.checkSuccess2 = false;
  1222. $scope.checkFailed2 = true;
  1223. return false;
  1224. }
  1225. User.validTelCheckCode({telCheckCode: telCheckCode,newUserTel:$scope.user.newUserTel},
  1226. function (data) {
  1227. var status = data.status;
  1228. var message = data.message;
  1229. if (status == 1) {
  1230. $scope.checkSuccess2 = true;
  1231. $scope.checkFailed2 = false;
  1232. } else {
  1233. $scope.checkSuccess2 = false;
  1234. $scope.checkFailed2 = true;
  1235. }
  1236. });
  1237. };
  1238. //修改手机
  1239. $scope.ok = function () {
  1240. //原手机校验
  1241. if(!$scope.checkSuccess){
  1242. $scope.checkUserTel($scope.user.userTel);
  1243. }
  1244. //新手机校验
  1245. if(!$scope.checkSuccess1){
  1246. $scope.telEnable($scope.user.newUserTel);
  1247. }
  1248. //验证码校验
  1249. $scope.validTelCheckCode($scope.telCheckCode);
  1250. if(!$scope.checkSuccess || !$scope.checkSuccess1 || !$scope.checkSuccess2){
  1251. return;
  1252. }
  1253. if ($scope.user.newUserTel == $scope.user.userTel) {
  1254. toaster.pop('error', '错误', '新手机号与旧手机号相同');
  1255. return;
  1256. }
  1257. User.updateUserTel({
  1258. newUserTel: $scope.user.newUserTel,
  1259. userTel: $scope.user.userTel,
  1260. telCheckCode:$scope.telCheckCode
  1261. }, {}, function () {
  1262. toaster.pop('success', '成功', '手机修改成功。');
  1263. $scope.userInfo.userTel = $scope.user.newUserTel.substr(0, 3)
  1264. + '****' + $scope.user.newUserTel.substr(7);
  1265. $scope.user.userTel = null;
  1266. $scope.user.newUserTel = null;
  1267. $scope.checking = false;
  1268. $scope.checkSuccess = false;
  1269. $scope.checkFailed = false;
  1270. $scope.checking1 = false;
  1271. $scope.checkSuccess1 = false;
  1272. $scope.checkFailed1 = false;
  1273. $scope.emailSuccess = false;
  1274. $scope.codeSuccess = false;
  1275. $scope.validSuccess = false;
  1276. window.location.href = "vendor#/account/management/sec";
  1277. window.location.reload();
  1278. $modalInstance.close();
  1279. }, function (response) {
  1280. toaster.pop('error', '错误', response.data);
  1281. //$modalInstance.close();
  1282. });
  1283. };
  1284. $scope.cancel = function () {
  1285. $modalInstance.close();
  1286. };
  1287. }]);
  1288. // 设置支付密码Controller
  1289. app.register.controller('UserPayCtrl',
  1290. ['$rootScope', '$scope', '$modalInstance', 'user', 'User', 'toaster',
  1291. function ($rootScope, $scope, $modalInstance, user, User, toaster) {
  1292. $rootScope.$on('$stateChangeStart',
  1293. function(event, toState, toParams, fromState, fromParams){
  1294. $modalInstance.dismiss();
  1295. })
  1296. //原密码框是否显示
  1297. $scope.user = angular.copy(user);
  1298. $scope.checking = true;
  1299. $scope.showNewUserPay = false;
  1300. $scope.showUserPay = false;
  1301. $scope.showNewUserPay1 = false;
  1302. $scope.reloadKeyboard = function (type, $event) {
  1303. $event.stopPropagation();
  1304. if (type === 'showNewUserPay') {
  1305. $scope.showNewUserPay = !$scope.showNewUserPay;
  1306. if (!$scope.showNewUserPay) {
  1307. $scope.checkNewUserPay($scope.user.newUserPay);
  1308. } else {
  1309. $scope.closeOtherKeyboard('showNewUserPay');
  1310. }
  1311. } else if (type === 'showUserPay') {
  1312. $scope.showUserPay = !$scope.showUserPay;
  1313. if (!$scope.showUserPay) {
  1314. $scope.checkUserPay($scope.user.userPay);
  1315. } else {
  1316. $scope.closeOtherKeyboard('showUserPay');
  1317. }
  1318. } else if (type === 'showNewUserPay1') {
  1319. $scope.showNewUserPay1 = !$scope.showNewUserPay1;
  1320. if (!$scope.showNewUserPay1) {
  1321. $scope.checkNewUserPay1($scope.user.newUserPay1);
  1322. } else {
  1323. $scope.closeOtherKeyboard('showNewUserPay1');
  1324. }
  1325. }
  1326. }
  1327. function resetNewUserPay() {
  1328. $scope.showNewUserPay = false;
  1329. $scope.checkNewUserPay($scope.user.newUserPay);
  1330. }
  1331. function resetUserPay() {
  1332. $scope.showUserPay = false;
  1333. $scope.checkUserPay($scope.user.userPay);
  1334. }
  1335. function resetNewUserPay1() {
  1336. $scope.showNewUserPay1 = false;
  1337. $scope.checkNewUserPay1($scope.user.newUserPay1);
  1338. }
  1339. $scope.closeOtherKeyboard = function (type) {
  1340. if (type == 'showNewUserPay') {
  1341. if ($scope.showUserPay) {
  1342. resetUserPay();
  1343. } else if ($scope.showNewUserPay1) {
  1344. resetNewUserPay1();
  1345. }
  1346. } else if (type == 'showUserPay') {
  1347. if ($scope.showNewUserPay) {
  1348. resetNewUserPay();
  1349. } else if ($scope.showNewUserPay1) {
  1350. resetNewUserPay1();
  1351. }
  1352. } else if (type == 'showNewUserPay1') {
  1353. if ($scope.showNewUserPay) {
  1354. resetNewUserPay();
  1355. } else if ($scope.showUserPay) {
  1356. resetUserPay();
  1357. }
  1358. }
  1359. }
  1360. $scope.closeKeyboard = function () {
  1361. if ($scope.showNewUserPay) {
  1362. $scope.showNewUserPay = false;
  1363. $scope.checkNewUserPay($scope.user.newUserPay);
  1364. } else if ($scope.showUserPay) {
  1365. $scope.showUserPay = false;
  1366. $scope.checkUserPay($scope.user.userPay);
  1367. } else if ($scope.showNewUserPay1) {
  1368. $scope.showNewUserPay1 = false;
  1369. $scope.checkNewUserPay1($scope.user.newUserPay1);
  1370. }
  1371. }
  1372. //验证是否设置密码
  1373. $scope.isNewSuccess = false;
  1374. $scope.isNewFailed = false;
  1375. $scope.checkHaveUserPay = function () {
  1376. $scope.isNewSuccess = false;
  1377. $scope.isNewFailed = true;
  1378. User.checkHaveUserPay(function (data) {
  1379. var flag = data.data;
  1380. if (flag == "false") {
  1381. //隐藏原密码输入框
  1382. angular.element(".oldUserPay").remove();
  1383. //修改新密码框内容
  1384. $scope.newUserPayLabel = "密码";
  1385. $scope.isNewSuccess = true;
  1386. $scope.isNewFailed = false;
  1387. }
  1388. });
  1389. }
  1390. //校验原密码是否正确
  1391. $scope.checkFailed = false;
  1392. $scope.checkSuccess = false;
  1393. $scope.checkUserPay = function (userPay) {
  1394. if (userPay == null) {
  1395. $scope.checkFailed = true;
  1396. $scope.checkSuccess = false;
  1397. return false;
  1398. }
  1399. $scope.checkSuccess = false;
  1400. $scope.checkFailed = false;
  1401. User.checkUserPay({userPay: userPay}, function () {
  1402. $scope.checkFailed = false;
  1403. $scope.checkSuccess = true;
  1404. }, function () {
  1405. $scope.checkFailed = true;
  1406. $scope.checkSuccess = false;
  1407. });
  1408. }
  1409. //输入新密码,进行校验
  1410. $scope.checkSuccess1 = false;
  1411. $scope.checkFailed1 = false;
  1412. $scope.checkNewUserPay = function (newUserPay) {
  1413. if (newUserPay == null) {
  1414. $scope.checkFailed1 = true;
  1415. $scope.checkSuccess1 = false;
  1416. return false;
  1417. }
  1418. //如果两者相同 则返回
  1419. if ($scope.checking && ($scope.user.userPay
  1420. == $scope.user.newUserPay)) {
  1421. toaster.pop('error', '错误', '新密码与原密码相同');
  1422. $scope.checkFailed1 = true;
  1423. $scope.checkSuccess1 = false;
  1424. return false;
  1425. }
  1426. //正则校验
  1427. var reg = /^\d{6}$/;
  1428. if (!reg.test(newUserPay)) {
  1429. $scope.checkFailed1 = true;
  1430. $scope.checkSuccess1 = false;
  1431. return false;
  1432. }
  1433. $scope.checkFailed1 = false;
  1434. $scope.checkSuccess1 = true;
  1435. }
  1436. //校验确认密码是否与新密码相同
  1437. $scope.checkSuccess2 = false;
  1438. $scope.checkFailed2 = false;
  1439. $scope.checkNewUserPay1 = function () {
  1440. if($scope.user.newUserPay1 == null){
  1441. $scope.checkSuccess2 = false;
  1442. $scope.checkFailed2 = true;
  1443. }
  1444. if ($scope.user.newUserPay1 != null) {
  1445. //如果输入密码正确,并且输入密码=重新输入密码
  1446. if ($scope.checkSuccess1 && ($scope.user.newUserPay
  1447. == $scope.user.newUserPay1)) {
  1448. $scope.checkSuccess2 = true;
  1449. $scope.checkFailed2 = false;
  1450. return false;
  1451. }
  1452. $scope.checkSuccess2 = false;
  1453. $scope.checkFailed2 = true;
  1454. }
  1455. }
  1456. //支付密码
  1457. $scope.ok = function () {
  1458. //原密码校验
  1459. if(!$scope.checkSuccess && $scope.userInfo.havePayPwd){
  1460. $scope.checkUserPay($scope.user.userPay);
  1461. }
  1462. //新密码校验
  1463. $scope.checkNewUserPay($scope.user.newUserPay);
  1464. //密码确认
  1465. $scope.checkNewUserPay1();
  1466. if((!$scope.checkSuccess && $scope.userInfo.havePayPwd) || !$scope.checkSuccess1 || !$scope.checkSuccess2){
  1467. return;
  1468. }
  1469. if ($scope.checking && ($scope.user.newUserPay
  1470. == $scope.user.userPay)) {
  1471. toaster.pop('error', '错误', '新密码与旧密码相同');
  1472. return;
  1473. }
  1474. User.updateUserPay({
  1475. newUserPay: $scope.user.newUserPay,
  1476. userPay: $scope.user.userPay
  1477. }, {}, function () {
  1478. toaster.pop('success', '成功', '支付密码设置成功。');
  1479. $scope.user.userPay = null;
  1480. $scope.user.newUserPay = null;
  1481. $scope.checkSuccess = false;
  1482. $scope.checkFailed = false;
  1483. $scope.checkSuccess1 = false;
  1484. $scope.checkFailed1 = false;
  1485. $scope.checkSuccess2 = false;
  1486. $scope.checkFailed2 = false;
  1487. $scope.checking = true;
  1488. window.location.href = "vendor#/account/management/sec";
  1489. window.location.reload();
  1490. $modalInstance.close();
  1491. }, function (response) {
  1492. toaster.pop('error', '错误', response.data);
  1493. $modalInstance.close();
  1494. });
  1495. };
  1496. $scope.cancel = function () {
  1497. $modalInstance.close();
  1498. };
  1499. }]);
  1500. // 设置密保问题Controller
  1501. app.register.controller('UserQuestionCtrl',
  1502. ['$rootScope', '$scope', '$modalInstance', 'user', 'User', 'toaster','$timeout',
  1503. function ($rootScope, $scope, $modalInstance, user, User, toaster,$timeout) {
  1504. $rootScope.$on('$stateChangeStart',
  1505. function(event, toState, toParams, fromState, fromParams){
  1506. $modalInstance.dismiss();
  1507. })
  1508. //查询所有的密保问题
  1509. $scope.pageInfo = {page: 1, count: 20};
  1510. User.getAllSecQuestion($scope.pageInfo, function (data) {
  1511. $scope.secQuestions = data.content;
  1512. //查询当前用户密保问题
  1513. User.getUserQuestion({userUU: $scope.userInfo.userUU},function (data) {
  1514. $scope.uq[0] = data[0];
  1515. $scope.uq[1] = data[1];
  1516. });
  1517. });
  1518. //选择问题 校验
  1519. $scope.checkSuccess = false;
  1520. $scope.checkFailed = false;
  1521. $scope.checkSuccess2 = false;
  1522. $scope.checkFailed2 = false;
  1523. $scope.choose = function () {
  1524. if ($scope.uq[0]!=undefined && $scope.uq[0].question != undefined && $scope.uq[0].question!="") {
  1525. $scope.checkSuccess = true;
  1526. $scope.checkFailed = false;
  1527. } else {
  1528. $scope.checkSuccess = false;
  1529. $scope.checkFailed = true;
  1530. }
  1531. }
  1532. $scope.choose1 = function () {
  1533. if ($scope.uq[1]!=undefined && $scope.uq[1].question != undefined && $scope.uq[1].question!="") {
  1534. $scope.checkSuccess2 = true;
  1535. $scope.checkFailed2 = false;
  1536. } else {
  1537. $scope.checkSuccess2 = false;
  1538. $scope.checkFailed2 = true;
  1539. }
  1540. }
  1541. //答案校验 不超过30个字符
  1542. $scope.checkSuccess1 = false;
  1543. $scope.checkFailed1 = false;
  1544. $scope.checkFailed1_1 = false;
  1545. $scope.checkSuccess3 = false;
  1546. $scope.checkFailed3 = false;
  1547. $scope.checkFailed3_1 = false;
  1548. $scope.inputAnswer = function () {
  1549. if ($scope.uq[0]==undefined || $scope.uq[0].answer == undefined || $scope.uq[0].answer=="") {
  1550. $scope.checkSuccess1 = false;
  1551. $scope.checkFailed1 = true;
  1552. $scope.checkFailed1_1 = false;
  1553. return false;
  1554. }
  1555. if ($scope.uq[0].answer.length > 30) {
  1556. $scope.checkSuccess1 = false;
  1557. $scope.checkFailed1 = false;
  1558. $scope.checkFailed1_1 = true;
  1559. return false;
  1560. }
  1561. $scope.checkSuccess1 = true;
  1562. $scope.checkFailed1 = false;
  1563. $scope.checkFailed1_1 = false;
  1564. }
  1565. $scope.inputAnswer1 = function () {
  1566. if ($scope.uq[1]==undefined || $scope.uq[1].answer == undefined || $scope.uq[1].answer=="") {
  1567. $scope.checkSuccess3 = false;
  1568. $scope.checkFailed3 = true;
  1569. $scope.checkFailed3_1 = false;
  1570. return false;
  1571. }
  1572. if ($scope.uq[1].answer.length > 30) {
  1573. $scope.checkSuccess3 = false;
  1574. $scope.checkFailed3 = false;
  1575. $scope.checkFailed3_1 = true;
  1576. return false;
  1577. }
  1578. $scope.checkSuccess3 = true;
  1579. $scope.checkFailed3 = false;
  1580. $scope.checkFailed3_1 = false;
  1581. }
  1582. //保存密保
  1583. $scope.ok = function () {
  1584. //问题1校验
  1585. $scope.choose();
  1586. $scope.inputAnswer();
  1587. $scope.choose1();
  1588. $scope.inputAnswer1();
  1589. if(!$scope.checkSuccess || !$scope.checkSuccess1 || !$scope.checkSuccess2 || !$scope.checkSuccess3){
  1590. return;
  1591. }
  1592. var arr = [];
  1593. for (var key in $scope.uq) {
  1594. $scope.uq[key].sort = Number(key) + 1;
  1595. arr[key] = $scope.uq[key];
  1596. }
  1597. User.updateUserQuestion({}, arr, function () {
  1598. toaster.pop('success', '成功', '密保问题设置成功。');
  1599. $modalInstance.close();
  1600. $scope.uq = null;
  1601. $scope.checkSuccess = false;
  1602. $scope.checkFailed = false;
  1603. $scope.checkSuccess1 = false;
  1604. $scope.checkFailed1 = false;
  1605. $scope.checkSuccess2 = false;
  1606. $scope.checkFailed2 = false;
  1607. $scope.checkSuccess3 = false;
  1608. $scope.checkFailed3 = false;
  1609. $scope.checkFailed3_1 = false;
  1610. $scope.checkFailed1_1 = false;
  1611. window.location.href = "vendor#/account/management/sec";
  1612. window.location.reload();
  1613. $modalInstance.close();
  1614. }, function (response) {
  1615. toaster.pop('error', '错误', response.data);
  1616. $modalInstance.close();
  1617. });
  1618. };
  1619. $scope.cancel = function () {
  1620. $modalInstance.close();
  1621. };
  1622. }]);
  1623. // 实名认证Controller
  1624. app.register.controller('UserRealAuthCtrl',
  1625. ['$rootScope', '$scope', '$modalInstance', 'user', 'User', 'toaster',
  1626. function ($rootScope, $scope, $modalInstance, user, User, toaster) {
  1627. $rootScope.$on('$stateChangeStart',
  1628. function(event, toState, toParams, fromState, fromParams){
  1629. $modalInstance.dismiss();
  1630. })
  1631. $scope.user = user;
  1632. //姓名验证 不超过20个字符
  1633. $scope.checkSuccess = false;
  1634. $scope.checkFailed = false;
  1635. $scope.checkUserName = function (userName) {
  1636. if (!userName) {
  1637. //toaster.pop('error', '请输入您的真实姓名');
  1638. $scope.checkSuccess = false;
  1639. $scope.checkFailed = true;
  1640. return false;
  1641. } else if (userName.length > 20) {
  1642. //toaster.pop('error', '请勿超过20个字符');
  1643. $scope.checkSuccess = false;
  1644. $scope.checkFailed_1 = true;
  1645. return false;
  1646. } else {
  1647. $scope.checkSuccess = true;
  1648. $scope.checkFailed = false;
  1649. $scope.checkFailed_1 = false;
  1650. }
  1651. }
  1652. //检查身份证
  1653. $scope.checkSuccess1 = false;
  1654. $scope.checkFailed1 = false;
  1655. $scope.checkFailed1_1 = false;
  1656. $scope.checkUserIdcode = function (userIdcode) {
  1657. if (userIdcode == null) {
  1658. //toaster.pop('error', '请输入您的身份证号');
  1659. $scope.checkSuccess1 = false;
  1660. $scope.checkFailed1 = true;
  1661. $scope.checkFailed1_1 = false;
  1662. return false;
  1663. } else if (!(/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(userIdcode))) {
  1664. //toaster.pop('error', '请输入18位的身份证号');
  1665. $scope.checkSuccess1 = false;
  1666. $scope.checkFailed1 = false;
  1667. $scope.checkFailed1_1 = true;
  1668. return false;
  1669. } else {
  1670. $scope.checkSuccess1 = true;
  1671. $scope.checkFailed1 = false;
  1672. $scope.checkFailed1_1 = false;
  1673. }
  1674. }
  1675. //图片上传
  1676. $scope.checkSuccess2 = false;
  1677. $scope.onUploadID = function ($data) {
  1678. if (!$data || !$data.path) {
  1679. toaster.pop('error', '图片上传失败');
  1680. return;
  1681. }
  1682. $scope.user.idImgUrl = $data.path;
  1683. $scope.checkSuccess2 = true;
  1684. };
  1685. $scope.deleteImg =function () {
  1686. $scope.user.idImgUrl = '';
  1687. $scope.checkSuccess2=false;
  1688. };
  1689. // 查看范例
  1690. $scope.showImg = function(imgUrl) {
  1691. var src = imgUrl, box = $('#image-box'), modal = $('.modal-content');
  1692. box.show();
  1693. box.find('img').attr('src', src);
  1694. box.find('a').click(function(){
  1695. box.hide();
  1696. });
  1697. box.dblclick(function(){
  1698. box.hide();
  1699. });
  1700. };
  1701. //保存
  1702. $scope.ok = function () {
  1703. //姓名
  1704. $scope.checkUserName($scope.user.userName);
  1705. //身份证
  1706. $scope.checkUserIdcode($scope.user.userIdcode);
  1707. //身份证
  1708. if(!$scope.checkSuccess2){
  1709. toaster.pop('error', '错误', '请上传您的证件...');
  1710. return;
  1711. }
  1712. if(!$scope.checkSuccess || !$scope.checkSuccess1 || !$scope.checkSuccess2){
  1713. return;
  1714. }
  1715. User.updateRealAuth({userName:$scope.user.userName,userIdcode:$scope.user.userIdcode,idImgUrl:$scope.user.idImgUrl},{},function(){
  1716. toaster.pop('success', '成功', '身份信息提交成功。');
  1717. $modalInstance.close();
  1718. $scope.checkSuccess2 = false;
  1719. $scope.checkSuccess1 = false;
  1720. $scope.checkFailed1 = false;
  1721. $scope.checkSuccess = false;
  1722. $scope.checkFailed = false;
  1723. window.location.href = "vendor#/account/management/sec";
  1724. window.location.reload();
  1725. $modalInstance.close();
  1726. }, function (response) {
  1727. toaster.pop('error', '错误', response.data);
  1728. $modalInstance.close();
  1729. });
  1730. };
  1731. $scope.cancel = function () {
  1732. $modalInstance.close();
  1733. };
  1734. }]);
  1735. //角色管理-编辑角色controller
  1736. app.register.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'BaseService', function ($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, BaseService) {
  1737. BaseService.scrollBackToTop();
  1738. $scope.role = angular.copy(role || {});
  1739. $scope.master = angular.copy($scope.role);
  1740. var isNew = role == null;
  1741. $scope.cancel = function () {
  1742. $modalInstance.close(false);
  1743. };
  1744. var getCheckRoleResource = function (data, rs) {
  1745. if (data.items.length > 0) {
  1746. var c = 0;
  1747. angular.forEach(data.items, function (item) {
  1748. if (rs.indexOf(item.id) > -1) {
  1749. item.$checked = true;
  1750. c += 1;
  1751. }
  1752. });
  1753. data.$checked = c > 0 && c == data.items.length;
  1754. data.$halfChecked = c > 0 && c < data.items.length;
  1755. } else {
  1756. angular.forEach(data.children, function (item) {
  1757. getCheckRoleResource(item, rs);
  1758. var activeCount = 0;
  1759. angular.forEach(data.children, function (item) {
  1760. if (!item.$checked) {
  1761. activeCount ++;
  1762. }
  1763. });
  1764. data.$checked = activeCount > 0 && activeCount == data.children.length;
  1765. data.$halfChecked = activeCount > 0 && activeCount < data.children.length;
  1766. });
  1767. }
  1768. }
  1769. AccountResource.query({}, function (data) {
  1770. if (data && data.length > 0) {
  1771. var rs = [];// 已分配的资源的id
  1772. if (role && role.resourceItems) {
  1773. angular.forEach(role.resourceItems, function (item) {
  1774. rs.push(item.id);
  1775. });
  1776. }
  1777. angular.forEach(data, function (data2) {
  1778. getCheckRoleResource(data2, rs);
  1779. })
  1780. $scope.resourceItems = data[0].items;
  1781. $scope.activeResource = data[0];
  1782. data[0].$active = true;
  1783. }
  1784. $scope.resources = data;
  1785. // if ($scope.role) {
  1786. // angular.forEach($scope.role.resourceItems,function (item) {
  1787. // angular.forEach($scope.resources, function (roleItem) {
  1788. // if (item.id == roleItem.id) {
  1789. // roleItem.$active = true;
  1790. // }
  1791. // })
  1792. // })
  1793. // }
  1794. $timeout(function () {
  1795. angular.forEach($scope.resources, function (resource) {
  1796. var c = 0;
  1797. angular.forEach(resource.items, function (item) {
  1798. item.$checked && (c += 1);
  1799. });
  1800. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  1801. });
  1802. }, 100);
  1803. getChecked();
  1804. });
  1805. $scope.onItemClick = function (resource) {
  1806. if (resource.items.length > 0) {
  1807. $scope.resourceItems = resource.items;
  1808. $scope.activeResource = resource;
  1809. } else {
  1810. $scope.resourceItems = [];
  1811. if (!resource.activeLevel) {
  1812. resource.activeLevel = true;
  1813. } else {
  1814. resource.activeLevel = false;
  1815. }
  1816. }
  1817. setNoActive($scope.resources);
  1818. resource.$active = true;
  1819. };
  1820. var setNoActive = function (obj) {
  1821. angular.forEach(obj, function (r) {
  1822. r.$active = false;
  1823. if (r.children) {
  1824. setNoActive(r.children);
  1825. }
  1826. });
  1827. }
  1828. var getChecked = function () {
  1829. var items = [];
  1830. angular.forEach($scope.resources, function (resource) {
  1831. pushCheckedResource(resource, items);
  1832. });
  1833. if ($scope.role) {
  1834. $scope.role.resourceItems = items;
  1835. }
  1836. };
  1837. var pushCheckedResource = function (resource, items) {
  1838. if (resource.items.length > 0) {
  1839. var activeCount = 0;
  1840. angular.forEach(resource.items, function (item) {
  1841. // item.$checked && items.push(item);
  1842. if (item.$checked) {
  1843. items.push(item);
  1844. activeCount ++;
  1845. }
  1846. });
  1847. resource.$checked = activeCount > 0 && activeCount == resource.items.length;
  1848. resource.$halfChecked = activeCount > 0 && activeCount < resource.items.length;
  1849. } else {
  1850. var halfCount = 0;
  1851. var fullCount = 0;
  1852. angular.forEach(resource.children, function (item) {
  1853. if (item.$checked) {
  1854. fullCount ++;
  1855. } else if (item.$halfChecked) {
  1856. halfCount ++;
  1857. }
  1858. pushCheckedResource(item, items);
  1859. })
  1860. resource.$halfChecked = halfCount > 0 || (fullCount > 0 && fullCount < resource.children.length);
  1861. resource.$checked = fullCount > 0 && fullCount == resource.children.length;
  1862. }
  1863. }
  1864. $scope.onResourceChange = function (resource) {
  1865. levelResourceChecked(resource);
  1866. getChecked();
  1867. };
  1868. var levelResourceChecked = function (resource) {
  1869. if (resource.items.length > 0) {
  1870. angular.forEach(resource.items, function (item) {
  1871. item.$checked = resource.$checked;
  1872. });
  1873. } else {
  1874. angular.forEach(resource.children, function (item) {
  1875. item.$checked = resource.$checked;
  1876. levelResourceChecked(item);
  1877. });
  1878. }
  1879. }
  1880. $scope.onItemChange = function () {
  1881. var activeCount = 0;
  1882. var resourceItems = $scope.resourceItems;
  1883. // debugger;
  1884. // console.log(resourceItems);
  1885. angular.forEach(resourceItems, function (item) {
  1886. if (item.$checked) {
  1887. activeCount++;
  1888. }
  1889. })
  1890. // console.log(activeCount);
  1891. // console.log( $scope.activeResource)
  1892. $scope.activeResource.$checked = activeCount == resourceItems.length;
  1893. $scope.activeResource.$halfChecked = activeCount > 0 && activeCount < resourceItems.length;
  1894. angular.forEach($scope.resources, function (resource) {
  1895. if (resource.$active) {
  1896. var c = 0;
  1897. angular.forEach(resource.items, function (item) {
  1898. item.$checked && (c += 1);
  1899. });
  1900. resource.$checked = (c == resource.items.length);
  1901. resource.$halfChecked = c > 0 && c < resource.items.length;
  1902. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  1903. }
  1904. });
  1905. getChecked();
  1906. };
  1907. $scope.isChanged = function (formData) {
  1908. if (!$scope.master)
  1909. return true;
  1910. return !angular.equals(formData, $scope.master);
  1911. };
  1912. $scope.save = function () {
  1913. $scope.master = angular.copy($scope.role);
  1914. if (!$scope.master.color || $scope.master.color == '') {
  1915. $scope.master.color = parseInt(Math.random() * 5) + 1 + '';
  1916. }
  1917. AccountRole.save($scope.master, function () {
  1918. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加' : '修改') + '成功');
  1919. $modalInstance.close(true);
  1920. }, function (response) {
  1921. toaster.pop('error', '错误', response.data);
  1922. });
  1923. };
  1924. $scope.del = function () {
  1925. if (confirm('确定删除角色(' + $scope.role.desc + ')吗?')) {
  1926. AccountRole.remove({id: role.id}, function () {
  1927. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  1928. $modalInstance.close(true);
  1929. }, function (response) {
  1930. toaster.pop('error', '错误', response.data);
  1931. });
  1932. }
  1933. };
  1934. }]);
  1935. app.register.controller('UserRoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'toaster', 'user', 'BaseService', 'AccountRole', 'User', function ($scope, $modalInstance, $timeout, AccountResource, toaster, user, BaseService, AccountRole, User) {
  1936. $scope.pages = [];
  1937. $scope.params = {
  1938. page: 1,
  1939. count: 6,
  1940. totalPage: 1,
  1941. currentPage: 1
  1942. };
  1943. var loadCurrentRoles = function () {
  1944. var start = ($scope.params.page - 1) * $scope.params.count;
  1945. var end = $scope.params.page * $scope.params.count;
  1946. $scope.currentRoles = $scope.rolesData.slice(start, end);
  1947. };
  1948. var init = function () {
  1949. $scope.user = angular.copy(user);
  1950. AccountRole.query({}, function (data) {
  1951. $scope.rolesData = data;
  1952. loadCurrentRoles();
  1953. $scope.params.totalPage = Math.ceil($scope.rolesData.length / 6);
  1954. $scope.acculatePages(1, $scope.params.totalPage);
  1955. angular.forEach($scope.rolesData, function (item) {
  1956. item.checked = false;
  1957. angular.forEach($scope.user.roles, function (userItem) {
  1958. if (item.id === userItem.id) {
  1959. item.checked = true;
  1960. }
  1961. });
  1962. });
  1963. });
  1964. }
  1965. init();
  1966. $scope.checked = [];
  1967. //勾选角色
  1968. $scope.checkRole = function (role) {
  1969. role.checked = !role.checked;
  1970. }
  1971. //关闭模态框
  1972. $scope.cancelModal = function () {
  1973. $modalInstance.close();
  1974. }
  1975. $scope.close = function (save) {
  1976. if (save) {
  1977. if (user.userUU) {
  1978. angular.forEach($scope.rolesData, function (item) {
  1979. if (item.checked) {
  1980. $scope.checked.push(item);
  1981. }
  1982. });
  1983. $scope.user.roles = $scope.checked;
  1984. User.update({}, $scope.user, function () {
  1985. toaster.pop('success', '提示', '保存成功');
  1986. user.roles = $scope.checked
  1987. $modalInstance.close(true);
  1988. }, function (response) {
  1989. toaster.pop('error', '保存失败', response.data);
  1990. });
  1991. } else {
  1992. $modalInstance.close(true, $scope.checked);
  1993. }
  1994. } else {
  1995. $modalInstance.close(false);
  1996. }
  1997. };
  1998. // //初始化分页数据
  1999. // var initPages = function () {
  2000. // $scope.totalPages = Math.ceil = ($scope.rolesData.length/6);
  2001. // }
  2002. //初始化页数信息
  2003. $scope.initPages = function (totalElementPages) {
  2004. var pageNum = [];
  2005. if (totalElementPages == 1) {
  2006. return;
  2007. } else if (totalElementPages < 10) {
  2008. for (var i = 0; i < totalElementPages + 2; i++) {
  2009. pageNum.push(i);
  2010. }
  2011. } else {
  2012. pageNum = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  2013. }
  2014. angular.forEach(pageNum, function (number) {
  2015. var page = {active: true, type: 'page', number: number};
  2016. if (number == 0) {
  2017. page.type = 'prev';
  2018. } else if (number == 1) {
  2019. page.type = 'first';
  2020. } else if (number == pageNum.length - 2) {
  2021. page.type = 'last';
  2022. page.number = totalElementPages;
  2023. } else if (number == pageNum.length - 1) {
  2024. page.type = 'next';
  2025. }
  2026. $scope.pages.push(page);
  2027. });
  2028. };
  2029. //当前页在后端计算方式
  2030. $scope.endSegment = function (currentPage, totalElementPages) {
  2031. if (totalElementPages > 8) {
  2032. angular.forEach($scope.pages, function (page) {
  2033. switch (page.number) {
  2034. case 2:
  2035. page.active = false;
  2036. page.type = 'more';
  2037. break;
  2038. case 10:
  2039. if (currentPage == totalElementPages) {
  2040. page.active = false;
  2041. }
  2042. break;
  2043. case 0:
  2044. case 1:
  2045. break;
  2046. default:
  2047. if (page.number != totalElementPages) {
  2048. page.number = totalElementPages - 9 + page.number;
  2049. }
  2050. page.current = (currentPage == page.number);
  2051. break;
  2052. }
  2053. });
  2054. }
  2055. };
  2056. //当前页在中间计算方式
  2057. $scope.middleSegment = function (currentPage) {
  2058. angular.forEach($scope.pages, function (page) {
  2059. switch (page.number) {
  2060. case 2:
  2061. case 8:
  2062. page.type = 'more';
  2063. page.active = false;
  2064. break;
  2065. case 3:
  2066. page.number = currentPage - 2;
  2067. break;
  2068. case 4:
  2069. page.number = currentPage - 1;
  2070. break;
  2071. case 5:
  2072. page.number = currentPage;
  2073. page.current = true;
  2074. break;
  2075. case 6:
  2076. page.number = currentPage + 1;
  2077. break;
  2078. case 7:
  2079. page.number = currentPage + 2;
  2080. break;
  2081. }
  2082. });
  2083. };
  2084. //当前页在前段的计算方式
  2085. $scope.frontSegment = function (currentPage, totalElementPages) {
  2086. if (totalElementPages > 8) {
  2087. angular.forEach($scope.pages, function (page) {
  2088. switch (page.number) {
  2089. case 8:
  2090. page.type = 'more';
  2091. page.active = false;
  2092. break;
  2093. case 0:
  2094. if (currentPage == 1) {
  2095. page.active = false;
  2096. }
  2097. default : {
  2098. page.current = (currentPage == page.number);
  2099. }
  2100. }
  2101. });
  2102. }
  2103. };
  2104. //输入框监听Enter事件
  2105. $scope.listenEnter = function () {
  2106. if (event.keyCode == 13) {
  2107. $scope.setPage("page", $scope.params.currentPage);
  2108. }
  2109. };
  2110. $scope.setPage = function (type, number) {
  2111. if (type != 'prev' && type != 'page' && type != 'next' && type != 'last' && type != 'first') {
  2112. return;
  2113. }
  2114. ;
  2115. var page = -1;
  2116. switch (type) {
  2117. case "page":
  2118. if (number < 1) {
  2119. page = 1;
  2120. } else if (number > $scope.params.totalPage) {
  2121. page = $scope.params.totalPage;
  2122. } else {
  2123. page = number;
  2124. }
  2125. ;
  2126. break;
  2127. case "prev":
  2128. if ($scope.params.page <= 1) {
  2129. page = 1;
  2130. } else {
  2131. page = $scope.params.page - 1;
  2132. }
  2133. ;
  2134. break;
  2135. case "next":
  2136. if ($scope.params.page >= $scope.params.totalPage) {
  2137. page = $scope.params.totalPage;
  2138. } else {
  2139. page = $scope.params.page + 1;
  2140. }
  2141. break;
  2142. case "first":
  2143. page = 1;
  2144. break;
  2145. case "last":
  2146. page = $scope.params.totalPage;
  2147. break;
  2148. }
  2149. if (page == $scope.params.page || page < 1 || page > $scope.params.totalPage) {
  2150. $scope.params.currentPage = $scope.params.page;
  2151. return;
  2152. }
  2153. $scope.params.page = page;
  2154. $scope.params.currentPage = page;
  2155. loadData();
  2156. };
  2157. //计算页数的方式。
  2158. $scope.acculatePages = function (currentPage, totalElementPages) {
  2159. $scope.pages = [];
  2160. if (totalElementPages < 1) {
  2161. return;
  2162. }
  2163. //初始化页面数据
  2164. $scope.initPages(totalElementPages);
  2165. if (currentPage < 6) {//当期页小于6
  2166. $scope.frontSegment(currentPage, totalElementPages);
  2167. } else if (currentPage > totalElementPages - 5) { //当期页在后面
  2168. $scope.endSegment(currentPage, totalElementPages);
  2169. } else { //当期页在中间
  2170. $scope.middleSegment(currentPage);
  2171. }
  2172. };
  2173. var loadData = function () {
  2174. loadCurrentRoles();
  2175. $scope.acculatePages($scope.params.page, $scope.params.totalPage);
  2176. };
  2177. }]);
  2178. });