123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- angular.module('push')
- .controller('userSearchCtrl', function ($scope, $timeout, $stateParams, $http, UtilService, SearchResultService, UserService, AuthorityModel, AuthorityService, AuthorityModelService) {
- $scope.searchtype = $stateParams.searchtype;//0:搜索用户关注、1:搜索用户添加
- var isset = $stateParams.isset;//0:创建、1:设置
- var authorityid = $stateParams.authorityid;
- var authoritycomefrom = $stateParams.authoritycomefrom;
- var modeltype = $stateParams.modeltype;//0:新建权限(默认),1:新建组
- $scope.key = "";
- $scope.userid = UserService.id;
- $scope.showbaidu = false;
- //已选择用户id拼接
- var useridlist = "";
- var getUserIdList = function () {
- useridlist = "";
- if (modeltype == 0) {
- angular.forEach(AuthorityModel.getMemberList(), function (value, index) {
- var tempid = "'" + value.userId + "'";
- useridlist = useridlist + tempid + ",";
- });
- } else {
- angular.forEach(AuthorityModelService.getMemberList(), function (value, index) {
- var tempid = "'" + value.userId + "'";
- useridlist = useridlist + tempid + ",";
- });
- }
- // console.log(useridlist);
- };
- getUserIdList();
- //关注用户刷选
- var toSelectUserList = function (userList) {
- $scope.userList = angular.copy(userList);
- angular.forEach(userList, function (data, index) {
- var tempid = "'" + data.userId + "'";
- if (useridlist.indexOf(tempid) != -1) {
- $scope.userList[index].isExisits = 1;
- } else {
- $scope.userList[index].isExisits = 0;
- }
- })
- };
- //根据关键字搜索综合、用户信息
- $scope.searchResultByKey = function (key) {
- if (!UtilService.isDefined(key)) {
- return;
- }
- searchUser(key);
- };
- //搜索用户
- var searchUser = function (key) {
- $scope.showbaidu = false;
- //加载动画Loading
- $scope.showLoadingToast();
- SearchResultService.searchUser(key).then(function (response) {
- // console.log(response);
- if (response.length == 0) {
- UtilService.showMess("未搜索到相关用户");
- }
- $scope.userList = response;
- toSelectUserList(response);
- }, function () {
- UtilService.showMess("网络不给力,请重试");
- }).finally(function () {
- $scope.hideLoadingToast();
- });
- };
- //关注
- $scope.doFocus = function (user, index) {
- SearchResultService.doFocus(user.isFocus, user.userId).then(function (response) {
- if (response.status) {
- $scope.userList[index].isFocus = user.isFocus == 1 ? 2 : 1;
- }
- }, function () {
- })
- };
- var adduseridlist = [];
- var addUser = function () {
- var useridstr = adduseridlist.join(',');
- AuthorityService.editAuthority(2, authorityid, authoritycomefrom, "", useridstr).then(function (response) {
- // console.log(response);
- AuthorityModel.editmemberflg = true;
- }, function () {
- UtilService.showMess("网络不给力,请稍后重试");
- });
- };
- //关注用户添加
- $scope.addMember = function (user, index) {
- if (isset == 0) {
- $scope.userList[index].isExisits = 1;
- var tempobj = {
- userId: user.userId,
- userName: user.userName,
- photo: user.photo,
- iscreator: 0,
- comefrom: user.comefrom
- };
- if (modeltype == 0) {
- AuthorityModel.addMemberList(tempobj);
- } else {
- AuthorityModelService.addMemberList(tempobj);
- }
- } else {
- adduseridlist = [];
- $scope.userList[index].isExisits = 1;
- adduseridlist.push(user.userId);
- addUser();
- }
- };
- $scope.gobackback = function () {
- $timeout(function () {
- $scope.goback();
- }, 350)
- };
- //清空搜索内容
- $scope.clearSearch = function () {
- $scope.key = "";
- };
- $scope.showFunc = function () {
- $scope.showbaidu = true;
- };
- //监测key变化,即时匹配词库
- $scope.fixKey = function () {
- if (angular.isDefined($scope.key) && $scope.key.length > 0) {
- $scope.searchKey($scope.key);
- }
- };
- $scope.data = [];
- //百度词库
- $scope.searchKey = function (searchName) {
- var search_history = angular.element(document.getElementById("his_search"));
- if (search_history.val().length != 0) {
- var baidu = angular.element(document.getElementById("baidu_search"));
- baidu.css("display", "block");
- }
- $http({
- method: 'JSONP',
- url: 'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=' + searchName + '&cb=JSON_CALLBACK'
- }).success(function (data) {
- $scope.data = data.s;
- });
- };
- });
|