order-scope.component.ts 13 KB

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