edit.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. (function ($app) {
  2. $app.module('ylmis').controller('editUserCtrl', function ($scope, $http, $filter, $modal, $ocLazyLoad, $alert, $loading, $state, AuthUser, $bsRouterState) {
  3. $scope.params = $scope.$parent.$parent.editData.params;
  4. $scope.parentLoad = $scope.$parent.$parent.editData.parentLoad;
  5. $scope.user = {};
  6. $scope.recordStatusList = [{ dickey: 1, dicvalue: '启用' }, { dickey: 0, dicvalue: '禁用' }];
  7. $scope.$watch("user.EmployeeId", function (newVal, oldVal) {
  8. if ($scope.employeeList && $scope.employeeList.length > 0 && newVal != oldVal) {
  9. $scope.user.Name = $.map($filter('filter')($scope.employeeList, { EmployeeId: newVal }), function (x) { return x.Name; })[0];
  10. if ($scope.params.userID == undefined || $scope.params.userID == null) {
  11. $scope.user.CmWorkLinkAccountPsid = $.map($filter('filter')($scope.employeeList, { EmployeeId: newVal }), function (x) { return x.EmployeeNo; })[0];
  12. $scope.user.LoginID = $.map($filter('filter')($scope.employeeList, { EmployeeId: newVal }), function (x) { return x.EmployeeNo; })[0];
  13. }
  14. }
  15. });
  16. $scope.loadData = function () {
  17. $loading.show();
  18. $http({
  19. method: "post",
  20. url: "../../api/systemsetting/User/GetUser",
  21. data: {
  22. userID: $scope.params.userID
  23. }
  24. }).then(function (result) {
  25. $loading.hide();
  26. $scope.user = result.data.Data;
  27. });
  28. };
  29. $scope.getEmpList = function () {
  30. $http
  31. ({
  32. method: 'post', url: '../../api/salary/Employee/GetListForSelect', data: { pageIndex: 1, pageSize: 999 }
  33. }).then(function (result) {
  34. $scope.employeeList = result.data.Data.rows;
  35. $scope.employeeList = $scope.employeeList.filter(function (r) { return r.UserId == null || r.UserId == $scope.params.userID })
  36. });
  37. };
  38. $scope.save = function (isflag) {
  39. if (isflag) {
  40. $loading.show();
  41. var url = "../../api/systemsetting/User/Add";
  42. if ($scope.user.UserID) {
  43. url = "../../api/systemsetting/User/Edit";
  44. }
  45. $http({
  46. method: "post",
  47. url: url,
  48. data: {
  49. user: $scope.user
  50. }
  51. }).then(function (result) {
  52. $loading.hide();
  53. if (result.data.IsSuccess) {
  54. $scope.showMsg('成功', '保存成功。');
  55. //重新刷新列表
  56. $scope.parentLoad();
  57. $scope.$hide();
  58. } else {
  59. $scope.showMsg('成功', result.data.Message);
  60. }
  61. }, function (resp) {
  62. $loading.hide();
  63. $scope.showMsg('错误', '服务器错误');
  64. });
  65. }
  66. }
  67. if ($scope.params.userID) {
  68. $scope.loadData();
  69. } else {
  70. $scope.user.RecordStatus = 1;
  71. };
  72. $scope.getEmpList();
  73. });
  74. })(angular);