| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004 |
- // index.ts
- import { api_queryByParamNameList, api_shopInstruments, api_shopProduct } from "../../api/login";
- import { api_getOpenId, api_trackPointLog } from "../../api/new";
- import { debounce, formatPrice, formatTime } from "../../utils/util";
- // 获取应用实例
- const app = getApp<IAppOption>();
- const PURCHASE_TYPE = {
- STUDENT: "WECHAT_MINI",
- TEACHER: "TEACHER_VIP",
- };
- const TEACHER_VIP_PARAM_NAME = "teacher_vip_purchase_list";
- const purchaseDataCache: any = {};
- let purchaseDataRequestId = 0;
- function getProductImage(item: any, userType: string) {
- if (!item) {
- return "";
- }
- if (userType === PURCHASE_TYPE.TEACHER) {
- return item.coverImg || item.pic || "";
- }
- return item.pic || item.coverImg || "";
- }
- function parseTeacherVipList(paramValue: any) {
- if (!paramValue) {
- return [];
- }
- const value = typeof paramValue === "string" ? JSON.parse(paramValue) : paramValue;
- if (Array.isArray(value)) {
- return value;
- }
- return value.list || value.goodsList || value.packages || [];
- }
- function formatPeriodText(num: any, type: string) {
- const unitText: any = {
- DAY: "天",
- MONTH: "个月",
- YEAR: "年",
- };
- if (!num || !type) {
- return "";
- }
- return `${num}${unitText[type] || ""}`;
- }
- function formatGiftText(item: any) {
- if (!item) {
- return "";
- }
- if (item.free?.number && item.free?.unit) {
- return formatPeriodText(item.free.number, item.free.unit);
- }
- if (item.giftFlag && item.giftVipDay && item.giftPeriod) {
- return formatPeriodText(item.giftVipDay, item.giftPeriod);
- }
- return "";
- }
- function buildPeriodList(list: 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 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[]) {
- 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({
- /**
- * 页面的初始数据
- */
- data: {
- imgList: [
- // 'https://oss.dayaedu.com/ktyq/1732585725698.png',
- // 'https://oss.dayaedu.com/ktyq/1732519468124.png',
- // 'https://oss.dayaedu.com/ktyq/1732519479416.png',
- // 'https://oss.dayaedu.com/ktyq/1733110029242.png',
- // 'https://oss.dayaedu.com/ktyq/1732519500580.png'
- "https://oss.dayaedu.com/ktyq/1733449062928.png",
- "https://oss.dayaedu.com/ktyq/1733449075055.png",
- "https://oss.dayaedu.com/ktyq/1733449085983.png",
- "https://oss.dayaedu.com/ktyq/1733449097054.png",
- ],
- goodsImgList: [
- "https://oss.dayaedu.com/ktyq/1739353790443.png",
- "https://oss.dayaedu.com/ktyq/1739353815962.png",
- "https://oss.dayaedu.com/ktyq/1739353843494.png",
- "https://oss.dayaedu.com/ktyq/03/1772550951364.png",
- ],
- detailImgList: [
- {
- url: "https://oss.dayaedu.com/ktyq/1733403675345.png",
- text: "合作学校音乐数字课堂公开课",
- },
- {
- url: "https://oss.dayaedu.com/ktyq/1733403707851.png",
- text: "音乐课课堂器乐教学",
- },
- {
- url: "https://oss.dayaedu.com/ktyq/1733403725644.png",
- text: "学期末汇报演出",
- },
- ],
- serviceShow: true,
- scrollTop: 0,
- current: 0,
- detailCurrent: 0,
- autoplay: false,
- interval: 5000,
- duration: 500,
- popupShow: false,
- videoHeight: "255px",
- list: [] as any,
- instrumentList: [] as any,
- isOverSaled: false, // 是否所有商品都没有库存
- selected: {} as any,
- selectInstrumentId: '', // 选中的乐器
- selectedInstrument: {} as any,
- formatSelectGood: {
- typeName: '',
- name: '',
- productImage: '',
- giftText: '',
- showSalePrice: '', // 显示的现价
- originalPrice: 0, // 原价
- salePrice: 0, // 现价
- discountPrice: '' // 已省
- } as any, // 格式化所有选中的数据
- opacity: 0,
- // showSelectedProduct: false, // 是否显示选中商品值
- scrolIntoViewStr: "",
- scrolIntoView: "",
- scrollDiscount: false, // 是否扣减启
- isScrollTT: false,
- scrollIntoViewType: false,
- headerHeight: 0, // 头部的高度
- initialScrollHeight: 0, // 滚动高度
- isFromPreviewImage: false,
- bannerPlay: false, // 视频是否播放
- titleControls: false, // 详情是否显示控制条
- liuControls: false, // 详情是否显示控制条
- bannerImageloaded: false, // Banner 图片是否加载完成
- userTypes: PURCHASE_TYPE.STUDENT, // 用户类型:WECHAT_MINI | TEACHER_VIP
- periodList: [] as any,
- selectedPeriod: '', // 选中的期限
- periodScrollIntoView: '',
- showBonusGift: false, // 是否显示额外赠送
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad() {
- // this.onInit()
- const wxWindowInfo = wx.getWindowInfo();
- this.setData({
- videoHeight: (wxWindowInfo.windowWidth / 16) * 9 + "px",
- });
- // 首页进入页面埋点
- this.onHomePageTrackPoint()
- },
- onHomePageTrackPoint() {
- // openId
- const openId = wx.getStorageSync("openId")
- if(openId) {
- this.onTrackPoint({
- openId,
- elementName: '首页'
- })
- } else {
- wx.login({
- success: async (res) => {
- await api_getOpenId({
- code: res.code,
- appId: app.globalData.appId
- }).then((res: any) => {
- // 存储 openId
- const openId = res.data.data
- wx.setStorageSync("openId", openId);
- this.onTrackPoint({
- openId,
- elementName: '首页'
- })
- })
- }
- })
- }
- },
- onReady() {
- const that = this;
- wx.createSelectorQuery()
- .select("#scroll-header")
- .boundingClientRect(function (rect) {
- that.setData({
- headerHeight: rect.height,
- });
- })
- .exec();
- wx.createSelectorQuery()
- .select("#scroll-view")
- .boundingClientRect(function (rect) {
- // console.log(rect, 'rect')
- that.setData({
- initialScrollHeight: rect.height,
- });
- })
- .exec();
- },
- onBannerVideoLoad() {
- this.setData({
- bannerImageloaded: true,
- });
- },
- onBannerPlay() {
- const bannerVideo = wx.createVideoContext("bannerVideo");
- const titleVideo = wx.createVideoContext("titleVideo");
- //
- this.setData(
- {
- bannerPlay: true,
- },
- () => {
- bannerVideo.play();
- titleVideo.pause();
- // liuVideo.stop()
- }
- );
- },
- onBannerVideoPlay() {
- const titleVideo = wx.createVideoContext("titleVideo");
- titleVideo.pause();
- // const liuVideo = wx.createVideoContext('liuVideo')
- // liuVideo.stop()
- },
- onTitlePlay() {
- const bannerVideo = wx.createVideoContext("bannerVideo");
- bannerVideo.pause();
- // const liuVideo = wx.createVideoContext('liuVideo')
- // liuVideo.stop()
- },
- onTItleVideoPlay() {
- const bannerVideo = wx.createVideoContext("bannerVideo");
- const titleVideo = wx.createVideoContext("titleVideo");
- // const liuVideo = wx.createVideoContext('liuVideo')
- this.setData(
- {
- titleControls: true,
- },
- () => {
- titleVideo.play();
- bannerVideo.pause();
- // liuVideo.stop()
- }
- );
- },
- onLiuPlay() {
- const bannerVideo = wx.createVideoContext("bannerVideo");
- bannerVideo.pause();
- const titleVideo = wx.createVideoContext("titleVideo");
- titleVideo.pause();
- },
- onLiuVideoPlay() {
- const bannerVideo = wx.createVideoContext("bannerVideo");
- const titleVideo = wx.createVideoContext("titleVideo");
- // const liuVideo = wx.createVideoContext('liuVideo')
- bannerVideo.pause();
- titleVideo.pause();
- this.setData(
- {
- liuControls: true,
- },
- () => {
- // liuVideo.play()
- }
- );
- },
- /**
- * 获取基础信息
- */
- async onInit() {
- const userType = this.data.userTypes;
- const requestId = ++purchaseDataRequestId;
- if (purchaseDataCache[userType]) {
- this.applyPurchaseData(purchaseDataCache[userType]);
- return
- }
- if (userType === PURCHASE_TYPE.TEACHER) {
- await this.onInitTeacherVip(requestId)
- return
- }
- try {
- const result = await api_shopInstruments({ appId: app.globalData.appId })
- const instrumentList = result.data.data || []
- instrumentList.forEach((item: any) => {
- item.showSalePrice = formatPrice(item.salePrice || 0, 'ALL')
- item.showOriginalPrice = formatPrice(item.originalPrice || 0, 'ALL')
- })
- const { data } = await api_shopProduct({ appId: app.globalData.appId });
- const list = data.data || [];
- let selected: any = {};
- let isOverSaled = true; // 是否销售完
- list.forEach((item: any) => {
- const salePrice = Number(item.salePrice || 0);
- const originalPrice = Number(item.originalPrice || salePrice);
- item.originalPrice = originalPrice;
- item.salePrice = salePrice;
- item.showSalePrice = formatPrice(salePrice, "ALL");
- item.showOriginalPrice = formatPrice(originalPrice, "ALL");
- item.typeName = this.formatPeriod(Number(item.num), item.period);
- item.discountPrice = formatPrice(
- originalPrice - salePrice,
- "ALL"
- );
- const prices: any = formatPrice(salePrice);
- item.integerPart = prices.integerPart;
- item.decimalPart = prices.decimalPart;
- // 格式化赠送内容
- item.giftLongTime = item.giftFlag
- ? this.formatGiftPeriod(item.giftVipDay, item.giftPeriod)
- : "";
- if (item.stockNum > 0) {
- isOverSaled = false;
- if (!selected.id) {
- selected = item;
- }
- }
- });
- if (isOverSaled) {
- // 没有可销售商品则默认选中第一个商品
- selected = list[0];
- }
- const purchaseData = {
- list,
- periodList: buildPeriodList(list),
- selectedPeriod: selected?.id ? String(selected.id) : '',
- instrumentList, // 乐器列表
- isOverSaled,
- selected,
- selectInstrumentId: '',
- selectedInstrument: {},
- showBonusGift: Boolean(formatGiftText(selected))
- };
- purchaseDataCache[userType] = purchaseData;
- if (requestId !== purchaseDataRequestId || this.data.userTypes !== userType) {
- return;
- }
- this.applyPurchaseData(purchaseData);
- } catch (e) {
- console.log(e, "e");
- }
- },
- // 格式化类型
- applyPurchaseData(purchaseData: any) {
- const periodList = markPeriodListActive(
- purchaseData.periodList,
- purchaseData.selectedPeriod
- );
- const periodScrollIntoView = getPeriodScrollIntoView(
- periodList,
- purchaseData.selectedPeriod
- );
- this.setData({
- list: purchaseData.list,
- periodList,
- selectedPeriod: purchaseData.selectedPeriod,
- periodScrollIntoView,
- instrumentList: purchaseData.instrumentList,
- isOverSaled: purchaseData.isOverSaled,
- selected: purchaseData.selected,
- selectInstrumentId: purchaseData.selectInstrumentId,
- selectedInstrument: purchaseData.selectedInstrument,
- showBonusGift: purchaseData.showBonusGift
- }, () => {
- this.onFormatGoods()
- });
- },
- async onInitTeacherVip(requestId: number) {
- const userType = PURCHASE_TYPE.TEACHER;
- try {
- const { data } = await api_queryByParamNameList({
- paramNames: TEACHER_VIP_PARAM_NAME
- });
- const configList = data.data || [];
- const config = Array.isArray(configList)
- ? configList.find((item: any) => item.paramName === TEACHER_VIP_PARAM_NAME) || configList[0]
- : configList;
- const list = parseTeacherVipList(config?.paramValue).map((item: any, index: number) => {
- const salePrice = Number(item.salePrice ?? item.currentPrice ?? item.price ?? item.paymentCashAmount ?? 0);
- const originalPrice = Number(item.originalPrice ?? item.marketPrice ?? item.originalAmount ?? salePrice);
- const period = item.period || item.unit;
- const num = item.num ?? item.number;
- const typeName = item.typeName || item.label || item.title || item.name || formatPeriodText(num, period);
- const prices: any = formatPrice(salePrice);
- return {
- ...item,
- id: item.id || item.goodsId || item.value || `${TEACHER_VIP_PARAM_NAME}_${index}`,
- name: item.name || item.title || typeName,
- pic: item.pic || item.coverImg || "",
- coverImg: item.coverImg || item.pic || "",
- shopId: item.shopId || "",
- stockNum: item.stockNum ?? 999999,
- originalPrice,
- salePrice,
- num,
- period,
- showSalePrice: formatPrice(salePrice, "ALL"),
- showOriginalPrice: formatPrice(originalPrice, "ALL"),
- discountPrice: formatPrice(originalPrice - salePrice, "ALL"),
- typeName,
- giftFlag: Boolean(item.free || item.giftFlag),
- giftVipDay: item.free?.number ?? item.giftVipDay,
- giftPeriod: item.free?.unit ?? item.giftPeriod,
- integerPart: prices.integerPart,
- decimalPart: prices.decimalPart,
- goodsType: item.goodsType || PURCHASE_TYPE.TEACHER,
- };
- });
- const selected = selectDefaultTeacherVip(list);
- const periodList = buildPeriodList(list);
- const purchaseData = {
- list,
- periodList,
- selectedPeriod: selected?.id ? String(selected.id) : '',
- instrumentList: [],
- isOverSaled: !list.some((item: any) => item.stockNum > 0),
- selected,
- selectInstrumentId: '',
- selectedInstrument: {},
- showBonusGift: Boolean(formatGiftText(selected))
- };
- purchaseDataCache[userType] = purchaseData;
- if (requestId !== purchaseDataRequestId || this.data.userTypes !== userType) {
- return;
- }
- this.applyPurchaseData(purchaseData);
- } catch (e) {
- console.log(e, "e");
- if (requestId !== purchaseDataRequestId || this.data.userTypes !== userType) {
- return;
- }
- this.setData({
- list: [],
- instrumentList: [],
- isOverSaled: true,
- selected: {},
- selectInstrumentId: '',
- selectedInstrument: {},
- showBonusGift: false
- }, () => {
- this.onFormatGoods()
- });
- }
- },
- formatPeriod(num: number, type: string) {
- const template: any = {
- DAY: "天卡",
- MONTH: "月卡",
- YEAR: "年卡",
- };
- if (type === "YEAR" && num >= 99) {
- return "永久卡";
- }
- return num + template[type];
- },
- formatGiftPeriod(num: number, type: string) {
- if (!num || !type) {
- return "";
- }
- const template: any = {
- DAY: "天",
- MONTH: "个月",
- YEAR: "年",
- };
- return num + template[type];
- },
- // 选择
- onSelectGoods(e: any) {
- const { dataset } = e.currentTarget;
- const item = this.data.list.find((item: any) => item.id === dataset.id);
- // 判断是否有库存
- if (item.stockNum <= 0) {
- return;
- }
- this.setData({
- selected: item || {}
- }, () => {
- this.onFormatGoods()
- });
- },
- /** 选中乐器 */
- onSelectInstrument(e: any) {
- if (this.data.userTypes === PURCHASE_TYPE.TEACHER) {
- return
- }
- const { dataset } = e.currentTarget;
- if (dataset.id === this.data.selectInstrumentId) {
- this.setData({
- selectInstrumentId: '',
- selectedInstrument: {}
- }, () => {
- this.onFormatGoods()
- })
- } else {
- const item = this.data.instrumentList.find((item: any) => item.id === dataset.id);
- this.setData({
- selectInstrumentId: dataset.id,
- selectedInstrument: item || {}
- }, () => {
- this.onFormatGoods()
- })
- }
- },
- /** 格式化选中的商品 */
- onFormatGoods() {
- const selected = this.data.selected;
- const selectedInstrument = this.data.selectedInstrument
- const params: any = {
- typeName: '',
- name: '',
- productImage: '',
- giftText: '',
- showSalePrice: '' as any, // 显示的现价
- originalPrice: 0, // 原价
- salePrice: 0, // 现价
- discountPrice: '' as any, // 已省
- integerPart: '',
- decimalPart: '',
- }
- // 选中期限
- if (selected.id) {
- params.typeName = selected.typeName
- params.name = selected.name
- params.productImage = getProductImage(selected, this.data.userTypes)
- params.giftText = formatGiftText(selected)
- params.showSalePrice = selected.showSalePrice
- params.originalPrice = selected.originalPrice
- params.salePrice = selected.salePrice
- params.discountPrice = selected.discountPrice
- const prices: any = formatPrice(params.salePrice);
- params.integerPart = prices.integerPart
- params.decimalPart = prices.decimalPart
- }
- // 选中乐器
- if (selectedInstrument.id) {
- params.typeName = selected.typeName ? selected.typeName + '+' + selectedInstrument.name : selectedInstrument.name
- params.name = selected.name ? selected.name + '+' + selectedInstrument.name : selectedInstrument.name
- params.originalPrice = Number(selected.originalPrice) + Number(selectedInstrument.originalPrice)
- params.salePrice = Number(selected.salePrice) + Number(selectedInstrument.salePrice)
- params.showSalePrice = formatPrice(params.salePrice, "ALL");
- params.discountPrice = formatPrice(
- params.originalPrice - params.salePrice,
- "ALL"
- );
- const prices: any = formatPrice(params.salePrice);
- params.integerPart = prices.integerPart
- params.decimalPart = prices.decimalPart
- }
- this.setData({
- formatSelectGood: params
- })
- },
- // 事件处理函数
- changeSwiper(e: any) {
- const detail = e.detail;
- if (detail.source === "touch" || detail.source == "autoplay") {
- this.setData({
- current: detail.current,
- });
- this.onTitlePlay();
- }
- },
- changeSwiperDetail(e: any) {
- const detail = e.detail;
- if (detail.source === "touch" || detail.source == "autoplay") {
- this.setData({
- detailCurrent: detail.current,
- });
- }
- },
- isLogin() {
- // 判断是否登录
- if (!app.globalData.isLogin) {
- wx.navigateTo({
- url: "../login/login",
- });
- return false;
- }
- return true;
- },
- /** 我的订单 */
- onOrder() {
- wx.navigateTo({
- url: "../orders/orders",
- });
- },
- onBuyShop() {
- this.setData({
- popupShow: true,
- // showSelectedProduct: true,
- });
- },
- /** 切换学生端/老师端 */
- onSwitchUserType(e: any) {
- const { dataset } = e.currentTarget;
- if (dataset.type === this.data.userTypes) {
- return
- }
- this.setData({
- 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 扩展
- this.onInit()
- })
- },
- /** 选择期限 */
- onSelectPeriod(e: any) {
- const { value } = e.currentTarget.dataset
- const periodItem = this.data.periodList.find((item: any) => String(item.value) === String(value))
- if (periodItem?.disabled) {
- wx.showToast({
- title: '暂无库存',
- icon: 'none',
- });
- return
- }
- const selectedItem = this.data.list.find((item: any) => String(item.id) === String(value))
- if (!selectedItem) {
- return
- }
- const selectedPeriod = String(value);
- const periodList = markPeriodListActive(this.data.periodList, selectedPeriod);
- this.setData({
- periodList,
- selectedPeriod,
- selected: selectedItem,
- periodScrollIntoView: getPeriodScrollIntoView(periodList, selectedPeriod),
- showBonusGift: Boolean(formatGiftText(selectedItem))
- }, () => {
- // 根据选中的期限更新商品
- this.onFormatGoods()
- })
- syncPurchaseDataCache(this.data.userTypes, {
- periodList,
- selectedPeriod,
- selected: selectedItem,
- selectInstrumentId: this.data.selectInstrumentId,
- selectedInstrument: this.data.selectedInstrument,
- showBonusGift: Boolean(formatGiftText(selectedItem))
- });
- },
- /** 根据期限更新商品列表 */
- onUpdatePeriodList() {
- if (this.data.userTypes === PURCHASE_TYPE.TEACHER) {
- return
- }
- const { selectedPeriod, list } = this.data
- const selectedItem = list.find((item: any) => String(item.id) === String(selectedPeriod))
- if (!selectedItem || Number(selectedItem.stockNum ?? 1) <= 0) {
- return
- }
- this.setData({
- selected: selectedItem,
- showBonusGift: Boolean(formatGiftText(selectedItem))
- }, () => {
- this.onFormatGoods()
- })
- },
- // 进行埋点
- onTrackPoint(options: { openId: string, elementName: string }) {
- const traceId = wx.getStorageSync("traceId");
- const deviceInfo = wx.getDeviceInfo();
- api_trackPointLog({
- traceId,
- openId: options.openId,
- elementName: options.elementName,
- deviceInfo: deviceInfo.brand + '_' + deviceInfo.model + '_' + deviceInfo.system + '_' + deviceInfo.platform,
- appName: "音乐数字 AI",
- // extParams: '',
- clickTime: formatTime(new Date(), '-') // 点击时间
- })
- },
- onClose() {
- this.setData({
- popupShow: false,
- });
- },
- onSubmit() {
- // 判断是否登录
- const that = this;
- debounce(function () {
- // if (!that.isLogin()) {
- // return;
- // }
- const params = [] as any
- const selected = that.data.selected
- if (selected.id) {
- params.push({
- pic: selected.pic,
- name: selected.name,
- originalPrice: selected.originalPrice,
- salePrice: selected.salePrice,
- shopId: selected.shopId,
- id: selected.id,
- goodsType: selected.goodsType || 'ACTIVATION_CODE', // INSTRUMENTS
- })
- }
- const selectedInstrument = that.data.selectedInstrument
- if (selectedInstrument.id) {
- params.push({
- pic: selectedInstrument.pic,
- name: selectedInstrument.name,
- originalPrice: selectedInstrument.originalPrice,
- salePrice: selectedInstrument.salePrice,
- shopId: selectedInstrument.shopId,
- id: selectedInstrument.id,
- goodsType: 'INSTRUMENTS', // INSTRUMENTS
- })
- }
- // openId
- const openId = wx.getStorageSync("openId")
- that.onTrackPoint({
- openId,
- elementName: "立即购买"
- })
- let info = JSON.stringify({
- ...params
- });
- info = encodeURIComponent(info);
- wx.navigateTo({
- url: `../orders/order-detail?orderInfo=${info}&orderType=${that.data.userTypes}`,
- success: () => {
- that.setData({
- popupShow: false,
- });
- },
- });
- }, 200)();
- },
- onPreivewBannerImg(e: { currentTarget: { dataset: any } }) {
- wx.previewImage({
- current: e.currentTarget.dataset.src,
- urls: this.data.imgList,
- success: () => {
- this.setData({
- isFromPreviewImage: true,
- });
- },
- });
- },
- onPreivewDetailImg(e: { currentTarget: { dataset: any } }) {
- wx.previewImage({
- current: e.currentTarget.dataset.src,
- urls: [
- "https://oss.dayaedu.com/ktyq/1733403675345.png",
- "https://oss.dayaedu.com/ktyq/1733403707851.png",
- "https://oss.dayaedu.com/ktyq/1733403725644.png",
- ],
- success: () => {
- this.setData({
- isFromPreviewImage: true,
- });
- },
- });
- },
- onPreivewDetailImg2(e: { currentTarget: { dataset: any } }) {
- wx.previewImage({
- current: e.currentTarget.dataset.src,
- urls: [
- "https://oss.dayaedu.com/ktyq/03/1772461866051.png",
- ],
- success: () => {
- this.setData({
- isFromPreviewImage: true,
- });
- },
- });
- },
- onPreivewGoodsImg(e: { currentTarget: { dataset: any } }) {
- wx.previewImage({
- current: e.currentTarget.dataset.src,
- urls: this.data.goodsImgList,
- success: () => {
- this.setData({
- isFromPreviewImage: true,
- });
- },
- });
- },
- onPreivewGoods(e: { currentTarget: { dataset: any } }) {
- wx.previewImage({
- current: e.currentTarget.dataset.src,
- urls: [e.currentTarget.dataset.src],
- success: () => {
- this.setData({
- isFromPreviewImage: true,
- });
- },
- });
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- if (!this.data.isFromPreviewImage) {
- this.onInit();
- } else {
- this.setData({
- isFromPreviewImage: false,
- });
- }
- this.setData({
- serviceShow: true,
- });
- },
- onHide() {
- this.setData({
- serviceShow: false,
- });
- },
- // 页面滚动时颜色变化
- onScrollView(e: { detail: any }) {
- const top = e.detail.scrollTop || 0;
- // const scrollHeight = e.detail.scrollHeight || 0;
- // 从 100 开始显示
- this.setData({
- // opacity: top < 100 ? 0 : (top - 100) > 150 ? 1 : (top - 100) / 150
- opacity: top < 100 ? 0 : top - 100 > 150 ? 1 : 1,
- });
- // if (top + this.data.initialScrollHeight >= scrollHeight - 80) {
- // // console.log('已经滑动到底部了');
- // // 相应业务逻辑处理
- // this.setData({
- // scrolIntoViewStr: "type2",
- // });
- // } else {
- // console.log(this.data.scrollDiscount, top, this.data.headerHeight, "top");
- if (this.data.scrollIntoViewType) {
- this.setData({
- scrollTop: this.data.scrollDiscount
- ? top - this.data.headerHeight
- : top,
- scrollIntoViewType: false,
- scrollDiscount: false,
- isScrollTT: true,
- });
- } else {
- if (!this.data.isScrollTT) {
- this.onChangeScroll();
- } else {
- this.setData({
- isScrollTT: false,
- });
- }
- }
- // }
- },
- onChangeScroll() {
- const that = this;
- debounce(function () {
- wx.createSelectorQuery()
- .select("#type3")
- .boundingClientRect(function (rect) {
- let check = false;
- if (rect.top > 0 && rect.top <= that.data.headerHeight) {
- that.setData({
- scrolIntoViewStr: "type3",
- });
- check = true;
- }
- if (rect.top > 0 && rect.top > that.data.headerHeight) {
- that.setData({
- scrolIntoViewStr: "type1",
- });
- check = true;
- }
- // console.log('checked', check)
- if (!check) {
- wx.createSelectorQuery()
- .select("#type2")
- .boundingClientRect(function (rect) {
- if (rect.top > 0 && rect.top <= that.data.headerHeight) {
- that.setData({
- scrolIntoViewStr: "type2",
- });
- }
- if (rect.top > 0 && rect.top > that.data.headerHeight) {
- that.setData({
- scrolIntoViewStr: "type3",
- });
- }
- })
- .exec();
- }
- })
- .exec();
- }, 100)();
- },
- onTapAnchor(e: { currentTarget: { dataset: any } }) {
- const type = e.currentTarget.dataset.type;
- this.setData({
- scrolIntoView: type,
- scrolIntoViewStr: type,
- scrollDiscount: true, // type !== 'type2' ? true : false,
- scrollIntoViewType: true,
- });
- },
- onShareAppMessage() {
- return {
- title: "音乐数字 AI",
- path: "/pages/index/index",
- imageUrl: "https://oss.dayaedu.com/ktyq/1739870592907.png",
- };
- },
- onShareTimeline() {
- return {
- title: "音乐数字 AI",
- path: "/pages/index/index",
- imageUrl: "https://oss.dayaedu.com/ktyq/1739870592907.png",
- };
- },
- });
|