employee_find.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. (function ($app) {
  2. $app.module('ylmis').provider('$employeeFind', function () {
  3. this.$get = function ($http, $filter, $q) {
  4. var empData = {
  5. departmentList: [],
  6. departmentTypeList: [],
  7. employeeTypeList: [],
  8. employeeTitleList: [],
  9. getDepartmentList: function () {
  10. $http({
  11. method: 'post',
  12. url: '../../api/salary/department/GetList'
  13. }).then(function (result) {
  14. empData.departmentList.length = 0;
  15. $app.forEach(result.data.Data, function (val) {
  16. empData.departmentList.push(val);
  17. });
  18. });
  19. },
  20. getDepartmentType: function () {
  21. $http({
  22. method: 'post', url: '../../api/systemsetting/dictionary/GetDicList', data: { code: 'DepartmentType' }
  23. }).then(function (result) {
  24. empData.departmentTypeList.length = 0;
  25. $app.forEach(result.data.Data, function (val) {
  26. empData.departmentTypeList.push(val);
  27. });
  28. });
  29. },
  30. getEmployeeType: function () {
  31. $http({
  32. method: 'post', url: '../../api/systemsetting/dictionary/GetDicList', data: { code: 'EmployeeType' }
  33. }).then(function (result) {
  34. empData.employeeTypeList.length = 0;
  35. $app.forEach(result.data.Data, function (val) {
  36. empData.employeeTypeList.push(val);
  37. });
  38. });
  39. },
  40. getEmployeeTitle: function () {
  41. $http({
  42. method: 'post', url: '../../api/systemsetting/dictionary/GetDicList', data: { code: 'Title' }
  43. }).then(function (result) {
  44. empData.employeeTitleList.length = 0;
  45. $app.forEach(result.data.Data, function (val) {
  46. empData.employeeTitleList.push(val);
  47. });
  48. });
  49. },
  50. setDataEmployeeDepartment: function (emp) {
  51. var list = $filter('filter')(empData.departmentList, function (x) {
  52. return x.DepartmentId == emp.DepartmentId;
  53. });
  54. if (list.length > 0) {
  55. emp.DataDepartment = list[0];
  56. } else {
  57. emp.DataDepartment = {};
  58. }
  59. }, setDataEmployeeTitle: function (emp) {
  60. var list = $filter('filter')(empData.employeeTitleList, function (x) {
  61. return x.Value == emp.Title;
  62. });
  63. if (list.length > 0) {
  64. emp.DataEmployeeTitle = list[0];
  65. } else {
  66. emp.DataEmployeeTitle = {};
  67. }
  68. },
  69. setDataEmployeeType: function (emp) {
  70. var list = $filter('filter')(empData.employeeTypeList, function (x) {
  71. return x.Value == emp.EmployeeTypeId;
  72. });
  73. if (list.length > 0) {
  74. emp.DataEmployeeType = list[0];
  75. } else {
  76. emp.DataEmployeeType = {};
  77. }
  78. },
  79. dataInit: function () {
  80. this.getDepartmentList();
  81. this.getDepartmentType();
  82. this.getEmployeeType();
  83. this.getEmployeeTitle();
  84. },
  85. loadEmployee: function (params) {
  86. /* 参数实体
  87. {employeeTypeIds: ''
  88. employeeTitleIds: '',
  89. departmentIds: '',
  90. empId:''
  91. }
  92. */
  93. return $http({
  94. method: 'post', url: '../../api/administrasalary/Allowance/findEmployees',
  95. data: params
  96. });
  97. }
  98. };
  99. return empData;
  100. };
  101. }).directive('employeeFind', function ($http, $q, $filter, $ocLazyLoad, $employeeFind) {
  102. $ocLazyLoad.load(['home/employee_find.css?' + window.sysVersion]);
  103. var directiveObject = {
  104. restrict: 'ECA',
  105. templateUrl: 'home/employee_find.html',
  106. scope: {
  107. employees: '='
  108. },
  109. link: function (scope, element, attr, controller) {
  110. scope.departmentList = $employeeFind.departmentList;
  111. scope.departmentTypeList = $employeeFind.departmentTypeList;
  112. scope.employeeTypeList = $employeeFind.employeeTypeList;
  113. scope.employeeTitleList = $employeeFind.employeeTitleList;
  114. scope.selectAll = function (list, $event) {
  115. angular.forEach(list, function (val) {
  116. val.checked = $event.target.checked;
  117. });
  118. }
  119. scope.selectDepartment = function (dt, $event) {
  120. var dts = $filter('filter')(scope.$employeeFind.departmentList, { DepartmentTypeId: dt.Value });
  121. angular.forEach(dts, function (val) {
  122. val.checked = $event.target.checked;
  123. });
  124. }
  125. scope.loadData = function () {
  126. var typeIds = $.map($filter('filter')(scope.employeeTypeList, { checked: true }), function (x) { return x.Value; });
  127. var titleIds = $.map($filter('filter')(scope.employeeTitleList, { checked: true }), function (x) { return x.Value; });
  128. var depareIds = $.map($filter('filter')(scope.departmentList, { checked: true }), function (x) { return x.DepartmentId; });
  129. var params = {
  130. employeeTypeIds: typeIds.join(','),
  131. employeeTitleIds: titleIds.join(','),
  132. departmentIds: depareIds.join(',')
  133. };
  134. $employeeFind.loadEmployee(params).then(function (result) {
  135. scope.employees.splice(0, scope.employees.length);
  136. angular.forEach(result.data.Data, function (val) {
  137. scope.employees.push(val);
  138. });
  139. });
  140. }
  141. $employeeFind.dataInit();
  142. }
  143. };
  144. return directiveObject;
  145. }).provider('$department', function () {
  146. this.$get = function ($modal, $http, $filter, $employeeFind) {
  147. var $depart = {
  148. selectDeparts: [],
  149. show: function (selectDatas) {
  150. $app.forEach(this.departmentList, function (x) {
  151. x.checked = false;
  152. });
  153. this.selectDeparts = selectDatas;
  154. modal.$promise.then(modal.show);
  155. },
  156. departmentList: [],
  157. departmentTypeList: [],
  158. getDepartment: function (id) {
  159. var dep = $filter('filter')(this.departmentList, { DepartmentId: id });
  160. if (dep.length > 0) {
  161. return dep[0];
  162. }
  163. return null;
  164. }
  165. };
  166. var getDepartmentList = function () {
  167. $http({
  168. method: 'post',
  169. url: '../../api/salary/department/GetList'
  170. }).then(function (result) {
  171. $depart.departmentList = result.data.Data;
  172. }, function (resp) {
  173. });
  174. };
  175. var getDepartmentType = function () {
  176. $http({
  177. method: 'post', url: '../../api/systemsetting/dictionary/GetDicList', data: { code: 'DepartmentType' }
  178. }).then(function (result) {
  179. $depart.departmentTypeList = result.data.Data;
  180. });
  181. }
  182. getDepartmentList();
  183. getDepartmentType();
  184. var ctrl = function ($scope) {
  185. $scope.title = '部门选择';
  186. $scope.departmentList = $depart.departmentList;
  187. $scope.departmentTypeList = $depart.departmentTypeList;
  188. $scope.selectAll = function (list, $event) {
  189. angular.forEach(list, function (val) {
  190. val.checked = $event.target.checked;
  191. });
  192. }
  193. $scope.selectDepartment = function (dt, $event) {
  194. var dts = $filter('filter')($scope.departmentList, function (x) {
  195. return x.DepartmentTypeId == dt.Value;
  196. });
  197. angular.forEach(dts, function (val) {
  198. val.checked = $event.target.checked;
  199. });
  200. }
  201. $app.forEach($depart.selectDeparts, function (val) {
  202. var departs = $filter('filter')($scope.departmentList, { DepartmentId: val.DepartmentId });
  203. if (departs.length > 0) {
  204. departs[0].checked = true;
  205. }
  206. });
  207. $scope.depSelected = function () {
  208. $depart.selectDeparts.length = 0;
  209. var dlist = $filter('filter')($scope.departmentList, { checked: true });
  210. $app.forEach(dlist, function (val) {
  211. $depart.selectDeparts.push(val);
  212. });
  213. $scope.$hide();
  214. }
  215. };
  216. ctrl.$inject = ['$scope'];
  217. var modal = $modal({
  218. resolve: {
  219. load: ['$ocLazyLoad', function ($ocLazyLoad) {
  220. $ocLazyLoad.load(['home/employee_find.css?' + window.sysVersion]);
  221. }]
  222. },
  223. controller: ctrl,
  224. templateUrl: 'home/m_department.html',
  225. show: false,
  226. animation: 'am-fade-and-slide-top'
  227. });
  228. return $depart;
  229. }
  230. }).provider('$employee', function () {
  231. this.$get = function ($modal, $http, $filter, $q, $alert, $employeeFind) {
  232. var $empResult = {
  233. isMulti: true,
  234. $deferred: null,
  235. empId:'',
  236. selectedEmployee:function() {
  237. var deferred = $q.defer();
  238. this.$deferred = deferred;
  239. this.empId = '';
  240. modal.$promise.then(modal.show);
  241. return deferred.promise;
  242. },
  243. getEmployee: function (id) {
  244. if ($employeeFind.departmentList.length == 0) {
  245. $employeeFind.dataInit();
  246. }
  247. var deferred = $q.defer();
  248. var params = {
  249. employeeTypeIds: '',
  250. employeeTitleIds:'',
  251. departmentIds: '',
  252. empId: id
  253. };
  254. $employeeFind.loadEmployee(params).then(function (result) {
  255. if (result.data.IsSuccess && result.data.Data.length > 0) {
  256. var empEnt = result.data.Data[0];
  257. $employeeFind.setDataEmployeeDepartment(empEnt);
  258. $employeeFind.setDataEmployeeTitle(empEnt);
  259. $employeeFind.setDataEmployeeType(empEnt);
  260. deferred.resolve(empEnt);
  261. } else {
  262. deferred.reject(null);
  263. }
  264. });
  265. return deferred.promise;
  266. }
  267. };
  268. var ctrl = function ($scope) {
  269. $scope.title = '人员选择';
  270. $scope.$own = $empResult;
  271. $scope.$deferred = $empResult.$deferred;
  272. $scope.employeeIds = [];
  273. $scope.selectEmployee = function () {
  274. //var a = $scope.employeeIds;
  275. var employees = $filter('filter')($scope.employeeIds, { checked: true });
  276. if ((!$empResult.isMulti) && employees.length > 1) {
  277. $alert({
  278. title: '消息:',
  279. content: '只能选择一个员工!',
  280. placement: 'top',
  281. type: 'info',
  282. show: true,
  283. duration: 3,
  284. container:'#m_employee'
  285. });
  286. return;
  287. }
  288. $app.forEach(employees, function (val) {
  289. $employeeFind.setDataEmployeeDepartment(val);
  290. $employeeFind.setDataEmployeeTitle(val);
  291. $employeeFind.setDataEmployeeType(val);
  292. });
  293. $empResult.$deferred.resolve(employees);
  294. $scope.$hide();
  295. };
  296. if ($empResult.empId != '') {
  297. }
  298. };
  299. ctrl.$inject = ['$scope'];
  300. var modal = $modal({
  301. resolve: {
  302. load: ['$ocLazyLoad', function ($ocLazyLoad) {
  303. //$ocLazyLoad.load(['home/employee_find.css?' + window.sysVersion]);
  304. }]
  305. },
  306. controller: ctrl,
  307. templateUrl: 'home/m_employee.html',
  308. show: false,
  309. animation: 'am-fade-and-slide-top'
  310. });
  311. return $empResult;
  312. };
  313. });
  314. })(angular);