|
@@ -1,26 +1,25 @@
|
|
|
-
|
|
|
Page({
|
|
|
dever: getApp().dever,
|
|
|
authdialog: null,
|
|
|
+ product_ids: '',
|
|
|
+ product_num: '',
|
|
|
data: {
|
|
|
- isUseAddress: false
|
|
|
+ isUseAddress: false,
|
|
|
+ settlement: 0.00
|
|
|
},
|
|
|
onLoad: function (options) {
|
|
|
+ var that = this;
|
|
|
+
|
|
|
|
|
|
- this.authdialog = this.selectComponent("#authdialog");
|
|
|
-
|
|
|
-
|
|
|
- var list = new Array();
|
|
|
- for(var i=1; i<=10; i++){
|
|
|
- var item = new Object();
|
|
|
- item.name = i+'盒有机韭菜';
|
|
|
- item.price = i*20;
|
|
|
- item.id = i;
|
|
|
- item.num = 1;
|
|
|
- list.push(item);
|
|
|
- }
|
|
|
- this.dever.setList(this, list);
|
|
|
-
|
|
|
+ that.authdialog = this.selectComponent("#authdialog");
|
|
|
+ that.dever.request('product.api.carts',{
|
|
|
+ signature: that.dever.getSignature()
|
|
|
+ },{
|
|
|
+ success: function(data, res){
|
|
|
+ that.dever.setList(that, data.carts);
|
|
|
+ that.doSettlement();
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
|
|
@@ -28,11 +27,27 @@ Page({
|
|
|
*/
|
|
|
delOrder: function(e){
|
|
|
var that = this;
|
|
|
+ var pid = e.currentTarget.dataset.id;
|
|
|
+ var delfun = function(){
|
|
|
+ that.dever.request('product.api.delCarts',{
|
|
|
+ json: 1,
|
|
|
+ signature: that.dever.getSignature(),
|
|
|
+ product_id: pid
|
|
|
+ },{
|
|
|
+ success: function(data, res){
|
|
|
+ that.dever.alert('删除成功!');
|
|
|
+ that.onLoad();
|
|
|
+ },
|
|
|
+ fail: function(res){
|
|
|
+ that.dever.alert('删除失败!');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
wx.showModal({
|
|
|
content: '确认删除该订单吗?',
|
|
|
success: function(res){
|
|
|
if (res.confirm){
|
|
|
- that.dever.alert('删除订单失败!');
|
|
|
+ delfun();
|
|
|
}
|
|
|
}
|
|
|
})
|
|
@@ -45,12 +60,13 @@ Page({
|
|
|
var id = e.currentTarget.dataset.id;
|
|
|
var list = this.data.list;
|
|
|
for(var i=0; i<list.length; i++){
|
|
|
- if (list[i].id == id){
|
|
|
+ if (list[i].product_id == id){
|
|
|
list[i].num = list[i].num-1<=0?1:list[i].num-1;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
this.dever.setList(this, list);
|
|
|
+ this.doSettlement();
|
|
|
},
|
|
|
|
|
|
* 增加商品数量>1 and <=库存
|
|
@@ -59,12 +75,60 @@ Page({
|
|
|
var id = e.currentTarget.dataset.id;
|
|
|
var list = this.data.list;
|
|
|
for (var i = 0; i < list.length; i++) {
|
|
|
- if (list[i].id == id) {
|
|
|
- list[i].num = list[i].num + 1;
|
|
|
+ if (list[i].product_id == id) {
|
|
|
+ ++list[i].num;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
this.dever.setList(this, list);
|
|
|
+ this.doSettlement();
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * 结算金额
|
|
|
+ */
|
|
|
+ doSettlement: function(){
|
|
|
+ var list = this.data.list;
|
|
|
+ var count=0;
|
|
|
+ for(var i=0; i<list.length; i++){
|
|
|
+ var product_id = list[i].product_id;
|
|
|
+ var pay_price = list[i].product.pay_price;
|
|
|
+ var num = list[i].num;
|
|
|
+ count += pay_price*num;
|
|
|
+ if(i==0){
|
|
|
+ this.product_ids += product_id;
|
|
|
+ this.product_num += num;
|
|
|
+ }else{
|
|
|
+ this.product_ids += ',' + product_id;
|
|
|
+ this.product_num += ',' + num;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.dever.set(this, 'settlement', count.toFixed(2));
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * 去支付
|
|
|
+ */
|
|
|
+ doPay: function(e){
|
|
|
+ var that = this;
|
|
|
+ var addrObj = that.data.addrObj;
|
|
|
+ that.dever.request('product.api.buy',{
|
|
|
+ signature: that.dever.getSignature(),
|
|
|
+ product_id: that.product_ids,
|
|
|
+ num: that.product_num,
|
|
|
+ name: addrObj.userName,
|
|
|
+ address: addrObj.provinceName + addrObj.cityName + addrObj.countyName + addrObj.detailInfo,
|
|
|
+ mobile: addrObj.telNumber
|
|
|
+ },{
|
|
|
+ success:function(data, res){
|
|
|
+ that.dever.redirect('pay/index');
|
|
|
+ that.dever.log('doPay success', res);
|
|
|
+ },
|
|
|
+ fail: function(res){
|
|
|
+ that.dever.alert('支付失败!');
|
|
|
+ that.dever.log('doPay fail', res);
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
|