const Parse = getApp().Parse; const company = getApp().globalData.company; const getTabs = require("../../../utils/getTabs") const login = require("../../../utils/login"); const dateF = require("../../../utils/date") Page({ /** * 页面的初始数据 */ data: { }, /** * 生命周期函数--监听页面加载 */ onLoad: async function (options) { // login.loginNow() try { let finalStoreId = options && options.storeId ? options.storeId : ''; // 标记是否是扫码进入(有明确的 storeId 参数) const isFromScan = !!finalStoreId; // 支持从 scene 读取(小程序码 getwxacodeunlimit 传参) if (!finalStoreId && options && options.scene) { const sceneStr = decodeURIComponent(options.scene); console.log('🎯 scene 参数:', sceneStr); if (sceneStr) { const pairs = sceneStr.split('&'); for (const p of pairs) { const [k, v] = p.split('='); if (k === 'storeId' && v) { finalStoreId = v; break; } } } } if (finalStoreId) { // 扫码进入时,强制设置店铺 ID,不被历史记录覆盖 wx.setStorageSync('storeId', finalStoreId); getApp().globalData.storeId = finalStoreId; // 标记这是扫码进入的店铺,优先级最高 if (isFromScan) { wx.setStorageSync('storeId_from_scan', true); console.log('✅ 扫码进入,已设置店铺 ID(优先级最高):', finalStoreId); } else { console.log('✅ 已设置店铺 ID:', finalStoreId); } } else { // 没有传入 storeId,检查是否有扫码标记 const isFromScanBefore = wx.getStorageSync('storeId_from_scan'); if (!isFromScanBefore) { // 不是扫码进入,可以使用历史店铺 console.log('ℹ️ 未传入店铺 ID,使用历史店铺或默认值'); } else { // 之前是扫码进入的,保持扫码的店铺 console.log('ℹ️ 保持扫码进入的店铺 ID'); } } } catch (e) { console.error('设置店铺 ID 失败:', e); } // ✅ 立即加载并设置店铺名称作为页面标题 await this.loadAndSetStoreTitle() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { console.log('📌 引导页 onReady'); }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { wx.reLaunch({ url: '/index', }); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { let uid = Parse.User.current().id return { title: '分享', // path: `index?invite=${uid}`, path: `index`, imageUrl: '', } }, /** * 加载店铺信息并设置页面标题 */ loadAndSetStoreTitle: async function () { try { // 计算当前有效的店铺 ID const defaultStoreId = 'pkPdAnLAUZ'; // 超级门店ID const effectiveStoreId = wx.getStorageSync('storeId') || getApp().globalData.storeId || defaultStoreId; // 查询指定的店铺 const storeQuery = new Parse.Query('ShopStore'); storeQuery.equalTo('objectId', effectiveStoreId); const store = await storeQuery.first(); if (store) { // 优先使用门店地址,如果没有地址则使用门店名称 const storeAddress = store.get('address'); const storeName = store.get('storeName'); const title = storeAddress || storeName; if (title) { console.log('📍 门店信息:', { id: effectiveStoreId, name: storeName, address: storeAddress, displayTitle: title }); // 延迟设置标题,确保页面已完全加载 setTimeout(() => { wx.setNavigationBarTitle({ title: title, success: () => { console.log('✅ 引导页标题设置成功:', title); }, fail: (err) => { console.warn('⚠️ 引导页标题设置失败(可忽略):', err.errMsg); // 不影响主流程,静默失败 } }); }, 300); } } } catch (error) { console.error('❌ 加载店铺信息失败:', error); } } })