169 lines
6.3 KiB
JavaScript
169 lines
6.3 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const common_http = require("../../common/http.js");
|
|
const common_assets = require("../../common/assets.js");
|
|
const _sfc_main = {
|
|
data() {
|
|
return {
|
|
isVip: false,
|
|
expire: "",
|
|
price: 0,
|
|
benefits: [],
|
|
normalAdmin: { isNormalAdmin: false, applicationStatus: "none" }
|
|
};
|
|
},
|
|
onShow() {
|
|
this.loadVip();
|
|
this.loadNormalAdminStatus();
|
|
this.composeBenefits();
|
|
},
|
|
computed: {
|
|
expireDisplay() {
|
|
const v = this.expire;
|
|
if (v === null || v === void 0)
|
|
return "";
|
|
if (typeof v === "number") {
|
|
const d = new Date(v);
|
|
if (!isNaN(d.getTime())) {
|
|
const y = d.getFullYear();
|
|
const m2 = String(d.getMonth() + 1).padStart(2, "0");
|
|
const dd = String(d.getDate()).padStart(2, "0");
|
|
return `${y}-${m2}-${dd}`;
|
|
}
|
|
return "";
|
|
}
|
|
const s = String(v);
|
|
const m = s.match(/^(\d{4}-\d{2}-\d{2})/);
|
|
if (m)
|
|
return m[1];
|
|
const idx = s.search(/[ T]/);
|
|
if (idx > 0) {
|
|
const head = s.slice(0, idx);
|
|
if (head)
|
|
return head;
|
|
}
|
|
const d2 = new Date(s);
|
|
if (!isNaN(d2.getTime())) {
|
|
const y = d2.getFullYear();
|
|
const m2 = String(d2.getMonth() + 1).padStart(2, "0");
|
|
const dd2 = String(d2.getDate()).padStart(2, "0");
|
|
return `${y}-${m2}-${dd2}`;
|
|
}
|
|
return s;
|
|
},
|
|
priceDisplay() {
|
|
const n = Number(this.price);
|
|
return Number.isFinite(n) && n > 0 ? n.toFixed(2) : "0.00";
|
|
},
|
|
applyDisabled() {
|
|
var _a, _b;
|
|
const s = String(((_a = this.normalAdmin) == null ? void 0 : _a.applicationStatus) || "none");
|
|
return !!(((_b = this.normalAdmin) == null ? void 0 : _b.isNormalAdmin) || s === "approved" || s === "pending");
|
|
},
|
|
applyBtnText() {
|
|
var _a, _b, _c;
|
|
if (((_a = this.normalAdmin) == null ? void 0 : _a.isNormalAdmin) || ((_b = this.normalAdmin) == null ? void 0 : _b.applicationStatus) === "approved")
|
|
return "已通过";
|
|
if (((_c = this.normalAdmin) == null ? void 0 : _c.applicationStatus) === "pending")
|
|
return "审核中";
|
|
if (!this.isVip)
|
|
return "仅限VIP";
|
|
return "提交申请";
|
|
}
|
|
},
|
|
methods: {
|
|
composeBenefits() {
|
|
this.benefits = [
|
|
{ key: "history", title: "完整历史留存", desc: "无限期保留交易、库存与客户数据", icon: "/static/icons/icons8-graph-report-50.png" },
|
|
{ key: "analysis", title: "高级统计面板", desc: "秒级汇总销售毛利,掌握生意节奏", icon: "/static/icons/icons8-profit-50.png" },
|
|
{ key: "priority", title: "优先客服支持", desc: "遇到问题优先处理,响应更迅速", icon: "/static/icons/icons8-account-male-100.png" }
|
|
];
|
|
},
|
|
async loadVip() {
|
|
try {
|
|
const data = await common_http.get("/api/vip/status");
|
|
this.isVip = !!(data == null ? void 0 : data.isVip);
|
|
this.expire = (data == null ? void 0 : data.expireAt) || "";
|
|
if (typeof (data == null ? void 0 : data.price) === "number")
|
|
this.price = data.price;
|
|
} catch (e) {
|
|
this.isVip = false;
|
|
}
|
|
},
|
|
async loadNormalAdminStatus() {
|
|
try {
|
|
const data = await common_http.get("/api/normal-admin/application/status");
|
|
this.normalAdmin = {
|
|
isNormalAdmin: !!(data == null ? void 0 : data.isNormalAdmin),
|
|
applicationStatus: String((data == null ? void 0 : data.applicationStatus) || "none")
|
|
};
|
|
} catch (e) {
|
|
this.normalAdmin = { isNormalAdmin: false, applicationStatus: "none" };
|
|
}
|
|
},
|
|
async onPay() {
|
|
try {
|
|
await common_http.post("/api/vip/pay", {});
|
|
common_vendor.index.showToast({ title: "已开通VIP", icon: "success" });
|
|
await this.loadVip();
|
|
} catch (e) {
|
|
common_vendor.index.showToast({ title: String(e.message || "开通失败"), icon: "none" });
|
|
}
|
|
},
|
|
async onApplyNormalAdmin() {
|
|
var _a, _b, _c;
|
|
if (this.applyDisabled) {
|
|
const msg = ((_a = this.normalAdmin) == null ? void 0 : _a.isNormalAdmin) || ((_b = this.normalAdmin) == null ? void 0 : _b.applicationStatus) === "approved" ? "已通过,无需重复申请" : ((_c = this.normalAdmin) == null ? void 0 : _c.applicationStatus) === "pending" ? "审核中,请耐心等待" : "不可申请";
|
|
return common_vendor.index.showToast({ title: msg, icon: "none" });
|
|
}
|
|
try {
|
|
await common_http.post("/api/normal-admin/apply", { remark: "从我的-会员发起申请" });
|
|
common_vendor.index.showToast({ title: "申请已提交", icon: "success" });
|
|
await this.loadNormalAdminStatus();
|
|
} catch (e) {
|
|
common_vendor.index.showToast({ title: String(e.message || "申请失败"), icon: "none" });
|
|
}
|
|
}
|
|
}
|
|
};
|
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
return common_vendor.e({
|
|
a: common_assets._imports_0$4,
|
|
b: common_vendor.t($data.isVip ? "VIP会员" : "升级 VIP 会员"),
|
|
c: common_vendor.t($data.isVip ? "尊享完整数据与高效体验" : "开通后可查看全部历史数据并解锁高级功能"),
|
|
d: common_vendor.t($data.isVip ? "已开通" : "普通用户"),
|
|
e: $data.isVip ? 1 : "",
|
|
f: $data.isVip
|
|
}, $data.isVip ? {
|
|
g: common_vendor.t($options.expireDisplay)
|
|
} : {
|
|
h: common_vendor.t($options.priceDisplay)
|
|
}, {
|
|
i: common_vendor.f($data.benefits, (item, k0, i0) => {
|
|
return common_vendor.e({
|
|
a: item.icon
|
|
}, item.icon ? {
|
|
b: item.icon
|
|
} : {}, {
|
|
c: common_vendor.t(item.title),
|
|
d: common_vendor.t(item.desc),
|
|
e: item.key
|
|
});
|
|
}),
|
|
j: $data.isVip
|
|
}, $data.isVip ? {
|
|
k: common_vendor.t($options.applyBtnText),
|
|
l: common_vendor.n({
|
|
disabled: $options.applyDisabled
|
|
}),
|
|
m: common_vendor.o((...args) => $options.onApplyNormalAdmin && $options.onApplyNormalAdmin(...args))
|
|
} : {}, {
|
|
n: !$data.isVip
|
|
}, !$data.isVip ? {
|
|
o: common_vendor.o((...args) => $options.onPay && $options.onPay(...args))
|
|
} : {});
|
|
}
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/my/vip.js.map
|