Newer
Older
import {Component} from '@angular/core';
import {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 {
cartList = [];
footerView = false;
chooseObj = [];
checkAll;
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);
}
//获取购物车列表
getCart() {
const data = {
P_pageNumber: '1',
P_pageSize: '100',
status: 1
};
this.serveSer.shoppingCar(data).subscribe(
(res) => {
this.cartList = res.list;
this.cartList.forEach(e => {
e.checkbox = false;
})
}
)
}
//选择规格 数量
choose(item) {
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});
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
161
162
163
164
165
166
167
168
//全选
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);
}