123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- angular.module('push')
- .controller('selectAuthorityMemberCtrl', function ($scope,$stateParams, $timeout,$ionicScrollDelegate,$ionicModal,ScienceCircleService,
- UserService, ResourceLibraryService, ConstantService, resourceLibraryModel, $ionicPopup, UtilService) {
- $scope.groupDetail={
- goupName:"",
- memberNum:0
- };
- $scope.mailDatas=[];
- // 设置来源
- $scope.sourcefrom = $stateParams.sourcefrom;
- // 从 【设置群组】 来
- if($scope.sourcefrom == 1){
- // 设置群组时选择的成员列表
- $scope.userlist = resourceLibraryModel.getTempUserList();
- }
- // 从 【谁可以看】 来
- else if($scope.sourcefrom == 2){
- // 选择的成员列表
- $scope.userlist = resourceLibraryModel.getUserList();
- }
- // 将已选择的userid组合
- $scope.useridlist = [];
- $scope.selectedSectionLength=0;
- if(UtilService.isDefined($scope.userlist) && $scope.userlist.length > 0){
- angular.forEach($scope.userlist, function (value, ind) {
- $scope.useridlist.push(value.userid);
- $scope.selectedSectionLength += 1;
- });
- }
- // 转换用到的userlist model
- $scope.requestModel=
- {
- //TODO
- userid:UserService.id,
- // userid:1,
- data:[]
- };
- // 我的通讯录列表
- var getContacts = function () {
- // 0:我的关注 1:我的粉丝 2:陌生人
- ScienceCircleService.getContacts(0).then(function (response) {
- // console.log(response);
- // 成员列表
- $scope.mailDatas = response;
- $timeout(function () {
- //联系人首字母字母数组
- $scope.letters = [];
- angular.forEach($scope.mailDatas, function (value) {
- $scope.letters.push(value.userUpper);
- angular.forEach(value.userlist, function (user, ind) {
- // 若已在群组中存在,则默认选中
- if($scope.useridlist.indexOf(user.userid) != -1){
- user.isChecked = true;
- }
- });
- });
- $scope.heightAccount=20*($scope.letters.length)+"px";
- }, 100);
- }, function () {
- });
- };
- getContacts();
- //联系人首字母字母数组
- $scope.letters = [];
- angular.forEach($scope.mailDatas, function (value) {
- $scope.letters.push(value.userUpper);
- });
- $scope.heightAccount=20*($scope.letters.length)+"px";
- // 触摸字母定位至对应联系人
- $scope.mTouch = function () {
- var handle=$ionicScrollDelegate.$getByHandle('businessList-handle');
- var c = $(this).attr("c");
- $scope.hint = c;
- $scope.showMiddle = true;
- $timeout(function () {
- $scope.showMiddle = false;
- }, 300);
- var scroll = document.getElementById($scope.hint).offsetTop- handle.getScrollPosition().top;
- $ionicScrollDelegate.scrollBy(0, scroll, true);
- var ele = document.getElementsByTagName("ion-content");
- ele[0].style.overflow = "auto"; //解决滑动右边的导航字母后,左边不能再滚动的bug,可以试着注释这两句来测试这个问题
- };
- // 手指从屏幕上离开 隐藏中间显示的字母
- $scope.mRelease = function () {
- $timeout(function () {
- $scope.showMiddle = false;
- }, 300);
- };
- // 记录选中群组列表索引
- var indexSectionlist = [];
- // 选择成员(多选)
- $scope.selectLabelOrgType = function (userId, parentIndex,index) {
- if ($scope.mailDatas[parentIndex].userlist[index].isChecked) {
- var ind = indexSectionlist.indexOf(index);
- indexSectionlist.splice(ind,1);
- $scope.selectedSectionLength -= 1;
- } else {
- indexSectionlist.push(userId);
- $scope.selectedSectionLength += 1;
- }
- $scope.mailDatas[parentIndex].userlist[index].isChecked = !$scope.mailDatas[parentIndex].userlist[index].isChecked;
- };
- //选择完成的时候判断是否把选择的成员存储为一个群组 isSetGroupEnter为是否重设置群组里的添加成员加入 0:是 1:否
- $scope.isSetGroupEnter = 1;
- $scope.judgeReturn=function () {
- if($scope.isSetGroupEnter==0){
- //function、then()、提示不显示、直接保存选择成员id
- }else {
- $ionicPopup.show({
- template: "<p style='text-align: center;'>保存为标签,下次可直接选用</p>",
- scope: $scope,
- buttons: [
- {
- text: "忽略",
- onTap: function () {
- //取消时function、保存成员id,成员id不组成群id
- console.log('取消');
- // 若多次进行完成,需初始化
- $scope.userlist = resourceLibraryModel.getUserList();
- // 将所有列出的成员比对,加入到传入接收userlist中
- angular.forEach($scope.mailDatas, function (value) {
- angular.forEach(value.userlist, function (user, ind) {
- // 若已在群组中存在,则默认选中
- if($scope.useridlist.indexOf(user.userid) == -1 && user.isChecked == true){
- $scope.userlist.push(user);
- }
- });
- });
- // 现有成员列表,传回
- resourceLibraryModel.setUserList($scope.userlist);
- console.log(resourceLibraryModel.getUserList());
- $timeout(function () {
- //TODO
- $scope.goback();
- }, 100);
- }
- },
- {
- text: '<span class="ionicAction_span">存为群组</span>',
- type: "button-positive",
- onTap: function () {
- // 获取传入的群组list
- $scope.grouplist = resourceLibraryModel.getGroupList();
- //确认时function保存成员id,成员id组成群id
- // 创建权限组
- // 保存时的成员列表
- // 将所有列出的成员比对,加入到传入接收userlist中
- $scope.userlist = [];// 存储为群组时,清空userlist
- angular.forEach($scope.mailDatas, function (value) {
- angular.forEach(value.userlist, function (user, ind) {
- // 若已在群组中存在,则默认选中
- if(user.isChecked == true){
- $scope.userlist.push(user);
- }
- });
- });
- $scope.requestModelForCreateGroup=
- {
- userid:UserService.id,
- data:{
- id:1,
- authname:"新群组",
- userlist:$scope.userlist
- }
- };
- // 创建组
- ResourceLibraryService.createAuthorityGroup($scope.requestModelForCreateGroup).then(function (response) {
- // console.log(response);
- // 获取创建好的group
- if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) {
- // 将创建好的group加入到前一页面中
- // 临时存储返回的group
- $scope.group = response.data;
- $scope.group.checkBoxEd = true;
- $scope.grouplist.push(response.data);
- resourceLibraryModel.setGroupList($scope.grouplist);
- }
- }, function () {
- UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
- });
- $scope.openModal = function() {
- $scope.groupDetail.groupName=$scope.groupDetail.groupNewName;
- $scope.isShowClear = true;
- $scope.modal.show();
- };
- console.log('确认保存为群组');
- $timeout(function () {
- //TODO
- $scope.goback();
- }, 100);
- }
- }
- ]
- });
- }
- }
- // 转换userlist为带拼音首字母的结果集
- var getTransferUserList = function (userlist) {
- $scope.requestModel.data = userlist;
- ResourceLibraryService.getTransferUserList($scope.requestModel).then(function (response) {
- if(response.code == ConstantService.INTERFACE_STATUS_CODE_3350){
- console.log(response);
- // 转换后的成员列表,放入回传数组里
- resourceLibraryModel.setMailDatas(response.data);
- }
- $timeout(function () {
- //TODO
- $scope.goback();
- }, 100);
- }, function () {
- });
- };
- // 返回至谁可以看页面
- $scope.gotoSourcePage=function () {
- // 不刷新页面
- resourceLibraryModel.setFlag(false);
- $scope.goback();
- };
- // 返回已选中的成员
- $scope.returnCheckedUserList=function () {
- // 不刷新页面
- resourceLibraryModel.setFlag(false);
- // 从 【设置群组】 来
- if($scope.sourcefrom == 1){
- // 将所有列出的成员比对,加入到传入接收userlist中
- angular.forEach($scope.mailDatas, function (value) {
- angular.forEach(value.userlist, function (user, ind) {
- // 若选中的人员不在传入的userlist中,则加入
- if($scope.useridlist.indexOf(user.userid) == -1 && user.isChecked == true){
- $scope.userlist.push(user);
- }else if($scope.useridlist.indexOf(user.userid) != -1 && user.isChecked == false){
- $scope.userlist.splice(ind, 1);
- }
- });
- });
- // 设置群组时选择的成员列表
- resourceLibraryModel.setTempUserList($scope.userlist);
- // 将成员列表转换格式
- getTransferUserList($scope.userlist);
- }
- // 从 【谁可以看】 来
- else if($scope.sourcefrom == 2){
- // 选择是否生成群组
- $scope.judgeReturn();
- }
- /*// 来源:设置群组
- if($scope.sourcefrom == 1){
- $scope.go('setAuthorityGroup', {sourcefrom: 1, userlist: resourceLibraryModel.getUserList()});
- }*/
- };
- //设置群组名称
- $ionicModal.fromTemplateUrl('my-modal.html', {
- scope: $scope,
- animation: 'slide-in-left'
- }).then(function(modal) {
- $scope.modal = modal;
- });
- //打开设置群组名称
- $scope.groupDetail.groupName=$scope.groupDetail.groupNewName;
- $scope.openModal = function() {
- $scope.groupDetail.groupName=$scope.groupDetail.groupNewName;
- $scope.isShowClear = true;
- $scope.modal.show();
- };
- //不更改群组名称
- $scope.closeModalAndNoset = function() {
- console.log('我不修改');
- if($scope.groupDetail.groupNewName!=''){
- $scope.groupDetail.groupName=$scope.groupDetail.groupNewName;
- }else {
- $scope.groupDetail.groupName=$scope.groupDetail.groupName;
- }
- $scope.modal.hide();
- };
- //更改群组名称
- $scope.closeModalAndreSet=function () {
- //function()保存群组名称更改
- console.log('更改成功');
- if($scope.groupDetail.groupNewName!=''){
- $scope.groupDetail.groupName=$scope.groupDetail.groupNewName;
- }else {
- $scope.groupDetail.groupName=$scope.groupDetail.groupName;
- }
- $scope.modal.hide();
- };
- // 搜索成员
- $scope.searchMemberList = function () {
- $scope.showLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- };
- $scope.keyfilter = {
- key: ""// 搜索关键词
- };
- //清空搜索内容
- $scope.clearSearch = function () {
- $scope.groupDetail.groupNewName = "";
- $timeout(function () {
- $scope.isShowClear = false;
- })
- };
- //清空搜索成员
- $scope.clearSearchFirst = function () {
- $scope.keyfilter.key = "";
- $scope.isShowClearFirst = false;
- };
- //是否显示清空按钮之成员
- $scope.isShowClearFirst = false;
- $scope.showFuncFirst = function () {
- $scope.isShowClearFirst = true;
- };
- //是否显示清空按钮之群组
- $scope.isShowClear = false;
- $scope.showFunc = function () {
- $scope.isShowClear = true;
- };
- });
|