acdr-ui/dist/dev/mp-weixin/modules/mall/sheep/components/s-coupon-block/s-coupon-block.js

160 lines
5.7 KiB
JavaScript
Raw Normal View History

2024-09-19 07:20:14 +08:00
"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());
});
};
2024-10-01 09:15:35 +08:00
const common_vendor = require("../../../../../common/vendor.js");
const modules_mall_sheep_index = require("../../index.js");
const modules_mall_sheep_api_promotion_coupon = require("../../api/promotion/coupon.js");
const modules_mall_sheep_util_const = require("../../util/const.js");
const modules_mall_sheep_util_index = require("../../util/index.js");
2024-09-19 07:20:14 +08:00
if (!Array) {
const _easycom_su_coupon2 = common_vendor.resolveComponent("su-coupon");
_easycom_su_coupon2();
}
const _easycom_su_coupon = () => "../../ui/su-coupon/su-coupon.js";
if (!Math) {
_easycom_su_coupon();
}
const _sfc_main = {
__name: "s-coupon-block",
props: {
data: {
type: Object,
default: () => ({})
},
styles: {
type: Object,
default: () => ({})
}
},
setup(__props) {
const props = __props;
const { columns, button } = props.data;
const SIZE_LIST = ["lg", "md", "xs"];
const couponBg = {
2024-10-01 09:15:35 +08:00
background: `url(${modules_mall_sheep_index.sheep.$url.cdn(props.data.bgImg)}) no-repeat top center / 100% 100%`
2024-09-19 07:20:14 +08:00
};
const btnStyles = {
background: button.bgColor,
color: button.color
};
const couponBoxStyleNormal = {
display: "flex",
"justify-content": "space-between"
};
const couponBoxStyleTwo = {
display: "flex",
"justify-content": "space-around"
};
const bgStyle = common_vendor.computed(() => {
const { bgType, bgImg, bgColor } = props.styles;
return {
background: bgType === "img" ? `url(${bgImg}) no-repeat top center / 100% 100%` : bgColor
};
});
const formatCouponDiscountType = (coupon) => {
2024-10-01 09:15:35 +08:00
if (coupon.discountType === modules_mall_sheep_util_const.PromotionDiscountTypeEnum.PRICE.type) {
2024-09-19 07:20:14 +08:00
return "reduce";
}
2024-10-01 09:15:35 +08:00
if (coupon.discountType === modules_mall_sheep_util_const.PromotionDiscountTypeEnum.PERCENT.type) {
2024-09-19 07:20:14 +08:00
return "percent";
}
return `未知【${coupon.discountType}`;
};
const formatCouponDiscountValue = (coupon) => {
2024-10-01 09:15:35 +08:00
if (coupon.discountType === modules_mall_sheep_util_const.PromotionDiscountTypeEnum.PRICE.type) {
return modules_mall_sheep_util_index.floatToFixed2(coupon.discountPrice);
2024-09-19 07:20:14 +08:00
}
2024-10-01 09:15:35 +08:00
if (coupon.discountType === modules_mall_sheep_util_const.PromotionDiscountTypeEnum.PERCENT.type) {
2024-09-19 07:20:14 +08:00
return coupon.discountPercent;
}
return `未知【${coupon.discountType}`;
};
const formatValidityType = (row) => {
2024-10-01 09:15:35 +08:00
if (row.validityType === modules_mall_sheep_util_const.CouponTemplateValidityTypeEnum.DATE.type) {
return `${modules_mall_sheep_util_index.formatDate(row.validStartTime)}${modules_mall_sheep_util_index.formatDate(row.validEndTime)}`;
2024-09-19 07:20:14 +08:00
}
2024-10-01 09:15:35 +08:00
if (row.validityType === modules_mall_sheep_util_const.CouponTemplateValidityTypeEnum.TERM.type) {
2024-09-19 07:20:14 +08:00
return `领取后第 ${row.fixedStartTerm} - ${row.fixedEndTerm} 天内可用`;
}
return "未知【" + row.validityType + "】";
};
const couponList = common_vendor.ref([]);
function onGetCoupon(id) {
return __async(this, null, function* () {
2024-10-01 09:15:35 +08:00
const { error, msg } = yield modules_mall_sheep_api_promotion_coupon.CouponApi.takeCoupon(id);
2024-09-19 07:20:14 +08:00
if (error === 0) {
common_vendor.index.showToast({
title: msg,
icon: "none"
});
return;
}
yield getCouponTemplateList();
});
}
const getCouponTemplateList = () => __async(this, null, function* () {
2024-10-01 09:15:35 +08:00
const { data } = yield modules_mall_sheep_api_promotion_coupon.CouponApi.getCouponTemplateListByIds(props.data.couponIds.join(","));
2024-09-19 07:20:14 +08:00
couponList.value = data;
});
common_vendor.onMounted(() => {
getCouponTemplateList();
});
return (_ctx, _cache) => {
return {
a: common_vendor.f(couponList.value, (item, index, i0) => {
return common_vendor.e(common_vendor.unref(columns) === 2 ? {
a: common_vendor.o(($event) => onGetCoupon(item.id), index),
b: common_vendor.s(btnStyles)
} : {
c: common_vendor.s(btnStyles),
d: common_vendor.o(($event) => onGetCoupon(item.id), index)
}, {
2024-10-01 09:15:35 +08:00
e: "a9578c9e-0-" + i0,
2024-09-19 07:20:14 +08:00
f: common_vendor.p({
size: SIZE_LIST[common_vendor.unref(columns) - 1],
textColor: __props.data.textColor,
background: "",
couponId: item.id,
title: item.name,
type: formatCouponDiscountType(item),
value: formatCouponDiscountValue(item),
sellBy: formatValidityType(item)
}),
g: index
});
}),
b: common_vendor.unref(columns) === 2,
c: common_vendor.s(couponBg),
d: common_vendor.s({
marginLeft: `${__props.data.space}px`
}),
e: common_vendor.s(couponList.value.length === 2 ? couponBoxStyleTwo : couponBoxStyleNormal),
f: common_vendor.s(bgStyle.value),
g: common_vendor.s({
marginLeft: `${__props.data.space}px`
})
};
};
}
};
2024-10-01 09:15:35 +08:00
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-a9578c9e"]]);
2024-09-19 07:20:14 +08:00
wx.createComponent(Component);