Skip to content
create-team.component.ts 5.04 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
wangqinghua's avatar
wangqinghua committed
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {NzMessageService, UploadFile} from 'ng-zorro-antd';
import {opr_company_type, opr_team_type} from '../../project.constants';
import {SystemService} from '../../../system/system.service';
import {ProjectService} from '../../project.service';
wangqinghua's avatar
wangqinghua committed
import {ProjectModalComponent} from '../project-modal/project-modal.component';
import {CompanyModalComponent} from '../company-modal/company-modal.component';
wangqinghua's avatar
wangqinghua committed
import {TrackInfoComponent} from '../track-info/track-info.component';
wangqinghua's avatar
wangqinghua committed

@Component({
    selector: 'smart-create-team',
    templateUrl: './create-team.component.html',
wangqinghua's avatar
wangqinghua committed
    styles: [
        `
            :host ::ng-deep .ant-input-disabled{
                color: rgba(0,0,0,.65);
                background-color: #fff;
            }
        `
    ]
wangqinghua's avatar
wangqinghua committed
})
export class CreateTeamComponent implements OnInit {
wangqinghua's avatar
wangqinghua committed
    @ViewChild('smartProjectModal') smartProjectModal: ProjectModalComponent;
    @ViewChild('smartCompanyModal') smartCompanyModal: CompanyModalComponent;
wangqinghua's avatar
wangqinghua committed
    @ViewChild('smartTrackInfo') smartTrackInfo: TrackInfoComponent;
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    @Output() done = new EventEmitter<any>();
    tabNum = 0;    //tabs面板的序列号

    title;
    isVisible = false;
    isOkLoading = false;
    validateForm: FormGroup;
    fileList: UploadFile[] = [];
    opr_team_type = opr_team_type;

    cID;

    constructor(private fb: FormBuilder, private systemSer: SystemService,
                private message: NzMessageService, private projectSer: ProjectService) {
    }

    ngOnInit(): void {
        this.initForm();
    }

    initForm() {
        this.validateForm = this.fb.group({
            name: [null, [Validators.required, Validators.minLength(2), Validators.maxLength(50)]],
wangqinghua's avatar
wangqinghua committed
            type: ['0', [Validators.required]],
wangqinghua's avatar
wangqinghua committed
            projectId: [null],
wangqinghua's avatar
wangqinghua committed
            projectName: [null],
wangqinghua's avatar
wangqinghua committed
            companyId: [null],
wangqinghua's avatar
wangqinghua committed
            companyName: [null],
wangqinghua's avatar
wangqinghua committed
            description: [null],
            principal: [null],
            principalId: [null],
        });
    }

    showAddModal(title) {
        this.isVisible = true;
        this.title = title;
    }

    showEditModal(data, title) {
        this.isVisible = true;
        this.title = title;
        this.cID = data.id;
        console.log(data);
        this.validateForm.patchValue(data);
    }

    handleCancel() {
        this.isVisible = false;
        this.initForm();
    }

    beforeUpload = (file: UploadFile): boolean => {
        const isExcel = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || 'application/octet-stream';
        if (!isExcel) {
            this.message.error('请上传正确的文件!');
        } else {
            this.fileList[0] = file;
        }
        return false;
    };

    handleOk() {
        for (let i in this.validateForm.controls) {
            this.validateForm.controls[i].markAsDirty();
            this.validateForm.controls[i].updateValueAndValidity();
        }
        if (this.validateForm.invalid) {
            return false;
        }
        this.isOkLoading = true;
wangqinghua's avatar
wangqinghua committed
        if (this.title == '新增运维团队') {
wangqinghua's avatar
wangqinghua committed
            this.create();
        }
wangqinghua's avatar
wangqinghua committed
        if (this.title == '编辑运维团队') {
wangqinghua's avatar
wangqinghua committed
            this.update();
        }
    }

    create() {
        this.projectSer.addMaintainTeam(this.validateForm.value).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.isVisible = false;
                    this.initForm();
                    this.done.emit();
wangqinghua's avatar
wangqinghua committed
                    this.message.success('新增运维团队成功');
wangqinghua's avatar
wangqinghua committed
                }
                this.isOkLoading = false;
            }
        );
    }

    update() {
        this.validateForm.addControl('id', new FormControl(this.cID));
        this.projectSer.updateMaintainTeam(this.validateForm.value).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.isVisible = false;
                    this.initForm();
                    this.done.emit();
                    this.message.success('更新信息成功');
                }
                this.isOkLoading = false;
            }
        );
    }

    //tabs切换
    tabsChange(num) {
        this.tabNum = num;
    }
wangqinghua's avatar
wangqinghua committed

    // 选择的项目
wangqinghua's avatar
wangqinghua committed
    showProjectmodal() {
        this.smartProjectModal.showModal();
wangqinghua's avatar
wangqinghua committed
    }

    //获取选择的项目
wangqinghua's avatar
wangqinghua committed
    getProject(e) {
        const d = {
            projectId: e.id,
            projectName: e.name
        };
        this.validateForm.patchValue(d);
wangqinghua's avatar
wangqinghua committed
    }

    //选择公司
wangqinghua's avatar
wangqinghua committed
    showCompany() {
wangqinghua's avatar
wangqinghua committed
        this.smartCompanyModal.showModal();
    }

wangqinghua's avatar
wangqinghua committed
    getCompany(e) {
        const d = {
            companyId: e.id,
            companyName: e.name
        };
        this.validateForm.patchValue(d);
    }

    //选择团队负责人
    showPeoplemodal() {

    }
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    getPeople(e) {
        const d = {
            principal: e.name,
            principalId: e.id
        };
        this.validateForm.patchValue(d);
wangqinghua's avatar
wangqinghua committed
    }
wangqinghua's avatar
wangqinghua committed
}