190 lines
6.9 KiB
JavaScript
190 lines
6.9 KiB
JavaScript
"use strict";
|
||
const common_vendor = require("../../common/vendor.js");
|
||
const api_points = require("../../api/points.js");
|
||
const api_coupon = require("../../api/coupon.js");
|
||
const api_store = require("../../api/store.js");
|
||
const api_config = require("../../api/config.js");
|
||
const common_assets = require("../../common/assets.js");
|
||
const RichContentPopup = () => "../../components/RichContentPopup.js";
|
||
const ConfirmDialog = () => "../../components/ConfirmDialog.js";
|
||
const NavBar = () => "../../components/NavBar.js";
|
||
const _sfc_main = {
|
||
components: { RichContentPopup, ConfirmDialog, NavBar },
|
||
data() {
|
||
return {
|
||
loading: false,
|
||
balance: 0,
|
||
availableList: [],
|
||
storeOptions: [{ label: "全部", value: "" }],
|
||
currentStoreId: "",
|
||
currentStoreName: "全部",
|
||
pointsDescVisible: false,
|
||
pointsDescContent: "",
|
||
confirmVisible: false,
|
||
confirmMessage: "",
|
||
yglTipVisible: false,
|
||
currentItem: null
|
||
};
|
||
},
|
||
computed: {
|
||
filteredList() {
|
||
if (!this.currentStoreId)
|
||
return this.availableList;
|
||
return this.availableList.filter((item) => item.storeId == this.currentStoreId);
|
||
}
|
||
},
|
||
onShow() {
|
||
this.loadData();
|
||
},
|
||
methods: {
|
||
formatDate(d) {
|
||
if (!d)
|
||
return "";
|
||
return d.substring(0, 10);
|
||
},
|
||
async loadData() {
|
||
var _a;
|
||
this.loading = true;
|
||
try {
|
||
const [balanceRes, availableRes, storesRes] = await Promise.all([
|
||
api_points.getBalance(),
|
||
api_coupon.getAvailable(),
|
||
api_store.getStores()
|
||
]);
|
||
this.balance = balanceRes.balance ?? ((_a = balanceRes.data) == null ? void 0 : _a.balance) ?? 0;
|
||
this.availableList = availableRes.data || availableRes || [];
|
||
const stores = storesRes.data || storesRes || [];
|
||
this.storeOptions = [
|
||
{ label: "全部", value: "" },
|
||
...stores.map((s) => ({ label: s.name, value: s.id }))
|
||
];
|
||
} catch (err) {
|
||
common_vendor.index.__f__("error", "at pages/points/index.vue:147", "加载积分数据失败:", err);
|
||
} finally {
|
||
this.loading = false;
|
||
}
|
||
},
|
||
onStoreChange(e) {
|
||
const idx = e.detail.value;
|
||
const opt = this.storeOptions[idx];
|
||
this.currentStoreId = opt.value;
|
||
this.currentStoreName = opt.label;
|
||
},
|
||
async showPointsDesc() {
|
||
var _a;
|
||
try {
|
||
const res = await api_config.getPopup("points-desc");
|
||
this.pointsDescContent = res.content || ((_a = res.data) == null ? void 0 : _a.content) || "";
|
||
this.pointsDescVisible = true;
|
||
} catch (err) {
|
||
common_vendor.index.__f__("error", "at pages/points/index.vue:164", "获取积分说明失败:", err);
|
||
}
|
||
},
|
||
goDetail() {
|
||
common_vendor.index.navigateTo({ url: "/pages/points/detail" });
|
||
},
|
||
onExchange(item) {
|
||
if (item.remainingCount <= 0)
|
||
return;
|
||
if (item.pointsCost > 0 && this.balance < item.pointsCost) {
|
||
common_vendor.index.showToast({ title: "积分不足", icon: "none" });
|
||
return;
|
||
}
|
||
this.currentItem = item;
|
||
if (item.source === "ygl") {
|
||
this.yglTipVisible = true;
|
||
} else {
|
||
this.confirmMessage = `确定使用 ${item.pointsCost} 积分兑换「${item.name}」吗?`;
|
||
this.confirmVisible = true;
|
||
}
|
||
},
|
||
async doExchange() {
|
||
this.confirmVisible = false;
|
||
await this.executeExchange();
|
||
},
|
||
async doExchangeYgl() {
|
||
this.yglTipVisible = false;
|
||
await this.executeExchange();
|
||
},
|
||
async executeExchange() {
|
||
if (!this.currentItem)
|
||
return;
|
||
try {
|
||
await api_coupon.exchange({ templateId: this.currentItem.id });
|
||
common_vendor.index.showToast({ title: "兑换成功", icon: "success" });
|
||
this.loadData();
|
||
} catch (err) {
|
||
common_vendor.index.__f__("error", "at pages/points/index.vue:199", "兑换失败:", err);
|
||
}
|
||
}
|
||
}
|
||
};
|
||
if (!Array) {
|
||
const _component_NavBar = common_vendor.resolveComponent("NavBar");
|
||
const _component_RichContentPopup = common_vendor.resolveComponent("RichContentPopup");
|
||
const _component_ConfirmDialog = common_vendor.resolveComponent("ConfirmDialog");
|
||
(_component_NavBar + _component_RichContentPopup + _component_ConfirmDialog)();
|
||
}
|
||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||
return common_vendor.e({
|
||
a: common_vendor.p({
|
||
title: "我的积分",
|
||
showBack: false
|
||
}),
|
||
b: common_vendor.t($data.balance),
|
||
c: common_vendor.o((...args) => $options.showPointsDesc && $options.showPointsDesc(...args)),
|
||
d: common_vendor.o((...args) => $options.goDetail && $options.goDetail(...args)),
|
||
e: common_vendor.t($data.currentStoreName),
|
||
f: $data.storeOptions,
|
||
g: common_vendor.o((...args) => $options.onStoreChange && $options.onStoreChange(...args)),
|
||
h: common_vendor.f($options.filteredList, (item, k0, i0) => {
|
||
return common_vendor.e({
|
||
a: item.couponType === "discount"
|
||
}, item.couponType === "discount" ? {
|
||
b: common_vendor.t(item.discountAmount)
|
||
} : {}, {
|
||
c: common_vendor.n(item.couponType === "discount" ? "left-discount" : "left-free"),
|
||
d: common_vendor.t(item.name),
|
||
e: common_vendor.t(item.code || "XXXX"),
|
||
f: common_vendor.t($options.formatDate(item.validStart)),
|
||
g: common_vendor.t($options.formatDate(item.validEnd)),
|
||
h: common_vendor.t(item.remainingCount),
|
||
i: item.source === "ygl"
|
||
}, item.source === "ygl" ? {} : {}, {
|
||
j: common_vendor.t(item.pointsCost),
|
||
k: common_vendor.o(($event) => $options.onExchange(item), item.id),
|
||
l: item.remainingCount <= 0 ? 1 : "",
|
||
m: item.id
|
||
});
|
||
}),
|
||
i: !$options.filteredList.length && !$data.loading
|
||
}, !$options.filteredList.length && !$data.loading ? {
|
||
j: common_assets._imports_1$1
|
||
} : {}, {
|
||
k: common_vendor.o(($event) => $data.pointsDescVisible = false),
|
||
l: common_vendor.p({
|
||
visible: $data.pointsDescVisible,
|
||
title: "积分说明",
|
||
content: $data.pointsDescContent,
|
||
icon: "/static/ic_points.png"
|
||
}),
|
||
m: common_vendor.o($options.doExchange),
|
||
n: common_vendor.o(($event) => $data.confirmVisible = false),
|
||
o: common_vendor.p({
|
||
visible: $data.confirmVisible,
|
||
title: "确认兑换",
|
||
message: $data.confirmMessage
|
||
}),
|
||
p: common_vendor.o($options.doExchangeYgl),
|
||
q: common_vendor.o(($event) => $data.yglTipVisible = false),
|
||
r: common_vendor.p({
|
||
visible: $data.yglTipVisible,
|
||
title: "温馨提示",
|
||
message: "该优惠券为驿公里券,兑换后需在驿公里APP/小程序中使用,确定兑换吗?"
|
||
})
|
||
});
|
||
}
|
||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-dd6e20da"]]);
|
||
wx.createPage(MiniProgramPage);
|
||
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/points/index.js.map
|