Authored by 肖亚东

加价购picker添加 — review by 黄义

... ... @@ -4,7 +4,6 @@ import { shouldDiscardTap, getImageUrlWithWH } from '../../utils/util';
//获取应用实例
let app = getApp();
// var Picker = require('../goodsDetail/picker/picker.js')
const screenHeight = app.globalData.systemInfo.screenHeight;
const screenWidth = app.globalData.systemInfo.screenWidth;
... ... @@ -26,6 +25,7 @@ Page({
current_skn: '',
selectedSKU: '',
//picker 需要的数据
pickerShow: false,
pickerData: {
view: {
isShow: false,
... ... @@ -64,8 +64,6 @@ Page({
this.setData({ promotion_ids, is_gift, status });
this.queryGiftPageData();
var that = this;
// Picker.init(that);
},
/**
... ... @@ -120,8 +118,6 @@ Page({
let data = event.currentTarget.dataset;
let product_skn = data.productSkn;
this.setData({ current_skn: product_skn });
// Picker.promotion_id = data.item.promotion_id;
// console.log(product_skn);
let param = {
method: 'app.product.gift',
uid: app.getUid(),
... ... @@ -199,104 +195,19 @@ Page({
});
// Picker.pickerShow(event, that);
this.setData({pickerShow: true});
})
.catch(error => {
});
},
//点击选择颜色
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
//重置库存、当前选中sku的值
tempData.storageNumber = 0
tempData.selectedSKU = 0
tempData.view.goodsList[Number(event.target.id)] = tempItem
tempData.view.sizeList = tempItem.size_list
//将购买数量设为初始状态
tempData.view.buyNumber = 1
this.setData({
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.buyButtonEnable = true
//将购买数量设为初始状态
tempData.view.buyNumber = 1
// console.log(event)
if (tempItem.storage_number <= 0) {
tt.showToast({
title: '该尺码已经售罄',
icon: 'none',
duration: 1000
});
tempData.view.buyButtonEnable = false
}
this.setData({
pickerData: tempData,
selectedSKU: tempItem.storage_number > 0 ? tempItem.product_sku : 0,
storageNumber: tempItem.storage_number,
});
},
//增加购买数量
bindPlus: function (event) {
},
//减少购买数量
bindMinus: function (event) {
},
pickerTap: function (event) {
if (event.target.id == "picker-bg") {
var that = this
// Picker.pickerHide(event, that);
this.setData({pickerShow: false});
this.resetPickerData();
}
},
... ... @@ -314,12 +225,12 @@ Page({
// 添加加价购商品到购物车
addShopCart: function (event) {
var that = this
this.setData(event.detail);
let select_sku = that.data.selectedSKU;
let select_skn = that.data.current_skn;
let goods_type = that.data.is_gift ? 1 : 2;
let promotion_id = Picker.promotion_id;
if (!select_sku) {
tt.showToast({
... ... @@ -331,6 +242,8 @@ Page({
}
// Picker.pickerHide(event, that);
this.setData({pickerShow: false});
that.resetPickerData();
let param = {};
... ... @@ -373,6 +286,43 @@ Page({
});
},
chooseSizeColorCompleted:function(event){
console.log('====================================');
console.log(event);
console.log('====================================');
this.setData(event.detail);
if (!this.data.selectedSKU) {
this.wetoast.toast({
title: '请选择颜色或尺码',
titleClassName: 'wetoast-title',
duration: 1000
});
return;
}
},
//点击背景,隐藏picker
showChange:function(){
let pickerShow = !this.data.pickerShow
this.setData({pickerShow});
},
errorToast: function(event) {
console.log('====================================');
console.log(event);
console.log('====================================');
let detail = event.detail;
this.wetoast.toast({
title: detail.title,
titleClassName: detail.titleClassName,
duration: 1000
});
},
/**
* 查询购物车数据,包括普通购物车和预售购物车
*/
... ...
... ... @@ -39,8 +39,13 @@
</scroll-view>
<!--
<template is="Picker" data="{{pickerData}}"/>
-->
<picker id="picker"
pickerData="{{pickerData}}" isloadingForPayment="{{isloadingForPayment}}"
pickerShow="{{pickerShow}}"
bind:showChange="showChange"
bind:errorToast="errorToast"
bind:addShopCart="addShopCart"
bind:chooseSizeColorCompleted="chooseSizeColorCompleted"
></picker>
</view>
... ...
... ... @@ -751,88 +751,6 @@ Page({
});
});
},
//减少购买数量
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
showChange:function(){
... ... @@ -849,65 +767,9 @@ Page({
});
},
//点击选择颜色
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) {
let {tempData, tempItem} = event.detail
this.setData({
pickerData: tempData,
selectedSKU: tempItem.storage_number > 0 ? tempItem.product_sku : 0,
storageNumber: tempItem.storage_number,
});
},
chooseSizeColorCompleted:function(event){
this.setData(event.detail);
if (!this.data.selectedSKU) {
this.wetoast.toast({
title: '请选择颜色或尺码',
... ...
{
"navigationBarTitleText": "购物车",
"usingComponents": {
"shoppingCartFooterView": "../../components/shopCart/footerView/shoppingCartFooterView",
"shoppingCartProductCell": "../../components/shopCart/cells/shoppingCartProductCell",
"shoppingCartGiftOrPriceCell": "../../components/shopCart/cells/shoppingCartGiftOrPriceCell",
"shoppingCartInvalidProductCell": "../../components/shopCart/cells/shoppingCartInvalidProductCell",
"shoppingCartPromotionCell": "../../components/shopCart/cells/shoppingCartPromotionCell",
"shoppingCartOneProductCell": "../../components/shopCart/cells/shoppingCartOneProductCell",
"picker":"../../components/picker/picker"
}
"navigationBarTitleText": "购物车",
"usingComponents": {
"shoppingCartFooterView": "../../components/shopCart/footerView/shoppingCartFooterView",
"shoppingCartProductCell": "../../components/shopCart/cells/shoppingCartProductCell",
"shoppingCartGiftOrPriceCell": "../../components/shopCart/cells/shoppingCartGiftOrPriceCell",
"shoppingCartInvalidProductCell": "../../components/shopCart/cells/shoppingCartInvalidProductCell",
"shoppingCartPromotionCell": "../../components/shopCart/cells/shoppingCartPromotionCell",
"shoppingCartOneProductCell": "../../components/shopCart/cells/shoppingCartOneProductCell",
"picker":"../../components/picker/picker"
}
}
\ No newline at end of file
... ...