controller.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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.push(emp);
  222. if (Member.routename != '') {
  223. $state.go(Member.routename, Member.routeparams);
  224. } else {
  225. $ionicHistory.goBack(); //todo:带参数跳转
  226. }
  227. };
  228. $scope.up = function () {
  229. var dept = _.find(Dept.all(), function (d) {
  230. return d.id == parseInt($scope.deptid);
  231. });
  232. getdept_emp(dept.parent);
  233. };
  234. $scope.cancel = function () {
  235. Member.dialogresult = 0;
  236. Member.selectedemplst = [];
  237. $ionicHistory.goBack();
  238. };
  239. var dep = {};
  240. $scope.changedept = function (dept) {
  241. dep = dept;
  242. getdept_emp(dept.id);
  243. };
  244. $scope.deptdisplay = function () {
  245. return $scope.deptlst.length > 0;
  246. };
  247. function getemp(deptid) {
  248. Dept.getEmp(deptid).then(function (data) {
  249. Member.member[deptid.toString()] = angular.copy(data);
  250. $scope.emplst = data;
  251. setitem();
  252. $scope.loading = false;
  253. });
  254. }
  255. function getdept_emp(did) {
  256. if (Member.member[did.toString()]) {
  257. set_member(did);
  258. } else {
  259. $scope.loading = true;
  260. Dept.getEmp(did).then(function (data) {
  261. Member.member[did.toString()] = angular.copy(data);
  262. set_member(did);
  263. $scope.loading = false;
  264. });
  265. }
  266. }
  267. var set_member = function (did) {
  268. $scope.deptlst = Dept.getChildDept(did);
  269. setdeptrighticon($scope.deptlst);
  270. $scope.emplst = Member.member[did.toString()];
  271. setitem();
  272. $scope.deptid = did;
  273. $scope.index = (startdept && did == startdept.id) ? 0 : 1;
  274. };
  275. function setitem() {
  276. _.each($scope.emplst, function (e) {
  277. e.selected = false;
  278. e.disabled = false;
  279. e.depname = dep.depname;
  280. _.each(Member.resourcemember, function (p) {
  281. if (p.user_id == parseInt(e.user_id)) {
  282. e.disabled = true;
  283. e.selected = true;
  284. if (!Member.disabled) e.disabled = false;
  285. }
  286. });
  287. _.each($scope.selectedemplst, function (e1) {
  288. if (e1.user_id == e.user_id) e.selected = true;
  289. });
  290. });
  291. }
  292. function setdeptrighticon(deptlst) {
  293. _.each(deptlst, function (d) {
  294. d.isShow = isShow(d);
  295. })
  296. }
  297. function isShow(dept) {
  298. return Dept.getChildDept(dept.id).length != 0;
  299. }
  300. $scope.$on("$destroy", function () {
  301. Member.member = {};
  302. });
  303. })
  304. .controller('SelectDeptCtrl', function ($scope, $state, $ionicHistory, $timeout, $controller, Dept, Member) {
  305. var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
  306. $scope.id = $state.params['id'];
  307. $scope.selecteddepts = Member.selecteddepts;
  308. $scope.selectdeptcount = '';
  309. $scope.isallcheck = Member.isallcheck;
  310. $scope.flag = 0;
  311. $scope.isAll = false;
  312. var deptid = 1;
  313. var resourcedept = [];
  314. var startdept = null;
  315. $scope.isAllCheck = function () {
  316. Member.dialogresult = 1;
  317. $scope.isallcheck = !$scope.isallcheck;
  318. Member.isallcheck = $scope.isallcheck;
  319. if (Member.isallcheck) {
  320. Member.selecteddepts = [];
  321. if (Member.routename != '') {
  322. $state.go(Member.routename, Member.routeparams);
  323. } else {
  324. $ionicHistory.goBack(); //todo:带参数跳转
  325. }
  326. }
  327. };
  328. $scope.cancel = function () {
  329. Member.dialogresult = 0;
  330. Member.selecteddepts = [];
  331. $ionicHistory.goBack();
  332. };
  333. $scope.ok = function () {
  334. console.log($scope.selecteddepts.length);
  335. Member.dialogresult = 1;
  336. Member.all = 0;
  337. if (Member.routename != '') {
  338. $state.go(Member.routename, Member.routeparams);
  339. } else {
  340. $ionicHistory.goBack(); //todo:带参数跳转
  341. }
  342. };
  343. $scope.up = function () {
  344. if ($scope.index == 0 && Member.showall) {
  345. $scope.showall = true;
  346. }
  347. var dept = _.find(Dept.all(), function (d) {
  348. return d.id == parseInt(deptid);
  349. });
  350. getChildDept(dept.parent);
  351. };
  352. $scope.change = function (dept) {
  353. if (Member.isallcheck) {
  354. $scope.isallcheck = !$scope.isallcheck;
  355. Member.isallcheck = $scope.isallcheck;
  356. }
  357. if (dept.selected) {
  358. $scope.selecteddepts.push(dept);
  359. Member.selecteddepts = $scope.selecteddepts;
  360. } else {
  361. $scope.selecteddepts = _.filter($scope.selecteddepts, function (e) {
  362. return e.id != parseInt(dept.id);
  363. });
  364. Member.selecteddepts = $scope.selecteddepts;
  365. }
  366. setselectedcount();
  367. };
  368. $scope.tochilddept = function (dept) {
  369. if ($scope.index == startdept.id) {
  370. $scope.showall = false;
  371. }
  372. getChildDept(dept.id);
  373. };
  374. function setdept(data) {
  375. _.each(data, function (item) {
  376. item.selected = false;
  377. item.isdisabled = false;
  378. item.ishide = false;
  379. item.disableddesc = '';
  380. item.isShow = isShow(item);
  381. if (Member.datatype == 3) {
  382. if (item.diarymobid != null && $state.params["id"] != item.diarymobid) {
  383. item.disableddesc = '(已设置)';
  384. item.isdisabled = true;
  385. }
  386. } else if (Member.datatype == 4) {
  387. if (item.workatdsetid != null && $state.params["id"] != item.workatdsetid) {
  388. item.disableddesc = '(已设置)';
  389. item.isdisabled = true;
  390. }
  391. }
  392. if (_.find(Member.resourcemember, function (rsc) {
  393. return rsc.id == item.id ? true : false
  394. })) {
  395. item.selected = true;
  396. }
  397. });
  398. $scope.deptlst = data;
  399. }
  400. function getChildDept(did) {
  401. var childdepts = Dept.getChildDept(did);
  402. if (childdepts.length > 0) {
  403. deptid = did;
  404. if (did == startdept.id) {
  405. $scope.index = 0;
  406. } else {
  407. $scope.index = 1;
  408. }
  409. setdept(childdepts);
  410. }
  411. }
  412. function setselectedcount() {
  413. if (Member.selecteddepts.length > 0) {
  414. $scope.selectcount = "(" + Member.selecteddepts.length + ")";
  415. } else {
  416. $scope.selectcount = "";
  417. }
  418. }
  419. function isShow(dept) {
  420. var childdepts = Dept.getChildDept(dept.id);
  421. if (childdepts.length == 0) {
  422. return false;
  423. } else {
  424. return true;
  425. }
  426. }
  427. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  428. $scope.loading = true;
  429. Dept.getDep().then(function (data) {
  430. startdept = _.find(data, function (itemdept) {
  431. return itemdept.parent == null; //获取公司的顶层部门
  432. });
  433. Member.selecteddepts = Member.resourcemember;
  434. $scope.selecteddepts = Member.selecteddepts;
  435. if (Member.datatype == 3) {
  436. _.each(data, function (item) {
  437. if (item.diarymobid != null) {
  438. $scope.flag++;
  439. }
  440. if (item.id == 1 && item.diarymobid != null) {
  441. $scope.isAll = true;
  442. }
  443. })
  444. } else if (Member.datatype == 4) {
  445. _.each(data, function (item) {
  446. if (item.workatdsetid != null) {
  447. $scope.flag++;
  448. }
  449. if (item.id == 1 && item.workatdsetid != null) {
  450. $scope.isAll = true;
  451. }
  452. })
  453. }
  454. if ($scope.id == -1) {
  455. if ($scope.flag == 1 && $scope.isAll) {
  456. $scope.showall = true;
  457. } else if ($scope.flag >= 1 && !$scope.isAll) {
  458. $scope.showall = false;
  459. }
  460. if ($scope.flag >= 1 && $scope.flag + 1 == data.length && !$scope.isAll) {
  461. $scope.isAll = true;
  462. }
  463. } else {
  464. if ($scope.flag == 1 && $scope.isAll) {
  465. $scope.showall = true;
  466. } else if ($scope.flag >= 1 && !$scope.isAll && Member.resourcemember.length == 0) {
  467. $scope.showall = true;
  468. } else if ($scope.flag >= 1 && !$scope.isAll && $scope.flag == Member.resourcemember.length) {
  469. $scope.showall = true;
  470. } else if ($scope.flag >= 1 && !$scope.isAll && $scope.flag != Member.resourcemember.length) {
  471. $scope.showall = false;
  472. }
  473. }
  474. var rst = _.filter(data, function (a) {
  475. return (a.level === 1);
  476. });
  477. setdept(rst);
  478. if (!Member.disabled) {
  479. _.each(Member.resourcemember, function (m) {
  480. $scope.selecteddepts.push(m);
  481. });
  482. Member.selecteddepts = $scope.selecteddepts;
  483. }
  484. setselectedcount();
  485. }).finally(function () {
  486. $scope.loading = false;
  487. });
  488. });
  489. $scope.$on("$destroy", function () {
  490. beforeEnter = null;
  491. })
  492. })
  493. .controller('SelectSingleDeptCtrl', function ($scope, $state, $ionicHistory, $timeout, Dept, Member) {
  494. $scope.titlename = Member.titlename;
  495. var active_dept_id = 1;
  496. var startdept = null;
  497. $scope.leftbtn = [{
  498. text: '取消',
  499. click: 'cancel'
  500. }, {
  501. text: '上一层',
  502. click: 'up'
  503. }];
  504. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  505. $scope.loading = true;
  506. Dept.getDep().then(function (data) {
  507. startdept = _.find(data, {'parent': null});
  508. $scope.id = Member.resourcemember.length > 0 ? Member.resourcemember[0].id : null;
  509. getChildDept(startdept.id);
  510. }).finally(function () {
  511. $scope.loading = false;
  512. });
  513. });
  514. $scope.cancel = function () {
  515. Member.dialogresult = 0;
  516. Member.selecteddepts = [];
  517. $ionicHistory.goBack();
  518. };
  519. $scope.up = function () {
  520. getChildDept(_.find(Dept.all(), {'id': active_dept_id}).parent);
  521. };
  522. $scope.change = function (dept) {
  523. Member.selecteddepts = [];
  524. if (dept.selected) {
  525. Member.selecteddepts.push(dept);
  526. Member.routename == "" ? $ionicHistory.goBack() : $state.go(Member.routename, Member.routeparams);
  527. }
  528. };
  529. $scope.tochilddept = function (dept) {
  530. getChildDept(dept.id);
  531. };
  532. $scope.is_showright = function (dept) {
  533. return Dept.getChildDept(dept.id).length > 0;
  534. };
  535. function getChildDept(did) {
  536. var childdepts = Dept.getChildDept(did);
  537. if (childdepts.length > 0) {
  538. active_dept_id = did;
  539. $scope.index = did == startdept.id ? 0 : 1;
  540. var item = _.find(childdepts, {'id': $scope.id});
  541. if (item != undefined) item.selected = item != undefined;
  542. $scope.deptlst = childdepts;
  543. }
  544. }
  545. $scope.$on("$destroy", function () {
  546. beforeEnter = null;
  547. })
  548. })
  549. .controller('TransferCtrl', function ($scope, $state, $stateParams, $ionicPopup, $ionicHistory, global, Member) {
  550. $scope.selectmember = function () {
  551. $scope.isremove = false;
  552. Member.resourcemember = [];
  553. Member.resourcemember.push({
  554. id: global.user.usrid
  555. });
  556. Member.routename = '';
  557. Member.titlename = '选择联系人';
  558. $state.go('selectmember');
  559. };
  560. $scope.goback = function () {
  561. $ionicHistory.goBack();
  562. };
  563. function selectMember() {
  564. if (Member.selectedemplst.length > 0) {
  565. $scope.memberlist.push(global.user.imusrid);
  566. _.each(Member.selectedemplst, function (item) {
  567. $scope.memberlist.push(item.im_usrid);
  568. });
  569. Member.selectedemplst = [];
  570. if (window.cordovaLinker != undefined) {
  571. var discussion = {
  572. name: "讨论组",
  573. ids: []
  574. };
  575. discussion.ids = $scope.memberlist;
  576. window.cordovaLinker.discuss(discussion, function (s) {
  577. console.log(s);
  578. var confirmPopup = $ionicPopup.confirm({
  579. title: '<br/><div>转发至</div><br/>',
  580. subTitle: discussion.name,
  581. okText: '是',
  582. cancelText: '否'
  583. });
  584. confirmPopup.then(function (res) {
  585. if (res) {
  586. //:todo转发
  587. }
  588. });
  589. }, function (err) {
  590. console.error(err);
  591. });
  592. }
  593. Member.resourcemember = [];
  594. }
  595. }
  596. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  597. $scope.module = $stateParams.module;
  598. $scope.id = $stateParams.id;
  599. $scope.linkurl = '/tab/app/' + $scope.module + '/' + $scope.id;
  600. console.log($scope.linkurl);
  601. $scope.memberlist = [];
  602. $scope.popup = {
  603. isPopup: false
  604. };
  605. selectMember();
  606. });
  607. $scope.$on("$destroy", function () {
  608. beforeEnter = null;
  609. })
  610. })