// pages/index/index.ts Page({ data: { appName: "", statusBarHeight: 0, navBarHeight: 44, searchValue: "", categories: [ { id: 1, name: "水果鲜花", icon: "🍎" }, { id: 2, name: "蔬菜豆制品", icon: "🥬" }, { id: 3, name: "肉禽蛋", icon: "🥩" }, { id: 4, name: "海鲜水产", icon: "🐟" }, { id: 5, name: "乳品烘焙", icon: "🥛" }, { id: 6, name: "熟食快", icon: "🍱" }, ], recommendTags: ["销量", "折扣", "价格"], activeTag: "荐 时令推荐", leftCategories: [ { id: 1, name: "鲜花/绿植", active: true }, { id: 2, name: "西梅/桃李枣", active: false }, { id: 3, name: "橘/柚/橙/柑", active: false }, { id: 4, name: "苹果/新梨/蕉", active: false }, { id: 5, name: "石榴/龙眼", active: false }, { id: 6, name: "西瓜/蜜瓜", active: false }, { id: 7, name: "严选", active: false }, { id: 8, name: "果切/小番茄", active: false }, { id: 9, name: "榴莲/热带果", active: false }, { id: 7, name: "严选", active: false }, { id: 8, name: "果切/小番茄", active: false }, { id: 9, name: "榴莲/热带果", active: false }, ], products: [ { id: 1, name: "【五彩心语】洋桔梗混色5枝", desc: "绚烂多姿 | 无刺玫瑰", tags: ["近90天最低价"], currentPrice: 7.96, originalPrice: 19.9, image: "/images/product1.jpg", badge: "出清价", }, { id: 2, name: "【节节高升】剑兰粉色 5枝", desc: "淡粉色颜值高 | 温柔浪漫", tags: ["近90天最低价"], currentPrice: 7.96, originalPrice: 19.9, image: "/images/product2.jpg", badge: "出清价", }, { id: 3, name: "时令【小玲珑】雏菊混搭花束", desc: "文艺装扮 | 玲珑可爱", tags: ["近30天最低价"], currentPrice: 3.95, originalPrice: 7.9, image: "/images/product3.jpg", badge: "出清价", }, { id: 4, name: "【清香宜人】茉莉花30枝", desc: "百个花头 | 芳香怡人", tags: ["近90天最低价"], currentPrice: 10.68, originalPrice: 17.8, image: "/images/product4.jpg", badge: "出清价", }, { id: 5, name: "时令【粉韵流光】粉色吸色牡丹菊 3枝", desc: "8cm大花头 | 菊花吸色工艺", tags: ["限时特价"], currentPrice: 15.8, originalPrice: 25.8, image: "/images/product5.jpg", badge: "秒杀", countdown: "01:18:44", }, ], }, onLoad() { const app = getApp(); this.setData({ appName: app.globalData.appName }); this.getSystemInfo(); }, getSystemInfo() { const systemInfo = wx.getSystemInfoSync(); this.setData({ statusBarHeight: systemInfo.statusBarHeight, }); }, onSearchInput(e: WechatMiniprogram.InputInput) { this.setData({ searchValue: e.detail.value, }); }, onSearch() { if (this.data.searchValue.trim()) { wx.showToast({ title: `搜索: ${this.data.searchValue}`, icon: "none", }); } }, onCategoryTap(e: WechatMiniprogram.TouchEvent) { const { index } = e.currentTarget.dataset; const categories = this.data.leftCategories.map((item, i) => ({ ...item, active: i === index, })); this.setData({ leftCategories: categories }); }, onTagTap(e: WechatMiniprogram.TouchEvent) { const { tag } = e.currentTarget.dataset; this.setData({ activeTag: tag }); }, onProductTap(e: WechatMiniprogram.TouchEvent) { const { id } = e.currentTarget.dataset; wx.navigateTo({ url: `/pages/product/detail?id=${id}`, }); }, onAddToCart(e: WechatMiniprogram.TouchEvent) { const { id } = e.currentTarget.dataset; wx.showToast({ title: "已加入购物车", icon: "success", }); }, }); interface PageData { statusBarHeight: number; navBarHeight: number; searchValue: string; categories: Category[]; recommendTags: string[]; activeTag: string; leftCategories: LeftCategory[]; products: Product[]; } interface Category { id: number; name: string; icon: string; } interface LeftCategory { id: number; name: string; active: boolean; } interface Product { id: number; name: string; desc: string; tags: string[]; currentPrice: number; originalPrice: number; image: string; badge: string; countdown?: string; } interface Coupon { title: string; status: string; expireTime: string; }