Newer
Older
import {Component, ViewChild} from '@angular/core';
import {InfiniteScrollContent, IonicPage, ModalController, NavController, NavParams} from 'ionic-angular';
import {ServeService} from "../../serve.service";
import {GoodsOrderPage} from "../goods-order/goods-order";
import {SpcesComponent} from "../../../../components/spces/spces";
import {CommonService} from "../../../../provide/common.service";
@Component({
selector: 'page-goods-cart',
templateUrl: 'goods-cart.html',
})
export class GoodsCartPage {
@ViewChild('infiniteScrollContent') infiniteScrollContent: InfiniteScrollContent;
cartList = [];
footerView = false;
chooseObj = [];
checkAll;
page = {
P_pageNumber: 1,
P_pageSize: AppGlobal.pageCount,
loadMore: false,
total: null
};
constructor(public navCtrl: NavController, public navParams: NavParams,
private serveSer: ServeService, private modalCtrl: ModalController,
private commonSer: CommonService, private appMainSer: AppMainService) {
}
ionViewDidEnter() {
this.footerView = true;
this.getCart();
//获取权限
this.appMainSer.role.subscribe(value => {
this.role = value;
}
);
}
ionViewWillLeave() {
this.footerView = false;
}
changeCheck(goods) {
const data = {
id: goods.id,
amount: goods.amount,
brand: goods.brand,
officeId: goods.officeId,
model: goods.model,
specs1: goods.specs1,
specs2: goods.specs2,
specs3: goods.specs3,
specs4: goods.specs4,
specs5: goods.specs5,
};
let get = 0;
let number;
this.chooseObj.forEach((e, index) => {
if (e.id == goods.id) {
get = 1;
number = index;
}
});
if (get == 0) this.chooseObj.push(data);
if (get == 1) this.chooseObj.splice(number, 1);
status: 1
};
this.serveSer.shoppingCar(data).subscribe(
(res) => {
this.cartList = res.list;
this.cartList.forEach(e => {
e.checkbox = false;
})
}
)
}
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
//下拉刷新
doRefresh(e) {
this.page.loadMore = true;
this.infiniteScrollContent.inf.enable(true);
const data = {
P_pageNumber: 1,
P_pageSize: this.page.P_pageSize,
status: 1
};
this.serveSer.shoppingCar(data).subscribe(
(res) => {
this.cartList = res.list;
this.page.total = res.data.total;
timer(800).subscribe(() => {
this.commonSer.toast('刷新成功');
e.complete()
});
}
)
}
doInfinite(e) {
if (this.page.total == this.cartList.length) {
console.log("没有更多了");
this.page.loadMore = false;
e.enable(false);
return false;
}
this.page.P_pageNumber++;
const data = {
P_pageNumber: this.page.P_pageNumber,
P_pageSize: this.page.P_pageSize,
status: 1
};
this.serveSer.searchCheckList(data).subscribe(
(res) => {
this.page.total = res.data.total;
res.list.forEach(e => {
this.cartList.push(e);
});
timer(800).subscribe(() => e.complete());
}
)
}
amount: item.amount,
specs1: item.specs1,
specs2: item.specs2,
specs3: item.specs3,
specs4: item.specs4,
specs5: item.specs5,
let modal = this.modalCtrl.create(SpcesComponent, {goodsId: item.officeId, data: data});
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//全选
selectAll(e) {
this.chooseObj = [];
if (e == false) {
this.cartList.forEach(e => {
e.checkbox = false;
})
} else {
this.cartList.forEach(e => {
e.checkbox = true;
this.chooseObj.push(e);
})
}
}
//提交订单
submit() {
if (this.chooseObj.length == 0) {
this.commonSer.toast('请选择申请物品')
return false;
}
const data = {
"status": 2,
"orderSuppies": this.chooseObj
};
this.commonSer.alert('确定申请所选物品?', () => {
this.serveSer.saveOrder(data).subscribe(
(res) => {
if (res.errcode == 1000) {
this.commonSer.toast("提交申请成功");
this.getCart();
} else {
this.commonSer.toast(res.errmsg);
}
}
)
});
}
//前往订单
goOrder() {
this.navCtrl.push(GoodsOrderPage);
}
//审核提交
goVerify() {
this.navCtrl.push(GoodsVerifyPage);
}