123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673 |
- starter.controller('SelectParentCtrl', function ($scope, $state, Member) {
- $scope.deptlst = [];
- $scope.emplst = [];
- $scope.index = 0;
- $scope.isUp = false;
- $scope.deptid = 1;
- $scope.titlename = Member.titlename;
- $scope.selectedemplst = Member.selectedemplst;
- $scope.disabled = Member.disabled;
- $scope.showall = Member.showall;
- $scope.showgroup = Member.showgroup;
- $scope.loading = true;
- $scope.leftbtn = [{
- text: '取消',
- click: 'cancel'
- }, {
- text: '上一层',
- click: 'up'
- }];
- })
- .controller('SelectMemberCtrl', function ($scope, $state, $ionicHistory, $rootScope, $ionicModal, $timeout, $controller, Dept, Member) {
- var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
- var showgroupmodel = $ionicModal.fromTemplateUrl('/templates/common/modal-selectgroup.html', {
- scope: $scope,
- animation: 'slide-in-right'
- });
- var startdept = null;
- $rootScope.commons.goBackIsDisable = true;
- var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
- if (Member.homerenderdata.length != 0) {
- $scope.loading = false;
- _.each(Member.homerenderdata, function (item) {
- $scope.deptlst.push(item);
- });
- init_selected(Member.resourcemember);
- } else {
- Dept.getDep().then(function (data) {
- startdept = _.find(data, function (itemdept) {
- return itemdept.parent == null; //获取公司的顶层部门
- });
- getemp(startdept.id);
- data = _.filter(data, function (item) {
- return item.parent == startdept.id;
- });
- $scope.deptlst = data;
- init_selected(Member.resourcemember);
- }, function (err) {
- alert(JSON.stringify(err))
- });
- }
- });
- $scope.changeindex = function (index, dtid) {
- $scope.index = index;
- $scope.deptid = dtid;
- };
- $scope.change = function (emp) {
- if (emp.selected) {
- $scope.selectedemplst.push(emp);
- Member.selectedemplst = $scope.selectedemplst;
- } else {
- $scope.selectedemplst = _.filter($scope.selectedemplst, function (e) {
- return e.user_id != parseInt(emp.user_id);
- });
- Member.selectedemplst = $scope.selectedemplst;
- }
- setselectedcount();
- };
- $scope.up = function () {
- var dept = undefined;
- if (Member.homerenderdata.length > 0) {
- dept = _.find(Member.homerenderdata, function (item) {
- return item.id == parseInt($scope.deptid);
- })
- }
- if (dept != undefined) {
- $scope.deptlst = $scope.deptlst.concat(Member.homerenderdata);
- $scope.emplst = [];
- $scope.index = 0;
- } else {
- dept = _.find(Dept.all(), function (d) {
- return d.id == parseInt($scope.deptid);
- });
- getdept_emp(dept.parent);
- }
- };
- $scope.cancel = function () {
- Member.selectedemplst = [];
- Member.dialogresult = 0;
- if (Member.cancelroutename != "") {
- $state.go(Member.cancelroutename, Member.cancelrouteparams);
- } else {
- $ionicHistory.goBack();
- }
- };
- var dep = {};
- $scope.changedept = function (dept) {
- dep = dept;
- getdept_emp(dept.id);
- };
- $scope.ok = function () {
- Member.dialogresult = 1;
- Member.all = 0;
- if (Member.routename != '') {
- $state.go(Member.routename, Member.routeparams);
- } else {
- $ionicHistory.goBack(); //todo:带参数跳转
- }
- };
- $scope.selectAll = function () {
- Member.all = 1;
- $state.go(Member.routename, Member.routeparams);
- };
- $scope.back = function () {
- if ($rootScope.commons.modal != null) {
- $rootScope.commons.modal.hide();
- }
- };
- $scope.toselectgroup = function () {
- showgroupmodel.then(function (modal) {
- $rootScope.commons.modal = modal;
- $rootScope.commons.modal.show();
- });
- };
- $scope.$on("$destroy", function () {
- $rootScope.commons.goBackIsDisable = false;
- Member.member = {};
- });
- function init_selected(data) {
- setdeptrighticon($scope.deptlst);
- Member.selectedemplst = [];
- if (!Member.disabled) {
- $scope.selectedemplst = $scope.selectedemplst.concat(data);
- Member.selectedemplst = $scope.selectedemplst;
- }
- setselectedcount();
- }
- function getemp(id) {
- Dept.getEmp(id).then(function (data) {
- console.log(data);
- Member.member[id.toString()] = angular.copy(data);
- $scope.emplst = data;
- setitem();
- $scope.loading = false;
- });
- }
- function getdept_emp(did) {
- if (Member.member[did.toString()]) {
- set_member(did);
- } else {
- $scope.loading = true;
- Dept.getEmp(did).then(function (data) {
- Member.member[did.toString()] = angular.copy(data);
- set_member(did);
- $scope.loading = false;
- }, function (err) {
- $scope.loading = false;
- });
- }
- }
- var set_member = function (did) {
- $scope.deptlst = Dept.getChildDept(did);
- setdeptrighticon($scope.deptlst);
- $scope.emplst = Member.member[did.toString()];
- setitem();
- $scope.deptid = did;
- $scope.index = (startdept && did == startdept.id) ? 0 : 1;
- };
- function setselectedcount() {
- $scope.selectcount = $scope.selectedemplst.length > 0 ? "(" + $scope.selectedemplst.length + ")" : "";
- }
- function setitem() {
- _.each($scope.emplst, function (e) {
- e.selected = false;
- e.disabled = false;
- e.depname = dep.depname;
- set_isenable(e, Member.resourcemember, true);
- set_isenable(e, Member.unenabledata, false);
- var e1 = _.find($scope.selectedemplst, {'user_id': e.user_id});
- if (e1 != undefined) e.selected = true;
- });
- }
- function set_isenable(e, data, op) {
- var p = _.find(data, {'user_id': e.user_id});
- if (p != undefined) {
- e.disabled = e.selected = true;
- if (!Member.disabled && op) e.disabled = false;
- }
- }
- function setdeptrighticon(deptlst) {
- _.each(deptlst, function (d) {
- d.isShow = isShow(d);
- })
- }
- function isShow(dept) {
- var childdepts = Dept.getChildDept(dept.id);
- return !(childdepts.length == 0);
- }
- })
- .controller('SelectSingleMemberCtrl', function ($scope, $ionicHistory, $state, $controller, Dept, Member) {
- var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
- var startdept = {};
- $scope.init = function () {
- Dept.getDep().then(function (data) {
- startdept = _.find(data, function (itemdept) {
- return itemdept.parent == null; //获取公司的顶层部门
- });
- getemp(startdept.id);
- data = _.filter(data, function (item) {
- return item.parent == startdept.id;
- });
- $scope.deptlst = data;
- setdeptrighticon($scope.deptlst);
- });
- };
- $scope.changeindex = function (index, dtid) {
- $scope.index = index;
- $scope.deptid = dtid;
- };
- $scope.change = function (emp) {
- Member.dialogresult = 1;
- Member.selectedemplst.push(emp);
- if (Member.routename != '') {
- $state.go(Member.routename, Member.routeparams);
- } else {
- $ionicHistory.goBack(); //todo:带参数跳转
- }
- };
- $scope.up = function () {
- var dept = _.find(Dept.all(), function (d) {
- return d.id == parseInt($scope.deptid);
- });
- getdept_emp(dept.parent);
- };
- $scope.cancel = function () {
- Member.dialogresult = 0;
- Member.selectedemplst = [];
- $ionicHistory.goBack();
- };
- var dep = {};
- $scope.changedept = function (dept) {
- dep = dept;
- getdept_emp(dept.id);
- };
- $scope.deptdisplay = function () {
- return $scope.deptlst.length > 0;
- };
- function getemp(deptid) {
- Dept.getEmp(deptid).then(function (data) {
- Member.member[deptid.toString()] = angular.copy(data);
- $scope.emplst = data;
- setitem();
- $scope.loading = false;
- });
- }
- function getdept_emp(did) {
- if (Member.member[did.toString()]) {
- set_member(did);
- } else {
- $scope.loading = true;
- Dept.getEmp(did).then(function (data) {
- Member.member[did.toString()] = angular.copy(data);
- set_member(did);
- $scope.loading = false;
- });
- }
- }
- var set_member = function (did) {
- $scope.deptlst = Dept.getChildDept(did);
- setdeptrighticon($scope.deptlst);
- $scope.emplst = Member.member[did.toString()];
- setitem();
- $scope.deptid = did;
- $scope.index = (startdept && did == startdept.id) ? 0 : 1;
- };
- function setitem() {
- _.each($scope.emplst, function (e) {
- e.selected = false;
- e.disabled = false;
- e.depname = dep.depname;
- _.each(Member.resourcemember, function (p) {
- if (p.user_id == parseInt(e.user_id)) {
- e.disabled = true;
- e.selected = true;
- if (!Member.disabled) e.disabled = false;
- }
- });
- _.each($scope.selectedemplst, function (e1) {
- if (e1.user_id == e.user_id) e.selected = true;
- });
- });
- }
- function setdeptrighticon(deptlst) {
- _.each(deptlst, function (d) {
- d.isShow = isShow(d);
- })
- }
- function isShow(dept) {
- return Dept.getChildDept(dept.id).length != 0;
- }
- $scope.$on("$destroy", function () {
- Member.member = {};
- });
- })
- .controller('SelectDeptCtrl', function ($scope, $state, $ionicHistory, $timeout, $controller, Dept, Member) {
- var parentctrl = $controller('SelectParentCtrl', {$scope: $scope});
- $scope.id = $state.params['id'];
- $scope.selecteddepts = Member.selecteddepts;
- $scope.selectdeptcount = '';
- $scope.isallcheck = Member.isallcheck;
- $scope.flag = 0;
- $scope.isAll = false;
- var deptid = 1;
- var resourcedept = [];
- var startdept = null;
- $scope.isAllCheck = function () {
- Member.dialogresult = 1;
- $scope.isallcheck = !$scope.isallcheck;
- Member.isallcheck = $scope.isallcheck;
- if (Member.isallcheck) {
- Member.selecteddepts = [];
- if (Member.routename != '') {
- $state.go(Member.routename, Member.routeparams);
- } else {
- $ionicHistory.goBack(); //todo:带参数跳转
- }
- }
- };
- $scope.cancel = function () {
- Member.dialogresult = 0;
- Member.selecteddepts = [];
- $ionicHistory.goBack();
- };
- $scope.ok = function () {
- console.log($scope.selecteddepts.length);
- Member.dialogresult = 1;
- Member.all = 0;
- if (Member.routename != '') {
- $state.go(Member.routename, Member.routeparams);
- } else {
- $ionicHistory.goBack(); //todo:带参数跳转
- }
- };
- $scope.up = function () {
- if ($scope.index == 0 && Member.showall) {
- $scope.showall = true;
- }
- var dept = _.find(Dept.all(), function (d) {
- return d.id == parseInt(deptid);
- });
- getChildDept(dept.parent);
- };
- $scope.change = function (dept) {
- if (Member.isallcheck) {
- $scope.isallcheck = !$scope.isallcheck;
- Member.isallcheck = $scope.isallcheck;
- }
- if (dept.selected) {
- $scope.selecteddepts.push(dept);
- Member.selecteddepts = $scope.selecteddepts;
- } else {
- $scope.selecteddepts = _.filter($scope.selecteddepts, function (e) {
- return e.id != parseInt(dept.id);
- });
- Member.selecteddepts = $scope.selecteddepts;
- }
- setselectedcount();
- };
- $scope.tochilddept = function (dept) {
- if ($scope.index == startdept.id) {
- $scope.showall = false;
- }
- getChildDept(dept.id);
- };
- function setdept(data) {
- _.each(data, function (item) {
- item.selected = false;
- item.isdisabled = false;
- item.ishide = false;
- item.disableddesc = '';
- item.isShow = isShow(item);
- if (Member.datatype == 3) {
- if (item.diarymobid != null && $state.params["id"] != item.diarymobid) {
- item.disableddesc = '(已设置)';
- item.isdisabled = true;
- }
- } else if (Member.datatype == 4) {
- if (item.workatdsetid != null && $state.params["id"] != item.workatdsetid) {
- item.disableddesc = '(已设置)';
- item.isdisabled = true;
- }
- }
- if (_.find(Member.resourcemember, function (rsc) {
- return rsc.id == item.id ? true : false
- })) {
- item.selected = true;
- }
- });
- $scope.deptlst = data;
- }
- function getChildDept(did) {
- var childdepts = Dept.getChildDept(did);
- if (childdepts.length > 0) {
- deptid = did;
- if (did == startdept.id) {
- $scope.index = 0;
- } else {
- $scope.index = 1;
- }
- setdept(childdepts);
- }
- }
- function setselectedcount() {
- if (Member.selecteddepts.length > 0) {
- $scope.selectcount = "(" + Member.selecteddepts.length + ")";
- } else {
- $scope.selectcount = "";
- }
- }
- function isShow(dept) {
- var childdepts = Dept.getChildDept(dept.id);
- if (childdepts.length == 0) {
- return false;
- } else {
- return true;
- }
- }
- var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
- $scope.loading = true;
- Dept.getDep().then(function (data) {
- startdept = _.find(data, function (itemdept) {
- return itemdept.parent == null; //获取公司的顶层部门
- });
- Member.selecteddepts = Member.resourcemember;
- $scope.selecteddepts = Member.selecteddepts;
- if (Member.datatype == 3) {
- _.each(data, function (item) {
- if (item.diarymobid != null) {
- $scope.flag++;
- }
- if (item.id == 1 && item.diarymobid != null) {
- $scope.isAll = true;
- }
- })
- } else if (Member.datatype == 4) {
- _.each(data, function (item) {
- if (item.workatdsetid != null) {
- $scope.flag++;
- }
- if (item.id == 1 && item.workatdsetid != null) {
- $scope.isAll = true;
- }
- })
- }
- if ($scope.id == -1) {
- if ($scope.flag == 1 && $scope.isAll) {
- $scope.showall = true;
- } else if ($scope.flag >= 1 && !$scope.isAll) {
- $scope.showall = false;
- }
- if ($scope.flag >= 1 && $scope.flag + 1 == data.length && !$scope.isAll) {
- $scope.isAll = true;
- }
- } else {
- if ($scope.flag == 1 && $scope.isAll) {
- $scope.showall = true;
- } else if ($scope.flag >= 1 && !$scope.isAll && Member.resourcemember.length == 0) {
- $scope.showall = true;
- } else if ($scope.flag >= 1 && !$scope.isAll && $scope.flag == Member.resourcemember.length) {
- $scope.showall = true;
- } else if ($scope.flag >= 1 && !$scope.isAll && $scope.flag != Member.resourcemember.length) {
- $scope.showall = false;
- }
- }
- var rst = _.filter(data, function (a) {
- return (a.level === 1);
- });
- setdept(rst);
- if (!Member.disabled) {
- _.each(Member.resourcemember, function (m) {
- $scope.selecteddepts.push(m);
- });
- Member.selecteddepts = $scope.selecteddepts;
- }
- setselectedcount();
- }).finally(function () {
- $scope.loading = false;
- });
- });
- $scope.$on("$destroy", function () {
- beforeEnter = null;
- })
- })
- .controller('SelectSingleDeptCtrl', function ($scope, $state, $ionicHistory, $timeout, Dept, Member) {
- $scope.titlename = Member.titlename;
- var active_dept_id = 1;
- var startdept = null;
- $scope.leftbtn = [{
- text: '取消',
- click: 'cancel'
- }, {
- text: '上一层',
- click: 'up'
- }];
- var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
- $scope.loading = true;
- Dept.getDep().then(function (data) {
- startdept = _.find(data, {'parent': null});
- $scope.id = Member.resourcemember.length > 0 ? Member.resourcemember[0].id : null;
- getChildDept(startdept.id);
- }).finally(function () {
- $scope.loading = false;
- });
- });
- $scope.cancel = function () {
- Member.dialogresult = 0;
- Member.selecteddepts = [];
- $ionicHistory.goBack();
- };
- $scope.up = function () {
- getChildDept(_.find(Dept.all(), {'id': active_dept_id}).parent);
- };
- $scope.change = function (dept) {
- Member.selecteddepts = [];
- if (dept.selected) {
- Member.selecteddepts.push(dept);
- Member.routename == "" ? $ionicHistory.goBack() : $state.go(Member.routename, Member.routeparams);
- }
- };
- $scope.tochilddept = function (dept) {
- getChildDept(dept.id);
- };
- $scope.is_showright = function (dept) {
- return Dept.getChildDept(dept.id).length > 0;
- };
- function getChildDept(did) {
- var childdepts = Dept.getChildDept(did);
- if (childdepts.length > 0) {
- active_dept_id = did;
- $scope.index = did == startdept.id ? 0 : 1;
- var item = _.find(childdepts, {'id': $scope.id});
- if (item != undefined) item.selected = item != undefined;
- $scope.deptlst = childdepts;
- }
- }
- $scope.$on("$destroy", function () {
- beforeEnter = null;
- })
- })
- .controller('TransferCtrl', function ($scope, $state, $stateParams, $ionicPopup, $ionicHistory, global, Member) {
- $scope.selectmember = function () {
- $scope.isremove = false;
- Member.resourcemember = [];
- Member.resourcemember.push({
- id: global.user.usrid
- });
- Member.routename = '';
- Member.titlename = '选择联系人';
- $state.go('selectmember');
- };
- $scope.goback = function () {
- $ionicHistory.goBack();
- };
- function selectMember() {
- if (Member.selectedemplst.length > 0) {
- $scope.memberlist.push(global.user.imusrid);
- _.each(Member.selectedemplst, function (item) {
- $scope.memberlist.push(item.im_usrid);
- });
- Member.selectedemplst = [];
- if (window.cordovaLinker != undefined) {
- var discussion = {
- name: "讨论组",
- ids: []
- };
- discussion.ids = $scope.memberlist;
- window.cordovaLinker.discuss(discussion, function (s) {
- console.log(s);
- var confirmPopup = $ionicPopup.confirm({
- title: '<br/><div>转发至</div><br/>',
- subTitle: discussion.name,
- okText: '是',
- cancelText: '否'
- });
- confirmPopup.then(function (res) {
- if (res) {
- //:todo转发
- }
- });
- }, function (err) {
- console.error(err);
- });
- }
- Member.resourcemember = [];
- }
- }
- var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
- $scope.module = $stateParams.module;
- $scope.id = $stateParams.id;
- $scope.linkurl = '/tab/app/' + $scope.module + '/' + $scope.id;
- console.log($scope.linkurl);
- $scope.memberlist = [];
- $scope.popup = {
- isPopup: false
- };
- selectMember();
- });
- $scope.$on("$destroy", function () {
- beforeEnter = null;
- })
- })
|