|
|
@@ -10,6 +10,7 @@ const PURCHASE_TYPE = {
|
|
|
TEACHER: "TEACHER_VIP",
|
|
|
};
|
|
|
const TEACHER_VIP_PARAM_NAME = "teacher_vip_purchase_list";
|
|
|
+const purchaseDataCache: any = {};
|
|
|
|
|
|
function getProductImage(item: any, userType: string) {
|
|
|
if (!item) {
|
|
|
@@ -280,7 +281,12 @@ Page({
|
|
|
* 获取基础信息
|
|
|
*/
|
|
|
async onInit() {
|
|
|
- if (this.data.userTypes === PURCHASE_TYPE.TEACHER) {
|
|
|
+ const userType = this.data.userTypes;
|
|
|
+ if (purchaseDataCache[userType]) {
|
|
|
+ this.applyPurchaseData(purchaseDataCache[userType]);
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (userType === PURCHASE_TYPE.TEACHER) {
|
|
|
await this.onInitTeacherVip()
|
|
|
return
|
|
|
}
|
|
|
@@ -327,7 +333,7 @@ Page({
|
|
|
selected = list[0];
|
|
|
}
|
|
|
|
|
|
- this.setData({
|
|
|
+ const purchaseData = {
|
|
|
list,
|
|
|
periodList: buildPeriodList(list),
|
|
|
selectedPeriod: selected?.id ? String(selected.id) : '',
|
|
|
@@ -337,14 +343,29 @@ Page({
|
|
|
selectInstrumentId: '',
|
|
|
selectedInstrument: {},
|
|
|
showBonusGift: Boolean(formatGiftText(selected))
|
|
|
- }, () => {
|
|
|
- this.onFormatGoods()
|
|
|
- });
|
|
|
+ };
|
|
|
+ purchaseDataCache[userType] = purchaseData;
|
|
|
+ this.applyPurchaseData(purchaseData);
|
|
|
} catch (e) {
|
|
|
console.log(e, "e");
|
|
|
}
|
|
|
},
|
|
|
// 格式化类型
|
|
|
+ applyPurchaseData(purchaseData: any) {
|
|
|
+ this.setData({
|
|
|
+ list: purchaseData.list,
|
|
|
+ periodList: purchaseData.periodList,
|
|
|
+ selectedPeriod: purchaseData.selectedPeriod,
|
|
|
+ instrumentList: purchaseData.instrumentList,
|
|
|
+ isOverSaled: purchaseData.isOverSaled,
|
|
|
+ selected: purchaseData.selected,
|
|
|
+ selectInstrumentId: purchaseData.selectInstrumentId,
|
|
|
+ selectedInstrument: purchaseData.selectedInstrument,
|
|
|
+ showBonusGift: purchaseData.showBonusGift
|
|
|
+ }, () => {
|
|
|
+ this.onFormatGoods()
|
|
|
+ });
|
|
|
+ },
|
|
|
async onInitTeacherVip() {
|
|
|
try {
|
|
|
const { data } = await api_queryByParamNameList({
|
|
|
@@ -389,7 +410,7 @@ Page({
|
|
|
|| list.find((item: any) => item.stockNum > 0)
|
|
|
|| list[0]
|
|
|
|| {};
|
|
|
- this.setData({
|
|
|
+ const purchaseData = {
|
|
|
list,
|
|
|
periodList: buildPeriodList(list),
|
|
|
selectedPeriod: selected?.id ? String(selected.id) : '',
|
|
|
@@ -399,9 +420,9 @@ Page({
|
|
|
selectInstrumentId: '',
|
|
|
selectedInstrument: {},
|
|
|
showBonusGift: Boolean(formatGiftText(selected))
|
|
|
- }, () => {
|
|
|
- this.onFormatGoods()
|
|
|
- });
|
|
|
+ };
|
|
|
+ purchaseDataCache[PURCHASE_TYPE.TEACHER] = purchaseData;
|
|
|
+ this.applyPurchaseData(purchaseData);
|
|
|
} catch (e) {
|
|
|
console.log(e, "e");
|
|
|
this.setData({
|
|
|
@@ -581,6 +602,9 @@ Page({
|
|
|
/** 切换学生端/老师端 */
|
|
|
onSwitchUserType(e: any) {
|
|
|
const { dataset } = e.currentTarget;
|
|
|
+ if (dataset.type === this.data.userTypes) {
|
|
|
+ return
|
|
|
+ }
|
|
|
this.setData({
|
|
|
userTypes: dataset.type
|
|
|
}, () => {
|