|
@@ -11,6 +11,7 @@ const PURCHASE_TYPE = {
|
|
|
};
|
|
};
|
|
|
const TEACHER_VIP_PARAM_NAME = "teacher_vip_purchase_list";
|
|
const TEACHER_VIP_PARAM_NAME = "teacher_vip_purchase_list";
|
|
|
const purchaseDataCache: any = {};
|
|
const purchaseDataCache: any = {};
|
|
|
|
|
+let purchaseDataRequestId = 0;
|
|
|
|
|
|
|
|
function getProductImage(item: any, userType: string) {
|
|
function getProductImage(item: any, userType: string) {
|
|
|
if (!item) {
|
|
if (!item) {
|
|
@@ -71,6 +72,23 @@ function getPeriodScrollIntoView(periodList: any[], selectedPeriod: string) {
|
|
|
return periodList.find((item: any) => String(item.value) === String(selectedPeriod))?.viewId || "";
|
|
return periodList.find((item: any) => String(item.value) === String(selectedPeriod))?.viewId || "";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function markPeriodListActive(periodList: any[], selectedPeriod: string) {
|
|
|
|
|
+ return periodList.map((item: any) => ({
|
|
|
|
|
+ ...item,
|
|
|
|
|
+ active: String(item.value) === String(selectedPeriod),
|
|
|
|
|
+ }));
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function syncPurchaseDataCache(userType: string, patch: any) {
|
|
|
|
|
+ if (!purchaseDataCache[userType]) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ purchaseDataCache[userType] = {
|
|
|
|
|
+ ...purchaseDataCache[userType],
|
|
|
|
|
+ ...patch,
|
|
|
|
|
+ };
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function selectDefaultTeacherVip(list: any[]) {
|
|
function selectDefaultTeacherVip(list: any[]) {
|
|
|
const saleableList = list.filter((item: any) => Number(item.stockNum ?? 1) > 0);
|
|
const saleableList = list.filter((item: any) => Number(item.stockNum ?? 1) > 0);
|
|
|
const candidates = saleableList.length ? saleableList : list;
|
|
const candidates = saleableList.length ? saleableList : list;
|
|
@@ -310,12 +328,13 @@ Page({
|
|
|
*/
|
|
*/
|
|
|
async onInit() {
|
|
async onInit() {
|
|
|
const userType = this.data.userTypes;
|
|
const userType = this.data.userTypes;
|
|
|
|
|
+ const requestId = ++purchaseDataRequestId;
|
|
|
if (purchaseDataCache[userType]) {
|
|
if (purchaseDataCache[userType]) {
|
|
|
this.applyPurchaseData(purchaseDataCache[userType]);
|
|
this.applyPurchaseData(purchaseDataCache[userType]);
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
if (userType === PURCHASE_TYPE.TEACHER) {
|
|
if (userType === PURCHASE_TYPE.TEACHER) {
|
|
|
- await this.onInitTeacherVip()
|
|
|
|
|
|
|
+ await this.onInitTeacherVip(requestId)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
@@ -373,6 +392,9 @@ Page({
|
|
|
showBonusGift: Boolean(formatGiftText(selected))
|
|
showBonusGift: Boolean(formatGiftText(selected))
|
|
|
};
|
|
};
|
|
|
purchaseDataCache[userType] = purchaseData;
|
|
purchaseDataCache[userType] = purchaseData;
|
|
|
|
|
+ if (requestId !== purchaseDataRequestId || this.data.userTypes !== userType) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
this.applyPurchaseData(purchaseData);
|
|
this.applyPurchaseData(purchaseData);
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
console.log(e, "e");
|
|
console.log(e, "e");
|
|
@@ -380,13 +402,17 @@ Page({
|
|
|
},
|
|
},
|
|
|
// 格式化类型
|
|
// 格式化类型
|
|
|
applyPurchaseData(purchaseData: any) {
|
|
applyPurchaseData(purchaseData: any) {
|
|
|
- const periodScrollIntoView = getPeriodScrollIntoView(
|
|
|
|
|
|
|
+ const periodList = markPeriodListActive(
|
|
|
purchaseData.periodList,
|
|
purchaseData.periodList,
|
|
|
purchaseData.selectedPeriod
|
|
purchaseData.selectedPeriod
|
|
|
);
|
|
);
|
|
|
|
|
+ const periodScrollIntoView = getPeriodScrollIntoView(
|
|
|
|
|
+ periodList,
|
|
|
|
|
+ purchaseData.selectedPeriod
|
|
|
|
|
+ );
|
|
|
this.setData({
|
|
this.setData({
|
|
|
list: purchaseData.list,
|
|
list: purchaseData.list,
|
|
|
- periodList: purchaseData.periodList,
|
|
|
|
|
|
|
+ periodList,
|
|
|
selectedPeriod: purchaseData.selectedPeriod,
|
|
selectedPeriod: purchaseData.selectedPeriod,
|
|
|
periodScrollIntoView,
|
|
periodScrollIntoView,
|
|
|
instrumentList: purchaseData.instrumentList,
|
|
instrumentList: purchaseData.instrumentList,
|
|
@@ -399,7 +425,8 @@ Page({
|
|
|
this.onFormatGoods()
|
|
this.onFormatGoods()
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
- async onInitTeacherVip() {
|
|
|
|
|
|
|
+ async onInitTeacherVip(requestId: number) {
|
|
|
|
|
+ const userType = PURCHASE_TYPE.TEACHER;
|
|
|
try {
|
|
try {
|
|
|
const { data } = await api_queryByParamNameList({
|
|
const { data } = await api_queryByParamNameList({
|
|
|
paramNames: TEACHER_VIP_PARAM_NAME
|
|
paramNames: TEACHER_VIP_PARAM_NAME
|
|
@@ -452,10 +479,16 @@ Page({
|
|
|
selectedInstrument: {},
|
|
selectedInstrument: {},
|
|
|
showBonusGift: Boolean(formatGiftText(selected))
|
|
showBonusGift: Boolean(formatGiftText(selected))
|
|
|
};
|
|
};
|
|
|
- purchaseDataCache[PURCHASE_TYPE.TEACHER] = purchaseData;
|
|
|
|
|
|
|
+ purchaseDataCache[userType] = purchaseData;
|
|
|
|
|
+ if (requestId !== purchaseDataRequestId || this.data.userTypes !== userType) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
this.applyPurchaseData(purchaseData);
|
|
this.applyPurchaseData(purchaseData);
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
console.log(e, "e");
|
|
console.log(e, "e");
|
|
|
|
|
+ if (requestId !== purchaseDataRequestId || this.data.userTypes !== userType) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
this.setData({
|
|
this.setData({
|
|
|
list: [],
|
|
list: [],
|
|
|
instrumentList: [],
|
|
instrumentList: [],
|
|
@@ -629,7 +662,28 @@ Page({
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
this.setData({
|
|
this.setData({
|
|
|
- userTypes: dataset.type
|
|
|
|
|
|
|
+ userTypes: dataset.type,
|
|
|
|
|
+ list: [],
|
|
|
|
|
+ periodList: [],
|
|
|
|
|
+ selectedPeriod: '',
|
|
|
|
|
+ periodScrollIntoView: '',
|
|
|
|
|
+ instrumentList: [],
|
|
|
|
|
+ selected: {},
|
|
|
|
|
+ selectInstrumentId: '',
|
|
|
|
|
+ selectedInstrument: {},
|
|
|
|
|
+ showBonusGift: false,
|
|
|
|
|
+ formatSelectGood: {
|
|
|
|
|
+ typeName: '',
|
|
|
|
|
+ name: '',
|
|
|
|
|
+ productImage: '',
|
|
|
|
|
+ giftText: '',
|
|
|
|
|
+ showSalePrice: '',
|
|
|
|
|
+ originalPrice: 0,
|
|
|
|
|
+ salePrice: 0,
|
|
|
|
|
+ discountPrice: '',
|
|
|
|
|
+ integerPart: '',
|
|
|
|
|
+ decimalPart: '',
|
|
|
|
|
+ }
|
|
|
}, () => {
|
|
}, () => {
|
|
|
// 这里可以根据用户类型重新加载商品数据
|
|
// 这里可以根据用户类型重新加载商品数据
|
|
|
// 目前先保持逻辑不变,后续可根据后端 API 扩展
|
|
// 目前先保持逻辑不变,后续可根据后端 API 扩展
|
|
@@ -639,8 +693,12 @@ Page({
|
|
|
/** 选择期限 */
|
|
/** 选择期限 */
|
|
|
onSelectPeriod(e: any) {
|
|
onSelectPeriod(e: any) {
|
|
|
const { value } = e.currentTarget.dataset
|
|
const { value } = e.currentTarget.dataset
|
|
|
- const periodItem = this.data.periodList.find((item: any) => item.value === value)
|
|
|
|
|
|
|
+ const periodItem = this.data.periodList.find((item: any) => String(item.value) === String(value))
|
|
|
if (periodItem?.disabled) {
|
|
if (periodItem?.disabled) {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '暂无库存',
|
|
|
|
|
+ icon: 'none',
|
|
|
|
|
+ });
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -649,15 +707,26 @@ Page({
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const selectedPeriod = String(value);
|
|
|
|
|
+ const periodList = markPeriodListActive(this.data.periodList, selectedPeriod);
|
|
|
this.setData({
|
|
this.setData({
|
|
|
- selectedPeriod: String(value),
|
|
|
|
|
|
|
+ periodList,
|
|
|
|
|
+ selectedPeriod,
|
|
|
selected: selectedItem,
|
|
selected: selectedItem,
|
|
|
- periodScrollIntoView: getPeriodScrollIntoView(this.data.periodList, String(value)),
|
|
|
|
|
|
|
+ periodScrollIntoView: getPeriodScrollIntoView(periodList, selectedPeriod),
|
|
|
showBonusGift: Boolean(formatGiftText(selectedItem))
|
|
showBonusGift: Boolean(formatGiftText(selectedItem))
|
|
|
}, () => {
|
|
}, () => {
|
|
|
// 根据选中的期限更新商品
|
|
// 根据选中的期限更新商品
|
|
|
this.onFormatGoods()
|
|
this.onFormatGoods()
|
|
|
})
|
|
})
|
|
|
|
|
+ syncPurchaseDataCache(this.data.userTypes, {
|
|
|
|
|
+ periodList,
|
|
|
|
|
+ selectedPeriod,
|
|
|
|
|
+ selected: selectedItem,
|
|
|
|
|
+ selectInstrumentId: this.data.selectInstrumentId,
|
|
|
|
|
+ selectedInstrument: this.data.selectedInstrument,
|
|
|
|
|
+ showBonusGift: Boolean(formatGiftText(selectedItem))
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
/** 根据期限更新商品列表 */
|
|
/** 根据期限更新商品列表 */
|
|
|
onUpdatePeriodList() {
|
|
onUpdatePeriodList() {
|