|
|
const app = getApp()
|
|
|
// shopCart.js
|
|
|
import api from '../../common/api.js';
|
|
|
import { curShoppingCartDataAddExpandedFlag, editInfoDicFromGoodsList, hasLackStorageGoodsInList, curPageDataAllSelectWhenEditing,
|
|
|
curPageDataSingleSelectWhenEditing, curPageDataSingleSelectBundleProductWhenEditing, editInfoOfAllGoods, editInfoSelectedGoodsList, editInfoDicFromBundleItem} from '../../utils/shopCartContent';
|
|
|
// var Picker = require('../goodsDetail/picker/picker.js')
|
|
|
import { getGoodInfo, getGoodSize, getGoodImages } from '../../utils/productDetail';
|
|
|
// import {
|
|
|
// logEvent,
|
|
|
// YB_MAIN_TAB_C,
|
|
|
// YB_PAGE_OPEN_L,
|
|
|
// } from '../../libs/analytics.js'
|
|
|
|
|
|
//获取应用实例
|
|
|
let app = getApp();
|
|
|
const screenHeight = app.globalData.systemInfo.screenHeight;
|
|
|
const screenWidth = app.globalData.systemInfo.screenWidth;
|
|
|
const pixelRatio = app.globalData.systemInfo.pixelRatio;
|
|
|
const DEVICE_WIDTH_RATIO = screenWidth / 375.0;
|
|
|
|
|
|
let imageWidth = Math.ceil(75 * DEVICE_WIDTH_RATIO * pixelRatio);
|
|
|
let imageHeight = Math.ceil(100 * DEVICE_WIDTH_RATIO * pixelRatio);
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
commonProductNaviTitle: '普通商品(0)',
|
|
|
commonShoppingCartData: {},
|
|
|
presellProductNavTitle: '预售商品(0)',
|
|
|
presellShoppingCartData: {},
|
|
|
isSelectCommonNavi: true,
|
|
|
curShoppingCartData: {},
|
|
|
scrollerViewTop: 0,
|
|
|
scrollerViewHeight: 0,
|
|
|
isEditing: false,
|
|
|
isReduceOrPlue: false,
|
|
|
current_page_name: 'shopcart',
|
|
|
has_close_price_down_tip: false, //是否已经关闭降价提示
|
|
|
|
|
|
touchX: 0,
|
|
|
touchY: 0,
|
|
|
tempSku: '',
|
|
|
AnimatingSku: '',
|
|
|
deleteAnimation: '', // 控制是否给相应的单元增加删除动画
|
|
|
enableScroll: true,
|
|
|
//picker 需要的数据
|
|
|
//选中的sku
|
|
|
selectedSKU: 0,
|
|
|
//选中sku的库存
|
|
|
storageNumber: 0,
|
|
|
//判断是否选择了颜色
|
|
|
colorSelected: false,
|
|
|
//当前操作的商品
|
|
|
curProcessGoodsItem: {},
|
|
|
pickerData: {
|
|
|
view: {
|
|
|
isShow: false,
|
|
|
isSoldOutSoon: false, //是否显示即将售罄
|
|
|
goodsList: [],
|
|
|
sizeList: [],
|
|
|
image: '',
|
|
|
goodPrice: '',
|
|
|
price: '',
|
|
|
buyNumber: 1,
|
|
|
minusButtonEnable: false,
|
|
|
plusButtonEnable: true,
|
|
|
buyButtonEnable: true,
|
|
|
should_hidden_number_view: false, //由于套餐不支持 修改数量 故弹窗需要隐藏
|
|
|
min_buy_number: 1,
|
|
|
},
|
|
|
sourceType: 'shopCart',
|
|
|
},
|
|
|
from_page: 'shopCart',
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
var that = this
|
|
|
// Picker.init(that);
|
|
|
// new app.WeToast();
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
onReady: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function () {
|
|
|
if (app.isLogin()) {
|
|
|
this.queryShoppingcartData();
|
|
|
}
|
|
|
|
|
|
this.animation = tt.createAnimation({
|
|
|
duration: 300,
|
|
|
timingFunction: 'ease',
|
|
|
})
|
|
|
|
|
|
//埋点上报 页面加载
|
|
|
|
|
|
var pages = getCurrentPages()
|
|
|
var currentPage = pages[pages.length - 1]
|
|
|
var url = currentPage.route
|
|
|
|
|
|
// logEvent(YB_MAIN_TAB_C, { TAB_ID: 2 });
|
|
|
// let params = {
|
|
|
// PAGE_NAME: this.data.from_page,
|
|
|
// PAGE_PARAM: '',
|
|
|
// FROM_PAGE_NAME: '',
|
|
|
// FROM_PAGE_PARAM: '',
|
|
|
// PAGE_PATH: url
|
|
|
|
|
|
// };
|
|
|
// logEvent(YB_PAGE_OPEN_L, params);
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
onHide: function () {
|
|
|
if (this.data.isEditing) {
|
|
|
this.setData({
|
|
|
isEditing: false,
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
onUnload: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
},
|
|
|
onLoad: function () {
|
|
|
console.log('头条小程序代码片段,可点击以下链接查看代码片段的详细文档')
|
|
|
|
|
|
/**
|
|
|
* 查询购物车数据,包括普通购物车和预售购物车
|
|
|
*/
|
|
|
queryShoppingcartData: function () {
|
|
|
let param = {
|
|
|
method: 'app.Shopping.queryCart',
|
|
|
uid: app.getUid()
|
|
|
};
|
|
|
|
|
|
api.post({data:param})
|
|
|
.then(json => {
|
|
|
if (json && json.code && json.code == 200) {
|
|
|
let data = json.data
|
|
|
this.processShopCartData(data);
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
},
|
|
|
|
|
|
navToGiftPage: function (event) {
|
|
|
let data = event.currentTarget.dataset;
|
|
|
let item = data.promotionItem;
|
|
|
// console.log(item);
|
|
|
|
|
|
tt.navigateTo({
|
|
|
url: './giftPage?promotion_id=' + item.promotion_ids + '&is_gift=' + item.isGift + '&status=10',
|
|
|
});
|
|
|
},
|
|
|
|
|
|
processShopCartData:function(data){
|
|
|
if (!data) {
|
|
|
return;
|
|
|
}
|
|
|
let commonShoppingCartData = data.ordinary_cart_data
|
|
|
let presellShoppingCartData = data.advance_cart_data
|
|
|
let commonProductNaviTitle = '普通商品(' + commonShoppingCartData.shopping_cart_data.goods_count + ')'
|
|
|
let presellProductNavTitle = '预售商品(' + presellShoppingCartData.shopping_cart_data.goods_count + ')'
|
|
|
commonShoppingCartData = curShoppingCartDataAddExpandedFlag(commonShoppingCartData);
|
|
|
// presellShoppingCartData = curShoppingCartDataAddExpandedFlag(presellShoppingCartData);
|
|
|
|
|
|
let curShoppingCartData = commonShoppingCartData;
|
|
|
// if (this.data.isSelectCommonNavi) {
|
|
|
// curShoppingCartData = commonShoppingCartData
|
|
|
// } else {
|
|
|
// curShoppingCartData = presellShoppingCartData
|
|
|
// }
|
|
|
const windowHeight = app.globalData.systemInfo.windowHeight;
|
|
|
let scrollerViewTop = 0;
|
|
|
if (curShoppingCartData.shipping_cost_prompt.shipping_cost_tips != '' || curShoppingCartData.shipping_cost_prompt.price_down_tips != '')
|
|
|
{
|
|
|
scrollerViewTop += 40;
|
|
|
}
|
|
|
let scrollerViewHeight = app.globalData.systemInfo.windowHeight - scrollerViewTop - 64;
|
|
|
console.log('=========curShoppingCartData========');
|
|
|
console.log(curShoppingCartData);
|
|
|
console.log(scrollerViewHeight);
|
|
|
console.log('====================================');
|
|
|
this.setData({
|
|
|
commonShoppingCartData,
|
|
|
presellShoppingCartData,
|
|
|
commonProductNaviTitle,
|
|
|
presellProductNavTitle,
|
|
|
curShoppingCartData,
|
|
|
scrollerViewTop,
|
|
|
scrollerViewHeight,
|
|
|
});
|
|
|
},
|
|
|
|
|
|
naviTabSelected:function(event) {
|
|
|
let selectedNaviType = event.currentTarget.dataset.type;
|
|
|
let isSelectCommonNavi = true;
|
|
|
let curShoppingCartData = this.data.commonShoppingCartData;
|
|
|
if (selectedNaviType == 'presellProduct') {
|
|
|
isSelectCommonNavi = false;
|
|
|
curShoppingCartData = this.data.presellShoppingCartData;
|
|
|
}
|
|
|
this.setData({
|
|
|
curShoppingCartData,
|
|
|
isSelectCommonNavi,
|
|
|
})
|
|
|
},
|
|
|
|
|
|
editBtnSelected:function(event) {
|
|
|
let isEditing = this.data.isEditing;
|
|
|
isEditing = !isEditing;
|
|
|
if (isEditing && this.data.AnimatingSku){
|
|
|
var tempAniamtion = this.animation.left('0px').step();
|
|
|
this.data.AnimatingSku = '';
|
|
|
this.setData({
|
|
|
AnimatingSku: '',
|
|
|
deleteAnimation: tempAniamtion.export(),
|
|
|
isEditing,
|
|
|
})
|
|
|
} else {
|
|
|
this.setData({
|
|
|
isEditing,
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
|
|
|
flexOrUnflexPromotion:function(poolItem) {
|
|
|
let index = poolItem.currentTarget.dataset.type;
|
|
|
let curShoppingCartData = this.data.curShoppingCartData;
|
|
|
let goodsPoolList = curShoppingCartData.goods_pool_list;
|
|
|
goodsPoolList[index].isPromotionExpanded = !goodsPoolList[index].isPromotionExpanded;
|
|
|
curShoppingCartData.goods_pool_list = goodsPoolList;
|
|
|
this.setData({
|
|
|
curShoppingCartData,
|
|
|
})
|
|
|
},
|
|
|
|
|
|
selectSingleGoodsAction:function(event) {
|
|
|
let goodsItem = event.currentTarget.dataset.type;
|
|
|
|
|
|
let isEditing = this.data.isEditing;
|
|
|
if (isEditing) {
|
|
|
let curShoppingCartData = this.data.curShoppingCartData;
|
|
|
curShoppingCartData = curPageDataSingleSelectWhenEditing(curShoppingCartData, goodsItem);
|
|
|
this.setData({
|
|
|
curShoppingCartData,
|
|
|
})
|
|
|
} else {
|
|
|
if (goodsItem.bLackStorage) {
|
|
|
this.wetoast.toast({
|
|
|
title: '您勾选的商品库存不足',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
let goodsEditInfoList = editInfoDicFromGoodsList([goodsItem], !goodsItem.bSelected);
|
|
|
this.queryShopCartGoodsWithSkuList(goodsEditInfoList);
|
|
|
}
|
|
|
},
|
|
|
|
|
|
selectAllGoodsAction:function(event){
|
|
|
let bSelectAll = event.currentTarget.dataset.type;
|
|
|
let isEditing = this.data.isEditing;
|
|
|
if(isEditing) {
|
|
|
let curShoppingCartData = this.data.curShoppingCartData;
|
|
|
curShoppingCartData = curPageDataAllSelectWhenEditing(curShoppingCartData, !bSelectAll);
|
|
|
curShoppingCartData.isValidGoodsSelectAll = !bSelectAll,
|
|
|
this.setData({
|
|
|
curShoppingCartData,
|
|
|
})
|
|
|
}else {
|
|
|
let allGoodsEditInfoList = editInfoDicFromGoodsList(this.data.curShoppingCartData.validGoodsList, !bSelectAll);
|
|
|
let allGoodsEditInfoJson = JSON.stringify(allGoodsEditInfoList);
|
|
|
let param = {
|
|
|
product_sku_list: allGoodsEditInfoJson,
|
|
|
method: 'app.Shopping.selectedAndQryCart',
|
|
|
is_support_mlp: 'Y',
|
|
|
shopping_key: '',
|
|
|
};
|
|
|
// console.log(param);
|
|
|
api.post({data:param})
|
|
|
.then(json => {
|
|
|
if (json && json.code && json.code == 200) {
|
|
|
let data = json.data;
|
|
|
this.processShopCartData(data);
|
|
|
if (hasLackStorageGoodsInList(this.data.curShoppingCartData.validGoodsList) && !bSelectAll) {
|
|
|
this.wetoast.toast({
|
|
|
title: '您全选的商品中存在库存不足商品,已帮您自动取消勾选成功',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
|
|
|
editCompletedAction:function(){
|
|
|
this.editBtnSelected(null);
|
|
|
let allGoodsEditInfoList = editInfoOfAllGoods(this.data.curShoppingCartData.validGoodsList);
|
|
|
this.queryShopCartGoodsWithSkuList(allGoodsEditInfoList);
|
|
|
},
|
|
|
}) |
|
|
|
|
|
moveStart: function (e) {
|
|
|
// console.log('moveStart');
|
|
|
let enableScroll = true;
|
|
|
let isEditing = this.data.isEditing;
|
|
|
if(isEditing){
|
|
|
return;
|
|
|
}
|
|
|
this.data.touchX = e.changedTouches[0].clientX;
|
|
|
this.data.touchY = e.changedTouches[0].clientY;
|
|
|
|
|
|
var tempAniamtion = this.animation.left('0px').step();
|
|
|
this.setData({
|
|
|
deleteAnimation: tempAniamtion.export(),
|
|
|
AnimatingSku: '',
|
|
|
enableScroll,
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
moveEnd: function (e) {
|
|
|
// console.log('moveEnd');
|
|
|
|
|
|
let isEditing = this.data.isEditing;
|
|
|
if (isEditing) {
|
|
|
return;
|
|
|
}
|
|
|
var X = e.changedTouches[0].clientX;
|
|
|
var Y = e.changedTouches[0].clientY;
|
|
|
var curGoods = e.currentTarget.dataset.type;
|
|
|
var data = null, tempAniamtion = null;
|
|
|
var angle = this.angle({ X: X, Y: Y }, { X: this.data.touchX, Y: this.data.touchY});
|
|
|
if (Math.abs(angle) > 30) return;
|
|
|
|
|
|
if (this.data.touchX - X > 3) {
|
|
|
// console.log('左滑动');
|
|
|
if (this.data.AnimatingSku) {
|
|
|
let enableScroll = false;
|
|
|
tempAniamtion = this.animation.left('0px').step();
|
|
|
this.setData({
|
|
|
AnimatingSku: '',
|
|
|
deleteAnimation: tempAniamtion.export(),
|
|
|
enableScroll,
|
|
|
})
|
|
|
} else {
|
|
|
let enableScroll = false;
|
|
|
tempAniamtion = this.animation.left('-70px').step();
|
|
|
this.setData({
|
|
|
AnimatingSku: curGoods && curGoods.product_sku?curGoods.product_sku:'',
|
|
|
deleteAnimation: tempAniamtion.export(),
|
|
|
tempSku: curGoods && curGoods.unique_identifier?curGoods.unique_identifier:'',
|
|
|
enableScroll,
|
|
|
})
|
|
|
}
|
|
|
} else if (this.data.touchX - X < -3) {
|
|
|
// console.log('右滑动');
|
|
|
let enableScroll = true;
|
|
|
tempAniamtion = this.animation.left('0px').step();
|
|
|
this.setData({
|
|
|
deleteAnimation: tempAniamtion.export(),
|
|
|
AnimatingSku: '',
|
|
|
enableScroll,
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
queryShopCartGoodsWithSkuList: function(skuListInfo){
|
|
|
let goodsEditInfoJson = JSON.stringify(skuListInfo);
|
|
|
let param = {
|
|
|
product_sku_list: goodsEditInfoJson,
|
|
|
method: 'app.Shopping.selectedAndQryCart',
|
|
|
is_support_mlp: 'Y',
|
|
|
shopping_key: '',
|
|
|
};
|
|
|
// console.log(param);
|
|
|
api.post({data:param})
|
|
|
.then(json => {
|
|
|
this.setData({
|
|
|
isReduceOrPlue: false,
|
|
|
});
|
|
|
if (json && json.code && json.code == 200) {
|
|
|
let data = json.data;
|
|
|
this.processShopCartData(data);
|
|
|
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
this.setData({
|
|
|
isReduceOrPlue: false,
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
|
|
|
deleteGoodsRequest:function(skuList){
|
|
|
let goodsInfoJson = JSON.stringify(skuList);
|
|
|
let param = {
|
|
|
product_sku_list: goodsInfoJson,
|
|
|
method: 'app.Shopping.removeAndQryCart',
|
|
|
is_support_mlp: 'Y',
|
|
|
uid: app.getUid(),
|
|
|
shopping_key: '',
|
|
|
};
|
|
|
api.post({data:param})
|
|
|
.then(json => {
|
|
|
if (json && json.code && json.code == 200) {
|
|
|
let data = json.data;
|
|
|
this.processShopCartData(data);
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
// console.log(error);
|
|
|
});
|
|
|
},
|
|
|
deleteGoodsCell:function(event){
|
|
|
let that = this;
|
|
|
tt.showModal({
|
|
|
title: '',
|
|
|
content: '是否确认删除此商品?',
|
|
|
cancelText: '取消',
|
|
|
confirmText: '确认',
|
|
|
confirmColor: "#d0021b",
|
|
|
success: function (res) {
|
|
|
if (res.confirm) {
|
|
|
let goodsItem = event.currentTarget.dataset.type;
|
|
|
if (that.data.AnimatingSku != '') {
|
|
|
var tempAniamtion = that.animation.left('0px').step();
|
|
|
that.setData({
|
|
|
AnimatingSku: '',
|
|
|
deleteAnimation: tempAniamtion.export(),
|
|
|
})
|
|
|
}
|
|
|
let goodsInfo = [{
|
|
|
buy_number: goodsItem.buy_number,
|
|
|
product_sku: goodsItem.product_sku,
|
|
|
promotion_id: goodsItem.promotion_id,
|
|
|
activity_id: goodsItem.bundle_activity_id ? goodsItem.bundle_activity_id : 0,
|
|
|
batch_no: goodsItem.batch_no ? goodsItem.batch_no : 0,
|
|
|
}];
|
|
|
that.deleteGoodsRequest(goodsInfo);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
cutDownBuyCountAction:function(event){
|
|
|
let isReduceOrPlue = this.data.isReduceOrPlue;
|
|
|
if (isReduceOrPlue){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let goodsItem = event.currentTarget.dataset.type;
|
|
|
let min_buy_number = goodsItem.min_buy_number > 0 ? goodsItem.min_buy_number : 1;
|
|
|
|
|
|
let current_buy_number = parseInt(goodsItem.buy_number);
|
|
|
if (current_buy_number > 0 && current_buy_number <= min_buy_number) {
|
|
|
this.wetoast.toast({
|
|
|
title: '最低' + min_buy_number + '件起',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this.setData({
|
|
|
isReduceOrPlue: true,
|
|
|
});
|
|
|
|
|
|
let reduceBuyCountParam = {
|
|
|
product_sku: goodsItem.product_sku,
|
|
|
decrease_number: 1,
|
|
|
method: 'app.Shopping.decrease',//app.Shopping.incrBundle
|
|
|
uid: app.getUid(),
|
|
|
shopping_key: '',
|
|
|
};
|
|
|
api.post({data:reduceBuyCountParam})
|
|
|
.then(json => {
|
|
|
if (json && json.code && json.code == 200) {
|
|
|
let reduceBuyGoodsInfo = [{
|
|
|
buy_number: goodsItem.buy_number - 1,
|
|
|
goods_type: goodsItem.goods_type,
|
|
|
product_sku: goodsItem.product_sku,
|
|
|
promotion_id: goodsItem.promotion_id,
|
|
|
selected: 'Y',
|
|
|
activity_id: goodsItem.bundle_activity_id ? goodsItem.bundle_activity_id : 0,
|
|
|
batch_no: goodsItem.batch_no ? goodsItem.batch_no : 0,
|
|
|
}];
|
|
|
this.queryShopCartGoodsWithSkuList(reduceBuyGoodsInfo);
|
|
|
} else {
|
|
|
this.setData({
|
|
|
isReduceOrPlue: false,
|
|
|
});
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
this.setData({
|
|
|
isReduceOrPlue: false,
|
|
|
});
|
|
|
this.wetoast.toast({
|
|
|
title: error.code + error.message + '',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
plusBuyCountAction:function(event){
|
|
|
let isReduceOrPlue = this.data.isReduceOrPlue;
|
|
|
if (isReduceOrPlue) {
|
|
|
return;
|
|
|
}
|
|
|
this.setData({
|
|
|
isReduceOrPlue: true,
|
|
|
});
|
|
|
let goodsItem = event.currentTarget.dataset.type;
|
|
|
let increaseBuyCountParam = {
|
|
|
product_sku: goodsItem.product_sku,
|
|
|
increase_number: 1,
|
|
|
method: 'app.Shopping.increase',
|
|
|
uid: app.getUid(),
|
|
|
shopping_key: '',
|
|
|
};
|
|
|
api.post({data:increaseBuyCountParam})
|
|
|
.then(json => {
|
|
|
if (json && json.code && json.code == 200) {
|
|
|
let increaseBuyGoodsInfo = [{
|
|
|
buy_number: goodsItem.buy_number + 1,
|
|
|
goods_type: goodsItem.goods_type,
|
|
|
product_sku: goodsItem.product_sku,
|
|
|
promotion_id: goodsItem.promotion_id,
|
|
|
selected: 'Y',
|
|
|
activity_id: goodsItem.bundle_activity_id ? goodsItem.bundle_activity_id : 0,
|
|
|
batch_no: goodsItem.batch_no ? goodsItem.batch_no : 0,
|
|
|
}];
|
|
|
this.queryShopCartGoodsWithSkuList(increaseBuyGoodsInfo);
|
|
|
} else {
|
|
|
this.setData({
|
|
|
isReduceOrPlue: false,
|
|
|
});
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
this.setData({
|
|
|
isReduceOrPlue: false,
|
|
|
});
|
|
|
this.wetoast.toast({
|
|
|
title: error.code + error.message + '',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
plusReachedMaxAction:function(event){
|
|
|
this.wetoast.toast({
|
|
|
title: '对不起,没有更多库存了',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
},
|
|
|
chooseSizeColorAction:function(event){
|
|
|
var that = this
|
|
|
let goodsItem = event.currentTarget.dataset.type;
|
|
|
// console.log(goodsItem);
|
|
|
this.setData({
|
|
|
curProcessGoodsItem: goodsItem,
|
|
|
should_hidden_number_view: (goodsItem.bundle_activity_id && goodsItem.batch_no),
|
|
|
});
|
|
|
let min_buy_number = goodsItem.min_buy_number > 0 ? goodsItem.min_buy_number : 1;
|
|
|
this.data.pickerData.view.should_hidden_number_view = (goodsItem.bundle_activity_id && goodsItem.batch_no);
|
|
|
this.data.pickerData.view.min_buy_number = min_buy_number;
|
|
|
this.fetchGoodInfo(goodsItem.product_skn);
|
|
|
// Picker.pickerShow(event, that);
|
|
|
},
|
|
|
//获取商品基本信息(包括颜色、尺码)
|
|
|
fetchGoodInfo: function (productSKN) {
|
|
|
let param = {
|
|
|
method: 'app.product.data',
|
|
|
product_skn: productSKN
|
|
|
}
|
|
|
var that = this
|
|
|
|
|
|
api.get({data:param})
|
|
|
.then(function (data) {
|
|
|
if (!data || data.code != 200)
|
|
|
return
|
|
|
|
|
|
let color_length = 0;
|
|
|
if (data.data.goods_list) {
|
|
|
color_length = data.data.goods_list.length;
|
|
|
}
|
|
|
let ImgUrls = [];
|
|
|
data.data.goods_list && data.data.goods_list.map((item, index) => {
|
|
|
let images = getGoodImages(item.images_list, imageWidth, imageHeight)
|
|
|
ImgUrls = [...ImgUrls, ...images]
|
|
|
if (index == 0 && color_length == 1) {
|
|
|
item.selected = true;
|
|
|
that.data.colorSelected = true;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
let isSoldOutSoon = false;
|
|
|
let tags = data.data.tags;
|
|
|
if (tags) {
|
|
|
tags.map((item) => {
|
|
|
if (item == "is_soon_sold_out") {
|
|
|
isSoldOutSoon = true;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//pickerData
|
|
|
var temData = that.data.pickerData;
|
|
|
temData.view.goodsList = data.data.goods_list;
|
|
|
temData.view.isSoldOutSoon = isSoldOutSoon;
|
|
|
|
|
|
//默认显示第一种颜色的尺码
|
|
|
temData.view.sizeList = data.data.goods_list.length > 0 ? data.data.goods_list[0].size_list : [];
|
|
|
|
|
|
let plusButtonEnable = false;
|
|
|
let minusButtonEnable = false;
|
|
|
//根据库存设置该尺码是否可以选择
|
|
|
let size_length = 0;
|
|
|
if (temData.view.sizeList) {
|
|
|
size_length = temData.view.sizeList.length;
|
|
|
}
|
|
|
temData.view.sizeList && temData.view.sizeList.map((item, index) => {
|
|
|
item.enable = item.storage_number > 0 ? true : false;
|
|
|
if (index == 0 && size_length == 1 && that.data.colorSelected) {
|
|
|
//当颜色被选中 并且只有一个size 时 才会自动 做选中尺码操作
|
|
|
temData.view.buyButtonEnable = item.enable;
|
|
|
if (item.enable) {
|
|
|
item.selected = true;
|
|
|
plusButtonEnable = item.storage_number > 1;
|
|
|
that.setData({
|
|
|
selectedSKU: item.product_sku,
|
|
|
storageNumber: item.storage_number,
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
temData.view.plusButtonEnable = plusButtonEnable;
|
|
|
temData.view.minusButtonEnable = minusButtonEnable;
|
|
|
temData.view.image = ImgUrls.length > 0 ? ImgUrls[0] : '';
|
|
|
temData.view.price = data.data.format_market_price;
|
|
|
temData.view.goodPrice = data.data.format_sales_price;
|
|
|
|
|
|
that.setData({
|
|
|
pickerData: temData,
|
|
|
});
|
|
|
})
|
|
|
.catch(function (error) {
|
|
|
this.wetoast.toast({
|
|
|
title: error.code + error.message + '',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
//减少购买数量
|
|
|
bindMinus: function (event) {
|
|
|
let pickerData = this.data.pickerData;
|
|
|
let buyNumber = parseInt(pickerData.view.buyNumber);
|
|
|
|
|
|
|
|
|
let min_buy_number = pickerData.view.min_buy_number > 0 ? pickerData.view.min_buy_number : 1;
|
|
|
|
|
|
if (buyNumber > 0 && buyNumber <= min_buy_number && min_buy_number != 1) {
|
|
|
this.wetoast.toast({
|
|
|
title: '最低' + min_buy_number + '件起',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (buyNumber > 1) {
|
|
|
buyNumber = buyNumber - 1;
|
|
|
}
|
|
|
|
|
|
pickerData.view.buyNumber = buyNumber;
|
|
|
|
|
|
if (buyNumber == 1) {
|
|
|
pickerData.view.minusButtonEnable = false;
|
|
|
} else {
|
|
|
pickerData.view.minusButtonEnable = true;
|
|
|
}
|
|
|
|
|
|
if (buyNumber < this.data.storageNumber) {
|
|
|
pickerData.view.plusButtonEnable = true;
|
|
|
}
|
|
|
this.setData({ pickerData });
|
|
|
},
|
|
|
|
|
|
//增加购买数量
|
|
|
bindPlus: function (event) {
|
|
|
if (!this.data.colorSelected) {
|
|
|
this.wetoast.toast({
|
|
|
title: '请选择颜色',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!this.data.selectedSKU) {
|
|
|
this.wetoast.toast({
|
|
|
title: '请选择尺码',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let pickerData = this.data.pickerData;
|
|
|
let buyNumber = pickerData.view.buyNumber;
|
|
|
|
|
|
if (buyNumber >= this.data.storageNumber) {
|
|
|
this.plusReachedMaxAction();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (buyNumber < this.data.storageNumber) {
|
|
|
pickerData.view.plusButtonEnable = true;
|
|
|
buyNumber = parseInt(buyNumber) + 1;
|
|
|
}
|
|
|
|
|
|
if (buyNumber >= this.data.storageNumber) {
|
|
|
pickerData.view.plusButtonEnable = false;
|
|
|
}
|
|
|
|
|
|
if (buyNumber > 1) {
|
|
|
pickerData.view.minusButtonEnable = true;
|
|
|
}
|
|
|
|
|
|
pickerData.view.buyNumber = buyNumber;
|
|
|
this.setData({ pickerData });
|
|
|
},
|
|
|
|
|
|
//点击背景,隐藏picker
|
|
|
pickerTap: function (event) {
|
|
|
if (event.target.id == "picker-bg") {
|
|
|
var that = this
|
|
|
// Picker.pickerHide(event, that);
|
|
|
this.resetPickerData();
|
|
|
}
|
|
|
},
|
|
|
|
|
|
//点击选择颜色
|
|
|
colorTap: function (event) {
|
|
|
//更新各个颜色的选中状态
|
|
|
var that = this
|
|
|
var tempData = that.data.pickerData;
|
|
|
//先遍历将所有颜色、尺码置为未选中状态
|
|
|
// console.log('color')
|
|
|
// console.log(tempData.view.goodsList)
|
|
|
|
|
|
tempData.view.goodsList && tempData.view.goodsList.map((item, index) => {
|
|
|
item.selected = false
|
|
|
item.size_list.map((subItem, index) => {
|
|
|
subItem.selected = false
|
|
|
subItem.enable = subItem.storage_number > 0 ? true : false
|
|
|
});
|
|
|
});
|
|
|
|
|
|
//将当前颜色置为选中状态
|
|
|
var tempItem = event.target.dataset.key
|
|
|
|
|
|
//遍历颜色尺码,根据库存切换显示状态
|
|
|
tempItem && tempItem.size_list && tempItem.size_list.map((item, index) => {
|
|
|
item.enable = item.storage_number > 0 ? true : false
|
|
|
})
|
|
|
|
|
|
tempItem.selected = true
|
|
|
|
|
|
//设置标志位,表示已经选择颜色
|
|
|
let colorSelected = true
|
|
|
|
|
|
//重置库存、当前选中sku的值
|
|
|
tempData.storageNumber = 0
|
|
|
tempData.selectedSKU = 0
|
|
|
|
|
|
tempData.view.goodsList[Number(event.target.id)] = tempItem
|
|
|
tempData.view.sizeList = tempItem.size_list
|
|
|
|
|
|
tempData.view.minusButtonEnable = false
|
|
|
//将购买数量设为初始状态
|
|
|
tempData.view.buyNumber = 1
|
|
|
|
|
|
this.setData({
|
|
|
colorSelected,
|
|
|
pickerData: tempData,
|
|
|
});
|
|
|
},
|
|
|
|
|
|
//点击选择尺码
|
|
|
sizeTap: function (event) {
|
|
|
var that = this
|
|
|
var tempData = that.data.pickerData
|
|
|
|
|
|
//现遍历将所有尺码置为未选中状态
|
|
|
tempData.view.sizeList && tempData.view.sizeList.map((item, index) => {
|
|
|
item.selected = false
|
|
|
});
|
|
|
|
|
|
//将当前尺码置为选中状态
|
|
|
var tempItem = event.currentTarget.dataset.key
|
|
|
tempItem.selected = true
|
|
|
tempData.view.sizeList[parseInt(event.currentTarget.id)] = tempItem
|
|
|
|
|
|
//设置数量加减按钮启用状态
|
|
|
tempData.view.plusButtonEnable = tempItem.storage_number > 1
|
|
|
tempData.view.minusButtonEnable = false
|
|
|
tempData.view.buyButtonEnable = true
|
|
|
//将购买数量设为初始状态
|
|
|
tempData.view.buyNumber = 1
|
|
|
// console.log(event)
|
|
|
if (tempItem.storage_number <= 0) {
|
|
|
this.wetoast.toast({
|
|
|
title: '该尺码已经售罄',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
|
|
|
tempData.view.buyButtonEnable = false
|
|
|
}
|
|
|
this.setData({
|
|
|
pickerData: tempData,
|
|
|
selectedSKU: tempItem.storage_number > 0 ? tempItem.product_sku : 0,
|
|
|
storageNumber: tempItem.storage_number,
|
|
|
});
|
|
|
},
|
|
|
chooseSizeColorCompleted:function(event){
|
|
|
|
|
|
if (!this.data.selectedSKU) {
|
|
|
this.wetoast.toast({
|
|
|
title: '请选择颜色或尺码',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let buyNumber = this.data.pickerData.view.buyNumber;
|
|
|
let min_buy_number = this.data.pickerData.view.min_buy_number > 0 ? this.data.pickerData.view.min_buy_number : 1;
|
|
|
|
|
|
if (buyNumber > 0 && buyNumber < min_buy_number && min_buy_number != 1) {
|
|
|
this.wetoast.toast({
|
|
|
title: '最低' + min_buy_number + '件起',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// Picker.pickerHide(event, this);
|
|
|
let processGoodsItem = this.data.curProcessGoodsItem;
|
|
|
let goodsInfo = [{
|
|
|
old_product_sku: processGoodsItem.product_sku,
|
|
|
new_product_sku: this.data.selectedSKU,
|
|
|
buy_number: this.data.pickerData.view.buyNumber,
|
|
|
activity_id: processGoodsItem.bundle_activity_id,
|
|
|
batch_no: processGoodsItem.batch_no,
|
|
|
selected: 'Y',
|
|
|
}];
|
|
|
let goodInfoJson = JSON.stringify(goodsInfo);
|
|
|
let swapParams ={
|
|
|
swap_data: goodInfoJson,
|
|
|
method: "app.Shopping.swap",
|
|
|
uid: app.getUid(),
|
|
|
};
|
|
|
api.post({data:swapParams})
|
|
|
.then(json => {
|
|
|
if (json && json.code && json.code == 200) {
|
|
|
let swapGoodsInfo = [{
|
|
|
buy_number: this.data.pickerData.view.buyNumber,
|
|
|
goods_type: processGoodsItem.goods_type,
|
|
|
product_sku: this.data.selectedSKU,
|
|
|
promotion_id: processGoodsItem.promotion_id,
|
|
|
selected: 'Y',
|
|
|
}];
|
|
|
this.queryShopCartGoodsWithSkuList(swapGoodsInfo);
|
|
|
this.resetPickerData();
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
this.resetPickerData();
|
|
|
});
|
|
|
},
|
|
|
resetPickerData:function(event){
|
|
|
let pickerData = this.data.pickerData;
|
|
|
pickerData.view.buyNumber = 1;
|
|
|
this.setData({
|
|
|
pickerData,
|
|
|
selectedSKU: 0,
|
|
|
storageNumber: 0,
|
|
|
colorSelected: false,
|
|
|
curProcessGoodsItem: {},
|
|
|
min_buy_number: 1,
|
|
|
})
|
|
|
},
|
|
|
mutilDeleteEditing:function(event){
|
|
|
|
|
|
let that = this;
|
|
|
|
|
|
tt.showModal({
|
|
|
title: '',
|
|
|
content: '是否删除选中的全部商品?',
|
|
|
cancelText: '取消',
|
|
|
confirmText: '确认',
|
|
|
confirmColor: "#d0021b",
|
|
|
success: function (res) {
|
|
|
if (res.confirm) {
|
|
|
let selectedGoodsInfo = editInfoSelectedGoodsList(that.data.curShoppingCartData.validGoodsList);
|
|
|
that.deleteGoodsRequest(selectedGoodsInfo);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
mutilAddToFav:function(event){
|
|
|
let selectedGoodsInfo = editInfoSelectedGoodsList(this.data.curShoppingCartData.validGoodsList);
|
|
|
let selectedGoodsJson = JSON.stringify(selectedGoodsInfo);
|
|
|
let param = {
|
|
|
product_sku_list: selectedGoodsJson,
|
|
|
method: 'app.Shopping.addfavoriteAndQryCart',
|
|
|
is_support_mlp: 'Y',
|
|
|
uid: app.getUid(),
|
|
|
shopping_key: '',
|
|
|
};
|
|
|
|
|
|
api.post({data:param})
|
|
|
.then(json => {
|
|
|
if (json && json.code && json.code == 200) {
|
|
|
let data = json.data;
|
|
|
this.processShopCartData(data);
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
// console.log(error);
|
|
|
});
|
|
|
},
|
|
|
|
|
|
navtoProductDetailPage: function(event){
|
|
|
|
|
|
if (this.data.AnimatingSku) {
|
|
|
let tempAniamtion = this.animation.left('0px').step();
|
|
|
this.setData({
|
|
|
deleteAnimation: tempAniamtion.export(),
|
|
|
AnimatingSku: ''
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let data = event.currentTarget.dataset.item;
|
|
|
// console.log(data);
|
|
|
|
|
|
if (data.off_shelves) {
|
|
|
this.wetoast.toast({
|
|
|
title: '商品已下架',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000,
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let productSkn = data.product_skn;
|
|
|
tt.navigateTo({
|
|
|
url: '../goodsDetail/goodsDetail?productSkn=' + productSkn + '&page_name=' + this.data.current_page_name,
|
|
|
});
|
|
|
},
|
|
|
|
|
|
navToPromotionPage: function(event) {
|
|
|
let promotionItem = event.currentTarget.dataset.promotionItem;
|
|
|
let promotion_type = promotionItem.promotion_type;
|
|
|
|
|
|
// console.log(promotionItem);
|
|
|
if (promotion_type == 'Gift' && (promotionItem.status == 10 || promotionItem.status == 30)) {
|
|
|
// console.log("跳转赠品页面");
|
|
|
tt.navigateTo({
|
|
|
url: './giftPage?promotion_id=' + promotionItem.promotion_id + '&is_gift=' + true + '&status=' + promotionItem.status,
|
|
|
});
|
|
|
} else if (promotion_type == 'Needpaygift' && (promotionItem.status == 10 || promotionItem.status == 30)) {
|
|
|
// console.log("跳转加价购页面");
|
|
|
tt.navigateTo({
|
|
|
url: './giftPage?promotion_id=' + promotionItem.promotion_id + '&is_gift=' + false + '&status=' + promotionItem.status,
|
|
|
});
|
|
|
} else {
|
|
|
// console.log("跳转促销商品列表页面");
|
|
|
let spliceUrl = "?title=优惠活动商品" + "&promotionTitle=以下商品参加【" + promotionItem.promotion_title + "】促销活动&promotion_id=" + promotionItem.promotion_id;
|
|
|
tt.navigateTo({
|
|
|
url: '../goodsList/PromotionList' + spliceUrl,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
//清空所有失效商品
|
|
|
cleanInvalidAction: function(event){
|
|
|
|
|
|
let that = this;
|
|
|
tt.showModal({
|
|
|
title: '',
|
|
|
content: '是否确认清空所有失效商品?',
|
|
|
cancelText: '取消',
|
|
|
confirmText: '确认',
|
|
|
confirmColor: "#d0021b",
|
|
|
success: function (res) {
|
|
|
if (res.confirm) {
|
|
|
let currentShopCartInfo = that.data.curShoppingCartData;
|
|
|
var invalidList = [];
|
|
|
// console.log(currentShopCartInfo);
|
|
|
// 售罄商品列表
|
|
|
let sold_out_goods_sku_list = editInfoOfAllGoods(currentShopCartInfo.sold_out_goods_list);
|
|
|
invalidList.push.apply(invalidList, sold_out_goods_sku_list);
|
|
|
|
|
|
//下架商品列表
|
|
|
let off_shelves_goods_sku_list = editInfoOfAllGoods(currentShopCartInfo.off_shelves_goods_list);
|
|
|
invalidList.push.apply(invalidList, off_shelves_goods_sku_list);
|
|
|
|
|
|
// //失效商品池 (套餐)
|
|
|
// let sold_out_goods_pool = currentShopCartInfo.sold_out_goods_pool;
|
|
|
// for (var index in sold_out_goods_pool) {
|
|
|
// let pool = sold_out_goods_pool[index];
|
|
|
// if (pool.pool_type == 3) {
|
|
|
// let bundle_invalid_sku_list = editInfoOfAllGoods(pool.goods_list);
|
|
|
// invalidList.push.apply(invalidList, bundle_invalid_sku_list);
|
|
|
// }
|
|
|
// }
|
|
|
// console.log("失效商品sku列表:");
|
|
|
// console.log(invalidList);
|
|
|
|
|
|
let param = {
|
|
|
product_sku_list: JSON.stringify(invalidList),
|
|
|
method: "app.Shopping.removeAndQryCart",
|
|
|
is_support_mlp: "Y",
|
|
|
uid: app.getUid(),
|
|
|
};
|
|
|
// console.log(param);
|
|
|
|
|
|
api.post({data:param})
|
|
|
.then(json => {
|
|
|
// console.log(json);
|
|
|
if (json && json.code && json.code == 200) {
|
|
|
let data = json.data
|
|
|
that.processShopCartData(data);
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
//仅有点击结算时 如果没有选择赠品才会调用
|
|
|
navToChooseGiftPage: function() {
|
|
|
let promotionIds = '';
|
|
|
this.data.curShoppingCartData.match_gift_ids.map((item, index) => {
|
|
|
promotionIds = promotionIds + (index == 0 ? '' : ',') + item;
|
|
|
});
|
|
|
tt.navigateTo({
|
|
|
url: './giftPage?promotion_id=' + promotionIds + '&is_gift=' + true + '&status=10',
|
|
|
});
|
|
|
},
|
|
|
|
|
|
// 跳转结算页面
|
|
|
paymentAction: function() {
|
|
|
//如果没有选中商品则不能进入结算页
|
|
|
if (this.data.curShoppingCartData.shopping_cart_data.selected_goods_count <= 0) {
|
|
|
this.wetoast.toast({
|
|
|
title: '您还没有选择宝贝哦',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (this.data.curShoppingCartData.match_gift_ids.length > 0) {
|
|
|
let that = this;
|
|
|
tt.showModal({
|
|
|
title: '',
|
|
|
content: '您还未选择赠品,是否去选择赠品?',
|
|
|
cancelText: '不要赠品',
|
|
|
confirmText: '去选择',
|
|
|
confirmColor: "#444444",
|
|
|
cancelColor: "#444444",
|
|
|
success: function (res) {
|
|
|
if (res.confirm) {
|
|
|
//去选择赠品
|
|
|
that.navToChooseGiftPage();
|
|
|
} else if (res.cancel) {
|
|
|
//直接跳转 结算页面
|
|
|
that.navToPaymentAction();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
this.navToPaymentAction();
|
|
|
},
|
|
|
|
|
|
navToPaymentAction: function() {
|
|
|
let paramters = {
|
|
|
method: 'app.Shopping.enhancedPayment',
|
|
|
cart_type: 'ordinary',
|
|
|
yoho_coin_mode: 0,
|
|
|
};
|
|
|
|
|
|
let that = this;
|
|
|
api.post({data:paramters})
|
|
|
.then(json => {
|
|
|
if (json && json.code && json.code == 200) {
|
|
|
|
|
|
let keyValue = 'paymentdata';
|
|
|
tt.setStorage({
|
|
|
key: keyValue,
|
|
|
data: json,
|
|
|
success: function (res) {
|
|
|
tt.navigateTo({
|
|
|
url: '../statements/statements?timestamp=' + keyValue + '&page_name=' + that.data.from_page,
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
that.wetoast.toast({
|
|
|
title: json.message,
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
that.wetoast.toast({
|
|
|
title: error.code + error.message + '',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
|
|
|
});
|
|
|
},
|
|
|
|
|
|
navToNewArriaval: function() {
|
|
|
tt.switchTab({
|
|
|
url: '../index/index' + '?page_name=' + this.data.current_page_name + '&page_param=' + '',
|
|
|
})
|
|
|
},
|
|
|
|
|
|
tapPriceDownTipsAction: function() {
|
|
|
this.setData({
|
|
|
has_close_price_down_tip: true,
|
|
|
});
|
|
|
},
|
|
|
|
|
|
tapBundleProductHeader: function(evevt) {
|
|
|
let bundleData = evevt.currentTarget.dataset.bundledata;
|
|
|
// console.log("点击套餐");
|
|
|
// console.log(bundleData);
|
|
|
|
|
|
let select = bundleData.selected;
|
|
|
|
|
|
if (select == 'N' && (bundleData.int_pool_buy_number > bundleData.int_pool_storage_number)) {
|
|
|
this.wetoast.toast({
|
|
|
title: '您勾选的商品库存不足',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
bundleData.selected = (select == 'Y' ? 'N' : 'Y');
|
|
|
let that = this;
|
|
|
if (that.data.isEditing) {
|
|
|
let curShoppingCartData = curPageDataSingleSelectBundleProductWhenEditing(that.data.curShoppingCartData, bundleData);
|
|
|
that.setData({
|
|
|
curShoppingCartData,
|
|
|
})
|
|
|
} else {
|
|
|
let goodsEditInfoList = editInfoDicFromBundleItem(bundleData);
|
|
|
that.queryShopCartGoodsWithSkuList(goodsEditInfoList);
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
bundleReduceTap: function(event) {
|
|
|
let isReduceOrPlue = this.data.isReduceOrPlue;
|
|
|
if (isReduceOrPlue) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let bundleItem = event.currentTarget.dataset.item;
|
|
|
// console.log('套餐 -');
|
|
|
// console.log(bundleItem);
|
|
|
|
|
|
this.setData({
|
|
|
isReduceOrPlue: true,
|
|
|
});
|
|
|
|
|
|
let reduceBuyCountParam = {
|
|
|
activity_id: bundleItem.pool_id,
|
|
|
batch_no: bundleItem.pool_batch_no,
|
|
|
decrease_number: 1,
|
|
|
method: 'app.Shopping.decrBundle',
|
|
|
};
|
|
|
let that = this;
|
|
|
api.post({data:reduceBuyCountParam})
|
|
|
.then(json => {
|
|
|
if (json && json.code && json.code == 200) {
|
|
|
let reduceBuyGoodsInfo = editInfoDicFromGoodsList(bundleItem.goods_list, true);
|
|
|
that.queryShopCartGoodsWithSkuList(reduceBuyGoodsInfo);
|
|
|
} else {
|
|
|
that.setData({
|
|
|
isReduceOrPlue: false,
|
|
|
});
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
that.setData({
|
|
|
isReduceOrPlue: false,
|
|
|
});
|
|
|
that.wetoast.toast({
|
|
|
title: error.code + error.message + '',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
|
|
|
bundleAddTap: function(event) {
|
|
|
let isReduceOrPlue = this.data.isReduceOrPlue;
|
|
|
if (isReduceOrPlue) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let bundleItem = event.currentTarget.dataset.item;
|
|
|
// console.log('套餐 +');
|
|
|
// console.log(bundleItem);
|
|
|
|
|
|
this.setData({
|
|
|
isReduceOrPlue: true,
|
|
|
});
|
|
|
|
|
|
let reduceBuyCountParam = {
|
|
|
activity_id: bundleItem.pool_id,
|
|
|
batch_no: bundleItem.pool_batch_no,
|
|
|
increase_number: 1,
|
|
|
method: 'app.Shopping.incrBundle',
|
|
|
};
|
|
|
let that = this;
|
|
|
api.post({data:reduceBuyCountParam})
|
|
|
.then(json => {
|
|
|
if (json && json.code && json.code == 200) {
|
|
|
let reduceBuyGoodsInfo = editInfoDicFromGoodsList(bundleItem.goods_list, true);
|
|
|
that.queryShopCartGoodsWithSkuList(reduceBuyGoodsInfo);
|
|
|
} else {
|
|
|
that.setData({
|
|
|
isReduceOrPlue: false,
|
|
|
});
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
that.setData({
|
|
|
isReduceOrPlue: false,
|
|
|
});
|
|
|
that.wetoast.toast({
|
|
|
title: error.code + error.message + '',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 计算滑动角度
|
|
|
* @param {Object} start 起点坐标
|
|
|
* @param {Object} end 终点坐标
|
|
|
*/
|
|
|
angle: function (start, end) {
|
|
|
var _X = end.X - start.X,
|
|
|
_Y = end.Y - start.Y
|
|
|
return 360 * Math.atan(_Y / _X) / (2 * Math.PI);
|
|
|
},
|
|
|
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|