修复优惠券微信小程序中出现的bug,以及拼团分享规格问题

master
lemon橪 2021-08-23 10:56:56 +08:00
parent 915aee9143
commit a2994454aa
3 changed files with 59 additions and 59 deletions

View File

@ -11,6 +11,7 @@
<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData"> <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
<!-- 空白页 --> <!-- 空白页 -->
<u-empty mode="coupon" text="暂无优惠券了" v-if="navItem.wheterEmpty"></u-empty> <u-empty mode="coupon" text="暂无优惠券了" v-if="navItem.wheterEmpty"></u-empty>
<!-- 数据 --> <!-- 数据 -->
<view v-if="navItem.dataList && coupon" class="coupon-item" :class="{ 'coupon-used': navIndex != 0 }" v-for="(coupon, index) in navItem.dataList" :key="index"> <view v-if="navItem.dataList && coupon" class="coupon-item" :class="{ 'coupon-used': navIndex != 0 }" v-for="(coupon, index) in navItem.dataList" :key="index">
<view class="left"> <view class="left">
@ -112,7 +113,7 @@ export default {
}; };
}, },
onLoad() { onShow() {
this.getData(); this.getData();
}, },
@ -142,7 +143,7 @@ export default {
let index = this.tabCurrentIndex; let index = this.tabCurrentIndex;
getMemberCoupons(this.navList[index].params).then((res) => { getMemberCoupons(this.navList[index].params).then((res) => {
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
if (res.statusCode == 200) { if (res.data.success) {
let data = res.data.result.records; let data = res.data.result.records;
if (data.length == 0) { if (data.length == 0) {
if (res.data.pageNumber == 1) { if (res.data.pageNumber == 1) {
@ -157,6 +158,7 @@ export default {
this.navList[index].dataList.push(...data); this.navList[index].dataList.push(...data);
} }
} }
console.log(this.navList[index].dataList)
uni.hideLoading(); uni.hideLoading();
}); });
}, },
@ -220,7 +222,7 @@ $item-color: #fff;
} }
.swiper-box { .swiper-box {
height: calc(100% - 40px); height: calc(100vh - 40px);
} }
.list-scroll-content { .list-scroll-content {

View File

@ -23,17 +23,19 @@
formatPrice(goodsDetail.price)[0] formatPrice(goodsDetail.price)[0]
}}</span> }}</span>
.{{ formatPrice(goodsDetail.price)[1] }} .{{ formatPrice(goodsDetail.price)[1] }}
<span></span>
</div> </div>
</view> </view>
<!-- 正常商品的价格 --> <!-- 正常商品的价格 -->
<view class="goods-price" v-else> <view class="goods-price" v-else>
<span>
<span class="goods-price-bigshow">{{ <span class="goods-price-bigshow">{{
formatPrice(goodsDetail.price)[0] formatPrice(goodsDetail.price)[0]
}}</span> }}</span>
.{{ formatPrice(goodsDetail.price)[1] }} .{{ formatPrice(goodsDetail.price)[1] }}
<span></span>
</span>
</view> </view>
<view class="goods-check-skus"> <view class="goods-check-skus">
已选 已选
@ -50,7 +52,7 @@
<view class="goods-skus-view" :key="specIndex" v-for="(spec, specIndex) in formatList"> <view class="goods-skus-view" :key="specIndex" v-for="(spec, specIndex) in formatList">
<view class="skus-view-list"> <view class="skus-view-list">
<view class="view-class-title">{{ spec.name }}</view> <view class="view-class-title">{{ spec.name }}</view>
<view :class="{ active: spec_val.id == currentSelceted[specIndex] }" class="skus-view-item" v-for="(spec_val, spec_index) in spec.values" :key="spec_index" <view :class="{ active: spec_val.value == currentSelceted[specIndex] }" class="skus-view-item" v-for="(spec_val, spec_index) in spec.values" :key="spec_index"
@click="handleClickSpec(spec, specIndex, spec_val)">{{ spec_val.value }}</view> @click="handleClickSpec(spec, specIndex, spec_val)">{{ spec_val.value }}</view>
</view> </view>
</view> </view>
@ -63,7 +65,8 @@
</view> </view>
<!-- 按钮 --> <!-- 按钮 -->
<view class="btns"> <view class="btns">
<view class="box-btn card" v-if="buyType !='PINTUAN'" @click="addToCartOrBuy('cart')"></view>
<view class="box-btn card" v-if="buyType != 'PINTUAN' && goodsDetail.goodsType!='VIRTUAL_GOODS'" @click="addToCartOrBuy('cart')"></view>
<view class="box-btn buy" @click="addToCartOrBuy('buy')"></view> <view class="box-btn buy" @click="addToCartOrBuy('buy')"></view>
</view> </view>
</view> </view>
@ -98,7 +101,13 @@ export default {
isClose: false, // isClose: false, //
}; };
}, },
props: ["goodsDetail", "buyMask", "selectedSku", "goodsSpec", "addr"], props: [
"goodsDetail", //
"buyMask",
"selectedSku",
"goodsSpec",
"addr",
],
watch: { watch: {
buyType: { buyType: {
handler(val) { handler(val) {
@ -129,14 +138,12 @@ export default {
/**点击规格 */ /**点击规格 */
handleClickSpec(val, index, specValue) { handleClickSpec(val, index, specValue) {
this.$set(this.currentSelceted, index, specValue.id); this.$set(this.currentSelceted, index, specValue.value);
let selectedSkuId = this.goodsSpec.find((i) => { let selectedSkuId = this.goodsSpec.find((i) => {
let matched = true; let matched = true;
let specValues = i.specValues.filter((j) => j.specName !== "images"); let specValues = i.specValues.filter((j) => j.specName !== "images");
for (let n = 0; n < specValues.length; n++) { for (let n = 0; n < specValues.length; n++) {
if (specValues[n].specValueId !== this.currentSelceted[n]) { if (specValues[n].specValue !== this.currentSelceted[n]) {
matched = false; matched = false;
return; return;
} }
@ -145,7 +152,6 @@ export default {
return i; return i;
} }
}); });
this.selectSkuList = { this.selectSkuList = {
spec: { spec: {
specName: val.name, specName: val.name,
@ -155,23 +161,9 @@ export default {
}; };
this.selectName = specValue.value; this.selectName = specValue.value;
this.$emit("handleClickSku", selectedSkuId.skuId, this.goodsDetail.id); this.$emit("handleClickSku", {
}, skuId: selectedSkuId.skuId,
goodsId: this.goodsDetail.goodsId,
/**
* 直接购买
*/
buy(data) {
API_trade.addToCart(data).then((res) => {
if (res.data.code == 200) {
uni.navigateTo({
url: `/pages/order/fillorder?way=${
data.cartType
}&addr=${""}&parentOrder=${encodeURIComponent(
JSON.stringify(this.parentOrder)
)}`,
});
}
}); });
}, },
@ -201,38 +193,39 @@ export default {
this.$emit("queryCart"); this.$emit("queryCart");
this.closeMask(); this.closeMask();
} else {
uni.showToast({
title: res.data.message,
duration: 2000,
icon: "none",
});
return false;
} }
}); });
} else { } else {
// //
if (this.buyType == "PINTUAN") { if (this.buyType) {
data.cartType = "PINTUAN"; data.cartType = "PINTUAN";
} else if (this.buyType == "POINTS") { } else if (this.goodsDetail.goodsType == "VIRTUAL_GOODS") {
data.cartType = "POINTS"; data.cartType = "VIRTUAL";
} else { } else {
data.cartType = "BUY_NOW"; data.cartType = "BUY_NOW";
} }
this.buy(data); API_trade.addToCart(data).then((res) => {
if (res.data.code == 200) {
uni.navigateTo({
url: `/pages/order/fillorder?way=${data.cartType}&addr=${
this.addr.id || ""
}&parentOrder=${encodeURIComponent(
JSON.stringify(this.parentOrder)
)}`,
});
}
});
} }
}, },
formatSku(list) { formatSku(list) {
// //
if (typeof list != Array) return false;
let arr = [{}]; let arr = [{}];
list.forEach((item, index) => { list.forEach((item, index) => {
item.specValues.forEach((spec, specIndex) => { item.specValues.forEach((spec, specIndex) => {
let id = spec.specNameId;
let name = spec.specName; let name = spec.specName;
let values = { let values = {
id: spec.specValueId,
value: spec.specValue, value: spec.specValue,
quantity: item.quantity, quantity: item.quantity,
}; };
@ -244,7 +237,7 @@ export default {
if ( if (
arrItem.name == name && arrItem.name == name &&
arrItem.values && arrItem.values &&
!arrItem.values.find((i) => i.id === values.id) !arrItem.values.find((i) => i.value === values.value)
) { ) {
arrItem.values.push(values); arrItem.values.push(values);
} }
@ -254,7 +247,6 @@ export default {
}); });
if (!keys.includes(name)) { if (!keys.includes(name)) {
arr.push({ arr.push({
id: id,
name: name, name: name,
values: [values], values: [values],
}); });
@ -271,7 +263,7 @@ export default {
item.specValues item.specValues
.filter((i) => i.specName !== "images") .filter((i) => i.specName !== "images")
.forEach((value, _index) => { .forEach((value, _index) => {
this.currentSelceted[_index] = value.specValueId; this.currentSelceted[_index] = value.specValue;
this.selectName = value.specValue; this.selectName = value.specValue;
@ -289,6 +281,8 @@ export default {
mounted() { mounted() {
this.formatSku(this.goodsSpec); this.formatSku(this.goodsSpec);
console.log(this.goodsDetail);
}, },
}; };
</script> </script>

View File

@ -140,7 +140,7 @@ export default {
async init(sn, sku) { async init(sn, sku) {
let res = await getPinTuanShare(sn, sku); let res = await getPinTuanShare(sn, sku);
if (res.data.success && res.data.result.promotionGoods) { if (res.data.success && res.data.result.promotionGoods) {
this.flage = true this.flage = true;
this.data = res.data.result; this.data = res.data.result;
this.selectedGoods = res.data.result.promotionGoods; this.selectedGoods = res.data.result.promotionGoods;
let endTime = Date.parse( let endTime = Date.parse(
@ -172,7 +172,10 @@ export default {
} else { } else {
this.isMaster = false; this.isMaster = false;
// //
this.getGoodsDetail(this.routers.sku, this.routers.goodsId); this.getGoodsDetail({
id: this.routers.sku,
goodsId: this.routers.goodsId,
});
} }
// //
@ -184,14 +187,15 @@ export default {
} }
} else { } else {
uni.showToast({ uni.showToast({
title: '当前拼团单有误!请联系管理员重试', title: "当前拼团单有误!请联系管理员重试",
duration: 2000, duration: 2000,
icon:"none" icon: "none",
}); });
} }
}, },
// //
getGoodsDetail(id, goodsId) { getGoodsDetail(val) {
let { id, goodsId } = val;
uni.showLoading({ uni.showLoading({
title: "加载中", title: "加载中",
mask: true, mask: true,