Authored by yyq

gift page

... ... @@ -2,6 +2,7 @@
"pages": [
"pages/index/index",
"pages/cart/cart",
"pages/cart/gift/gift",
"pages/cart/ensure/ensure",
"pages/cart/invoice/invoice",
"pages/pay/success",
... ...
... ... @@ -107,7 +107,6 @@ function _processGiftList(list, isGift) {
let statusCount10 = 0;//已满足
let statusCount20 = 0;//已售罄
let promotionArr = [];
list.map(item => {
switch (+item.status) {
case 10:
... ... @@ -145,7 +144,10 @@ const formatOrdinaryCartData = (data, needAllGoods) => {
data = data || {};
data = data.ordinary_cart_data || {};
let ordinaryCart = {};
let ordinaryCart = {
shippingCostTips: '',
priceDownTips: ''
};
let isEmptyCart = true;
let pid = 10;
... ... @@ -186,16 +188,16 @@ const formatOrdinaryCartData = (data, needAllGoods) => {
});
isEmptyCart = false;
ordinaryCart.goodsPoolList = goodsPoolList;
}
ordinaryCart.goodsPoolList = goodsPoolList;
// 商品列表
let goodsList = data.goods_list;
if (goodsList && goodsList.length) {
isEmptyCart = false;
allGoodsSelect.check(goodsList);
ordinaryCart.goodsList = goodsList;
}
ordinaryCart.goodsList = goodsList;
// 加价购&赠品
let gGiftAndPriceGiftList = [];
... ... @@ -204,10 +206,7 @@ const formatOrdinaryCartData = (data, needAllGoods) => {
giftItem && gGiftAndPriceGiftList.push(giftItem);
priceGiftItem && gGiftAndPriceGiftList.push(priceGiftItem);
if (gGiftAndPriceGiftList.length) {
ordinaryCart.gGiftAndPriceGiftList = gGiftAndPriceGiftList;
}
ordinaryCart.gGiftAndPriceGiftList = gGiftAndPriceGiftList;
//失效商品
ordinaryCart.invalidGoodsList = [...(data.off_shelves_goods_list || []), ...(data.sold_out_goods_list || [])];
... ... @@ -223,12 +222,11 @@ const formatOrdinaryCartData = (data, needAllGoods) => {
needAllGoods && (ordinaryCart.allGoodsList = allGoodsSelect.getAllGoodsList());
if (data.promotion_info && data.promotion_info.length) {
ordinaryCart.promotionInfo = data.promotion_info;
}
ordinaryCart.promotionInfo = data.promotion_info || [];
return {
isEmptyCart,
// eslint-disable-next-line
...ordinaryCart
};
}
... ...
... ... @@ -2,10 +2,10 @@ import { api } from '../../common/api';
export default {
/**
* 购物车数据
* @param params
* @returns {*}
*/
* 购物车数据
* @param params
* @returns {*}
*/
getCartData(params) {
return api.get({
url: '',
... ... @@ -14,11 +14,27 @@ export default {
}, params)
});
},
/**
* 选中/取消选中并查询购物车
* @param params
* @returns {*}
*/
* 加入购物车
* @param params
* @returns {*}
*/
addToShoppingCart(params) {
return api.get({
url: '',
data: Object.assign({
app_type: getApp().getAppType(),
method: 'app.Shopping.add',
}, params)
});
},
/**
* 选中/取消选中并查询购物车
* @param params
* @returns {*}
*/
selectAndQueryCart(params) {
return api.get({
url: '',
... ... @@ -29,11 +45,12 @@ export default {
}, params)
});
},
/**
* 删除并查询购物车
* @param params
* @returns {*}
*/
* 删除并查询购物车
* @param params
* @returns {*}
*/
removeAndQueryCart(params) {
return api.get({
url: '',
... ... @@ -44,12 +61,13 @@ export default {
}, params)
});
},
/**
* 编辑购物车商品数量
* @param params
* @param isAdd
* @returns {*}
*/
* 编辑购物车商品数量
* @param params
* @param isAdd
* @returns {*}
*/
editCartGoodsNum(params, isAdd) {
if (isAdd) {
Object.assign(params, {
... ... @@ -70,12 +88,13 @@ export default {
data: params
});
},
/**
* 编辑购物车套餐数量
* @param params
* @param isAdd
* @returns {*}
*/
* 编辑购物车套餐数量
* @param params
* @param isAdd
* @returns {*}
*/
editCartBundleNum(params, isAdd) {
if (isAdd) {
Object.assign(params, {
... ... @@ -94,11 +113,12 @@ export default {
data: params
});
},
/**
* 编辑购物车商品
* @param params
* @returns {*}
*/
* 编辑购物车商品
* @param params
* @returns {*}
*/
editCartGoods(params) {
return api.get({
url: '',
... ...
import { api } from '../../common/api';
export default {
/**
* 赠品
* @param params
* @returns {*}
*/
productGift(params) {
return api.get({
url: '',
data: Object.assign({
method: 'app.product.gift'
}, params)
});
},
/**
* queryPromotionGifts
* @param params
* @returns {*}
*/
getPromotionGifts(params) {
return api.get({
url: '',
data: Object.assign({
method: 'app.Shopping.queryPromotionGifts'
}, params)
});
},
/**
* 编辑赠品
* @param params
* @returns {*}
*/
editCartGiftGoods(params) {
return api.get({
url: '',
data: Object.assign(params, {
method: 'app.Shopping.swapGift'
})
});
}
};
... ...
... ... @@ -163,6 +163,42 @@ Page({
promotionMoreStatus[pid] = !promotionMoreStatus[pid];
this.setData({promotionMoreStatus});
},
navToPromotionPage(e) {
let pItem = e.currentTarget.dataset.promotionItem;
let promotion_type = pItem.promotion_type;
let gStatus = (+pItem.status === 10 || +pItem.status === 30);
if (promotion_type == 'Gift' && gStatus) {
router.go('cartGift', {
promotion_id: pItem.promotion_id,
is_gift: 1,
status: pItem.status
});
} else if (promotion_type == 'Needpaygift' && gStatus) {
router.go('cartGift', {
promotion_id: pItem.promotion_id,
status: pItem.status
});
} else {
// console.log("跳转促销商品列表页面");
let spliceUrl = "?title=优惠活动商品" + "&promotionTitle=以下商品参加【" + pItem.promotion_title + "】促销活动&promotion_id=" + promotionItem.promotion_id;
wx.navigateTo({
url: '../goodsList/PromotionList' + spliceUrl,
});
}
},
navToGiftPage(e) {
let promotion = e.currentTarget.dataset.promotion;
if (promotion.showArrow) {
router.go('cartGift', {
promotion_id: promotion.promotion_ids,
is_gift: promotion.isGift ? 1 : 0,
status: 10
});
}
},
chooseGoodsItem(e) {
let item = e.detail;
... ... @@ -203,7 +239,7 @@ Page({
editGoodsColorSize(e) {
let goods = e.detail;
let pickData = this.data.pickerData;
console.log(e);
this._cureditGoods = goods;
pickData.view.should_hidden_number_view = (goods.bundle_activity_id && goods.batch_no);
... ... @@ -431,5 +467,6 @@ console.log(e);
}
});
},
...Picker.pickerAction // eslint-disable-line
// eslint-disable-next-line
...Picker.pickerAction
});
... ...
... ... @@ -33,7 +33,7 @@
<template is="cartGoodsPool" data="{{goodsPoolList, isEditing, isEditSelectAll, promotionMoreStatus, touchKey}}"/>
<!-- 商品列表 -->
<view wx:if="{{goodsList}}">
<view wx:if="{{goodsList && goodsList.length}}">
<template is="cartGoodsList" data="{{goodsList, isEditing, isEditSelectAll, touchKey}}"/>
<view class="split-line"></view>
</view>
... ...
import cartModel from '../../../models/cart/cart';
import giftModel from '../../../models/cart/gift';
import formatImage from '../../../utils/formatImage';
// 获取应用实例
let app = getApp();
let Picker = require('../../goodsDetail/picker/picker.js');
const screenWidth = app.globalData.systemInfo.screenWidth;
Page({
/**
* 页面的初始数据
*/
data: {
isGift: false,
screen_width: screenWidth,
current_section_title: '.',
promotion_data_ary: [],
current_skn: '',
selectedSKU: '',
// picker 需要的数据
pickerData: {
view: {
isShow: false,
isSoldOutSoon: false, // 是否显示即将售罄
goodsList: [],
sizeList: [],
image: '',
goodPrice: '',
price: '',
buyNumber: 1,
minusButtonEnable: false,
plusButtonEnable: false,
buyButtonEnable: true,
},
sourceType: 'goodsDetail',
},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this._isGift = +options.is_gift > 0;
this._status = +(options.status || 0);
this.queryGiftPageData(options.promotion_id);
this._isGift && this.setData({isGift: true});
Picker.init(this);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
wx.setNavigationBarTitle({
title: this._isGift ? '领取赠品' : '换购商品'
});
},
showToast(title) {
wx.showToast({
title: title,
icon: 'none',
duration: 1000
});
},
onPressProduct: function(event) {
let cdata = event.currentTarget.dataset;
let product_skn = cdata.productSkn;
this.setData({ current_skn: product_skn });
Picker.promotion_id = cdata.item.promotion_id;
let that = this;
giftModel.productGift({
product_skn,
promotion_id: cdata.item.promotion_id
}).then(data => {
if (!data || data.code !== 200) {
return;
}
let colorSelected = false;
let color_length = 0;
if (data.data.goods_list) {
color_length = data.data.goods_list.length;
}
let ImgUrls = [];
data.data.goods_list.map((item, index) => {
let images = formatImage.image(item.color_image, 75, 100);
ImgUrls = [...ImgUrls, images];
if (index === 0 && color_length === 1) {
item.selected = true;
colorSelected = true;
}
});
let isSoldOutSoon = false;
let tags = data.data.tags;
if (tags) {
tags.map((item) => {
if (item === 'is_soon_sold_out') {
isSoldOutSoon = true;
}
});
}
// pickerData
let 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 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 && colorSelected) {
// 当颜色被选中 并且只有一个size 时 才会自动 做选中尺码操作
temData.view.buyButtonEnable = item.enable;
if (item.enable) {
item.selected = true;
that.setData({
selectedSKU: item.product_sku,
});
}
}
});
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,
});
Picker.pickerShow(that);
}).catch(console.log);
},
// 点击选择颜色
colorTap: function(event) {
// 更新各个颜色的选中状态
let that = this;
let tempData = that.data.pickerData;
// 先遍历将所有颜色、尺码置为未选中状态
tempData.view.goodsList && tempData.view.goodsList.map(item => {
item.selected = false;
item.size_list.map(subItem => {
subItem.selected = false;
subItem.enable = subItem.storage_number > 0 ? true : false;
});
});
// 将当前颜色置为选中状态
let tempItem = event.target.dataset.key;
// 遍历颜色尺码,根据库存切换显示状态
tempItem && tempItem.size_list && tempItem.size_list.map(item => {
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) {
let that = this;
let tempData = that.data.pickerData;
// 现遍历将所有尺码置为未选中状态
tempData.view.sizeList && tempData.view.sizeList.map(item => {
item.selected = false;
});
// 将当前尺码置为选中状态
let 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) {
this.showToast('该尺码已经售罄');
tempData.view.buyButtonEnable = false;
}
this.setData({
pickerData: tempData,
selectedSKU: tempItem.storage_number > 0 ? tempItem.product_sku : 0,
storageNumber: tempItem.storage_number,
});
},
// 增加购买数量
bindPlus: function() {
},
// 减少购买数量
bindMinus: function() {
},
pickerTap: function(event) {
if (event.target.id === 'picker-bg') {
let that = this;
Picker.pickerHide(event, that);
this.resetPickerData();
}
},
resetPickerData: function() {
let pickerData = this.data.pickerData;
pickerData.view.buyNumber = 1;
this.setData({
pickerData,
selectedSKU: 0,
storageNumber: 0,
curProcessGoodsItem: {},
});
},
// 添加加价购商品到购物车
confirmChoose: function() {
let select_sku = this.data.selectedSKU;
let select_skn = this.data.current_skn;
let goods_type = this._isGift ? 1 : 2;
let promotion_id = Picker.promotion_id;
if (!select_sku) {
return this.showToast('请选择颜色或尺码');
}
Picker.pickerHide(this);
this.resetPickerData();
let status = this._status;
if (status === 10) {
cartModel.addToShoppingCart({
product_sku: select_sku,
promotion_id: promotion_id,
buy_number: 1,
selected: 'Y',
goods_type: goods_type,
edit_product_sku: 0,
}).then(json => {
if (json && json.code) {
wx.navigateBack({});
}
});
} else if (status === 30) {
giftModel.editCartGiftGoods({
new_product_skn: select_skn,
new_product_sku: select_sku,
promotion_id: promotion_id,
goods_type: goods_type,
buy_number: 1,
}).then(json => {
if (json && json.code) {
wx.navigateBack({});
}
});
} else {
wx.navigateBack({});
}
},
/**
* 查询购物车数据,包括普通购物车和预售购物车
*/
queryGiftPageData: function(promotionIds) {
giftModel.getPromotionGifts({
promotion_ids: promotionIds
}).then(json => {
if (json && json.code && json.code === 200) {
let data = json.data;
let promotion_data_ary = data.arrays;
if (promotion_data_ary.length) {
promotion_data_ary.map(item => {
item.goods_list.map(obj => {
let default_images = formatImage.image(obj.goods_images, 75, 100);
let default_last_price = obj.last_price ? obj.last_price : 0;
obj.last_price = '¥' + default_last_price.toFixed(2);
obj.goods_images = default_images;
});
});
let title = promotion_data_ary[0].promotion_title;
this.setData({ current_section_title: title });
}
this.setData({ promotion_data_ary });
// console.log(this.data);
}
});
}
});
... ...
<import src="../../goodsDetail/picker/picker.wxml"/>
<view class="container">
<scroll-view class="scroll-container" scroll-y="true" enable-back-to-top="true">
<block wx:for="{{promotion_data_ary}}"
wx:for-item="promotionItem"
wx:key="promotionItem">
<view class="real-header">
<text class="header-text">{{promotionItem.promotion_title}}</text>
</view>
<block wx:for="{{promotionItem.goods_list}}"
wx:for-item="goodsItem"
wx:key="index">
<view class="cell-container"
data-product-skn="{{goodsItem.product_skn}}"
data-product-sku="{{goodsItem.product_sku}}"
data-item="{{promotionItem}}"
bindtap="onPressProduct">
<view class="image-container">
<image class="image" src="{{goodsItem.goods_images}}">
<view class="goods-type gift-tag" wx:if="{{isGift}}">
<text>赠品</text>
</view>
<view class="goods-type price-gift-tag" wx:else>
<text>加价购</text>
</view>
</image>
</view>
<!-- 商品名称 价格 加入购物车按钮 -->
<view class="product-info-container">
<view>
<view class="title-text">{{goodsItem.product_name}}</view>
<view wx:if="{{!is_gift}}" class="price-title">{{goodsItem.last_price}}</view>
</view>
<image class="add-shop-btn-image" src="https://img12.static.yhbimg.com/sns/2018/07/02/17/029f2bee7c8fc4a47d9cac71d0c0ac5f20.png"/>
</view>
<view wx:if="{{index!=0}}" class="separator"></view>
</view>
</block>
</block>
</scroll-view>
<template is="Picker" data="{{pickerData}}"/>
</view>
... ...
@import "../../goodsDetail/picker/picker.wxss";
.container {
background-color: white;
display: flex;
}
.title {
padding: 20rpx 0rpx;
font-size: 30rpx;
font-weight: bold;
color: #444;
}
.real-header {
background-color: #f0f0f0;
height: 71rpx;
width: 100%;
top: 0;
left: 0;
display: flex;
flex-direction: column;
justify-content: center;
}
.header-text {
font-size: 28rpx;
color: #444;
line-height: 1.43;
text-align: left;
margin-left: 30rpx;
width: 690rpx;
overflow: hidden;
text-overflow: ellipsis;
}
.scroll-container {
display: flex;
width: 100%;
height: 100%;
background-color: white;
position: absolute;
flex-direction: column;
}
.cell-container {
background-color: white;
width: 100%;
height: 240rpx;
flex-direction: row;
align-items: top;
display: flex;
}
.image-container {
width: 150rpx;
height: 200rpx;
flex-direction: column;
margin-top: 20rpx;
margin-left: 30rpx;
background-color: gray;
display: flex;
}
.image {
width: 150rpx;
height: 200rpx;
position: absolute;
}
.goods-type {
width: 100%;
height: 30rpx;
line-height: 30rpx;
font-size: 20rpx;
background-color: #444;
color: #fff;
text-align: center;
position: absolute;
left: 0;
bottom: 0;
}
.goods-type.price-gift-tag {
background-color: #fc1261;
}
.goods-type.gift-tag {
background-color: #85c45c;
}
.product-info-container {
display: flex;
flex-direction: row;
margin-left: 30rpx;
height: 240rpx;
justify-content: space-between;
}
.product-info-container .title-text {
margin-top: 38rpx;
font-size: 26rpx;
line-height: 1.38;
width: 417rpx;
color: #444;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.product-info-container .price-title {
font-size: 26rpx;
margin-top: 30rpx;
color: #d0021b;
}
.product-info-container .add-shop-btn-image {
width: 80rpx;
height: 46rpx;
margin-top: 154rpx;
}
.separator {
position: absolute;
background-color: #e0e0e0;
margin-top: 0;
left: 30rpx;
width: 720rpx;
height: 2rpx;
}
... ...
<template name="cartGiftList">
<block wx:if="{{giftList}}">
<view class="gift-wrap">
<view class="gift-cell" wx:for="{{giftList}}" wx:key="unique">
<text class="iconfont" wx:if="{{item.isGift}}"></text>
<text class="iconfont" wx:else></text>
<text class="giftOrPriceTitle">{{item.title}}</text>
<view class="gift-cell" wx:for="{{giftList}}" wx:key="unique" data-promotion="{{item}}" bindtap="navToGiftPage">
<view class="right-option">
<text class="{{item.showArrow ? '' : 'disable-text'}}">{{item.statusString}}</text>
<text class="iconfont icon-right" wx:if="{{item.showArrow}}"></text>
<text class="{{item.showArrow ? '' : 'disable-text'}}">{{item.statusString}}</text>
<text class="iconfont icon-right" wx:if="{{item.showArrow}}"></text>
</view>
<text class="iconfont icon-right" wx:if="{{item.isGift}}"></text>
<text class="iconfont icon-right" wx:else></text>
<text class="giftOrPriceTitle">{{item.title}}</text>
</view>
<view class="split-line"></view>
</view>
... ...
.gift-wrap {
background-color: #fff;
font-size: 26rpx;
}
.gift-wrap .gift-cell {
border-top: 1rpx solid #f0f0f0;
line-height: 80rpx;
padding: 0 30rpx;
}
.gift-wrap .gift-cell:first-child {
border-top: 0;
}
.gift-wrap .right-option {
float: right;
}
... ...
... ... @@ -57,4 +57,4 @@
]
}
}
}
\ No newline at end of file
}
... ...
... ... @@ -21,6 +21,7 @@ export default {
orderDetail: {path: '/pages/home/order/detail', auth: true, report: {paramKey: 'orderCode'}},
orderExpress: {path: '/pages/home/order/express/express', auth: true, report: {paramKey: 'order_code'}},
shoppingCart: {path: '/pages/cart/cart', type: jump.switchTab, auth: true},
cartGift: {path: '/pages/cart/gift/gift', auth: true, report: {paramKey: 'promotion_id'}},
cartEnsure: {path: '/pages/cart/ensure/ensure', auth: true, report: {paramKey: 'productSku'}},
cartInvoice: {path: '/pages/cart/invoice/invoice'},
paySuccess: {path: '/pages/pay/success', type: jump.redirectTo, auth: true},
... ...