商品详情:优惠劵信息的接入

This commit is contained in:
YunaiV
2023-12-16 19:16:21 +08:00
parent b422c7414f
commit 275e8a278f
4 changed files with 41 additions and 37 deletions
+11 -8
View File
@@ -209,18 +209,21 @@
}
}
// 领取优惠劵
async function getCoupon() {
const { error, msg } = await sheep.$api.coupon.get(state.id);
if (error === 0) {
uni.showToast({
title: msg,
});
setTimeout(() => {
getCouponContent(state.id, state.couponId);
}, 1000);
const { code } = await CouponApi.takeCoupon(state.id);
if (code !== 0) {
return;
}
uni.showToast({
title: '领取成功',
});
setTimeout(() => {
getCouponContent();
}, 1000);
}
// 加载优惠劵信息
async function getCouponContent() {
const { code, data } = state.id > 0 ? await CouponApi.getCouponTemplate(state.id)
: await CouponApi.getCoupon(state.couponId);
+1 -1
View File
@@ -111,7 +111,7 @@
state.currentTab = e.index;
state.type = e.value;
resetPagination(state.pagination)
if (state.currentTab == 0) {
if (state.currentTab === 0) {
getData();
} else {
getCoupon();
+19 -19
View File
@@ -186,18 +186,16 @@
// 立即领取 TODO 芋艿:待测试
async function onGet(id) {
const {
error,
msg
} = await sheep.$api.coupon.get(id);
if (error === 0) {
uni.showToast({
title: msg,
});
setTimeout(() => {
getCoupon();
}, 1000);
}
const { code } = await CouponApi.takeCoupon(id);
if (code !== 0) {
return;
}
uni.showToast({
title: '领取成功',
});
setTimeout(() => {
getCoupon();
}, 1000);
}
// TODO 芋艿:待测试
@@ -221,7 +219,14 @@
}, );
});
onLoad(async (options) => {
async function getCoupon() {
const { code, data } = await CouponApi.getCouponTemplateList(state.goodsId, 2, 10);
if (code === 0) {
state.couponInfo = data;
}
}
onLoad((options) => {
// 非法参数
if (!options.id) {
state.goodsInfo = null;
@@ -249,12 +254,7 @@
});
// 2. 加载优惠劵信息
CouponApi.getCouponTemplateList(state.goodsId, 2, 10).then((res) => {
if (res.code !== 0) {
return;
}
state.couponInfo = res.data;
});
getCoupon();
// 3. 加载营销活动信息
ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {