From 96a439a8dfa3b3d7ed973147c9671225e28f712c Mon Sep 17 00:00:00 2001
From: lifizer <913626195@qq.com>
Date: Sat, 30 Mar 2024 13:02:38 +0800
Subject: [PATCH] =?UTF-8?q?Fix(=E5=95=86=E5=93=81):[#1015]=E8=A7=84?=
=?UTF-8?q?=E6=A0=BC=E6=94=B9=E4=B8=BA=E5=8C=85=E5=90=AB=E5=B0=8F=E6=95=B0?=
=?UTF-8?q?=E7=82=B9=E7=9A=84=E5=90=8D=E7=A7=B0=E5=90=8E=EF=BC=8C=E6=97=A0?=
=?UTF-8?q?=E6=B3=95=E6=93=8D=E4=BD=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
components/ProductWindow.vue | 26 ++-
pages/shop/GoodsCon/index.vue | 364 ++++++++++------------------------
2 files changed, 123 insertions(+), 267 deletions(-)
diff --git a/components/ProductWindow.vue b/components/ProductWindow.vue
index acee08f..d339fc4 100644
--- a/components/ProductWindow.vue
+++ b/components/ProductWindow.vue
@@ -24,14 +24,14 @@
:key="indexn"
:class="{
'on': item.index == indexn,
- 'disabled': productValue[itemn.attr].stock === 0
+ 'disabled': getAttrItemData(itemn.attr).stock === 0
}"
class="itemn"
@click="tapAttr(indexw, indexn, itemn)"
>
{{ itemn.attr }}
缺货
@@ -71,6 +71,12 @@ export default {
type: String,
default: '{}'
},
+ productValueArr: {
+ type: Array,
+ default: () => {
+ return []
+ }
+ },
cartNum: {
type: Number,
default: () => 1
@@ -91,12 +97,18 @@ export default {
CartNumAdd: function() {
this.$emit("changeFun", { action: "ChangeCartNum", value: 1 })
},
- tapAttr: function(indexw, indexn, itemn) {
- const productValue = JSON.parse(this.productValueStr || '{}')
- if (productValue[itemn.attr]) {
- if (productValue[itemn.attr].stock === 0) {
- return
+ getAttrItemData(attr) {
+ let result = {}
+ this.productValueArr.map(item => {
+ if (item.attrItemkey === attr) {
+ result = item
}
+ })
+ return result
+ },
+ tapAttr: function(indexw, indexn, itemn) {
+ if (this.getAttrItemData(itemn.attr).stock === 0) {
+ return
}
// 修改商品规格不生效的原因:
// H5端下面写法,attr更新,但是除H5外其他端不支持,
diff --git a/pages/shop/GoodsCon/index.vue b/pages/shop/GoodsCon/index.vue
index be348da..7907444 100644
--- a/pages/shop/GoodsCon/index.vue
+++ b/pages/shop/GoodsCon/index.vue
@@ -23,41 +23,12 @@
{{ attr.productSelect.otPrice }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
已享受会员价格
-
-
-
-
-
-
@@ -76,31 +47,6 @@
{{ attr.productSelect.otPrice }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
{{ storeInfo.origin }}
@@ -266,32 +212,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -357,48 +277,8 @@
-
-
-
-
-
-
@@ -475,7 +355,7 @@
{
+ getPreSale(this.activityId).then(({ data }) => {
var now = new Date().getTime();
var nowStr = formatDateTime(now, 'yyyy-MM-dd');
data.surplus = diffDay(nowStr, data.stopTime.substring(0, 10))
@@ -850,9 +728,7 @@ export default {
},
// v4 秒杀
getKillInfo() {
- getYxStoreSeckill(this.activityId).then(({
- data
- }) => {
+ getYxStoreSeckill(this.activityId).then(({ data }) => {
let stopTime = data.storeInfo.stopTime;
let stopDate = new Date(stopTime.replace(/-/g, "/"));
data.stop = Math.floor(stopDate.getTime() / 1000);
@@ -862,9 +738,7 @@ export default {
},
// v4 每日特价
getDayInfo() {
- getDailyGoods(this.activityId).then(({
- data
- }) => {
+ getDailyGoods(this.activityId).then(({ data }) => {
let stopTime = data.stopTime;
let stopDate = new Date(stopTime.replace(/-/g, "/"));
data.stop = Math.floor(stopDate.getTime() / 1000);
@@ -874,40 +748,15 @@ export default {
},
// 关联商品规格
handleAttr(data) {
- this.$set(this.attr, "productAttr", data.productAttr);
- this.$set(this, "productValue", data.productValue);
- this.DefaultSelect();
- },
-
- priceRangeStr: function (prices) {
- var ret = '';
- var maxPrice = 0;
- var minPrice = Object.values(prices)[0].price;
-
- Object.values(prices).forEach((item) => {
- minPrice = Math.min(minPrice, item.price);
- maxPrice = Math.max(maxPrice, item.price);
- })
- if (maxPrice >= 0 && minPrice >= 0) {
- if (maxPrice > minPrice) {
- ret = minPrice + '-' + maxPrice;
- } else if (maxPrice == minPrice) {
- ret = minPrice;
- }
- }
- return ret;
- },
- minMaxOtPrice: function (prices) {
- var maxPrice = Object.values(prices)[0].otPrice;
- var minPrice = Object.values(prices)[0].otPrice;
- Object.values(prices).forEach((item) => {
- minPrice = Math.min(minPrice, item.otPrice);
- maxPrice = Math.max(maxPrice, item.otPrice);
- })
- return {
- min: minPrice,
- max: maxPrice
+ this.$set(this.attr, "productAttr", data.productAttr)
+ this.productValueArr = []
+ for (const key in data.productValue) {
+ this.productValueArr.push({
+ attrItemkey: key,
+ ...data.productValue[key]
+ })
}
+ this.DefaultSelect()
},
fetchCompanyDatea: function () {
var that = this;
@@ -921,17 +770,9 @@ export default {
force2Decimal(v) {
return this.$force2Decimal(v);
},
- toggleProductInfo() {
- this.isProductInfoExpand = !this.isProductInfoExpand;
- },
goShoppingCart() {
this.$yrouter.switchTab("/pages/cart");
},
- goCustomerList() {
- this.$yrouter.push({
- path: "/pages/user/CustomerList/index"
- });
- },
goStoreList() {
this.$yrouter.push({
path: "/pages/shop/StoreList/index"
@@ -977,105 +818,108 @@ export default {
},
//产品详情接口;
productCon: function () {
- let that = this;
- let from = this.location;
- if (this.$deviceType == "app") {
- from.from = "app";
+ const from = this.location
+ if (this.$deviceType == 'app') {
+ from.from = 'app'
}
- if (that.source === 'kill') {
- from.seckillId = that.activityId
+ if (this.source === 'kill') {
+ from.seckillId = this.activityId
}
-
uni.showLoading({
- title: "加载中",
+ title: '加载中',
mask: true
- });
- getProductDetail(that.id, from)
- .then(res => {
- // 会造成两个style属性,并且生效的是后一个
- // res.data.storeInfo.description = res.data.storeInfo.description.replace(
- // /\
{
+ const { data } = res
+ this.$set(this, 'storeInfo', data.storeInfo)
+ this.isWenwan = data.isWenwan
+ // 给 attr 赋值,将请求回来的规格赋值给 attr
+ if (this.source === '' || this.source === 'famous') {
+ this.$set(this.attr, 'productAttr', data.productAttr)
+ this.productValueArr = []
+ for (const key in data.productValue) {
+ this.productValueArr.push({
+ attrItemkey: key,
+ ...data.productValue[key]
+ })
+ }
+ }
+ this.attr.defaultSku = data.defaultSku
+ this.attr.defaultSkuIndex = data.defaultSkuIndex
- // 给 attr 赋值,将请求回来的规格赋值给 attr
- if (this.source === "" || this.source === 'famous') {
- that.$set(that.attr, "productAttr", res.data.productAttr);
- that.$set(that, "productValue", res.data.productValue);
- }
- that.attr.defaultSku = res.data.defaultSku
- that.attr.defaultSkuIndex = res.data.defaultSkuIndex
+ data.couponList['unusable']?.map(item => item.status = 2)
+ this.$set(this, 'couponList', data.couponList)
+ this.$set(this, 'replyCount', data.replyCount)
+ this.$set(this, 'replyChance', data.replyChance)
+ this.reply = data.reply ? [data.reply] : []
+ this.$set(this, 'reply', this.reply)
+ this.$set(this, 'priceName', data.priceName)
+ this.$set(this, 'tempName', data.tempName)
+ this.$set(this, 'merBestProducts', data.merBestProducts)
+ this.posterData.image = this.storeInfo.image
+ if (this.storeInfo.storeName.length > 30) {
+ this.posterData.title = this.storeInfo.storeName.substring(0, 30) + '...'
+ } else {
+ this.posterData.title = this.storeInfo.storeName
+ }
+ this.posterData.price = this.storeInfo.price
+ this.posterData.code = this.storeInfo.codeBase
+ this.systemStore = data.systemStore
+ const good_list = data.goodList || []
+ const goodArray = []
+ const count = Math.ceil(good_list.length / 6)
+ for (let i = 0; i < count; i++) {
+ const list = good_list.slice(i * 6, 6)
+ if (list.length) {
+ goodArray.push({
+ list: list
+ })
+ }
+ }
+ this.mapKay = data.mapKay
+ this.$set(this, 'goodList', goodArray)
+ this.DefaultSelect()
+ this.getCartCount()
- res.data.couponList['unusable']?.map(item => item.status = 2)
- that.$set(that, 'couponList', res.data.couponList)
- that.$set(that, "replyCount", res.data.replyCount);
- that.$set(that, "replyChance", res.data.replyChance);
- that.reply = res.data.reply ? [res.data.reply] : [];
- that.$set(that, "reply", that.reply);
- that.$set(that, "priceName", res.data.priceName);
- that.$set(that, "tempName", res.data.tempName);
- that.$set(that, "merBestProducts", res.data.merBestProducts);
- that.posterData.image = that.storeInfo.image;
- if (that.storeInfo.storeName.length > 30) {
- that.posterData.title =
- that.storeInfo.storeName.substring(0, 30) + "...";
- } else {
- that.posterData.title = that.storeInfo.storeName;
- }
- that.posterData.price = that.storeInfo.price;
- that.posterData.code = that.storeInfo.codeBase;
- that.systemStore = res.data.systemStore;
- let good_list = res.data.goodList || [];
- let goodArray = [];
- let count = Math.ceil(good_list.length / 6);
- for (let i = 0; i < count; i++) {
- var list = good_list.slice(i * 6, 6);
- if (list.length)
- goodArray.push({
- list: list
- });
- }
- that.mapKay = res.data.mapKay;
- that.$set(that, "goodList", goodArray);
- that.DefaultSelect();
- that.getCartCount();
-
- //动态配置share
- that.$set(that, "share", {
- title: that.storeInfo.storeName,
- path: '/pages/shop/GoodsCon/index?id=' + that.id,
- imageUrl: that.storeInfo.image,
- desc: '',
- content: ''
- });
-
- })
- .catch(err => {
- uni.showToast({
- title: err.msg || err.response.data.msg || err.response.data.message,
- icon: "none",
- duration: 2000
- });
- })
- .finally(() => {
- uni.hideLoading();
- });
+ // 动态配置share
+ this.$set(this, 'share', {
+ title: this.storeInfo.storeName,
+ path: '/pages/shop/GoodsCon/index?id=' + this.id,
+ imageUrl: this.storeInfo.image,
+ desc: '',
+ content: ''
+ })
+ }).catch(err => {
+ uni.showToast({
+ title: err.msg || err.response.data.msg || err.response.data.message,
+ icon: 'none',
+ duration: 2000
+ })
+ }).finally(() => {
+ uni.hideLoading()
+ })
+ },
+ getAttrItemData(attr) {
+ let result = {}
+ this.productValueArr.map(item => {
+ if (item.attrItemkey === attr) {
+ result = item
+ }
+ })
+ return result
},
//默认选中属性;
DefaultSelect: function () {
- let productAttr = this.attr.productAttr;
- let value = [];
+ const productAttr = this.attr.productAttr
for (let i = 0; i < productAttr.length; i++) {
this.$set(productAttr[i], "index", this.attr.defaultSkuIndex[i]);
- value.push(productAttr[i].attrValueArr[1]);
}
- //sort();排序函数:数字-英文-汉字;
- // let productSelect = this.productValue[value.sort().join(",")];
const skuKey = this.attr.defaultSku?.join(',')
- let productSelect = this.productValue[skuKey]
+ if (!skuKey) {
+ return
+ }
+ const productSelect = this.getAttrItemData(skuKey)
if (productSelect && productAttr.length) {
this.$set(
this.attr.productSelect,
@@ -1129,7 +973,7 @@ export default {
ChangeCartNum: function (changeValue) {
//changeValue:是否 加|减
//获取当前变动属性
- let productSelect = this.productValue[this.attrValue];
+ const productSelect = this.getAttrItemData(this.attrValue);
//如果没有属性,赋值给商品默认库存
if (productSelect === undefined && !this.attr.productAttr.length) {
productSelect = this.attr.productSelect;
@@ -1180,7 +1024,7 @@ export default {
//选择属性;
ChangeAttr: function (res) {
// 修改了规格
- let productSelect = this.productValue[res.value];
+ let productSelect = this.getAttrItemData(res.value)
if (productSelect) {
this.attr.productAttr[res.indexw].index = res.indexn;
this.$set(this.attr.productSelect, "image", productSelect.image);
@@ -1217,7 +1061,7 @@ export default {
// 加入购物车;
goCat: function (news) {
let that = this,
- productSelect = that.productValue[this.attrValue];
+ productSelect = this.getAttrItemData(this.attrValue)
//打开属性
if (that.attrValue) {
//默认选中了属性,但是没有打开过属性弹窗还是自动打开让用户查看默认选中的属性