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


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

    obj = {
        orderDate: null,
wangqinghua's avatar
wangqinghua committed
        type: [],
wangqinghua's avatar
wangqinghua committed
        typeText: '请选择',
        peopleCount: '',
        standard: '',
        standardText: '请选择',
        amount: '请选择',
        remark: '',
    };

    checkObj = {
        orderDate: false,
        type: false,
        peopleCount: false,
        standard: false,
    };

    personList = [];
    applyId; //是否编辑
    type;

    constructor(public navCtrl: NavController, public navParams: NavParams,
                private serveSer: ServeService, public modalCtrl: ModalController,
                private commonSer: CommonService, private datePipe: DatePipe,
                private actionSheetCtrl: ActionSheetController) {
    }

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

    //初始化参数
    initParams() {
        const data = this.navParams.get('data');
        console.log(data);
        if (data) {

        } else {
            this.obj.orderDate = this.datePipe.transform(new Date(), 'yyyy-MM-ddTHH:mm');
        }
    }

    //用车详情
    meetDetail() {
        this.serveSer.detailMeals(this.applyId).subscribe(
            (res) => {
                if (res) {

                }
            }
        )
    }

    // 选择时间点
wangqinghua's avatar
wangqinghua committed
    chooseTime(type) {
        const index = this.obj.type.indexOf(type);
        if(index === -1){
            this.obj.type.push(type);
        }else{
            this.obj.type.splice(index,0);
        }
wangqinghua's avatar
wangqinghua committed
    }


    //选择标准
    chooseStandard() {
        const buttonsArr = [
            {
                text: '15元',
                handler: () => {
                    this.obj.standard = '1';
                    this.obj.standardText = '15元';
                    this.obj.amount = '15';
                }
            },
            {
                text: '20元',
                handler: () => {
                    this.obj.standard = '2';
                    this.obj.standardText = '20元';
                    this.obj.amount = '20';
                }
            },
            {
                text: '其他',
                handler: () => {
                    this.obj.standard = '3';
                    this.obj.standardText = '15元';
                    this.obj.amount = '15';
                }
            }, {
                text: '取消',
                role: 'cancel',
                handler: () => {
                    console.log('Cancel clicked');
                }
            }
        ];
        const actionSheet = this.actionSheetCtrl.create({
            cssClass: 'cameraAction',
            buttons: buttonsArr
        });
        actionSheet.present();
    }

    //选择人员
    choose() {
        let modal = this.modalCtrl.create(PersonMulComponent, {
            enterAnimation: 'modal-scale-enter',
            leaveAnimation: 'modal-scale-leave'
        });
        modal.onDidDismiss(data => {
            if (data) {
                this.personList = data;
            }
        });
        modal.present();
    }

    //移除人员
    removePerson(index) {
        this.personList.splice(index, 1);
    }

    //提交申请
    submit() {
        //校验
        let checkBool = false;
        for (let i in this.checkObj) {
            if (!this.obj[i]) {
                checkBool = true;
                this.checkObj[i] = true;
            } else {
                this.checkObj[i] = false;
            }
        }

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

        let carUser = [];
        this.personList.forEach(e => {
            carUser.push(e.id);
        });
        const data = {
            orderDate: this.datePipe.transform(this.obj.orderDate,'yyyy-MM-dd'),
            type: this.obj.type,
            peopleCount: this.obj.peopleCount,
            standard: this.obj.peopleCount,
            amount: this.obj.amount,
            remark: this.obj.remark,
        };
        console.log(data);
        this.commonSer.alert('确认提交?', () => {
            this.serveSer.saveMeals(data).subscribe(
                (res) => {
                    if (res.errcode == 1000) {
                        this.commonSer.toast('提交申请成功');
                        this.navCtrl.pop();
                    } else {
                        this.commonSer.toast(res.errmsg);
                    }
                }
            )
        });
    }

}