controllers.js 31 KB

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