controller.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. starter.controller('SelectParentCtrl', function ($scope, $state, Member) {
  2. $scope.deptlst = [];
  3. $scope.emplst = [];
  4. $scope.index = 0;
  5. $scope.isUp = false;
  6. $scope.deptid = 1;
  7. $scope.titlename = Member.titlename;
  8. $scope.selectedemplst = Member.selectedemplst;
  9. $scope.disabled = Member.disabled;
  10. $scope.showall = Member.showall;
  11. $scope.showgroup = Member.showgroup;
  12. $scope.loading = true;
  13. $scope.leftbtn = [{
  14. text: '取消',
  15. click: 'cancel'
  16. }, {
  17. text: '上一层',
  18. click: 'up'
  19. }];
  20. })
  21. .controller('SelectMemberCtrl', function ($scope, $state, $ionicHistory, $rootScope, $ionicModal, $timeout, $controller, Dept, Member) {
  22. var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
  23. var showgroupmodel = $ionicModal.fromTemplateUrl('/templates/common/modal-selectgroup.html', {
  24. scope: $scope,
  25. animation: 'slide-in-right'
  26. });
  27. var startdept = null;
  28. $rootScope.commons.goBackIsDisable = true;
  29. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  30. if (Member.homerenderdata.length != 0) {
  31. $scope.loading = false;
  32. _.each(Member.homerenderdata, function (item) {
  33. $scope.deptlst.push(item);
  34. });
  35. init_selected(Member.resourcemember);
  36. } else {
  37. Dept.getDep().then(function (data) {
  38. startdept = _.find(data, function (itemdept) {
  39. return itemdept.parent == null; //获取公司的顶层部门
  40. });
  41. getemp(startdept.id);
  42. data = _.filter(data, function (item) {
  43. return item.parent == startdept.id;
  44. });
  45. $scope.deptlst = data;
  46. init_selected(Member.resourcemember);
  47. }, function (err) {
  48. alert(JSON.stringify(err))
  49. });
  50. }
  51. });
  52. $scope.changeindex = function (index, dtid) {
  53. $scope.index = index;
  54. $scope.deptid = dtid;
  55. };
  56. $scope.change = function (emp) {
  57. if (emp.selected) {
  58. $scope.selectedemplst.push(emp);
  59. Member.selectedemplst = $scope.selectedemplst;
  60. } else {
  61. $scope.selectedemplst = _.filter($scope.selectedemplst, function (e) {
  62. return e.user_id != parseInt(emp.user_id);
  63. });
  64. Member.selectedemplst = $scope.selectedemplst;
  65. }
  66. setselectedcount();
  67. };
  68. $scope.up = function () {
  69. var dept = undefined;
  70. if (Member.homerenderdata.length > 0) {
  71. dept = _.find(Member.homerenderdata, function (item) {
  72. return item.id == parseInt($scope.deptid);
  73. })
  74. }
  75. if (dept != undefined) {
  76. $scope.deptlst = $scope.deptlst.concat(Member.homerenderdata);
  77. $scope.emplst = [];
  78. $scope.index = 0;
  79. } else {
  80. dept = _.find(Dept.all(), function (d) {
  81. return d.id == parseInt($scope.deptid);
  82. });
  83. getdept_emp(dept.parent);
  84. }
  85. };
  86. $scope.cancel = function () {
  87. Member.selectedemplst = [];
  88. Member.dialogresult = 0;
  89. if (Member.cancelroutename != "") {
  90. $state.go(Member.cancelroutename, Member.cancelrouteparams);
  91. } else {
  92. $ionicHistory.goBack();
  93. }
  94. };
  95. var dep = {};
  96. $scope.changedept = function (dept) {
  97. dep = dept;
  98. getdept_emp(dept.id);
  99. };
  100. $scope.ok = function () {
  101. Member.dialogresult = 1;
  102. Member.all = 0;
  103. if (Member.routename != '') {
  104. $state.go(Member.routename, Member.routeparams);
  105. } else {
  106. $ionicHistory.goBack(); //todo:带参数跳转
  107. }
  108. };
  109. $scope.selectAll = function () {
  110. Member.all = 1;
  111. $state.go(Member.routename, Member.routeparams);
  112. };
  113. $scope.back = function () {
  114. if ($rootScope.commons.modal != null) {
  115. $rootScope.commons.modal.hide();
  116. }
  117. };
  118. $scope.toselectgroup = function () {
  119. showgroupmodel.then(function (modal) {
  120. $rootScope.commons.modal = modal;
  121. $rootScope.commons.modal.show();
  122. });
  123. };
  124. $scope.$on("$destroy", function () {
  125. $rootScope.commons.goBackIsDisable = false;
  126. Member.member = {};
  127. });
  128. function init_selected(data) {
  129. setdeptrighticon($scope.deptlst);
  130. Member.selectedemplst = [];
  131. if (!Member.disabled) {
  132. $scope.selectedemplst = $scope.selectedemplst.concat(data);
  133. Member.selectedemplst = $scope.selectedemplst;
  134. }
  135. setselectedcount();
  136. }
  137. function getemp(id) {
  138. Dept.getEmp(id).then(function (data) {
  139. console.log(data);
  140. Member.member[id.toString()] = angular.copy(data);
  141. $scope.emplst = data;
  142. setitem();
  143. $scope.loading = false;
  144. });
  145. }
  146. function getdept_emp(did) {
  147. if (Member.member[did.toString()]) {
  148. set_member(did);
  149. } else {
  150. $scope.loading = true;
  151. Dept.getEmp(did).then(function (data) {
  152. Member.member[did.toString()] = angular.copy(data);
  153. set_member(did);
  154. $scope.loading = false;
  155. }, function (err) {
  156. $scope.loading = false;
  157. });
  158. }
  159. }
  160. var set_member = function (did) {
  161. $scope.deptlst = Dept.getChildDept(did);
  162. setdeptrighticon($scope.deptlst);
  163. $scope.emplst = Member.member[did.toString()];
  164. setitem();
  165. $scope.deptid = did;
  166. $scope.index = (startdept && did == startdept.id) ? 0 : 1;
  167. };
  168. function setselectedcount() {
  169. $scope.selectcount = $scope.selectedemplst.length > 0 ? "(" + $scope.selectedemplst.length + ")" : "";
  170. }
  171. function setitem() {
  172. _.each($scope.emplst, function (e) {
  173. e.selected = false;
  174. e.disabled = false;
  175. e.depname = dep.depname;
  176. set_isenable(e, Member.resourcemember, true);
  177. set_isenable(e, Member.unenabledata, false);
  178. var e1 = _.find($scope.selectedemplst, {'user_id': e.user_id});
  179. if (e1 != undefined) e.selected = true;
  180. });
  181. }
  182. function set_isenable(e, data, op) {
  183. var p = _.find(data, {'user_id': e.user_id});
  184. if (p != undefined) {
  185. e.disabled = e.selected = true;
  186. if (!Member.disabled && op) e.disabled = false;
  187. }
  188. }
  189. function setdeptrighticon(deptlst) {
  190. _.each(deptlst, function (d) {
  191. d.isShow = isShow(d);
  192. })
  193. }
  194. function isShow(dept) {
  195. var childdepts = Dept.getChildDept(dept.id);
  196. return !(childdepts.length == 0);
  197. }
  198. })
  199. .controller('SelectSingleMemberCtrl', function ($scope, $ionicHistory, $state, $controller, Dept, Member) {
  200. var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
  201. var startdept = {};
  202. $scope.init = function () {
  203. Dept.getDep().then(function (data) {
  204. startdept = _.find(data, function (itemdept) {
  205. return itemdept.parent == null; //获取公司的顶层部门
  206. });
  207. getemp(startdept.id);
  208. data = _.filter(data, function (item) {
  209. return item.parent == startdept.id;
  210. });
  211. $scope.deptlst = data;
  212. setdeptrighticon($scope.deptlst);
  213. });
  214. };
  215. $scope.changeindex = function (index, dtid) {
  216. $scope.index = index;
  217. $scope.deptid = dtid;
  218. };
  219. $scope.change = function (emp) {
  220. Member.dialogresult = 1;
  221. Member.selectedemplst = [];
  222. Member.selectedemplst.push(emp);
  223. if (Member.routename != '') {
  224. $state.go(Member.routename, Member.routeparams);
  225. } else {
  226. $ionicHistory.goBack(); //todo:带参数跳转
  227. }
  228. };
  229. $scope.up = function () {
  230. var dept = _.find(Dept.all(), function (d) {
  231. return d.id == parseInt($scope.deptid);
  232. });
  233. getdept_emp(dept.parent);
  234. };
  235. $scope.cancel = function () {
  236. Member.dialogresult = 0;
  237. Member.selectedemplst = [];
  238. $ionicHistory.goBack();
  239. };
  240. var dep = {};
  241. $scope.changedept = function (dept) {
  242. dep = dept;
  243. getdept_emp(dept.id);
  244. };
  245. $scope.deptdisplay = function () {
  246. return $scope.deptlst.length > 0;
  247. };
  248. function getemp(deptid) {
  249. Dept.getEmp(deptid).then(function (data) {
  250. Member.member[deptid.toString()] = angular.copy(data);
  251. $scope.emplst = data;
  252. setitem();
  253. $scope.loading = false;
  254. });
  255. }
  256. function getdept_emp(did) {
  257. if (Member.member[did.toString()]) {
  258. set_member(did);
  259. } else {
  260. $scope.loading = true;
  261. Dept.getEmp(did).then(function (data) {
  262. Member.member[did.toString()] = angular.copy(data);
  263. set_member(did);
  264. $scope.loading = false;
  265. });
  266. }
  267. }
  268. var set_member = function (did) {
  269. $scope.deptlst = Dept.getChildDept(did);
  270. setdeptrighticon($scope.deptlst);
  271. $scope.emplst = Member.member[did.toString()];
  272. setitem();
  273. $scope.deptid = did;
  274. $scope.index = (startdept && did == startdept.id) ? 0 : 1;
  275. };
  276. function setitem() {
  277. _.each($scope.emplst, function (e) {
  278. e.selected = false;
  279. e.disabled = false;
  280. e.depname = dep.depname;
  281. _.each(Member.resourcemember, function (p) {
  282. if (p.user_id == parseInt(e.user_id)) {
  283. e.disabled = true;
  284. e.selected = true;
  285. if (!Member.disabled) e.disabled = false;
  286. }
  287. });
  288. _.each($scope.selectedemplst, function (e1) {
  289. if (e1.user_id == e.user_id) e.selected = true;
  290. });
  291. });
  292. }
  293. function setdeptrighticon(deptlst) {
  294. _.each(deptlst, function (d) {
  295. d.isShow = isShow(d);
  296. })
  297. }
  298. function isShow(dept) {
  299. return Dept.getChildDept(dept.id).length != 0;
  300. }
  301. $scope.$on("$destroy", function () {
  302. Member.member = {};
  303. });
  304. $scope.$on('$ionicView.beforeLeave', function (e) {
  305. if (Member.emit.is_have)
  306. $scope.$emit(Member.emit.name);
  307. });
  308. })
  309. .controller('SelectDeptCtrl', function ($scope, $state, $ionicHistory, $timeout, $controller, Dept, Member) {
  310. var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
  311. $scope.id = $state.params['id'];
  312. $scope.selecteddepts = Member.selecteddepts;
  313. $scope.selectdeptcount = '';
  314. $scope.isallcheck = Member.isallcheck;
  315. $scope.flag = 0;
  316. $scope.isAll = false;
  317. var deptid = 1;
  318. var resourcedept = [];
  319. var startdept = null;
  320. $scope.isAllCheck = function () {
  321. Member.dialogresult = 1;
  322. $scope.isallcheck = !$scope.isallcheck;
  323. Member.isallcheck = $scope.isallcheck;
  324. if (Member.isallcheck) {
  325. Member.selecteddepts = [];
  326. if (Member.routename != '') {
  327. $state.go(Member.routename, Member.routeparams);
  328. } else {
  329. $ionicHistory.goBack(); //todo:带参数跳转
  330. }
  331. }
  332. };
  333. $scope.cancel = function () {
  334. Member.dialogresult = 0;
  335. Member.selecteddepts = [];
  336. $ionicHistory.goBack();
  337. };
  338. $scope.ok = function () {
  339. console.log($scope.selecteddepts.length);
  340. Member.dialogresult = 1;
  341. Member.all = 0;
  342. if (Member.routename != '') {
  343. $state.go(Member.routename, Member.routeparams);
  344. } else {
  345. $ionicHistory.goBack(); //todo:带参数跳转
  346. }
  347. };
  348. $scope.up = function () {
  349. if ($scope.index == 0 && Member.showall) {
  350. $scope.showall = true;
  351. }
  352. var dept = _.find(Dept.all(), function (d) {
  353. return d.id == parseInt(deptid);
  354. });
  355. getChildDept(dept.parent);
  356. };
  357. $scope.change = function (dept) {
  358. if (Member.isallcheck) {
  359. $scope.isallcheck = !$scope.isallcheck;
  360. Member.isallcheck = $scope.isallcheck;
  361. }
  362. if (dept.selected) {
  363. $scope.selecteddepts.push(dept);
  364. Member.selecteddepts = $scope.selecteddepts;
  365. } else {
  366. $scope.selecteddepts = _.filter($scope.selecteddepts, function (e) {
  367. return e.id != parseInt(dept.id);
  368. });
  369. Member.selecteddepts = $scope.selecteddepts;
  370. }
  371. setselectedcount();
  372. };
  373. $scope.tochilddept = function (dept) {
  374. if ($scope.index == startdept.id) {
  375. $scope.showall = false;
  376. }
  377. getChildDept(dept.id);
  378. };
  379. function setdept(data) {
  380. _.each(data, function (item) {
  381. item.selected = false;
  382. item.isdisabled = false;
  383. item.ishide = false;
  384. item.disableddesc = '';
  385. item.isShow = isShow(item);
  386. if (Member.datatype == 3) {
  387. if (item.diarymobid != null && $state.params["id"] != item.diarymobid) {
  388. item.disableddesc = '(已设置)';
  389. item.isdisabled = true;
  390. }
  391. } else if (Member.datatype == 4) {
  392. if (item.workatdsetid != null && $state.params["id"] != item.workatdsetid) {
  393. item.disableddesc = '(已设置)';
  394. item.isdisabled = true;
  395. }
  396. }
  397. if (_.find(Member.resourcemember, function (rsc) {
  398. return rsc.id == item.id ? true : false
  399. })) {
  400. item.selected = true;
  401. }
  402. });
  403. $scope.deptlst = data;
  404. }
  405. function getChildDept(did) {
  406. var childdepts = Dept.getChildDept(did);
  407. if (childdepts.length > 0) {
  408. deptid = did;
  409. if (did == startdept.id) {
  410. $scope.index = 0;
  411. } else {
  412. $scope.index = 1;
  413. }
  414. setdept(childdepts);
  415. }
  416. }
  417. function setselectedcount() {
  418. if (Member.selecteddepts.length > 0) {
  419. $scope.selectcount = "(" + Member.selecteddepts.length + ")";
  420. } else {
  421. $scope.selectcount = "";
  422. }
  423. }
  424. function isShow(dept) {
  425. var childdepts = Dept.getChildDept(dept.id);
  426. if (childdepts.length == 0) {
  427. return false;
  428. } else {
  429. return true;
  430. }
  431. }
  432. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  433. $scope.loading = true;
  434. Dept.getDep().then(function (data) {
  435. startdept = _.find(data, function (itemdept) {
  436. return itemdept.parent == null; //获取公司的顶层部门
  437. });
  438. Member.selecteddepts = Member.resourcemember;
  439. $scope.selecteddepts = Member.selecteddepts;
  440. if (Member.datatype == 3) {
  441. _.each(data, function (item) {
  442. if (item.diarymobid != null) {
  443. $scope.flag++;
  444. }
  445. if (item.id == 1 && item.diarymobid != null) {
  446. $scope.isAll = true;
  447. }
  448. })
  449. } else if (Member.datatype == 4) {
  450. _.each(data, function (item) {
  451. if (item.workatdsetid != null) {
  452. $scope.flag++;
  453. }
  454. if (item.id == 1 && item.workatdsetid != null) {
  455. $scope.isAll = true;
  456. }
  457. })
  458. }
  459. if ($scope.id == -1) {
  460. if ($scope.flag == 1 && $scope.isAll) {
  461. $scope.showall = true;
  462. } else if ($scope.flag >= 1 && !$scope.isAll) {
  463. $scope.showall = false;
  464. }
  465. if ($scope.flag >= 1 && $scope.flag + 1 == data.length && !$scope.isAll) {
  466. $scope.isAll = true;
  467. }
  468. } else {
  469. if ($scope.flag == 1 && $scope.isAll) {
  470. $scope.showall = true;
  471. } else if ($scope.flag >= 1 && !$scope.isAll && Member.resourcemember.length == 0) {
  472. $scope.showall = true;
  473. } else if ($scope.flag >= 1 && !$scope.isAll && $scope.flag == Member.resourcemember.length) {
  474. $scope.showall = true;
  475. } else if ($scope.flag >= 1 && !$scope.isAll && $scope.flag != Member.resourcemember.length) {
  476. $scope.showall = false;
  477. }
  478. }
  479. var rst = _.filter(data, function (a) {
  480. return (a.level === 1);
  481. });
  482. setdept(rst);
  483. if (!Member.disabled) {
  484. _.each(Member.resourcemember, function (m) {
  485. $scope.selecteddepts.push(m);
  486. });
  487. Member.selecteddepts = $scope.selecteddepts;
  488. }
  489. setselectedcount();
  490. }).finally(function () {
  491. $scope.loading = false;
  492. });
  493. });
  494. $scope.$on("$destroy", function () {
  495. beforeEnter = null;
  496. })
  497. })
  498. .controller('SelectSingleDeptCtrl', function ($scope, $state, $ionicHistory, $timeout, Dept, Member) {
  499. $scope.titlename = Member.titlename;
  500. var active_dept_id = 1;
  501. var startdept = null;
  502. $scope.leftbtn = [{
  503. text: '取消',
  504. click: 'cancel'
  505. }, {
  506. text: '上一层',
  507. click: 'up'
  508. }];
  509. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  510. $scope.loading = true;
  511. Dept.getDep().then(function (data) {
  512. startdept = _.find(data, {'parent': null});
  513. $scope.id = Member.resourcemember.length > 0 ? Member.resourcemember[0].id : null;
  514. getChildDept(startdept.id);
  515. }).finally(function () {
  516. $scope.loading = false;
  517. });
  518. });
  519. $scope.cancel = function () {
  520. Member.dialogresult = 0;
  521. Member.selecteddepts = [];
  522. $ionicHistory.goBack();
  523. };
  524. $scope.up = function () {
  525. getChildDept(_.find(Dept.all(), {'id': active_dept_id}).parent);
  526. };
  527. $scope.change = function (dept) {
  528. Member.selecteddepts = [];
  529. if (dept.selected) {
  530. Member.selecteddepts.push(dept);
  531. Member.routename == "" ? $ionicHistory.goBack() : $state.go(Member.routename, Member.routeparams);
  532. }
  533. };
  534. $scope.tochilddept = function (dept) {
  535. getChildDept(dept.id);
  536. };
  537. $scope.is_showright = function (dept) {
  538. return Dept.getChildDept(dept.id).length > 0;
  539. };
  540. function getChildDept(did) {
  541. var childdepts = Dept.getChildDept(did);
  542. if (childdepts.length > 0) {
  543. active_dept_id = did;
  544. $scope.index = did == startdept.id ? 0 : 1;
  545. var item = _.find(childdepts, {'id': $scope.id});
  546. if (item != undefined) item.selected = item != undefined;
  547. $scope.deptlst = childdepts;
  548. }
  549. }
  550. $scope.$on("$destroy", function () {
  551. beforeEnter = null;
  552. })
  553. })
  554. .controller('TransferCtrl', function ($scope, $state, $stateParams, $ionicPopup, $ionicHistory, global, Member) {
  555. $scope.selectmember = function () {
  556. $scope.isremove = false;
  557. Member.resourcemember = [];
  558. Member.resourcemember.push({
  559. id: global.user.usrid
  560. });
  561. Member.routename = '';
  562. Member.titlename = '选择联系人';
  563. $state.go('selectmember');
  564. };
  565. $scope.goback = function () {
  566. $ionicHistory.goBack();
  567. };
  568. function selectMember() {
  569. if (Member.selectedemplst.length > 0) {
  570. $scope.memberlist.push(global.user.imusrid);
  571. _.each(Member.selectedemplst, function (item) {
  572. $scope.memberlist.push(item.im_usrid);
  573. });
  574. Member.selectedemplst = [];
  575. if (window.cordovaLinker != undefined) {
  576. var discussion = {
  577. name: "讨论组",
  578. ids: []
  579. };
  580. discussion.ids = $scope.memberlist;
  581. window.cordovaLinker.discuss(discussion, function (s) {
  582. console.log(s);
  583. var confirmPopup = $ionicPopup.confirm({
  584. title: '<br/><div>转发至</div><br/>',
  585. subTitle: discussion.name,
  586. okText: '是',
  587. cancelText: '否'
  588. });
  589. confirmPopup.then(function (res) {
  590. if (res) {
  591. //:todo转发
  592. }
  593. });
  594. }, function (err) {
  595. console.error(err);
  596. });
  597. }
  598. Member.resourcemember = [];
  599. }
  600. }
  601. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  602. $scope.module = $stateParams.module;
  603. $scope.id = $stateParams.id;
  604. $scope.linkurl = '/tab/app/' + $scope.module + '/' + $scope.id;
  605. console.log($scope.linkurl);
  606. $scope.memberlist = [];
  607. $scope.popup = {
  608. isPopup: false
  609. };
  610. selectMember();
  611. });
  612. $scope.$on("$destroy", function () {
  613. beforeEnter = null;
  614. })
  615. })