Skip to content
driver.ts 2.69 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, Input} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {CommonService} from "../../../../provide/common.service";
import {ServeService} from "../../serve.service";

@Component({
    selector: 'page-driver',
    templateUrl: 'driver.html',
})
export class DriverPage {
    @Input() applyId;

    opObj = {
        isOwner: <any>"1",  //是否是内部车辆(1是,0否)
        driverName: '',
        carNumber: '',
        carOrg: '',
        mobile: '',
    };
    checkOpObj = {
        driverName: false,
        carNumber: false,
        carOrg: false,
        mobile: false,
    };

    carList = [];
    driverList = [];

    constructor(public navCtrl: NavController, public navParams: NavParams,
                private commonSer: CommonService, private serveSer: ServeService) {
        this.getList();
    }

    //车辆 司机
    getList() {
        this.serveSer.getCarList().subscribe(
            (res) => {
                this.carList = res.data;
            }
        );
        this.serveSer.getDriverList().subscribe(
            (res) => {
                this.driverList = res.data;
            }
        );
    }

    //提交审核
    submitOp(status) {
        let data;
        const data_company = {
            applyId: this.applyId,
            driverName: this.opObj.driverName,
            carNumber: this.opObj.carNumber,
            status: status,
            isOwner: Number(this.opObj.isOwner)
        };
        const data_lease = {
            applyId: this.applyId,
            driverName: this.opObj.driverName,
            carNumber: this.opObj.carNumber,
            carOrg: this.opObj.carOrg,
            mobile: this.opObj.mobile,
            status: status,
            isOwner: Number(this.opObj.isOwner)
        };
        data = this.opObj.isOwner == "1" ? data_company : data_lease;

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

        if (checkBool) {
            this.commonSer.toast("请输入必填项!");
            return false;
        }

        this.commonSer.alert('确认提交?', () => {
            this.serveSer.carOperate(data).subscribe(
                (res) => {
                    if (res.errcode == 1000) {
                        this.commonSer.toast('审核成功');
                        this.navCtrl.pop();
                    } else {
                        this.commonSer.toast(res.errmsg);
                    }
                }
            )
        });
    }

}