|
|
@@ -56,7 +56,284 @@ define(['app/app'], function(app) {
|
|
|
$scope.purcByEn = function (businessCode) {
|
|
|
$rootScope.businessCode = businessCode;
|
|
|
window.location.hash = "#/purc/addOrder";
|
|
|
- }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 分配用户
|
|
|
+ $scope.addUserInfo = function (customer) {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ animation: true,
|
|
|
+ templateUrl: 'static/view/vendor/b2b/modal/add_userInfo.html',
|
|
|
+ controller: 'AddUserInfoCtrl',
|
|
|
+ resolve: {
|
|
|
+ customer: function () {
|
|
|
+ return customer;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ modalInstance.result.then(function (changed, checked) {
|
|
|
+ if (changed) {
|
|
|
+ if (checked)
|
|
|
+ $scope.newUser.roles = checked;
|
|
|
+ else
|
|
|
+ loadUsers();
|
|
|
+ }
|
|
|
+ $scope.customerParams.reload();
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 转移权限
|
|
|
+ $scope.transferUserInfo = function (customer) {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ animation: true,
|
|
|
+ templateUrl: 'static/view/vendor/b2b/modal/transfer_userInfo.html',
|
|
|
+ controller: 'TransferUserInfoCtrl',
|
|
|
+ resolve: {
|
|
|
+ customer: function () {
|
|
|
+ return customer;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ modalInstance.result.then(function (changed, checked) {
|
|
|
+ if (changed) {
|
|
|
+ if (checked)
|
|
|
+ $scope.newUser.roles = checked;
|
|
|
+ else
|
|
|
+ loadUsers();
|
|
|
+ }
|
|
|
+ $scope.customerParams.reload();
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ }]);
|
|
|
+
|
|
|
+ // 转移权限
|
|
|
+ app.register.controller('TransferUserInfoCtrl', ['$scope', '$rootScope', '$modalInstance', 'customer', 'B2bAccountUser', 'toaster', 'B2bAuthenticationService', function ($scope, $rootScope, $modalInstance, customer, AccountUser, toaster, AuthenticationService) {
|
|
|
+ AuthenticationService.getAuthentication().success(function (data) {
|
|
|
+ $scope.loading = false;
|
|
|
+ $scope.thisUser = data;
|
|
|
+ $scope.checkboxes = {
|
|
|
+ checked: false
|
|
|
+ };
|
|
|
+ $scope.loading = true;
|
|
|
+ $scope.transfer = [];
|
|
|
+ AccountUser.findSaleUsers({id : customer.id}, {}, function (data) {
|
|
|
+ $scope.userinfos = data;
|
|
|
+ var transfer = [];
|
|
|
+ angular.forEach($scope.userinfos, function (user, index) {
|
|
|
+ // 当前用户是被管理员转移权限时,转移的是被管理员转移的权限。
|
|
|
+ if ($scope.thisUser.userUU === user.userUU && user.transfer) {
|
|
|
+ $scope.thisUser.transfer = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ angular.forEach($scope.userinfos, function (user, index) {
|
|
|
+ if ($scope.thisUser.sys || $scope.thisUser.transfer) {
|
|
|
+ if (user.transfer) {
|
|
|
+ transfer.push({num: index});
|
|
|
+ user.checked = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (user.distribute) {
|
|
|
+ transfer.push({num: index});
|
|
|
+ user.checked = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $scope.transfer = transfer;
|
|
|
+ $scope.havedone = angular.copy($scope.transfer);
|
|
|
+ $scope.loading = false;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ var checkStatus = function (userinfos) {
|
|
|
+ var transfer = [];
|
|
|
+ angular.forEach(userinfos, function (user, index) {
|
|
|
+ if (user.transfer) {
|
|
|
+ transfer.push({num: index});
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $scope.transfer = transfer;
|
|
|
+ $scope.isChanged = !angular.equals($scope.havedone, $scope.transfer);
|
|
|
+ };
|
|
|
+ $scope.isChanged = false;
|
|
|
+ $scope.isChangedAll = false;
|
|
|
+ $scope.changes = [];
|
|
|
+ // 点击其中一个明细的复选框
|
|
|
+ $scope.checkOne = function (user) {
|
|
|
+ $scope.changes = [];
|
|
|
+ if ($scope.thisUser.sys) { // 管理员操作
|
|
|
+ user.$checked = !user.$checked;
|
|
|
+ angular.forEach($scope.userinfos, function (userInfo) {
|
|
|
+ if ($scope.thisUser.userUU === user.userUU && user.transfer) {
|
|
|
+ $scope.thisUser.transfer = true;
|
|
|
+ }
|
|
|
+ if (user.userUU !== userInfo.userUU) {
|
|
|
+ userInfo.transfer = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if ($scope.thisUser.transfer) { // 被管理员转移权限的非管理员操作
|
|
|
+ user.$checked = !user.$checked;
|
|
|
+ angular.forEach($scope.userinfos, function (userInfo) {
|
|
|
+ if (user.userUU !== userInfo.userUU) {
|
|
|
+ userInfo.transfer = false;
|
|
|
+ } else {
|
|
|
+ userInfo.transfer = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else { // 被分配客户的用户
|
|
|
+ user.$checked = !user.$checked;
|
|
|
+ angular.forEach($scope.userinfos, function (userInfo) {
|
|
|
+ if (user.userUU !== userInfo.userUU) {
|
|
|
+ // userInfo.distribute = false;
|
|
|
+ userInfo.checked = false;
|
|
|
+ userInfo.transfer = false;
|
|
|
+ } else {
|
|
|
+ // userInfo.distribute = true;
|
|
|
+ userInfo.checked = true;
|
|
|
+ userInfo.transfer = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ checkStatus($scope.userinfos);
|
|
|
+ };
|
|
|
+ $scope.close = function (save) {
|
|
|
+ var chooseResult = [];
|
|
|
+ if (save) {
|
|
|
+ if (customer.vendorEnterprise.uu) {
|
|
|
+ // 当前用户是管理员时
|
|
|
+ if ($scope.thisUser.sys) {
|
|
|
+ angular.forEach($scope.userinfos, function (item, i) {
|
|
|
+ chooseResult.push(item);
|
|
|
+ });
|
|
|
+ if (chooseResult.length > 0) {
|
|
|
+ $scope.loading = true;
|
|
|
+ AccountUser.transferSaleUserToVendor({id : customer.id}, chooseResult, function (data) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('success', '提示', '保存成功');
|
|
|
+ $modalInstance.close(false);
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '保存失败', response.data);
|
|
|
+ $modalInstance.close(false);
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ toaster.pop('error', '保存失败', "您未勾选任何记录");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ toaster.pop('info', '提示', "您没有权限转移对象");
|
|
|
+ // 非管理员转移自己的权限时
|
|
|
+ // angular.forEach($scope.userinfos, function (item, i) {
|
|
|
+ // if (item.transfer && item.userUU !== $scope.thisUser.userUU) {
|
|
|
+ // $scope.target = item;
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // if (!$scope.target) {
|
|
|
+ // toaster.pop('error', '保存失败', "您未选择权限转移对象");
|
|
|
+ // } else {
|
|
|
+ // $scope.loading = true;
|
|
|
+ // AccountUser.transferMyDistribute({custUU: customer.myEnterprise.uu, userUU: $scope.target.userUU}, {} ,function (data) {
|
|
|
+ // $scope.loading = false;
|
|
|
+ // toaster.pop('success', '提示', '保存成功');
|
|
|
+ // $modalInstance.close(false);
|
|
|
+ // }, function (response) {
|
|
|
+ // $scope.loading = false;
|
|
|
+ // toaster.pop('error', '保存失败', response.data);
|
|
|
+ // $modalInstance.close(false);
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $modalInstance.close(true, $scope.checkboxes.checked);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $modalInstance.close(false);
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
}]);
|
|
|
+ app.register.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'B2bAccountUser', 'toaster', 'AuthenticationService',
|
|
|
+ function ($scope, $modalInstance, customer, AccountUser, toaster, AuthenticationService) {
|
|
|
+ AuthenticationService.getAuthentication().success(function (data) {
|
|
|
+ $scope.thisUser = data;
|
|
|
+ $scope.checkboxes = {
|
|
|
+ checked: false
|
|
|
+ };
|
|
|
+ $scope.loading = true;
|
|
|
+ $scope.distribute = [];
|
|
|
+ AccountUser.findSaleUsers({id : customer.id}, null, function (data) {
|
|
|
+ $scope.userinfos = data;
|
|
|
+ var distribute = [];
|
|
|
+ angular.forEach($scope.userinfos, function (user, index) {
|
|
|
+ if (user.distribute) {
|
|
|
+ distribute.push({num: index});
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $scope.distribute = distribute;
|
|
|
+ $scope.havedone = angular.copy($scope.distribute);
|
|
|
+ $scope.loading = false;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ var checkStatus = function (userinfos) {
|
|
|
+ var distribute = [];
|
|
|
+ angular.forEach(userinfos, function (user, index) {
|
|
|
+ if (user.distribute) {
|
|
|
+ distribute.push({num: index});
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $scope.distribute = distribute;
|
|
|
+ $scope.isChanged = !angular.equals($scope.havedone, $scope.distribute);
|
|
|
+ }
|
|
|
+ $scope.isChanged = false;
|
|
|
+ $scope.isChangedAll = false;
|
|
|
+ $scope.changes = [];
|
|
|
+ // 点击勾选全部的复选框
|
|
|
+ $scope.checkAll = function () {
|
|
|
+ angular.forEach($scope.userinfos, function (item, index) {
|
|
|
+ item.distribute = $scope.checkboxes.checked;
|
|
|
+ });
|
|
|
+ checkStatus($scope.userinfos);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 点击其中一个明细的复选框
|
|
|
+ $scope.checkOne = function () {
|
|
|
+ var result = true;
|
|
|
+ angular.forEach($scope.userinfos, function (item) {
|
|
|
+ if (item.distribute != true) {
|
|
|
+ result = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $scope.checkboxes.checked = result;
|
|
|
+ checkStatus($scope.userinfos);
|
|
|
+ };
|
|
|
+ $scope.close = function (save) {
|
|
|
+ var chooseResult = [];
|
|
|
+ if (save) {
|
|
|
+ if (customer.id) {
|
|
|
+ angular.forEach($scope.userinfos, function (item, i) {
|
|
|
+ chooseResult.push(item);
|
|
|
+ });
|
|
|
+ if (chooseResult.length > 0) {
|
|
|
+ $scope.loading = true;
|
|
|
+ AccountUser.addSaleUserToVendor({id : customer.id}, chooseResult, function (data) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('success', '提示', '保存成功');
|
|
|
+ $modalInstance.close(false);
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '保存失败', response.data);
|
|
|
+ $modalInstance.close(false);
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ toaster.pop('error', '保存失败', "您未勾选任何记录");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $modalInstance.close(true, $scope.checkboxes.checked);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $modalInstance.close(false);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ }]);
|
|
|
});
|