|
@@ -1,30 +1,43 @@
|
|
const getReq = require('./../../config.js').getReq;
|
|
const getReq = require('./../../config.js').getReq;
|
|
Page({
|
|
Page({
|
|
data: {
|
|
data: {
|
|
- free_info:{
|
|
|
|
- type:Array
|
|
|
|
|
|
+ free_info: {
|
|
|
|
+ type: Array
|
|
},
|
|
},
|
|
- summary:{
|
|
|
|
- type:Array
|
|
|
|
|
|
+ summary: {
|
|
|
|
+ type: Array
|
|
},
|
|
},
|
|
- cart_list:{
|
|
|
|
- type:Array
|
|
|
|
- }
|
|
|
|
|
|
+ cart_list: {
|
|
|
|
+ type: Array
|
|
|
|
+ },
|
|
|
|
+ all_checked: false,
|
|
|
|
+ allPrice: 0,
|
|
|
|
+ allGoodsPrice: 0
|
|
},
|
|
},
|
|
onLoad: function () {
|
|
onLoad: function () {
|
|
-
|
|
|
|
|
|
+
|
|
},
|
|
},
|
|
- onShow:function(){
|
|
|
|
|
|
+ onShow: function () {
|
|
let self = this;
|
|
let self = this;
|
|
getReq({
|
|
getReq({
|
|
act: 'cart',
|
|
act: 'cart',
|
|
op: 'list'
|
|
op: 'list'
|
|
}, function (res) {
|
|
}, function (res) {
|
|
- console.log(res);
|
|
|
|
if (res.code == 200) {
|
|
if (res.code == 200) {
|
|
let free_info = res.datas.free_info;
|
|
let free_info = res.datas.free_info;
|
|
- let summary = res.datas.summary;
|
|
|
|
|
|
+ let summary_datas = res.datas.summary;
|
|
let cart_list = res.datas.cart_list;
|
|
let cart_list = res.datas.cart_list;
|
|
|
|
+ let summary = [];
|
|
|
|
+ for (let item of cart_list) {
|
|
|
|
+ item.checked = false;
|
|
|
|
+ }
|
|
|
|
+ for (let i = 0; i < cart_list.length; i++) {
|
|
|
|
+ for (let j = 0; j < summary_datas.length; j++) {
|
|
|
|
+ if (cart_list[i].goods_id == summary_datas[j].goods_id) {
|
|
|
|
+ summary.push(summary_datas[j]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
self.setData({
|
|
self.setData({
|
|
free_info,
|
|
free_info,
|
|
summary,
|
|
summary,
|
|
@@ -32,5 +45,153 @@ Page({
|
|
});
|
|
});
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ goods_checked(e) {
|
|
|
|
+ let goods_id = e.currentTarget.dataset.goodsid;
|
|
|
|
+ let cart_list = this.data.cart_list;
|
|
|
|
+ let all_checked_state = 0;
|
|
|
|
+ for (let item of cart_list) {
|
|
|
|
+ if (item.goods_id == goods_id) {
|
|
|
|
+ item.checked = !item.checked;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (let item of cart_list) {
|
|
|
|
+ if (item.checked) {
|
|
|
|
+ all_checked_state = all_checked_state + 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (all_checked_state == cart_list.length) {
|
|
|
|
+ all_checked_state = true;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ all_checked_state = false;
|
|
|
|
+ }
|
|
|
|
+ this.setData({
|
|
|
|
+ cart_list,
|
|
|
|
+ all_checked: all_checked_state
|
|
|
|
+ });
|
|
|
|
+ this.total();
|
|
|
|
+ },
|
|
|
|
+ all_checked() {
|
|
|
|
+ let cart_list = this.data.cart_list;
|
|
|
|
+ let all_checked_state = this.data.all_checked;
|
|
|
|
+ for (let item of cart_list) {
|
|
|
|
+ item.checked = !all_checked_state;
|
|
|
|
+ }
|
|
|
|
+ this.setData({
|
|
|
|
+ cart_list,
|
|
|
|
+ all_checked: !all_checked_state
|
|
|
|
+ });
|
|
|
|
+ this.total();
|
|
|
|
+ },
|
|
|
|
+ req_goods_num(cart_id, quantity,callback){
|
|
|
|
+ let self = this;
|
|
|
|
+ getReq({
|
|
|
|
+ act: 'cart',
|
|
|
|
+ op: 'edit',
|
|
|
|
+ cart_id,
|
|
|
|
+ quantity
|
|
|
|
+ }, function (res) {
|
|
|
|
+ if (res.code == 200) {
|
|
|
|
+ let goods_num = res.datas.goods_num;
|
|
|
|
+ let cart_list = self.data.cart_list;
|
|
|
|
+ for (let item of cart_list) {
|
|
|
|
+ if (item.cart_id == cart_id) {
|
|
|
|
+ item.goods_num = goods_num;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ self.setData({
|
|
|
|
+ cart_list
|
|
|
|
+ });
|
|
|
|
+ callback;
|
|
|
|
+ for (let i = 0; i < self.data.cart_list.length;i++) {
|
|
|
|
+ if (self.data.cart_list[i].checked) {
|
|
|
|
+ self.total();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ wx.showToast({
|
|
|
|
+ title:res.message,
|
|
|
|
+ icon:"none"
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ goods_num_handle(e) {
|
|
|
|
+ let self = this;
|
|
|
|
+ let cart_id = e.target.dataset.cartid;
|
|
|
|
+ let num = e.target.dataset.num;
|
|
|
|
+ let compute_function = e.target.dataset.function;
|
|
|
|
+ let goods_id = e.target.dataset.goodsid;
|
|
|
|
+ let quantity = 1;
|
|
|
|
+ if (compute_function == 'add') {
|
|
|
|
+ quantity = num + quantity;
|
|
|
|
+ this.req_goods_num(cart_id, quantity);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ quantity = num - quantity;
|
|
|
|
+ if (quantity <= 0) {
|
|
|
|
+ wx.showModal({
|
|
|
|
+ title: "提示",
|
|
|
|
+ content: "确定要删除吗?",
|
|
|
|
+ success: function (res) {
|
|
|
|
+ if (res.confirm) {
|
|
|
|
+ self.req_goods_num(cart_id, quantity, self.del_cart(cart_id, goods_id));
|
|
|
|
+ } else if (res.cancel) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ self.req_goods_num(cart_id, quantity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ del_cart(cart_id, goods_id) {
|
|
|
|
+ let summary = this.data.summary;
|
|
|
|
+ let cart_list = this.data.cart_list;
|
|
|
|
+ for (let i = 0; i < summary.length;i++) {
|
|
|
|
+ if (summary[i].goods_id == goods_id) {
|
|
|
|
+ summary.splice(i,1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (let i = 0; i < cart_list.length; i++) {
|
|
|
|
+ if (cart_list[i].goods_id == goods_id) {
|
|
|
|
+ cart_list.splice(i,1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ this.setData({
|
|
|
|
+ summary,
|
|
|
|
+ cart_list
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ total(){
|
|
|
|
+ let self = this;
|
|
|
|
+ let cart_item = [];
|
|
|
|
+ for (let item of this.data.cart_list){
|
|
|
|
+ cart_item.push(item.cart_id);
|
|
|
|
+ }
|
|
|
|
+ let carts = cart_item.join(",");
|
|
|
|
+ getReq({
|
|
|
|
+ act: 'member_buy',
|
|
|
|
+ op: 'calc_cash',
|
|
|
|
+ ifcart: 1,
|
|
|
|
+ cart_id: carts
|
|
|
|
+ }, function (res) {
|
|
|
|
+ if (res.code == 200) {
|
|
|
|
+ let datas = res.datas.payinfo;
|
|
|
|
+ let allPrice = parseFloat((datas.goods_amount + datas.freight - datas.available_pred - datas.full_discount - datas.opgoods_discount).toFixed(2));
|
|
|
|
+ let allGoodsPrice = parseFloat((datas.goods_amount).toFixed(2));
|
|
|
|
+ self.setData({
|
|
|
|
+ allPrice,
|
|
|
|
+ allGoodsPrice
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
}
|
|
}
|
|
})
|
|
})
|