Skip to content
change-create.component.ts 6.81 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
import {ProjectModalComponent} from '../../../project-manager/modal/project-modal/project-modal.component';
import {CompanyModalComponent} from '../../../project-manager/modal/company-modal/company-modal.component';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {NzMessageService, UploadFile} from 'ng-zorro-antd';
import {SystemService} from '../../../system/system.service';
import {SystemChangeService} from '../../system-change.service';
import {SelectPersonComponent} from '../../../modal/select-person/select-person.component';
import {change_level} from '../../system-change.constants';
wangqinghua's avatar
wangqinghua committed
import {TrackInfoComponent} from '../../../project-manager/modal/track-info/track-info.component';
wangqinghua's avatar
wangqinghua committed
import {LocalStorageService} from 'ngx-webstorage';
wangqinghua's avatar
wangqinghua committed
import {WorkService} from '../../../work/work.service';
wangqinghua's avatar
wangqinghua committed

@Component({
    selector: 'smart-change-create',
    templateUrl: './change-create.component.html',
    styles: []
})
export class ChangeCreateComponent implements OnInit {
    @ViewChild('smartProjectModal') smartProjectModal: ProjectModalComponent;
    @ViewChild('smartCompanyModal') smartCompanyModal: CompanyModalComponent;
wangqinghua's avatar
wangqinghua committed
    @ViewChild('smartTrackInfo') smartTrackInfo: TrackInfoComponent;
wangqinghua's avatar
wangqinghua committed
    @ViewChild('smartSelectPerson') smartSelectPerson: SelectPersonComponent;

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

    title;
    isVisible = false;
    isOkLoading = false;
    validateForm: FormGroup;
    fileList: UploadFile[] = [];
wangqinghua's avatar
wangqinghua committed
    fileId = [];
wangqinghua's avatar
wangqinghua committed
    change_level = change_level;
    typeList = [];

    cID;
wangqinghua's avatar
wangqinghua committed
    userInfo;  //用户信息
wangqinghua's avatar
wangqinghua committed

    constructor(private fb: FormBuilder, private systemSer: SystemService,
wangqinghua's avatar
wangqinghua committed
                private sysChangeSer: SystemChangeService,
                private localStorage: LocalStorageService,
wangqinghua's avatar
wangqinghua committed
                private workSer: WorkService,
wangqinghua's avatar
wangqinghua committed
                private message: NzMessageService, private systemChangeSer: SystemChangeService) {
    }

    ngOnInit(): void {
wangqinghua's avatar
wangqinghua committed
        this.userInfo = this.localStorage.retrieve('userInfo');
        console.log(this.userInfo);
wangqinghua's avatar
wangqinghua committed
        this.initForm();
        this.getType();
    }

    //初始化
    initForm() {
        this.validateForm = this.fb.group({
wangqinghua's avatar
wangqinghua committed
            manageUserId: [this.userInfo.userId],
            manageUserName: [this.userInfo.userName],
            organizationId: [this.userInfo.organizationId],
            organizationName: [this.userInfo.organizationName],
wangqinghua's avatar
wangqinghua committed
            type: ['1', [Validators.required]],
            classifyId: [null, [Validators.required]],
            status: ['1'],
wangqinghua's avatar
wangqinghua committed
            title: ['变更'],
            changeTime: [null],
wangqinghua's avatar
wangqinghua committed
            projectId: [null],
            projectName: [null],
            verifyUserId: [null],
            verifyUserName: [null],
wangqinghua's avatar
wangqinghua committed
            description: [null,[Validators.required]],
wangqinghua's avatar
wangqinghua committed
        });
    }

    //变更分类
wangqinghua's avatar
wangqinghua committed
    getType() {
        this.systemChangeSer.findByType('sys_change_type').subscribe(
wangqinghua's avatar
wangqinghua committed
            (res) => {
                if (res.data) {
                    this.typeList = res.data;
                } else {
                    this.message.warning('暂无变更类型');
                }
            }
        );
    }

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

    showEditModal(data, title) {
        this.isVisible = true;
        this.title = title;
        this.cID = data.id;
wangqinghua's avatar
wangqinghua committed
        this.getDetail();
    }

    //查询变更详情
    getDetail() {
        this.sysChangeSer.find(this.cID).subscribe(
            (res) => {
                res.data.type += '';
                res.data.status += '';
                this.validateForm.patchValue(res.data);
            }
        );
wangqinghua's avatar
wangqinghua committed
    }

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

    beforeUpload = (file: UploadFile): boolean => {
wangqinghua's avatar
wangqinghua committed
        this.fileList.push(file);
        let file1 = <any>file;
        const formData = new FormData();
        formData.append('file', file1);
        this.workSer.sysFileUpload(formData).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.fileId.push(res.data.id);
                }
            }
        );

wangqinghua's avatar
wangqinghua committed
        return false;
    };

wangqinghua's avatar
wangqinghua committed
    handleOk(status) {
wangqinghua's avatar
wangqinghua committed
        for (let i in this.validateForm.controls) {
            this.validateForm.controls[i].markAsDirty();
            this.validateForm.controls[i].updateValueAndValidity();
        }
        if (this.validateForm.invalid) {
            return false;
        }
wangqinghua's avatar
wangqinghua committed
        this.validateForm.patchValue({
            status: status
        });
wangqinghua's avatar
wangqinghua committed
        this.isOkLoading = true;
wangqinghua's avatar
wangqinghua committed
        this.validateForm.patchValue({
            changeTime: new Date(this.validateForm.value.changeTime).getTime()
        });
wangqinghua's avatar
wangqinghua committed
        if (this.title.includes('新增')) this.create();
wangqinghua's avatar
wangqinghua committed
        if (this.title.includes('提交审核')) this.update();
wangqinghua's avatar
wangqinghua committed
    }

    create() {
wangqinghua's avatar
wangqinghua committed
        this.validateForm.addControl('fileId', new FormControl(this.fileId.join(',')));
wangqinghua's avatar
wangqinghua committed
        this.systemChangeSer.sysChangeSave(this.validateForm.value).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.isVisible = false;
                    this.initForm();
                    this.done.emit();
                    this.message.success('新增成功');
                }
                this.isOkLoading = false;
            }
        );
    }

    update() {
        this.validateForm.addControl('id', new FormControl(this.cID));
        this.systemChangeSer.sysChangeUpdate(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;
    }

    // 选择的项目
    showProjectmodal() {
        this.smartProjectModal.showModal();
    }

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

    //选择公司
    showCompany() {
        this.smartCompanyModal.showModal();
    }

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

    //选择团队负责人
    showPeoplemodal() {
        this.smartSelectPerson.showModal('选择审批人', null);
    }

    setPeolpe(e) {
        console.log(e);
        const d = {
            verifyUserName: e[0].name,
            verifyUserId: e[0].id
        };
        this.validateForm.patchValue(d);
    }

}