controllers.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. starter.controller('AccountManageCtrl', function ($scope, global, showPopup, CompManage) {
  2. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  3. $scope.show = {
  4. isshow: false
  5. };
  6. global.fetch_user().then(function (data) {
  7. $scope.is_showcurrent = (global.user.compno != null);
  8. if (global.user.token != "") {
  9. CompManage.get_Compdata().then(function (data) {
  10. data = _.filter(data, function (item) {
  11. return item.usr_status == 2;
  12. });
  13. if (data.length > 0) {
  14. _.each(data, function (c) {
  15. c.check = false;
  16. if (c.id == global.user.compno) {
  17. $scope.currentcomp = c;
  18. c.check = true;
  19. }
  20. });
  21. }
  22. $scope.compdata = data;
  23. }, function (err) {
  24. $scope.is_showcurrent = false;
  25. alert(JSON.stringify(err))
  26. });
  27. } else {
  28. $scope.compdata = [];
  29. }
  30. });
  31. });
  32. $scope.change = function (comp) {
  33. if ($scope.compdata.length > 0) {
  34. if ($scope.currentcomp != comp) {
  35. showPopup.showLoading(1, '', false);
  36. var password = global.user.password;
  37. CompManage.post_authcheck(global.user.im_usrid, comp.id).then(function (data) {
  38. $scope.currentcomp = comp;
  39. $scope.show.isshow = false;
  40. _.each($scope.compdata, function (_comp) {
  41. if (comp.id != _comp.id) {
  42. _comp.check = false;
  43. }
  44. });
  45. global.user = data;
  46. global.user.password = password;
  47. CompManage.store_user().then(function (data) {
  48. console.log(data);
  49. showPopup.hideLoading();
  50. }, function (error) {
  51. showPopup.hideLoading();
  52. console.log('store error:' + JSON.stringify(error));
  53. });
  54. }, function (error) {
  55. showPopup.hideLoading();
  56. alert(JSON.stringify(error));
  57. });
  58. }
  59. }
  60. };
  61. $scope.goBack = function () {
  62. global.goBack();
  63. };
  64. $scope.showcomplist = function () {
  65. if ($scope.compdata.length > 0) $scope.show.isshow = !$scope.show.isshow;
  66. }
  67. })
  68. .controller('ManageCompCtrl', function ($scope, $state, $ionicPopup, $rootScope, $ionicHistory, $q, $location, $window, global, ImageManage, showPopup, CompManage) {
  69. $scope.newcompname = {
  70. "compname": ""
  71. };
  72. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  73. $scope.loading = ($scope.compdata == undefined);
  74. global.fetch_user().then(function (data) {
  75. if (global.user.token != "") {
  76. getmycomplist();
  77. } else {
  78. $scope.compdata = [];
  79. $scope.loading = false;
  80. }
  81. $scope.popup = {
  82. isSetPopup: false
  83. };
  84. });
  85. });
  86. $scope.tocompinfo = function (compid, op) {
  87. $state.go('compinfo', {
  88. 'compid': compid,
  89. 'op': op
  90. });
  91. };
  92. $scope.showaddcompmodel = function () {
  93. showPopup.modalTemplate('templates/createcomp-modaltemplate.html', 'slide-in-right', $scope).then(function (modal) {
  94. $rootScope.commons.modal = modal;
  95. $rootScope.commons.modal.show();
  96. });
  97. };
  98. $scope.cancel = function () {
  99. $rootScope.commons.modal.hide();
  100. $scope.logourl = '../../../img/logo.png';
  101. };
  102. $scope.createcomp = function () {
  103. var newcompdata = {"compname": "", "cellphone": global.user.cellphone, "username": "", "imid": "", "password": global.user.password};
  104. newcompdata.username = global.user.usrname;
  105. newcompdata.compname = $scope.newcompname.compname;
  106. newcompdata.imid = global.user.im_usrid;
  107. showPopup.showLoading(1, '正在提交', true, $scope.logourl != "../../../img/logo.png" ? 20000 : 10000);
  108. CompManage.post_Register(newcompdata).then(function (compdata) {
  109. if ($scope.logourl != "../../../img/logo.png") {
  110. if (global.user.token == "") {
  111. var password = global.user.password;
  112. CompManage.post_authcheck(global.user.im_usrid, compdata.compid).then(function (data) {
  113. global.user = data;
  114. global.user.password = password;
  115. uploadcomplogo(compdata);
  116. CompManage.store_user().then(function () {
  117. }, function (error) {
  118. showPopup.hideLoading();
  119. console.log('store error:' + JSON.stringify(error));
  120. });
  121. }, function (err) {
  122. showPopup.hideLoading();
  123. alert('post_authcheck error:' + JSON.stringify(err))
  124. });
  125. } else {
  126. uploadcomplogo(compdata)
  127. }
  128. } else {
  129. get_authcheckInfo(compdata.compid);
  130. }
  131. }, function (e) {
  132. showPopup.hideLoading();
  133. if (_.has(e.data, 'msg')) showPopup.PopupWindow(0, e.data.msg, false, 2000);
  134. else alert(JSON.stringify(e));
  135. });
  136. };
  137. $scope.$on('$destroy', function () {
  138. if ($rootScope.commons.modal != null) {
  139. $rootScope.commons.modal.remove();
  140. }
  141. beforeEnter = null;
  142. });
  143. $scope.logourl = '../../../img/logo.png';
  144. $scope.editlogo = function () {
  145. $scope.popup.optionsPopup = showPopup.showSelectImgPopup(Camera, ImagePicker, $scope);
  146. $scope.popup.isSetPopup = true;
  147. };
  148. $scope.import = function () {
  149. $window.location.href = "http://" + $window.location.host + "/apps/compmanage/index.html#/index";
  150. // $location.url('http://192.168.1.5:8101/apps/compmanage/index.html#/index');
  151. };
  152. function uploadcomplogo(comp) {
  153. ImageManage.uploadImage($scope.logourl, 'comp', comp.compid, 'complogo').then(function (res) {
  154. $q.all(res).then(function (res1) {
  155. get_authcheckInfo(comp.id);
  156. }, function (error) {
  157. showPopup.hideLoading();
  158. alert('upload error:' + JSON.stringify(error));
  159. });
  160. }, function (err) {
  161. showPopup.hideLoading();
  162. alert('upload token error:' + JSON.stringify(err));
  163. });
  164. }
  165. function get_authcheckInfo(compid) {
  166. if (global.user.token == '') {
  167. var password = global.user.password;
  168. CompManage.post_authcheck(global.user.im_usrid, compid).then(function (data) {
  169. global.user = data;
  170. global.user.password = password;
  171. getmycomplist();
  172. CompManage.store_user().then(function (data) {
  173. console.log(data);
  174. $ionicHistory.goBack();
  175. showPopup.hideLoading();
  176. }, function (error) {
  177. showPopup.hideLoading();
  178. console.log('store error:' + JSON.stringify(error));
  179. });
  180. }, function (err) {
  181. showPopup.hideLoading();
  182. alert('post_authcheck error:' + JSON.stringify(err))
  183. });
  184. } else {
  185. showPopup.hideLoading();
  186. if ($rootScope.commons.modal != null) $rootScope.commons.modal.hide();
  187. getmycomplist();
  188. }
  189. }
  190. function getmycomplist() {
  191. CompManage.get_Compdata().then(function (data) {
  192. _.each(data, function (comp) {
  193. if (comp.file_thumbnail_path == null) {
  194. comp.file_thumbnail_path = $scope.logourl;
  195. }
  196. var admin = _.find(comp.compadmin, function (adminitem) {
  197. return adminitem.user_id == global.user.usrid;
  198. });
  199. comp.op = admin == undefined ? 0 : 1;
  200. comp.compadmins = _.pluck(comp.compadmin, 'username').join(',');
  201. });
  202. $scope.compdata = _.sortBy(data, 'op').reverse();
  203. $scope.loading = false;
  204. $scope.newcompname.compname = "";
  205. $scope.logourl = "../../../img/logo.png"
  206. }, function (err) {
  207. $scope.loading = false;
  208. alert(JSON.stringify(err));
  209. });
  210. }
  211. var ImagePicker = function () { //打开相册
  212. $scope.popup.optionsPopup.close();
  213. ImageManage.ImagePicker_getPictures(1).then(function (results) {
  214. if (results.length == 0) return;
  215. $q.all(results).then(function (res) {
  216. $scope.logourl = res[0];
  217. })
  218. });
  219. };
  220. var Camera = function () {
  221. $scope.popup.optionsPopup.close();
  222. ImageManage.Camera_getPicture(true).then(function (result) {
  223. $scope.logourl = result;
  224. });
  225. };
  226. })
  227. .controller('JoinCompCtrl', function ($scope, $ionicHistory, $timeout, CompManage, global, showPopup) {
  228. $scope.data = {
  229. "compid": ""
  230. };
  231. var compdata = _.pick(global.user, 'cellphone', 'password');
  232. compdata.username = global.user.usrname;
  233. compdata.imid = global.user.im_usrid;
  234. $scope.addedcomp = {};
  235. $scope.is_show_jointip = false;
  236. $scope.joincomp = function () {
  237. var complist = CompManage.getComplist();
  238. var comp = _.findWhere(complist, {'id': $scope.data.compid});
  239. compdata.compid = $scope.data.compid;
  240. if (comp == undefined) { //未加入过
  241. showPopup.showLoading(1, '正在提交', true);
  242. CompManage.post_Joinin(compdata).then(function (res) {
  243. showPopup.hideLoading();
  244. if (res.status == 201)
  245. $scope.is_show_jointip = true;
  246. else
  247. showPopup.PopupWindow(0, res.msg, false, 2000);
  248. $timeout(function () {
  249. $scope.is_show_jointip = false;
  250. }, 5000);
  251. }, function (e) {
  252. showPopup.hideLoading();
  253. if (_.has(e.data, 'msg')) showPopup.PopupWindow(0, e.data.msg, false, 2000);
  254. else alert(JSON.stringify(e));
  255. });
  256. } else {
  257. if (comp.file_thumbnail_path == "") {
  258. comp.file_thumbnail_path = '../../../img/logo.png'
  259. }
  260. showPopup.PopupWindow(0, '你已加入该公司!', false, 2000);
  261. $scope.addedcomp = comp;
  262. }
  263. };
  264. })
  265. .controller('CompInfoCtrl', function ($scope, $ionicPopup, $state, $ionicHistory, $q, showPopup, ImageManage, CompManage, global) {
  266. var compid = $state.params['compid'];
  267. $scope.op = $state.params['op'];
  268. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  269. var compdata = CompManage.getComplist();
  270. $scope.rdata = _.find(compdata, function (comp) {
  271. return comp.id == $state.params['compid'];
  272. });
  273. console.log($scope.rdata);
  274. $scope.data = _.clone($scope.rdata);
  275. $scope.popup = {
  276. isPopup: false
  277. };
  278. });
  279. $scope.$on("$destroy", function () {
  280. beforeEnter = null;
  281. });
  282. $scope.selectphoto = function () {
  283. if ($scope.op == 0) {
  284. return;
  285. }
  286. $scope.popup.optionsPopup = showPopup.showSelectImgPopup(Camera, ImagePicker, $scope);
  287. $scope.popup.isPopup = true;
  288. };
  289. $scope.disbandcomp = function () {
  290. showPopup.confirm('确定解散公司吗?', '确定', '取消').then(function (res) {
  291. if (res) {
  292. //解散
  293. showPopup.showLoading(1, '', false);
  294. CompManage.dismiss_comp($scope.data.id).then(function () {
  295. CheckComp();
  296. // alert('dismiss_comp success')
  297. }, function (error) {
  298. showPopup.hideLoading();
  299. alert('error disbandcomp:' + JSON.stringify(error));
  300. });
  301. }
  302. })
  303. };
  304. $scope.leavecomp = function () {
  305. showPopup.confirm('确定退出公司吗?', '确定', '取消').then(function (res) {
  306. if (res) {
  307. if ($scope.op == 1) { //admin
  308. if ($scope.rdata.compadmin.length > 1) { //admin count>=2
  309. //退出
  310. showPopup.showLoading(1, '', false);
  311. CompManage.leave_comp($scope.data.id).then(function () {
  312. CheckComp();
  313. }, function (error) {
  314. showPopup.hideLoading();
  315. alert('error leavecomp:' + JSON.stringify(error));
  316. })
  317. } else {
  318. showPopup.PopupWindow(0, '你是该公司唯一的管理员不允许退出!', false);
  319. }
  320. } else {
  321. //退出
  322. showPopup.showLoading(1, '', false, 20000);
  323. CompManage.leave_comp($scope.data.id).then(function () {
  324. CheckComp();
  325. }, function (error) {
  326. showPopup.hideLoading();
  327. alert('error leavecomp:' + JSON.stringify(error));
  328. });
  329. }
  330. }
  331. })
  332. };
  333. $scope.showeditpopup = function () {
  334. if ($scope.op == 0) {
  335. return;
  336. }
  337. $scope.editdata = _.clone($scope.data);
  338. var myPopup = $ionicPopup.show({
  339. template: '<div class="popup-edit-comp" ><input type="text" ng-model="editdata.name" ><label ></label></div>',
  340. title: '<div><h5>修改公司名称</h5></div>',
  341. scope: $scope,
  342. buttons: [{
  343. text: '取消',
  344. onTap: function () {
  345. return false;
  346. }
  347. }, {
  348. text: '<b>保存</b>',
  349. type: 'button-positive',
  350. onTap: function (e) {
  351. if (!$scope.editdata.name) {
  352. e.preventDefault();
  353. } else {
  354. return true;
  355. }
  356. }
  357. }]
  358. });
  359. myPopup.then(function (res) {
  360. if (res) {
  361. // alert('editComp');
  362. if ($scope.editdata.name != $scope.data.name) {
  363. CompManage.editComp($scope.editdata).then(function (data) {
  364. $scope.data.name = $scope.editdata.name;
  365. // alert(1);
  366. }, function (err) {
  367. alert('Error:' + JSON.stringify(err));
  368. });
  369. }
  370. }
  371. });
  372. };
  373. $scope.image_list = [];
  374. var ImagePicker = function () { //打开相册
  375. $scope.popup.optionsPopup.close();
  376. ImageManage.ImagePicker_getPictures(1).then(function (results) {
  377. if (results.length == 0) return;
  378. $q.all(results).then(function (res) {
  379. uploadimage(res[0]);
  380. })
  381. });
  382. };
  383. var Camera = function () {
  384. $scope.popup.optionsPopup.close();
  385. ImageManage.Camera_getPicture(true).then(function (result) {
  386. uploadimage(result);
  387. });
  388. };
  389. function CheckComp() {
  390. var compdata = CompManage.getComplist();
  391. compdata.splice(_.findIndex(compdata, {'id': $scope.data.id}), 1);
  392. if (compdata.length > 0 && global.user.compno == $scope.data.id) { //退出/解散当前登录的公司
  393. var comp = compdata[0];
  394. var password = global.user.password;
  395. CompManage.post_authcheck(global.user.im_usrid, comp.id).then(function (data) {
  396. global.user = data;
  397. global.user.password = password;
  398. showPopup.hideLoading();
  399. $ionicHistory.goBack();
  400. CompManage.store_user().then(function (data) {
  401. console.log(data);
  402. }, function (error) {
  403. console.log('store error:' + JSON.stringify(error));
  404. });
  405. });
  406. } else if (compdata.length == 0) { //用户没有公司时
  407. global.user.token = "";
  408. global.user.compno = "";
  409. global.user.compname = "";
  410. global.user.deptno = "";
  411. global.user.deptname = "";
  412. global.user.roleid = "";
  413. showPopup.hideLoading();
  414. $ionicHistory.goBack();
  415. CompManage.store_user().then(function (data) {
  416. console.log(JSON.stringify(data));
  417. }, function (error) {
  418. console.log('store error:' + JSON.stringify(error));
  419. });
  420. } else {
  421. showPopup.hideLoading();
  422. $ionicHistory.goBack();
  423. }
  424. }
  425. function uploadimage(result) {
  426. showPopup.showLoading(1, '', false, 20000);
  427. ImageManage.uploadImage(result, 'comp', $scope.data.id, 'complogo').then(function (res) {
  428. $q.all(res).then(function (res1) {
  429. showPopup.hideLoading();
  430. $scope.data.file_thumbnail_path = JSON.parse(res1[0].response).file_thumbnail_path;
  431. }, function (error) {
  432. showPopup.hideLoading();
  433. alert('upload error:' + JSON.stringify(error));
  434. })
  435. }, function (error) {
  436. alert('get token error:' + JSON.stringify(error));
  437. showPopup.hideLoading();
  438. });
  439. }
  440. })
  441. .controller('ApplyCheckCtrl', function ($scope, $ionicPlatform, $cordovaPreferences, $location, global, CompManage, showPopup) {
  442. var compid = $location.search().compid;
  443. global.fetch_user().then(function (data) {
  444. getAuditUsers();
  445. }, function (error) {
  446. alert(JSON.stringify(error));
  447. });
  448. $scope.check = function (user, op) { //todo:y=0;n=1
  449. // alert(JSON.stringify($scope.audituserlst))
  450. showPopup.showLoading(1, '正在提交', false);
  451. CompManage.auditUser(user, op, compid).then(function (data) {
  452. showPopup.hideLoading();
  453. $scope.audituserlst.splice(_.indexOf($scope.audituserlst, user), 1);
  454. }, function (err) {
  455. showPopup.hideLoading();
  456. alert(JSON.stringify(err));
  457. });
  458. };
  459. $scope.doRefresh = function () {
  460. getAuditUsers();
  461. };
  462. $scope.goBack = function () {
  463. global.goBack();
  464. }
  465. function getAuditUsers() {
  466. if (global.user.token != "") {
  467. CompManage.getUserAuditstatus(1, compid).then(function (data) {
  468. $scope.audituserlst = data;
  469. }, function (err) {
  470. alert(JSON.stringify(err));
  471. }).finally(function () {
  472. $scope.$broadcast('scroll.refreshComplete');
  473. });
  474. }
  475. }
  476. })
  477. .controller('ContactsCompanylstCtrl', function ($scope, $cordovaPreferences, $ionicPlatform, $state, global, Dept, CompManage) {
  478. $scope.complistdata = [];
  479. $scope.logourl = '../../../img/logo.png';
  480. $scope.loading = true;
  481. var beforeEnter = $scope.$on('$ionicView.beforeEnter', function () {
  482. Dept.setdeptlst([]);
  483. // alert(Dept.all().length);
  484. });
  485. $scope.init = function () {
  486. global.fetch_user().then(function (data) {
  487. if (global.user.token != "") {
  488. CompManage.get_Compdata().then(function (data) {
  489. // alert(JSON.stringify(data));
  490. _.each(data, function (c) {
  491. if (c.file_thumbnail_path == null) {
  492. c.file_thumbnail_path = $scope.logourl;
  493. }
  494. })
  495. $scope.complistdata = data;
  496. $scope.loading = false;
  497. });
  498. } else {
  499. $scope.loading = false;
  500. }
  501. }, function (error) {
  502. $scope.loading = false;
  503. alert(JSON.stringify(error));
  504. });
  505. };
  506. $scope.goBack = function () {
  507. global.goBack();
  508. }
  509. $scope.tocompuser = function (compid, compname) {
  510. $state.go('deptlst', {
  511. id: -1,
  512. name: compname,
  513. compid: compid
  514. })
  515. };
  516. function getcompdata() {
  517. if (global.user.token != "") {
  518. CompManage.get_Compdata().then(function (data) {
  519. $scope.complistdata = data;
  520. });
  521. }
  522. }
  523. })
  524. .controller('DeptCtrl', function ($scope, $state, $http, $stateParams, Dept, $ionicViewSwitcher) {
  525. $scope.deptlst = [];
  526. $scope.emplst = [];
  527. $scope.titleName = '';
  528. $scope.checked = false;
  529. $scope.titleName = $stateParams.name;
  530. $scope.deptid = -1;
  531. $scope.$on('$ionicView.beforeEnter', function () {
  532. $scope.deptid = setdeptid();
  533. if (Dept.all().length == 0) {
  534. $scope.loading = true;
  535. Dept.getDep($stateParams.compid).then(function (data) {
  536. $scope.deptid = setdeptid();
  537. data = _.filter(data, function (item) {
  538. return item.parent == $scope.deptid;
  539. });
  540. $scope.dept_data = data;
  541. $scope.deptlst = data;
  542. getemp();
  543. }, function (err) {
  544. $scope.loading = false;
  545. });
  546. } else {
  547. $scope.loading = false;
  548. var data = Dept.getChildDept($scope.deptid);
  549. $scope.dept_data = data;
  550. $scope.deptlst = data;
  551. getemp();
  552. }
  553. });
  554. function setdeptid() {
  555. var deptid = parseInt($stateParams.id);
  556. if (Dept.all().length > 0) {
  557. if (deptid < 0) {
  558. deptid = _.find(Dept.all(), function (item) {
  559. return item.level == 0
  560. }).id;
  561. }
  562. }
  563. return deptid;
  564. }
  565. function getemp() {
  566. Dept.getEmp($scope.deptid, $stateParams.compid).then(function (data) {
  567. console.log('user json:' + JSON.stringify(data));
  568. $scope.emplst = data;
  569. $scope.loading = false;
  570. }, function (err) {
  571. $scope.loading = false;
  572. alert(JSON.stringify(err));
  573. });
  574. }
  575. $scope.deptdisplay = function () {
  576. if ($scope.deptlst.length > 0) {
  577. return true;
  578. } else {
  579. return false;
  580. }
  581. };
  582. $scope.empdisplay = function () {
  583. if ($scope.emplst.length > 0) {
  584. return true;
  585. } else {
  586. return false;
  587. }
  588. };
  589. $scope.search = function () {
  590. $state.go('search');
  591. };
  592. $scope.editDep = function () {
  593. $state.go('editDep', {
  594. id: $scope.deptid,
  595. compid: $stateParams.compid,
  596. name: $stateParams.name
  597. });
  598. $ionicViewSwitcher.nextDirection("back");
  599. };
  600. $scope.cancel = function () {
  601. $state.go('addGroup2');
  602. };
  603. $scope.lookMsg = function (im_id, name, cellphone) {
  604. var data = {
  605. 'im_id': im_id,
  606. 'name': name,
  607. 'cellphone': cellphone
  608. }
  609. console.log(data)
  610. if (window.cordovaLinker != undefined) {
  611. window.cordovaLinker.startChat(data, function (s) {
  612. console.log(s);
  613. }, function (err) {
  614. console.error(err);
  615. });
  616. }
  617. };
  618. $scope.todept = function (dept) {
  619. $state.go('deptlst', {id: dept.id, name: dept.depname, compid: $stateParams.compid})
  620. };
  621. })
  622. .controller('EditDepCtrl', function ($scope, $ionicPopup, $stateParams, $timeout, $ionicHistory, Dept, showPopup, Tool) {
  623. $scope.deptlst = [];
  624. $scope.titleName = $stateParams.name;
  625. var del_deptids = [];
  626. var dept_data = [];
  627. var compid = $stateParams.compid;
  628. var beforeenter = $scope.$on('$ionicView.beforeEnter', function () {
  629. $scope.deptlst = angular.copy(Dept.getChildDept($stateParams.id));
  630. dept_data = angular.copy($scope.deptlst);
  631. });
  632. $scope.add = function () {
  633. $timeout(function () {
  634. $scope.deptlst.push({
  635. depname: '',
  636. parent_id: $stateParams.id
  637. })
  638. })
  639. };
  640. $scope.remove = function (dept, index) {
  641. if (_.has(dept, 'id')) del_deptids.push(dept.id);
  642. $scope.deptlst.splice(index, 1);
  643. };
  644. $scope.save = function () {
  645. var deptlst = _.filter($scope.deptlst, function (dep) {
  646. return Tool.trim(dep.depname).length > 0;
  647. });
  648. if (deptlst.length > _.uniq(_.pluck(deptlst, 'depname')).length) {
  649. showPopup.PopupWindow(0, '名称不能重复!', false);
  650. return;
  651. }
  652. var depts = _.partition(deptlst, 'id');
  653. var up_depts = _.map(_.difference(_.map(depts[0], JSON.stringify), _.map(dept_data, JSON.stringify)), JSON.parse);
  654. var add_depts = depts[1];
  655. if (del_deptids.length > 0 || add_depts.length > 0 || up_depts.length > 0) {
  656. showPopup.showLoading(1, '', false);
  657. $scope.isdisabled_ok = true;
  658. Dept.save(up_depts, del_deptids, add_depts, compid).then(function (data) {
  659. Dept.setdeptlst([]);
  660. $ionicHistory.goBack();
  661. }, function (err) {
  662. console.log(err);
  663. }).finally(function (f) {
  664. showPopup.hideLoading();
  665. $scope.isdisabled_ok = false;
  666. }); //修改、删除、添加;
  667. }
  668. };
  669. $scope.cancel = function () {
  670. if (JSON.stringify($scope.deptlst) != JSON.stringify(dept_data)) {
  671. showPopup.confirm('是否退出编辑?', '是', '否').then(function (res) {
  672. if (res) {
  673. $ionicHistory.goBack();
  674. }
  675. });
  676. } else $ionicHistory.goBack();
  677. };
  678. })
  679. .controller('PersonInfoCtrl', function ($scope, $state, $rootScope, $ionicPopup, $ionicModal, $q, $timeout, $ionicHistory, formatFilter, Dept, showPopup, global, ImageManage, Member) {
  680. $scope.personinfo = {value: ''};
  681. $scope.selectdatas = [{
  682. name: '女',
  683. id: 0
  684. }, {
  685. name: '男',
  686. id: 1
  687. }];
  688. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  689. global.fetch_user().then(function (data) {
  690. $scope.loading = $scope.userinfo == undefined;
  691. Dept.getUsrDetail().then(function (data) {
  692. $scope.userinfo = angular.copy(data);
  693. $scope.userinfo.photo = data.photo == null ? '../../../img/panda.png' : data.photo;
  694. $scope.userinfo.compname = global.user.compname;
  695. $scope.userinfo.compno = global.user.compno;
  696. $scope.loading = false;
  697. }, function (err) {
  698. alert(JSON.stringify(err))
  699. });
  700. });
  701. $scope.popup = {
  702. isPopup: false,
  703. optionsPopup: null
  704. };
  705. });
  706. $scope.selectimg = function () {
  707. $scope.popup.optionsPopup = showPopup.showSelectImgPopup(Camera, ImagePicker, $scope);
  708. $scope.popup.isPopup = true;
  709. };
  710. $scope.editInfo = function (title, input_type, field_name, value) {
  711. $scope.userinfo[field_name] = value == undefined ? '' : value;
  712. $scope.personinfo.value = value == undefined ? '' : value;
  713. var template = formatFilter('<div rj-close-back-drop><label class="item item-input"> <input type="{0}" ng-model="personinfo.value" placeholder="输入{1}"></label></div>', input_type, title);
  714. $scope.popup.optionsPopup = $ionicPopup.show({
  715. template: template,
  716. title: '<div><h4>' + title + '</h4></div>',
  717. scope: $scope,
  718. buttons: [{
  719. text: '取消',
  720. onTap: function () {
  721. return false;
  722. }
  723. }, {
  724. text: '<b>保存</b>',
  725. type: 'button-positive',
  726. onTap: function (e) {
  727. if (!$scope.personinfo.value) e.preventDefault(); else return true;
  728. }
  729. }]
  730. });
  731. $scope.popup.optionsPopup.then(function (res) {
  732. if (res) {
  733. $scope.userinfo[field_name] = $scope.personinfo.value;
  734. $scope.updateInfo();
  735. $scope.popup.optionsPopup.close();
  736. }
  737. });
  738. $scope.popup.isPopup = true;
  739. };
  740. var ImagePicker = function () {
  741. $scope.popup.optionsPopup.close();
  742. ImageManage.ImagePicker_getPictures(1).then(function (results) {
  743. if (results.length == 0) return;
  744. $q.all(results).then(function (res) {
  745. uploadimg(res);
  746. })
  747. });
  748. };
  749. var Camera = function () {
  750. $scope.popup.optionsPopup.close();
  751. ImageManage.Camera_getPicture(true).then(function (result) {
  752. uploadimg([result])
  753. });
  754. };
  755. function uploadimg(files) {
  756. showPopup.showLoading(1, '', true);
  757. ImageManage.uploadImage(files, 'user', global.user.usrid, 'userfile').then(function (ps) {
  758. $q.all(ps).then(function (fs) {
  759. $scope.userinfo.photo = JSON.parse(fs[0].response).file_thumbnail_path;
  760. showPopup.hideLoading();
  761. }, function (err) {
  762. showPopup.hideLoading();
  763. })
  764. }, function (err) {
  765. showPopup.hideLoading();
  766. })
  767. }
  768. $scope.updateInfo = function () {
  769. showPopup.showLoading(1, '', false);
  770. Dept.putUsrInfo($scope.userinfo).then(function (res) {
  771. showPopup.hideLoading();
  772. }, function (err) {
  773. showPopup.hideLoading();
  774. })
  775. };
  776. $scope.$on("$destroy", function () {
  777. beforeEnter = null;
  778. Member.selecteddepts = [];
  779. if ($rootScope.commons.modal != null) $rootScope.commons.modal.remove();
  780. })
  781. })
  782. .controller('EditDeptDegreeCtrl', function ($scope, $state, $rootScope, $ionicHistory, $timeout, global, Member, showPopup, Dept, Tool) {
  783. $scope.userinfo = {};
  784. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  785. global.fetch_user().then(function (data) {
  786. if (Member.selecteddepts.length > 0) {
  787. $scope.userinfo.depname = Member.selecteddepts[0].depname;
  788. $scope.userinfo.dept_id = Member.selecteddepts[0].id;
  789. } else $scope.userinfo = Tool.getTempData('userinfo');
  790. });
  791. });
  792. $scope.selectdept = function () {
  793. Member.routename = 'editdeptdegree';
  794. Member.titlename = '选择部门';
  795. Member.resourcemember = [{'id': $scope.userinfo.dept_id, 'depname': $scope.userinfo.depname}];
  796. Member.selecteddepts = [];
  797. $state.go('selectsingledept');
  798. };
  799. $scope.ok = function () {
  800. showPopup.showLoading(1, '', false);
  801. Dept.putUsrInfo($scope.userinfo).then(function (res) {
  802. showPopup.hideLoading();
  803. $ionicHistory.goBack();
  804. }, function (err) {
  805. showPopup.hideLoading();
  806. alert(JSON.stringify(err));
  807. })
  808. };
  809. $scope.cancel = function () {
  810. $ionicHistory.goBack();
  811. };
  812. $scope.$on("$destroy", function () {
  813. beforeEnter = null;
  814. Member.selecteddepts = [];
  815. })
  816. })
  817. ;