106 lines
4.7 KiB
JavaScript
106 lines
4.7 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const api_appUser = require("../../api/appUser.js");
|
|
const _sfc_main = {
|
|
__name: "index",
|
|
setup(__props) {
|
|
const avatar = common_vendor.ref(common_vendor.index.getStorageSync("avatar") || "");
|
|
const nickname = common_vendor.ref(common_vendor.index.getStorageSync("nickname") || "");
|
|
const userId = common_vendor.ref(common_vendor.index.getStorageSync("user_id") || "");
|
|
const phoneNumber = common_vendor.ref(common_vendor.index.getStorageSync("phone_number") || "");
|
|
const inviteCode = common_vendor.ref(common_vendor.index.getStorageSync("invite_code") || (common_vendor.index.getStorageSync("user_info") || {}).invite_code || "");
|
|
const pointsBalance = common_vendor.ref(common_vendor.index.getStorageSync("points_balance") || 0);
|
|
const stats = common_vendor.ref(common_vendor.index.getStorageSync("user_stats") || {});
|
|
const loading = common_vendor.ref(false);
|
|
const error = common_vendor.ref("");
|
|
async function refresh() {
|
|
const token = common_vendor.index.getStorageSync("token");
|
|
const phoneBound = !!common_vendor.index.getStorageSync("phone_bound");
|
|
if (!token || !phoneBound) {
|
|
common_vendor.index.showModal({
|
|
title: "提示",
|
|
content: "请先登录并绑定手机号",
|
|
confirmText: "去登录",
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
common_vendor.index.navigateTo({ url: "/pages/login/index" });
|
|
}
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
const user_id = common_vendor.index.getStorageSync("user_id");
|
|
loading.value = true;
|
|
error.value = "";
|
|
try {
|
|
const s = await api_appUser.getUserStats(user_id);
|
|
stats.value = s || {};
|
|
common_vendor.index.setStorageSync("user_stats", stats.value);
|
|
const b = await api_appUser.getPointsBalance(user_id);
|
|
const balance = b && b.balance !== void 0 ? b.balance : b;
|
|
pointsBalance.value = balance || 0;
|
|
common_vendor.index.setStorageSync("points_balance", pointsBalance.value);
|
|
} catch (e) {
|
|
error.value = e && (e.message || e.errMsg) || "数据获取失败";
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
function toPoints() {
|
|
common_vendor.index.navigateTo({ url: "/pages/points/index" });
|
|
}
|
|
function toOrders(status) {
|
|
const s = status === "completed" ? "completed" : "pending";
|
|
common_vendor.index.navigateTo({ url: `/pages/orders/index?status=${s}` });
|
|
}
|
|
function toAddresses() {
|
|
common_vendor.index.navigateTo({ url: "/pages/address/index" });
|
|
}
|
|
function toHelp() {
|
|
common_vendor.index.navigateTo({ url: "/pages/help/index" });
|
|
}
|
|
common_vendor.onShow(() => {
|
|
avatar.value = common_vendor.index.getStorageSync("avatar") || avatar.value;
|
|
nickname.value = common_vendor.index.getStorageSync("nickname") || nickname.value;
|
|
userId.value = common_vendor.index.getStorageSync("user_id") || userId.value;
|
|
phoneNumber.value = common_vendor.index.getStorageSync("phone_number") || phoneNumber.value;
|
|
const ui = common_vendor.index.getStorageSync("user_info") || {};
|
|
inviteCode.value = common_vendor.index.getStorageSync("invite_code") || ui.invite_code || inviteCode.value;
|
|
pointsBalance.value = common_vendor.index.getStorageSync("points_balance") || pointsBalance.value;
|
|
const s = common_vendor.index.getStorageSync("user_stats");
|
|
if (s)
|
|
stats.value = s;
|
|
refresh();
|
|
});
|
|
common_vendor.onLoad(() => {
|
|
refresh();
|
|
});
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: avatar.value || "/static/logo.png",
|
|
b: common_vendor.t(nickname.value || "未登录"),
|
|
c: common_vendor.t(userId.value || "-"),
|
|
d: common_vendor.t(phoneNumber.value || "未绑定"),
|
|
e: common_vendor.t(inviteCode.value || "-"),
|
|
f: common_vendor.o(toPoints),
|
|
g: common_vendor.t(pointsBalance.value),
|
|
h: common_vendor.t(stats.value.coupon_count || 0),
|
|
i: common_vendor.t(stats.value.item_card_count || 0),
|
|
j: common_vendor.o(refresh),
|
|
k: loading.value,
|
|
l: error.value
|
|
}, error.value ? {
|
|
m: common_vendor.t(error.value)
|
|
} : {}, {
|
|
n: common_vendor.o(($event) => toOrders("pending")),
|
|
o: common_vendor.o(($event) => toOrders("completed")),
|
|
p: common_vendor.o(toAddresses),
|
|
q: common_vendor.o(toHelp)
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-569e925a"]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/mine/index.js.map
|