acdr-ui/dist/dev/mp-weixin/modules/mall/coupon/detail.js
2024-10-01 09:15:35 +08:00

310 lines
12 KiB
JavaScript

"use strict";
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
const common_vendor = require("../../../common/vendor.js");
const modules_mall_sheep_index = require("../sheep/index.js");
const modules_mall_sheep_api_promotion_coupon = require("../sheep/api/promotion/coupon.js");
const modules_mall_sheep_hooks_useGoods = require("../sheep/hooks/useGoods.js");
const modules_mall_sheep_api_product_spu = require("../sheep/api/product/spu.js");
const modules_mall_sheep_api_product_category = require("../sheep/api/product/category.js");
const modules_mall_sheep_util_index = require("../sheep/util/index.js");
if (!Array) {
const _easycom_uni_collapse_item2 = common_vendor.resolveComponent("uni-collapse-item");
const _easycom_uni_collapse2 = common_vendor.resolveComponent("uni-collapse");
const _easycom_su_tabs2 = common_vendor.resolveComponent("su-tabs");
const _easycom_su_sticky2 = common_vendor.resolveComponent("su-sticky");
const _easycom_s_goods_column2 = common_vendor.resolveComponent("s-goods-column");
const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
(_easycom_uni_collapse_item2 + _easycom_uni_collapse2 + _easycom_su_tabs2 + _easycom_su_sticky2 + _easycom_s_goods_column2 + _easycom_uni_load_more2 + _easycom_s_empty2 + _easycom_s_layout2 + _component_layout_default_uni)();
}
const _easycom_uni_collapse_item = () => "../../../uni_modules/uni-collapse/components/uni-collapse-item/uni-collapse-item.js";
const _easycom_uni_collapse = () => "../../../uni_modules/uni-collapse/components/uni-collapse/uni-collapse.js";
const _easycom_su_tabs = () => "../sheep/ui/su-tabs/su-tabs.js";
const _easycom_su_sticky = () => "../sheep/ui/su-sticky/su-sticky.js";
const _easycom_s_goods_column = () => "../sheep/components/s-goods-column/s-goods-column.js";
const _easycom_uni_load_more = () => "../../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
const _easycom_s_empty = () => "../sheep/components/s-empty/s-empty.js";
const _easycom_s_layout = () => "../sheep/components/s-layout/s-layout.js";
if (!Math) {
(_easycom_uni_collapse_item + _easycom_uni_collapse + _easycom_su_tabs + _easycom_su_sticky + _easycom_s_goods_column + _easycom_uni_load_more + _easycom_s_empty + _easycom_s_layout)();
}
const _sfc_main = {
__name: "detail",
setup(__props) {
const state = common_vendor.reactive({
id: 0,
// 优惠劵模版编号 templateId
couponId: 0,
// 用户优惠劵编号 couponId
coupon: {},
// 优惠劵信息
pagination: {
list: [],
total: 0,
pageNo: 1,
pageSize: 1
},
categoryId: 0,
// 选中的商品分类编号
tabMaps: [],
// 指定分类时,每个分类构成一个 tab
currentTab: 0,
// 选中的 tabMaps 下标
loadStatus: ""
});
function onTabsChange(e) {
modules_mall_sheep_util_index.resetPagination(state.pagination);
state.currentTab = e.index;
state.categoryId = e.value;
getGoodsListByCategory();
}
function getGoodsListByCategory() {
return __async(this, null, function* () {
state.loadStatus = "loading";
const { code, data } = yield modules_mall_sheep_api_product_spu.SpuApi.getSpuPage({
categoryId: state.categoryId,
pageNo: state.pagination.pageNo,
pageSize: state.pagination.pageSize
});
if (code !== 0) {
return;
}
state.pagination.list = common_vendor.lodash.concat(state.pagination.list, data.list);
state.pagination.total = data.total;
state.loadStatus = state.pagination.list.length < state.pagination.total ? "more" : "noMore";
});
}
function getGoodsListById() {
return __async(this, null, function* () {
const { data, code } = yield modules_mall_sheep_api_product_spu.SpuApi.getSpuListByIds(state.coupon.productScopeValues.join(","));
if (code !== 0) {
return;
}
state.pagination.list = data;
});
}
function getCategoryList() {
return __async(this, null, function* () {
const { data, code } = yield modules_mall_sheep_api_product_category.CategoryApi.getCategoryListByIds(
state.coupon.productScopeValues.join(",")
);
if (code !== 0) {
return;
}
state.tabMaps = data.map((category) => ({ name: category.name, value: category.id }));
if (state.tabMaps.length > 0) {
state.categoryId = state.tabMaps[0].value;
yield getGoodsListByCategory();
}
});
}
function getCoupon() {
return __async(this, null, function* () {
const { code } = yield modules_mall_sheep_api_promotion_coupon.CouponApi.takeCoupon(state.id);
if (code !== 0) {
return;
}
common_vendor.index.showToast({
title: "领取成功"
});
setTimeout(() => {
getCouponContent();
}, 1e3);
});
}
function getCouponContent() {
return __async(this, null, function* () {
const { code, data } = state.id > 0 ? yield modules_mall_sheep_api_promotion_coupon.CouponApi.getCouponTemplate(state.id) : yield modules_mall_sheep_api_promotion_coupon.CouponApi.getCoupon(state.couponId);
if (code !== 0) {
return;
}
state.coupon = data;
if (state.coupon.productScope === 2) {
yield getGoodsListById();
} else if (state.coupon.productScope === 3) {
yield getCategoryList();
}
});
}
function loadMore() {
if (state.loadStatus === "noMore") {
return;
}
state.pagination.pageNo++;
getGoodsListByCategory();
}
common_vendor.onLoad((options) => {
state.id = options.id;
state.couponId = options.couponId;
getCouponContent(state.id, state.couponId);
});
common_vendor.onReachBottom(() => {
loadMore();
});
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.unref(modules_mall_sheep_index.sheep).$url.static("/static/img/shop/app/coupon_icon.png"),
b: common_vendor.t(state.coupon.name),
c: common_vendor.t(common_vendor.unref(modules_mall_sheep_hooks_useGoods.fen2yuan)(state.coupon.usePrice)),
d: common_vendor.t(state.coupon.discountType === 1 ? "减 " + common_vendor.unref(modules_mall_sheep_hooks_useGoods.fen2yuan)(state.coupon.discountPrice) + " 元" : "打 " + state.coupon.discountPercent / 10 + " 折"),
e: state.id > 0
}, state.id > 0 ? {
f: common_vendor.t(state.coupon.canTake ? "立即领取" : "已领取")
} : {
g: common_vendor.t(state.coupon.status === 1 ? "立即使用" : state.coupon.status === 2 ? "已使用" : "已过期")
}, {
h: common_vendor.n(state.coupon.canTake || state.coupon.status === 1 ? "use-btn" : "disable-btn"),
i: !state.coupon.canTake,
j: common_vendor.o(getCoupon),
k: state.coupon.validityType === 2
}, state.coupon.validityType === 2 ? {
l: common_vendor.t(state.coupon.fixedEndTerm)
} : {
m: common_vendor.t(common_vendor.unref(modules_mall_sheep_index.sheep).$helper.timeFormat(state.coupon.validStartTime, "yyyy-mm-dd")),
n: common_vendor.t(common_vendor.unref(modules_mall_sheep_index.sheep).$helper.timeFormat(state.coupon.validEndTime, "yyyy-mm-dd"))
}, {
o: common_vendor.t(state.coupon.discountType === 1 ? "满减券" : "折扣券"),
p: state.coupon.description
}, state.coupon.description ? {
q: common_vendor.t(state.coupon.description),
r: common_vendor.p({
title: "优惠券说明"
})
} : {}, {
s: state.coupon.productScope === 1
}, state.coupon.productScope === 1 ? {} : common_vendor.e({
t: common_vendor.t(state.coupon.productScope === 2 ? "指定商品可用" : "指定分类可用"),
v: state.coupon.productScope === 3
}, state.coupon.productScope === 3 ? {
w: common_vendor.o(onTabsChange),
x: common_vendor.p({
scrollable: true,
list: state.tabMaps,
current: state.currentTab
})
} : {}, {
y: common_vendor.p({
bgColor: "#fff"
})
}), {
z: state.coupon.productScope === 2
}, state.coupon.productScope === 2 ? {
A: common_vendor.f(state.pagination.list, (item, index, i0) => {
return {
a: common_vendor.o(($event) => common_vendor.unref(modules_mall_sheep_index.sheep).$router.go("/modules/mall/goods/index", {
id: item.id
}), index),
b: "bb34ca7d-6-" + i0 + ",bb34ca7d-1",
c: common_vendor.p({
size: "lg",
data: item,
goodsFields: {
title: {
show: true
},
subtitle: {
show: true
},
price: {
show: true
},
original_price: {
show: true
},
sales: {
show: true
},
stock: {
show: false
}
}
}),
d: index
};
})
} : {}, {
B: state.coupon.productScope === 3
}, state.coupon.productScope === 3 ? {
C: common_vendor.f(state.pagination.list, (item, index, i0) => {
return {
a: common_vendor.o(($event) => common_vendor.unref(modules_mall_sheep_index.sheep).$router.go("/modules/mall/goods/index", {
id: item.id
}), index),
b: "bb34ca7d-7-" + i0 + ",bb34ca7d-1",
c: common_vendor.p({
size: "lg",
data: item,
goodsFields: {
title: {
show: true
},
subtitle: {
show: true
},
price: {
show: true
},
original_price: {
show: true
},
sales: {
show: true
},
stock: {
show: false
}
}
}),
d: index
};
})
} : {}, {
D: state.pagination.total > 0 && state.coupon.productScope === 3
}, state.pagination.total > 0 && state.coupon.productScope === 3 ? {
E: common_vendor.o(loadMore),
F: common_vendor.p({
status: state.loadStatus,
["content-text"]: {
contentdown: "上拉加载更多"
}
})
} : {}, {
G: state.coupon.productScope === 3 && state.pagination.total === 0
}, state.coupon.productScope === 3 && state.pagination.total === 0 ? {
H: common_vendor.p({
paddingTop: "0",
icon: "/static/soldout-empty.png",
text: "暂无商品"
})
} : {}, {
I: common_vendor.p({
title: "优惠券详情"
})
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-bb34ca7d"]]);
wx.createPage(MiniProgramPage);