|
|
import wx from '../../utils/wx';
|
|
|
import formatImage from '../../utils/formatImage';
|
|
|
import detailModel from '../../models/product/detail';
|
|
|
import cartModel from '../../models/cart/cart';
|
|
|
import cartHandle from '../../models/cart/cart-handle';
|
|
|
|
|
|
import Picker from '../product/detail/picker/picker';
|
|
|
|
|
|
const app = getApp();
|
|
|
const router = global.router;
|
|
|
|
...
|
...
|
@@ -12,10 +16,28 @@ const reverseSelected = { |
|
|
|
|
|
Page({
|
|
|
data: {
|
|
|
isEditing: false
|
|
|
isEditing: false,
|
|
|
pickerData: {
|
|
|
view: {
|
|
|
isShow: false,
|
|
|
isSoldOutSoon: false,
|
|
|
goodsList: [],
|
|
|
sizeList: [],
|
|
|
image: '',
|
|
|
goodPrice: '',
|
|
|
price: '',
|
|
|
buyNumber: 1,
|
|
|
minusButtonEnable: false,
|
|
|
plusButtonEnable: true,
|
|
|
buyButtonEnable: true,
|
|
|
buy_limit_number: 0,
|
|
|
bundle_count: 0
|
|
|
},
|
|
|
sourceType: 'goodsDetail'
|
|
|
}
|
|
|
},
|
|
|
onLoad() {
|
|
|
|
|
|
Picker.init(this);
|
|
|
},
|
|
|
onShow() {
|
|
|
this.getCartData();
|
...
|
...
|
@@ -30,17 +52,17 @@ Page({ |
|
|
wx.showToast({
|
|
|
title: title,
|
|
|
icon: 'none',
|
|
|
duration: 2000
|
|
|
duration: 1000
|
|
|
});
|
|
|
},
|
|
|
showModal(title) {
|
|
|
return wx.showModal({
|
|
|
showModal(title, options) {
|
|
|
return wx.showModal(Object.assign({
|
|
|
title: '',
|
|
|
content: title,
|
|
|
cancelText: '取消',
|
|
|
confirmText: '确认',
|
|
|
confirmColor: '#d0021b'
|
|
|
});
|
|
|
}, options));
|
|
|
},
|
|
|
goShopping() {
|
|
|
router.go('home');
|
...
|
...
|
@@ -153,9 +175,92 @@ Page({ |
|
|
if (res && res.code === 200) {
|
|
|
this.editCart(bundle.goods_list, 'Y');
|
|
|
}
|
|
|
})
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
editGoodsColorSize(e) {
|
|
|
let goods = e.detail;
|
|
|
let pickData = this.data.pickerData;
|
|
|
|
|
|
this._cureditGoods = goods;
|
|
|
|
|
|
pickData.view.should_hidden_number_view = (goods.bundle_activity_id && goods.batch_no);
|
|
|
pickData.view.min_buy_number = goods.min_buy_number > 0 ? goods.min_buy_number : 1;
|
|
|
|
|
|
detailModel.productInfo(goods.product_skn).then(res => {
|
|
|
if (res && res.code === 200) {
|
|
|
let ImgUrls = [];
|
|
|
let color_length = 0;
|
|
|
|
|
|
if (res.data.goods_list) {
|
|
|
color_length = res.data.goods_list.length;
|
|
|
}
|
|
|
res.data.goods_list.map((item, index) => {
|
|
|
let images = item.images_list;
|
|
|
|
|
|
ImgUrls = [...ImgUrls, ...images];
|
|
|
if (index === 0 && color_length === 1) {
|
|
|
item.selected = true;
|
|
|
this.data.colorSelected = true;
|
|
|
this.data.selectedProductId = item.goods_id;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
let isSoldOutSoon = false;
|
|
|
let tags = res.data.tags;
|
|
|
|
|
|
if (tags) {
|
|
|
isSoldOutSoon = tags.includes('is_soon_sold_out');
|
|
|
}
|
|
|
|
|
|
pickData.view.goodsList = res.data.goods_list;
|
|
|
pickData.view.isSoldOutSoon = isSoldOutSoon;
|
|
|
|
|
|
// 默认显示第一种颜色的尺码
|
|
|
pickData.view.sizeList = res.data.goods_list.length ? res.data.goods_list[0].size_list : [];
|
|
|
|
|
|
let plusButtonEnable = false;
|
|
|
let minusButtonEnable = false;
|
|
|
|
|
|
// 根据库存设置该尺码是否可以选择
|
|
|
let size_length = 0;
|
|
|
|
|
|
if (pickData.view.sizeList) {
|
|
|
size_length = pickData.view.sizeList.length;
|
|
|
}
|
|
|
|
|
|
pickData.view.sizeList && pickData.view.sizeList.map((item, index) => {
|
|
|
item.enable = item.storage_number > 0;
|
|
|
if (index === 0 && size_length === 1 && this.data.colorSelected) {
|
|
|
// 当颜色被选中 并且只有一个size 时 才会自动 做选中尺码操作
|
|
|
pickData.view.buyButtonEnable = item.enable;
|
|
|
if (item.enable) {
|
|
|
item.selected = true;
|
|
|
plusButtonEnable = item.storage_number > 1;
|
|
|
this.setData({
|
|
|
selectedSKU: item.product_sku,
|
|
|
storageNumber: item.storage_number
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
pickData.view.plusButtonEnable = plusButtonEnable;
|
|
|
pickData.view.minusButtonEnable = minusButtonEnable;
|
|
|
pickData.view.image = formatImage.image(ImgUrls.length > 0 ? ImgUrls[0].image_url : '', 168, 232);
|
|
|
pickData.view.price = res.data.format_market_price;
|
|
|
pickData.view.goodPrice = res.data.format_sales_price;
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
pickerData: pickData
|
|
|
});
|
|
|
Picker.pickerShow(this);
|
|
|
}
|
|
|
}).catch(err => {
|
|
|
this.showToast(err.code + err.message + '');
|
|
|
});
|
|
|
},
|
|
|
removeGoodsListInEdit(e) {
|
|
|
let info = e.detail;
|
|
|
|
...
|
...
|
@@ -223,5 +328,77 @@ Page({ |
|
|
this.showToast('您全选的商品中存在库存不足商品,已帮您自动取消勾选成功');
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
paymentAction: function() {
|
|
|
//如果没有选中商品则不能进入结算页
|
|
|
if (this.data.shoppingCartData.selected_goods_count <= 0) {
|
|
|
return this.showToast('您还没有选择宝贝哦');
|
|
|
}
|
|
|
|
|
|
if (this.data.matchGiftIds && this.data.matchGiftIds.length > 0) {
|
|
|
return this.showModal('您还未选择赠品,是否去选择赠品?', {
|
|
|
cancelText: '不要赠品',
|
|
|
confirmText: '去选择',
|
|
|
confirmColor: '#444444',
|
|
|
cancelColor: '#444444',
|
|
|
}).then(res => {
|
|
|
if (res.confirm) {
|
|
|
// TODO 去选择赠品
|
|
|
// that.navToChooseGiftPage();
|
|
|
} else if (res.cancel) {
|
|
|
//直接跳转 结算页面
|
|
|
router.go('cartEnsure');
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
router.go('cartEnsure');
|
|
|
},
|
|
|
|
|
|
hidePicker(e) {
|
|
|
if (e.target.id === 'picker-bg') {
|
|
|
Picker.pickerHide(this);
|
|
|
}
|
|
|
},
|
|
|
confirmChoose(e) {
|
|
|
let sku = this.data.selectedSKU;
|
|
|
|
|
|
if (!sku) {
|
|
|
return this.showToast('请选择颜色或尺码');
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
return this.showToast('最低' + min_buy_number + '件起');
|
|
|
}
|
|
|
|
|
|
let goods = this._cureditGoods;
|
|
|
let goodsInfo = [{
|
|
|
old_product_sku: goods.product_sku,
|
|
|
new_product_sku: sku,
|
|
|
buy_number: buyNumber,
|
|
|
activity_id: goods.bundle_activity_id,
|
|
|
batch_no: goods.batch_no,
|
|
|
selected: 'Y',
|
|
|
}];
|
|
|
|
|
|
return cartModel.editCartGoods({
|
|
|
swap_data: JSON.stringify(goodsInfo),
|
|
|
uid: app.getUid()
|
|
|
}).then(res => {
|
|
|
if (res && res.code === 200) {
|
|
|
this.editCart([{
|
|
|
buy_number: buyNumber,
|
|
|
goods_type: goods.goods_type,
|
|
|
product_sku: sku,
|
|
|
promotion_id: goods.promotion_id,
|
|
|
selected: 'Y',
|
|
|
}], 'Y');
|
|
|
Picker.pickerHide(this);
|
|
|
this.clearPickerData && this.clearPickerData();
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
...Picker.pickerAction
|
|
|
}); |
...
|
...
|
|