controllers.js 31 KB

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