123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- import { Component, OnInit, Output, Input } from '@angular/core';
- import { EventEmitter } from '@angular/core';
- import { MainService } from 'src/app/services/main.service';
- import { ToolService } from 'src/app/services/tool.service';
- @Component({
- selector: 'app-order-scope',
- templateUrl: './order-scope.component.html',
- styleUrls: ['./order-scope.component.less']
- })
- export class OrderScopeComponent implements OnInit {
- @Input() hsmsData:any = {
- checkedHos: undefined,
- scopeGroups: [],
- orderScopeRadio: undefined,
- }
- @Input() itsmData:any = {
- checkedHos: undefined,
- scopeGroups: [],
- orderScopeRadio: undefined,
- }
- @Output() confirmModal = new EventEmitter();
- @Output() cancelModal = new EventEmitter();
- constructor(
- private mainService: MainService,
- private tool: ToolService,
- ) { }
- user = JSON.parse(localStorage.getItem("user")); //用户信息
- checkedHos;//转运-院区
- orderScopeRadio:any = '0';//转运-工单范围
- itsmCheckedHos:any[] = [];//运维-院区
- itsmCheckedGroup:any[] = [];//运维-分组
- itsmOrderScopeRadio:any = '0';//运维-工单范围
- isAllItsmGroupChecked:boolean = false;//运维-是否全选分组
- ngOnInit() {
- this.initHsms();
- this.initItsm();
- }
- initHsms(){
- console.log('hsmsData:', this.hsmsData);
- this.scopeTabs[0].checked = this.hsmsData.hsmsSwitch;
- this.checkedHos = this.hsmsData.checkedHos;
- this.orderScopeRadio = this.hsmsData.orderScopeRadio;
- this.initOrderScope();
- this.getOrderScope();
- }
- initItsm(){
- console.log('itsmData', this.itsmData);
- this.scopeTabs[1].checked = this.itsmData.mdv2Switch;
- this.itsmOrderScopeRadio = this.itsmData.orderScopeRadio;
- this.itsmInitOrderScope();
- this.itsmGetOrderScope();
- }
- // 工单范选项卡
- scopeTabs:any[] = [
- { name: '运维', value: 1, checked: false },
- { name: '配送', value: 2, checked: false },
- ];
- activeScopeTab = this.scopeTabs[0];
- //#region 工单范围-运维start
- allDuty:number = 1;
- itsmInitOrderScope(){
- }
- // 工单范围数据
- itsmGetOrderScope() {
- // 是否不限制部门
- this.allDuty = this.itsmData.allDuty === undefined ? 1 : this.itsmData.allDuty;
- // 权限内的院区和组
- let hosList = this.user.infoPermission.dutyList || [];
- let groups = this.user.infoPermission.dutyGroupList || [];
- // 选中的院区和组
- let itsmCheckedHos = this.itsmData.checkedHos || [];
- let itsmCheckedGroup = this.itsmData.scopeGroups || [];
- let hosIds = itsmCheckedHos.map(v => v.id);
- let groupIds = itsmCheckedGroup.map(v => v.id);
- this.itsmCheckedHos = hosList.map(v => ({ label: v.hosName, value: v.id, checked: hosIds.includes(v.id) }));
- 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) }));
- this.isAllItsmGroupChecked = this.itsmCheckedGroup.length ? this.itsmCheckedGroup.every(v => v.checked) : false;
- }
- // 全选、全不选分组
- updateAllItsmGroupChecked(){
- this.itsmCheckedGroup.forEach(v => v.checked = this.isAllItsmGroupChecked);
- }
- // 选择分组
- changeItsmGroup(e){
- this.isAllItsmGroupChecked = this.itsmCheckedGroup.length ? this.itsmCheckedGroup.every(v => v.checked) : false;
- }
- // 选择院区
- changeItsmHospital(hospitalList){
- console.log('hospitalList:', hospitalList)
- // 权限内的院区和组
- let groups = this.user.infoPermission.dutyGroupList || [];
- // 选中的院区和组
- let itsmCheckedHos = this.itsmCheckedHos || [];
- let itsmCheckedGroup = this.itsmCheckedGroup || [];
- let hosIds = itsmCheckedHos.filter(v => v.checked).map(v => v.value);
- let groupIds = itsmCheckedGroup.filter(v => v.checked).map(v => v.value);
- 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) }));
- console.log('this.itsmCheckedGroup:', this.itsmCheckedGroup)
- this.isAllItsmGroupChecked = this.itsmCheckedGroup.length ? this.itsmCheckedGroup.every(v => v.checked) : false;
- }
- //#endregion 工单范围-运维end
- //#region 工单范围-配送start
- // 工单范围数据
- hosList = []; //院区
- taskTypes = []; //当前权限下所有工单类型
- userGroups = []; //当前权限下所有人员分组
- hosTaskTypes = {}; //当前权限下所有院区对应的任务类型
- hosGroups = {}; //当前权限下所有院区对应的人员分组
- getOrderScope() {
- this.hosList = this.user.infoPermission.hospitals.filter(v => !this.tool.isDuty(v));
- this.taskTypes = this.user.infoPermission.taskTypes;
- this.userGroups = this.user.infoPermission.groups.filter(v => v.type !== 3);
- this.hosList.forEach((e) => {
- let arrT = [],
- arrG = [];
- this.taskTypes.forEach((el) => {
- if (el.hosId.id == e.id) {
- arrT.push(el);
- this.hosTaskTypes["hos" + e.id] = arrT;
- }
- });
- this.userGroups.forEach((ele) => {
- if (ele.hospital.id == e.id) {
- arrG.push(ele);
- this.hosGroups["hos" + e.id] = arrG;
- }
- });
- });
- console.log(this.hosTaskTypes, this.hosGroups);
- // 工单范围全选按钮是否选中
- this.allTypeChecked = false;
- if (this.user.user.scope && this.user.user.scope.typeIds) {
- if (
- this.user.user.scope.typeIds.length ==
- this.hosTaskTypes["hos" + this.checkedHos].length
- ) {
- this.allTypeChecked = true;
- }
- }
- this.allGroupChecked = false;
- if (this.user.user.scope && this.user.user.scope.groupIds) {
- if (
- this.user.user.scope.groupIds.length ==
- this.hosGroups["hos" + this.checkedHos].length
- ) {
- this.allGroupChecked = true;
- }
- }
- }
- // 工单类型全选
- allTypeChecked: boolean = false; //工单类型全选框
- updateAllTypeChecked() {
- let arr = [];
- this.hosTaskTypes["hos" + this.checkedHos].forEach((e) => {
- arr.push(e.id);
- });
- this.changeTaskTypes(this.allTypeChecked ? arr : [], false);
- }
- // 工单类型
- checkedTypes = []; //已选中taskTypes的ID数组
- changeType: boolean = false; //是否改变工单类型
- hosTypesChecked = {}; //当前权限下所有院区下选中的工单类型
- changeTaskTypes(val, isOwn = true) {
- this.checkedTypes = val;
- this.changeType = true;
- this.hosTypesChecked["hos" + this.checkedHos] = val;
- console.log(this.hosTypesChecked);
- if (val.length == this.hosTaskTypes["hos" + this.checkedHos].length) {
- this.allTypeChecked = true;
- } else {
- this.allTypeChecked = false;
- }
- if(isOwn){
- let obj = {};
- console.log('arr:', val)
- console.log('hosTaskTypes:', this.hosTaskTypes)
- val.forEach((e) => {
- obj[e] = true;
- });
- this.initTypes = obj;
- }else{
- let obj = {};
- console.log('arr:', val)
- console.log('hosTaskTypes:', this.hosTaskTypes)
- val.forEach((e) => {
- obj[e] = this.allTypeChecked;
- });
- this.initTypes = obj;
- }
- }
- // 人员分组全选
- allGroupChecked: boolean = false; //工单类型全选框
- updateAllGroupChecked() {
- let arr = [];
- this.hosGroups["hos" + this.checkedHos].forEach((e) => {
- arr.push(e.id);
- });
- this.changeGroups(this.allGroupChecked ? arr : [], false);
- }
- // 人员分组
- checkedGroups = [];
- changeGroup: boolean = false; //是否改变分组
- hosGroupsChecked = {}; //当前权限下所有院区下选中的人员分组
- changeGroups(val, isOwn = true) {
- this.checkedGroups = val;
- this.changeGroup = true;
- this.hosGroupsChecked["hos" + this.checkedHos] = val;
- console.log(this.hosGroupsChecked);
- if (val.length == this.hosGroups["hos" + this.checkedHos].length) {
- this.allGroupChecked = true;
- } else {
- this.allGroupChecked = false;
- }
- if(isOwn){
- let obj = {};
- val.forEach((e) => {
- obj[e] = true;
- });
- this.initGroups = obj;
- }else{
- let obj = {};
- val.forEach((e) => {
- obj[e] = this.allGroupChecked;
- });
- this.initGroups = obj;
- }
- }
- // 工单范围院区切换
- getTypeAndGroup() {
- this.allTypeChecked = false;
- this.allGroupChecked = false;
- for (let k1 in this.initTypes) {
- this.initTypes[k1] = false;
- }
- for (let k1 in this.initGroups) {
- this.initGroups[k1] = false;
- }
- this.orderScopeRadio = "0";
- }
- // 保存工单范围设置
- saveLoading: boolean = false; //保存按钮loading状态
- saveOrderScope() {
- this.saveLoading = true;
- let types = [];
- if (!this.changeType) {
- // 没有改变当前工单类型设置,取初始化设置,
- for (var i in this.initTypes) {
- if (this.initTypes[i]) {
- types.push(Number(i));
- }
- }
- } else {
- let arr = this.hosTypesChecked["hos" + this.checkedHos] || [];
- arr.forEach(function (val) {
- types.push(Number(val));
- });
- }
- let groups = [];
- if (!this.changeGroup) {
- // 没有改变当前分组设置,取初始化设置,
- for (var k in this.initGroups) {
- if (this.initGroups[k]) {
- groups.push(Number(k));
- }
- }
- } else {
- let arr = this.hosGroupsChecked["hos" + this.checkedHos] || [];
- arr.forEach(function (val) {
- groups.push(Number(val));
- });
- }
- types = [...new Set(types)];
- groups = [...new Set(groups)];
- let groupsId = [];
- groups.forEach((e) => {
- groupsId.push({ id: e });
- });
- let typesId = [];
- types.forEach((e) => {
- typesId.push({ id: e });
- });
- let itsm = this.scopeTabs.find(v => v.value == 1);
- let hsms = this.scopeTabs.find(v => v.value == 2);
- let postData:any = {
- workerOrderScope: {
- userId: this.user.user.id,
- mdv2Switch: Number(itsm.checked),
- hsmsSwitch: Number(hsms.checked),
- },
- };
- if(itsm.checked){
- postData.workerOrderScope.allDuty = this.allDuty;
- postData.workerOrderScope.dutyIds = this.itsmCheckedHos.filter(v => v.checked).map(v => v.value).toString();
- postData.workerOrderScope.dutyGroupIds = this.itsmCheckedGroup.filter(v => v.checked).map(v => v.value).toString();
- postData.workerOrderScope.dutyRange = this.itsmOrderScopeRadio - 0;
- }
- if(hsms.checked){
- postData.workerOrderScope.hospitalId = { id: this.checkedHos - 0 };
- postData.workerOrderScope.typeIds = typesId;
- postData.workerOrderScope.groupIds = groupsId;
- postData.workerOrderScope.range = this.orderScopeRadio - 0;
- }
- if (this.user.user.scope && this.user.user.scope.id) {
- postData.workerOrderScope["id"] = this.user.user.scope.id;
- }
- console.log('allDuty', this.allDuty)
- console.log('itsmCheckedHos', this.itsmCheckedHos)
- console.log('itsmCheckedGroup', this.itsmCheckedGroup)
- console.log('itsmOrderScopeRadio', this.itsmOrderScopeRadio)
- console.log(postData);
- // return;
- this.mainService
- .coopTypeConfig("addData", "workerOrderScope", postData)
- .subscribe((data) => {
- this.saveLoading = false;
- this.confirmModal.emit(data);
- });
- }
- // 关闭弹窗
- cancelInit() {
- this.cancelModal.emit();
- }
- // 工单范围设置回显
- initTypes = {}; //工单类型
- initGroups = {}; //人员分组
- initOrderScope() {
- if (!this.user || !this.user.user || !this.user.user.scope) return;
- let scopeInfo = this.user.user.scope;
- if (!this.taskTypes.length) {
- this.initTypes = {};
- } else {
- this.taskTypes.forEach((val, idx) => {
- this.initTypes[val.id] = false;
- });
- }
- if (!scopeInfo.typeIds) {
- this.initTypes = {};
- this.allTypeChecked = false;
- } else {
- scopeInfo.typeIds.forEach((val, idx) => {
- this.initTypes[val.id] = true;
- });
- }
- console.log(this.initTypes);
- if (!this.userGroups || !this.userGroups.length) {
- this.initGroups = {};
- } else {
- this.userGroups.forEach((val, idx) => {
- this.initGroups[val.id] = false;
- });
- }
- if (!scopeInfo.groupIds || !scopeInfo.groupIds.length) {
- this.initGroups = {};
- } else {
- scopeInfo.groupIds.forEach((val, idx) => {
- this.initGroups[val.id] = true;
- });
- }
- console.log(this.initGroups);
- console.log(this.initTypes);
- }
- //#endregion 工单范围-配送end
- }
|