|
|
@@ -59,12 +59,39 @@ function formatGiftText(item: any) {
|
|
|
}
|
|
|
|
|
|
function buildPeriodList(list: any[]) {
|
|
|
- return list.map((item: any) => ({
|
|
|
+ return list.map((item: any, index: number) => ({
|
|
|
label: item.typeName || item.title || item.name || formatPeriodText(item.num, item.period),
|
|
|
value: String(item.id),
|
|
|
disabled: Number(item.stockNum ?? 1) <= 0,
|
|
|
+ viewId: `period-${index}`,
|
|
|
}));
|
|
|
}
|
|
|
+
|
|
|
+function getPeriodScrollIntoView(periodList: any[], selectedPeriod: string) {
|
|
|
+ return periodList.find((item: any) => String(item.value) === String(selectedPeriod))?.viewId || "";
|
|
|
+}
|
|
|
+
|
|
|
+function selectDefaultTeacherVip(list: any[]) {
|
|
|
+ const saleableList = list.filter((item: any) => Number(item.stockNum ?? 1) > 0);
|
|
|
+ const candidates = saleableList.length ? saleableList : list;
|
|
|
+ const getSearchText = (item: any) => [
|
|
|
+ item.name,
|
|
|
+ item.title,
|
|
|
+ item.label,
|
|
|
+ item.typeName,
|
|
|
+ ].filter(Boolean).join("");
|
|
|
+ const isOneYear = (item: any) => {
|
|
|
+ const text = getSearchText(item);
|
|
|
+ return (Number(item.num) === 1 && item.period === "YEAR") || /(?:1|一)年/.test(text);
|
|
|
+ };
|
|
|
+ const isTrial = (item: any) => /体验卡/.test(getSearchText(item));
|
|
|
+
|
|
|
+ return candidates.find((item: any) => isOneYear(item) && isTrial(item))
|
|
|
+ || candidates.find(isOneYear)
|
|
|
+ || candidates.find((item: any) => item.isHot)
|
|
|
+ || candidates[0]
|
|
|
+ || {};
|
|
|
+}
|
|
|
// pages/orders/orders.ts
|
|
|
Page({
|
|
|
/**
|
|
|
@@ -144,6 +171,7 @@ Page({
|
|
|
userTypes: PURCHASE_TYPE.STUDENT, // 用户类型:WECHAT_MINI | TEACHER_VIP
|
|
|
periodList: [] as any,
|
|
|
selectedPeriod: '', // 选中的期限
|
|
|
+ periodScrollIntoView: '',
|
|
|
showBonusGift: false, // 是否显示额外赠送
|
|
|
},
|
|
|
|
|
|
@@ -352,10 +380,15 @@ Page({
|
|
|
},
|
|
|
// 格式化类型
|
|
|
applyPurchaseData(purchaseData: any) {
|
|
|
+ const periodScrollIntoView = getPeriodScrollIntoView(
|
|
|
+ purchaseData.periodList,
|
|
|
+ purchaseData.selectedPeriod
|
|
|
+ );
|
|
|
this.setData({
|
|
|
list: purchaseData.list,
|
|
|
periodList: purchaseData.periodList,
|
|
|
selectedPeriod: purchaseData.selectedPeriod,
|
|
|
+ periodScrollIntoView,
|
|
|
instrumentList: purchaseData.instrumentList,
|
|
|
isOverSaled: purchaseData.isOverSaled,
|
|
|
selected: purchaseData.selected,
|
|
|
@@ -406,13 +439,11 @@ Page({
|
|
|
goodsType: item.goodsType || PURCHASE_TYPE.TEACHER,
|
|
|
};
|
|
|
});
|
|
|
- const selected = list.find((item: any) => item.isHot && item.stockNum > 0)
|
|
|
- || list.find((item: any) => item.stockNum > 0)
|
|
|
- || list[0]
|
|
|
- || {};
|
|
|
+ const selected = selectDefaultTeacherVip(list);
|
|
|
+ const periodList = buildPeriodList(list);
|
|
|
const purchaseData = {
|
|
|
list,
|
|
|
- periodList: buildPeriodList(list),
|
|
|
+ periodList,
|
|
|
selectedPeriod: selected?.id ? String(selected.id) : '',
|
|
|
instrumentList: [],
|
|
|
isOverSaled: !list.some((item: any) => item.stockNum > 0),
|
|
|
@@ -581,19 +612,11 @@ Page({
|
|
|
},
|
|
|
/** 我的订单 */
|
|
|
onOrder() {
|
|
|
- // 判断是否登录
|
|
|
- if (!this.isLogin()) {
|
|
|
- return;
|
|
|
- }
|
|
|
wx.navigateTo({
|
|
|
url: "../orders/orders",
|
|
|
});
|
|
|
},
|
|
|
onBuyShop() {
|
|
|
- // 判断是否登录
|
|
|
- if (!this.isLogin()) {
|
|
|
- return;
|
|
|
- }
|
|
|
this.setData({
|
|
|
popupShow: true,
|
|
|
// showSelectedProduct: true,
|
|
|
@@ -629,6 +652,7 @@ Page({
|
|
|
this.setData({
|
|
|
selectedPeriod: String(value),
|
|
|
selected: selectedItem,
|
|
|
+ periodScrollIntoView: getPeriodScrollIntoView(this.data.periodList, String(value)),
|
|
|
showBonusGift: Boolean(formatGiftText(selectedItem))
|
|
|
}, () => {
|
|
|
// 根据选中的期限更新商品
|
|
|
@@ -676,9 +700,9 @@ Page({
|
|
|
// 判断是否登录
|
|
|
const that = this;
|
|
|
debounce(function () {
|
|
|
- if (!that.isLogin()) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ // if (!that.isLogin()) {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
const params = [] as any
|
|
|
const selected = that.data.selected
|
|
|
if (selected.id) {
|