order-scope.component.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. import { Component, OnInit, Output, Input } from '@angular/core';
  2. import { EventEmitter } from '@angular/core';
  3. import { MainService } from 'src/app/services/main.service';
  4. import { ToolService } from 'src/app/services/tool.service';
  5. @Component({
  6. selector: 'app-order-scope',
  7. templateUrl: './order-scope.component.html',
  8. styleUrls: ['./order-scope.component.less']
  9. })
  10. export class OrderScopeComponent implements OnInit {
  11. @Input() hsmsData:any = {
  12. checkedHos: undefined,
  13. scopeGroups: [],
  14. orderScopeRadio: undefined,
  15. }
  16. @Input() itsmData:any = {
  17. checkedHos: undefined,
  18. scopeGroups: [],
  19. orderScopeRadio: undefined,
  20. }
  21. @Output() confirmModal = new EventEmitter();
  22. @Output() cancelModal = new EventEmitter();
  23. constructor(
  24. private mainService: MainService,
  25. private tool: ToolService,
  26. ) { }
  27. user = JSON.parse(localStorage.getItem("user")); //用户信息
  28. checkedHos;//转运-院区
  29. orderScopeRadio:any = '0';//转运-工单范围
  30. itsmCheckedHos:any[] = [];//运维-院区
  31. itsmCheckedGroup:any[] = [];//运维-分组
  32. itsmOrderScopeRadio = '0';//运维-工单范围
  33. isAllItsmGroupChecked:boolean = false;//运维-是否全选分组
  34. ngOnInit() {
  35. this.initHsms();
  36. this.initItsm();
  37. }
  38. initHsms(){
  39. this.checkedHos = this.hsmsData.checkedHos;
  40. this.orderScopeRadio = this.hsmsData.orderScopeRadio;
  41. this.initOrderScope();
  42. this.getOrderScope();
  43. }
  44. initItsm(){
  45. this.itsmOrderScopeRadio = this.itsmData.orderScopeRadio;
  46. this.itsmGetOrderScope();
  47. }
  48. // 工单范选项卡
  49. activeScopeTabValue = 1;
  50. scopeTabs:any[] = [
  51. { name: '运维', value: 1 },
  52. { name: '配送', value: 2 },
  53. ];
  54. // =============================工单范围-运维start========================================
  55. // 工单范围数据
  56. itsmGetOrderScope() {
  57. // 权限内的院区和组
  58. let hosList = this.user.infoPermission.hospitals || [];
  59. let groups = this.user.infoPermission.groups || [];
  60. // 选中的院区和组
  61. let itsmCheckedHos = this.itsmData.checkedHos || [];
  62. let itsmCheckedGroup = this.itsmData.scopeGroups || [];
  63. let hosIds = itsmCheckedHos.map(v => v.id);
  64. let groupIds = itsmCheckedGroup.map(v => v.id);
  65. this.itsmCheckedHos = hosList.map(v => ({ label: v.hosName, value: v.id, checked: hosIds.includes(v.id) }));
  66. this.itsmCheckedGroup = groups.filter(v => hosIds.includes(v.hospital.id)).map(v => ({ label: v.hospital.hosName + '-' + v.groupName, value: v.id, checked: groupIds.includes(v.id) }));
  67. this.isAllItsmGroupChecked = this.itsmCheckedGroup.length ? this.itsmCheckedGroup.every(v => v.checked) : false;
  68. }
  69. // 全选、全不选分组
  70. updateAllItsmGroupChecked(){
  71. this.isAllItsmGroupChecked = !this.isAllItsmGroupChecked;
  72. let flag = this.itsmCheckedGroup.length ? this.itsmCheckedGroup.every(v => v.checked) : false;
  73. this.itsmCheckedGroup.forEach(v => v.checked = !flag);
  74. }
  75. // 选择分组
  76. changeItsmGroup(e){
  77. this.isAllItsmGroupChecked = this.itsmCheckedGroup.length ? this.itsmCheckedGroup.every(v => v.checked) : false;
  78. }
  79. // 选择院区
  80. changeItsmHospital(hospitalList){
  81. // 权限内的院区和组
  82. let groups = this.user.infoPermission.groups || [];
  83. // 选中的院区和组
  84. let itsmCheckedHos = this.itsmCheckedHos || [];
  85. let itsmCheckedGroup = this.itsmCheckedGroup || [];
  86. let hosIds = itsmCheckedHos.filter(v => v.checked).map(v => v.value);
  87. let groupIds = itsmCheckedGroup.filter(v => v.checked).map(v => v.value);
  88. this.itsmCheckedGroup = groups.filter(v => hosIds.includes(v.hospital.id)).map(v => ({ label: v.hospital.hosName + '-' + v.groupName, value: v.id, checked: groupIds.includes(v.id) }));
  89. this.isAllItsmGroupChecked = this.itsmCheckedGroup.length ? this.itsmCheckedGroup.every(v => v.checked) : false;
  90. }
  91. // =============================工单范围-运维end========================================
  92. // =============================工单范围-配送start========================================
  93. // 工单范围数据
  94. hosList = []; //院区
  95. taskTypes = []; //当前权限下所有工单类型
  96. userGroups = []; //当前权限下所有人员分组
  97. hosTaskTypes = {}; //当前权限下所有院区对应的任务类型
  98. hosGroups = {}; //当前权限下所有院区对应的人员分组
  99. getOrderScope() {
  100. this.hosList = this.user.infoPermission.hospitals;
  101. this.taskTypes = this.user.infoPermission.taskTypes;
  102. this.userGroups = this.user.infoPermission.groups;
  103. this.hosList.forEach((e) => {
  104. let arrT = [],
  105. arrG = [];
  106. this.taskTypes.forEach((el) => {
  107. if (el.hosId.id == e.id) {
  108. arrT.push(el);
  109. this.hosTaskTypes["hos" + e.id] = arrT;
  110. }
  111. });
  112. this.userGroups.forEach((ele) => {
  113. if (ele.hospital.id == e.id) {
  114. arrG.push(ele);
  115. this.hosGroups["hos" + e.id] = arrG;
  116. }
  117. });
  118. });
  119. console.log(this.hosTaskTypes, this.hosGroups);
  120. // 工单范围全选按钮是否选中
  121. this.allTypeChecked = false;
  122. if (this.user.user.scope && this.user.user.scope.typeIds) {
  123. if (
  124. this.user.user.scope.typeIds.length ==
  125. this.hosTaskTypes["hos" + this.checkedHos].length
  126. ) {
  127. this.allTypeChecked = true;
  128. }
  129. }
  130. this.allGroupChecked = false;
  131. if (this.user.user.scope && this.user.user.scope.groupIds) {
  132. if (
  133. this.user.user.scope.groupIds.length ==
  134. this.hosGroups["hos" + this.checkedHos].length
  135. ) {
  136. this.allGroupChecked = true;
  137. }
  138. }
  139. }
  140. // 工单类型全选
  141. allTypeChecked: boolean = false; //工单类型全选框
  142. updateAllTypeChecked() {
  143. let arr = [];
  144. this.hosTaskTypes["hos" + this.checkedHos].forEach((e) => {
  145. arr.push(e.id);
  146. });
  147. this.changeTaskTypes(this.allTypeChecked ? arr : []);
  148. let obj = {};
  149. arr.forEach((e) => {
  150. obj[e] = this.allTypeChecked;
  151. });
  152. this.initTypes = obj;
  153. }
  154. // 工单类型
  155. checkedTypes = []; //已选中taskTypes的ID数组
  156. changeType: boolean = false; //是否改变工单类型
  157. hosTypesChecked = {}; //当前权限下所有院区下选中的工单类型
  158. changeTaskTypes(val) {
  159. this.checkedTypes = val;
  160. this.changeType = true;
  161. this.hosTypesChecked["hos" + this.checkedHos] = val;
  162. console.log(this.hosTypesChecked);
  163. if (val.length == this.hosTaskTypes["hos" + this.checkedHos].length) {
  164. this.allTypeChecked = true;
  165. } else {
  166. this.allTypeChecked = false;
  167. }
  168. }
  169. // 人员分组全选
  170. allGroupChecked: boolean = false; //工单类型全选框
  171. updateAllGroupChecked() {
  172. let arr = [];
  173. this.hosGroups["hos" + this.checkedHos].forEach((e) => {
  174. arr.push(e.id);
  175. });
  176. this.changeGroups(this.allGroupChecked ? arr : []);
  177. let obj = {};
  178. arr.forEach((e) => {
  179. obj[e] = this.allGroupChecked;
  180. });
  181. this.initGroups = obj;
  182. }
  183. // 人员分组
  184. checkedGroups = [];
  185. changeGroup: boolean = false; //是否改变分组
  186. hosGroupsChecked = {}; //当前权限下所有院区下选中的人员分组
  187. changeGroups(val) {
  188. this.checkedGroups = val;
  189. this.changeGroup = true;
  190. this.hosGroupsChecked["hos" + this.checkedHos] = val;
  191. console.log(this.hosGroupsChecked);
  192. if (val.length == this.hosGroups["hos" + this.checkedHos].length) {
  193. this.allGroupChecked = true;
  194. } else {
  195. this.allGroupChecked = false;
  196. }
  197. }
  198. // 工单范围院区切换
  199. getTypeAndGroup() {
  200. this.allTypeChecked = false;
  201. this.allGroupChecked = false;
  202. for (let k1 in this.initTypes) {
  203. this.initTypes[k1] = false;
  204. }
  205. for (let k1 in this.initGroups) {
  206. this.initGroups[k1] = false;
  207. }
  208. this.orderScopeRadio = "0";
  209. }
  210. // 保存工单范围设置
  211. saveLoading: boolean = false; //保存按钮loading状态
  212. saveOrderScope() {
  213. this.saveLoading = true;
  214. let types = [];
  215. if (!this.changeType) {
  216. // 没有改变当前工单类型设置,取初始化设置,
  217. for (var i in this.initTypes) {
  218. if (this.initTypes[i]) {
  219. types.push(Number(i));
  220. }
  221. }
  222. } else {
  223. let arr = this.hosTypesChecked["hos" + this.checkedHos] || [];
  224. arr.forEach(function (val) {
  225. types.push(Number(val));
  226. });
  227. }
  228. let groups = [];
  229. if (!this.changeGroup) {
  230. // 没有改变当前分组设置,取初始化设置,
  231. for (var k in this.initGroups) {
  232. if (this.initGroups[k]) {
  233. groups.push(Number(k));
  234. }
  235. }
  236. } else {
  237. let arr = this.hosGroupsChecked["hos" + this.checkedHos] || [];
  238. arr.forEach(function (val) {
  239. groups.push(Number(val));
  240. });
  241. }
  242. types = [...new Set(types)];
  243. groups = [...new Set(groups)];
  244. let groupsId = [];
  245. groups.forEach((e) => {
  246. groupsId.push({ id: e });
  247. });
  248. let typesId = [];
  249. types.forEach((e) => {
  250. typesId.push({ id: e });
  251. });
  252. let postData = {
  253. workerOrderScope: {
  254. hospitalId: { id: this.checkedHos - 0 },
  255. typeIds: typesId,
  256. groupIds: groupsId,
  257. range: this.orderScopeRadio - 0,
  258. userId: this.user.user.id,
  259. },
  260. };
  261. if (this.user.user.scope && this.user.user.scope.id) {
  262. postData.workerOrderScope["id"] = this.user.user.scope.id;
  263. }
  264. console.log(postData);
  265. return;
  266. this.mainService
  267. .coopTypeConfig("addData", "workerOrderScope", postData)
  268. .subscribe((data) => {
  269. this.saveLoading = false;
  270. this.confirmModal.emit(data);
  271. });
  272. }
  273. // 关闭弹窗
  274. cancelInit() {
  275. this.cancelModal.emit();
  276. }
  277. // 工单范围设置回显
  278. initTypes = {}; //工单类型
  279. initGroups = {}; //人员分组
  280. initOrderScope() {
  281. if (!this.user || !this.user.user || !this.user.user.scope) return;
  282. let scopeInfo = this.user.user.scope;
  283. if (!this.taskTypes.length) {
  284. this.initTypes = {};
  285. } else {
  286. this.taskTypes.forEach((val, idx) => {
  287. this.initTypes[val.id] = false;
  288. });
  289. }
  290. if (!scopeInfo.typeIds) {
  291. this.initTypes = {};
  292. this.allTypeChecked = false;
  293. } else {
  294. scopeInfo.typeIds.forEach((val, idx) => {
  295. this.initTypes[val.id] = true;
  296. });
  297. }
  298. console.log(this.initTypes);
  299. if (!this.userGroups || !this.userGroups.length) {
  300. this.initGroups = {};
  301. } else {
  302. this.userGroups.forEach((val, idx) => {
  303. this.initGroups[val.id] = false;
  304. });
  305. }
  306. if (!scopeInfo.groupIds || !scopeInfo.groupIds.length) {
  307. this.initGroups = {};
  308. } else {
  309. scopeInfo.groupIds.forEach((val, idx) => {
  310. this.initGroups[val.id] = true;
  311. });
  312. }
  313. console.log(this.initGroups);
  314. console.log(this.initTypes);
  315. }
  316. // =============================工单范围-配送end========================================
  317. }