securitySetCtrl.js 89 KB

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