Newer
Older
import {
ActionSheetController,
IonicPage,
LoadingController,
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";
import {TimeFormatService} from "../../../../provide/timeFormat.service";
@Component({
selector: 'page-food-apply',
templateUrl: 'food-apply.html',
})
export class FoodApplyPage {
obj = {
orderDate: null,
typeText: '请选择',
peopleCount: '',
standard: '',
standardText: '请选择',
peopleCount: false,
standard: false,
};
personList = [];
applyId; //是否编辑
type;
constructor(public navCtrl: NavController, public navParams: NavParams,private timeFormat:TimeFormatService,
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');
this.nowDate = this.datePipe.transform(new Date(), 'yyyy-MM-ddTHH:mm');
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);
changeStartTime(e) {
this.obj.orderDate = this.timeFormat.ionTimeFormat(e);
}
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
154
155
156
157
158
159
160
//选择标准
chooseStandard() {
const buttonsArr = [
{
text: '15元',
handler: () => {
this.obj.standard = '1';
this.obj.standardText = '15元';
this.obj.amount = '15';
}
},
{
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,
let loading = this.loading.create({
content:'提交中...'
});
loading.present();
this.serveSer.saveMeals(data).subscribe(
(res) => {
if (res.errcode == 1000) {
this.commonSer.toast('提交申请成功');
this.navCtrl.pop();
} else {
this.commonSer.toast(res.errmsg);
}