Newer
Older
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,
typeText: '请选择',
peopleCount: '',
standard: '',
standardText: '请选择',
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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) {
this.obj.orderDate = res.data.orderDate;
this.obj.standard = res.data.standard;
this.obj.peopleCount = res.data.peopleCount;
this.obj.amount = res.data.amount;
this.obj.typeList = res.data.typeList;
this.obj.remark = res.data.remark;
const index = this.obj.typeList.indexOf(type);
if (index === -1) {
this.obj.typeList.push(type);
} else {
this.obj.typeList.splice(index, 0);
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
}
//选择标准
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';
}
}, {
text: '取消',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
];
const actionSheet = this.actionSheetCtrl.create({
cssClass: 'cameraAction',
buttons: buttonsArr
});
actionSheet.present();
}
//提交申请
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 =<any> {
orderDate: this.datePipe.transform(this.obj.orderDate, 'yyyy-MM-dd'),
typeList: this.obj.typeList,
peopleCount: this.obj.peopleCount,
standard: this.obj.peopleCount,
amount: this.obj.amount,
remark: this.obj.remark,
};
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);
}
}
)
});
}
}