|
|
@@ -51,11 +51,15 @@ export default {
|
|
|
},
|
|
|
onUnload() {},
|
|
|
computed: {
|
|
|
- ...mapGetters(["getSelectInfo"]),
|
|
|
+ ...mapGetters(["getSelectInfo", "getLimitBuyInfo"]),
|
|
|
//当前页面选中的商品列表
|
|
|
selectList() {
|
|
|
return this.getSelectInfo[this.pageType] || [];
|
|
|
},
|
|
|
+ //当前页面限购信息列表
|
|
|
+ limitBuyList() {
|
|
|
+ return this.getLimitBuyInfo[this.pageType] || [];
|
|
|
+ },
|
|
|
scrollClassId() {
|
|
|
const curClass = this.productInfo[this.classIndex];
|
|
|
if (curClass) {
|
|
|
@@ -81,15 +85,7 @@ export default {
|
|
|
let price = 0;
|
|
|
if (this.selectList) {
|
|
|
for (const item of this.selectList) {
|
|
|
- const itemInfo = this.getSelectItemById(item.id, item.classId);
|
|
|
- if (
|
|
|
- itemInfo &&
|
|
|
- !this.$util.isEmpty(itemInfo.bigPrice) &&
|
|
|
- !this.$util.isEmpty(itemInfo.smallPrice)
|
|
|
- ) {
|
|
|
- price += item.bigCount * Number(itemInfo.bigPrice);
|
|
|
- price += item.smallCount * Number(itemInfo.smallPrice);
|
|
|
- }
|
|
|
+ price += this.getLimitBuyPriceInfo(item).total;
|
|
|
}
|
|
|
}
|
|
|
return Math.round(price * 100) / 100;
|
|
|
@@ -193,7 +189,120 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- ...mapActions(["setSelectInfoByType", "resetSelectInfoByType"]),
|
|
|
+ ...mapActions(["setSelectInfoByType", "resetSelectInfoByType", "setLimitBuyInfoByType", "resetLimitBuyInfoByType"]),
|
|
|
+ isTrueValue(value) {
|
|
|
+ return value === true || value === 1 || value === "1";
|
|
|
+ },
|
|
|
+ toSafeNumber(value) {
|
|
|
+ const num = Number(value);
|
|
|
+ return isNaN(num) ? 0 : num;
|
|
|
+ },
|
|
|
+ getLimitBuyItemById(id) {
|
|
|
+ if (!Array.isArray(this.limitBuyList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return this.limitBuyList.find(item => String(item.id) === String(id)) || null;
|
|
|
+ },
|
|
|
+ isLimitSpecialItem(item) {
|
|
|
+ const limitItem = this.getLimitBuyItemById(item.id);
|
|
|
+ return !!(limitItem && this.isTrueValue(limitItem.isLimit) && this.isTrueValue(limitItem.specialPrice));
|
|
|
+ },
|
|
|
+ getLimitBuyPriceInfo(item) {
|
|
|
+ const itemInfo = this.getSelectItemById(item.id, item.classId);
|
|
|
+
|
|
|
+ const specialPrice = this.toSafeNumber(item.price);
|
|
|
+ const originalPrice = this.toSafeNumber(item.prePrice);
|
|
|
+ const result = {
|
|
|
+ total: 0, //总价
|
|
|
+ specialPrice: specialPrice, //特价
|
|
|
+ originalPrice: originalPrice, //原价
|
|
|
+ exceedNum: 0, //超出数量
|
|
|
+ limitBuy: 0, //限购数量
|
|
|
+ hasBuyNum: 0, //已购买数量
|
|
|
+ currentBuyNum: 0, //此次购买数量
|
|
|
+ isLimitSpecial: false
|
|
|
+ };
|
|
|
+
|
|
|
+ result.total = itemInfo.bigCount * specialPrice + itemInfo.smallCount * originalPrice;
|
|
|
+ const limitItem = this.getLimitBuyItemById(item.id);
|
|
|
+ if (!limitItem || !this.isLimitSpecialItem(item)) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ const exceedNum = this.toSafeNumber(limitItem.exceedNum) + this.toSafeNumber(limitItem.currentBuyNum);
|
|
|
+ result.exceedNum = exceedNum; //超出数量
|
|
|
+ result.limitBuy = this.toSafeNumber(limitItem.limitBuy);
|
|
|
+ result.hasBuyNum = this.toSafeNumber(limitItem.hasBuyNum);
|
|
|
+ result.currentBuyNum = this.toSafeNumber(limitItem.currentBuyNum);
|
|
|
+ result.isLimitSpecial = true;
|
|
|
+
|
|
|
+ if (result.exceedNum <= 0) {
|
|
|
+ result.total = result.currentBuyNum * specialPrice;
|
|
|
+ } else if (result.exceedNum > 0 && result.hasBuyNum > result.limitBuy) {
|
|
|
+ result.total = result.currentBuyNum * originalPrice;
|
|
|
+ } else {
|
|
|
+ result.total = (result.currentBuyNum - result.exceedNum) * specialPrice + result.exceedNum * originalPrice;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 确认页花材价格展示:主价 + 可选删除线原价(限购特价部分超出时)
|
|
|
+ * @returns {{ main: string, strike: string, showStrike: boolean }}
|
|
|
+ */
|
|
|
+ getLimitBuyPriceDisplayParts(item) {
|
|
|
+ const priceInfo = this.getLimitBuyPriceInfo(item);
|
|
|
+ const fmt = (n) => parseFloat(Number(n) || 0);
|
|
|
+ if (!priceInfo.isLimitSpecial) {
|
|
|
+ const big = Number(item.bigCount) > 0;
|
|
|
+ const p = big
|
|
|
+ ? this.toSafeNumber(item.bigPrice)
|
|
|
+ : this.toSafeNumber(item.smallPrice);
|
|
|
+ return {
|
|
|
+ showStrike: false,
|
|
|
+ main: `¥${fmt(p)}`,
|
|
|
+ strike: ""
|
|
|
+ };
|
|
|
+ }
|
|
|
+ if (priceInfo.exceedNum <= 0) {
|
|
|
+ return {
|
|
|
+ showStrike: false,
|
|
|
+ main: `¥${fmt(priceInfo.specialPrice)}`,
|
|
|
+ strike: ""
|
|
|
+ };
|
|
|
+ }
|
|
|
+ if (priceInfo.exceedNum > 0 && priceInfo.hasBuyNum > priceInfo.limitBuy) {
|
|
|
+ return {
|
|
|
+ showStrike: false,
|
|
|
+ main: `¥${fmt(priceInfo.originalPrice)}`,
|
|
|
+ strike: ""
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ showStrike: true,
|
|
|
+ main: `¥${fmt(priceInfo.specialPrice)}`,
|
|
|
+ strike: `¥${fmt(priceInfo.originalPrice)}`
|
|
|
+ };
|
|
|
+ },
|
|
|
+ getLimitBuyPriceText(item) {
|
|
|
+ const parts = this.getLimitBuyPriceDisplayParts(item);
|
|
|
+ if (parts.showStrike) {
|
|
|
+ return `${parts.main} ${parts.strike}`;
|
|
|
+ }
|
|
|
+ return parts.main;
|
|
|
+ },
|
|
|
+ getLimitBuyPriceTip(item) {
|
|
|
+ const priceInfo = this.getLimitBuyPriceInfo(item);
|
|
|
+ if (!priceInfo.isLimitSpecial) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if (priceInfo.exceedNum <= 0) {
|
|
|
+ return `限购 ${priceInfo.limitBuy},未超限购,按特价计算`;
|
|
|
+ }
|
|
|
+ if (priceInfo.exceedNum > 0 && priceInfo.hasBuyNum > priceInfo.limitBuy) {
|
|
|
+ return `限购 ${priceInfo.limitBuy},已超出,按原价计算`;
|
|
|
+ }
|
|
|
+ return `限购 ${priceInfo.limitBuy},${priceInfo.currentBuyNum - priceInfo.exceedNum} 扎按特价,超出 ${priceInfo.exceedNum} 扎按原价`;
|
|
|
+ },
|
|
|
//记忆已选的花材
|
|
|
rememberProduct(){
|
|
|
//采购或预订的记忆花材
|
|
|
@@ -224,6 +333,7 @@ export default {
|
|
|
uni.removeStorageSync('selectList'+this.pageType);
|
|
|
}
|
|
|
this.resetSelectInfoByType(this.pageType);
|
|
|
+ this.resetLimitBuyInfoByType(this.pageType);
|
|
|
},
|
|
|
//大小单位切换
|
|
|
switchGlobalUnitType(){
|