Skip to content
vistor-apply.ts 2.64 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component} from '@angular/core';
import {ActionSheetController, ModalController, NavController, NavParams} from 'ionic-angular';
import {ServeService} from "../../serve.service";
import {AppMainService} from "../../../../app/app.service";
import {CommonService} from "../../../../provide/common.service";
import {DatePipe} from "@angular/common";
import {PersonMulComponent} from "../../../../components/person-mul/person-mul";


@Component({
    selector: 'page-vistor-apply',
    templateUrl: 'vistor-apply.html',
})
export class VistorApplyPage {

    obj =<any> {
        visitorName: '',
        visitorOrg: '',
        carNumber: '',
        visitTime: '',
        remark: '',
    };

    check = {
        visitorName: false,
        visitTime: false,
    };


    applyId; //是否编辑
    mineInfo;  //申请人信息

    constructor(public navCtrl: NavController, public navParams: NavParams, private actionSheetCtrl: ActionSheetController,
                private serveSer: ServeService, public _modalCtrl: ModalController, private appMainSer: AppMainService,
                private commonSer: CommonService, private datePipe: DatePipe) {
        this.appMainSer.mineInfo.subscribe(value => {
            this.mineInfo = value;
        })
    }

    ionViewDidLoad() {
        this.initParams();
        this.applyId = this.navParams.get('id');
        if (this.applyId) {
            this.meetDetail();
        }
    }

    //时间和会议室初始化
    initParams() {
        const data = this.navParams.get('data');

    }

    //会议详情
    meetDetail() {
        this.serveSer.editVisitorApply(this.applyId).subscribe(
            (res) => {
                if (res) {

                }
            }
        )
    }

    submit() {

        //校验
        let checkBool = false;
        for (let i in this.check) {
            if (!this.obj[i]) {
                checkBool = true;
                this.check[i] = true;
            } else {
                this.check[i] = false;
            }
        }

        if (checkBool) return false;
        this.obj.visitTime = this.datePipe.transform(this.obj.visitTime,'yyyy-MM-dd HH:mm');
        if(this.applyId) this.obj.id = this.applyId;

        this.commonSer.alert('确定提交登记?', () => {
            this.serveSer.saveVisitorApply(this.obj).subscribe(
                (res) => {
                    if (res.errcode == 1000) {
                        this.navCtrl.pop()
                        this.commonSer.toast('访客登记成功');
                    } else {
                        this.commonSer.toast(res.errmsg);
                    }
                }
            )
        });
    }

}