order-scope.component.ts 14 KB

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