import { useState } from "react"; import { View, Text, Image, Button, Input } from "@tarojs/components"; import Taro from "@tarojs/taro"; import type { TemplateProps } from "../../../apps/taro/src/runtime/template"; import { navigate } from "../../../apps/taro/src/runtime/navigation"; import { presentation, offering, slot, text, rows } from "../../../apps/taro/src/runtime/content"; import type { RuntimeWorkspace } from "@personal-brand/types"; import "./style.css"; const asset = (name: string) => `/assets/${PREVIEW_ALL_TEMPLATES ? "acheng-campus-food/" : ""}${name}`; function Home({ workspace }: { workspace: RuntimeWorkspace }) { const brand = workspace.brand; const p = presentation(workspace, "home"); const list = workspace.offerings.map(offering).slice(0, 2); return ( {text(brand.avatarUrl) && } {text(brand.founder)} {text(brand.title)} “{text(brand.description)}” {p.stallTitle || "服务地点"} {text(brand.address)} {p.stallTime && {p.stallTime}} {text(brand.name)} {text(brand.heroImage) && ( navigate("service")} /> )} {p.worksEyebrow || "餐品与服务"} {p.worksTitle || "可选餐品"} navigate("offerings")}> {p.moreAction || "查看全部"} › {list.map((item) => ( navigate("detail", { id: item.id })} > {item.name} {item.desc} {item.priceRange} ))} {p.manifestoTitle} {workspace.trustItems .filter((item) => ["promise", "case"].includes(item.type)) .map((item) => ( {item.title} {item.summary && {item.summary}} {item.content} ))} ); } function Service({ workspace }: { workspace: RuntimeWorkspace }) { const schedule = slot(workspace, "schedule"); const c = slot(workspace, "coverage"); const process = slot(workspace, "process"); const p = presentation(workspace, "service"); const config = schedule?.config || {}; const scheduleRows = [ { title: text(config.weekdayLabel), detail: text(config.weekdayDetail), hours: text(config.weekdayHours), tag: text(config.weekdayTag), tone: "orange", }, { title: text(config.weekendLabel), detail: text(config.weekendDetail), hours: text(config.weekendHours), tag: text(config.weekendTag), tone: "blue", }, ].filter((row) => row.title && row.detail); const steps = rows(process?.config.steps).filter((step) => step.title && step.detail); return ( {schedule && scheduleRows.length > 0 && ( {schedule.title} {text(config.status) && {text(config.status)}} {scheduleRows.map((row) => ( {row.title} {row.tag && ( {row.tag} )} {row.detail} {row.hours && {row.hours}} ))} )} {c && text(c.config.pickupDetail) && text(c.config.deliveryDetail) && ( {c.title} {["pickup", "delivery"].map((key) => ( {text(c.config[key + "Title"])} {text(c.config[key + "Detail"])} ))} )} {process && steps.length > 0 && ( {process.title} {text(process.config.intro) && ( {text(process.config.intro)} )} {steps.map((step, index) => ( {index + 1} {step.title} {step.detail} ))} {text(process.config.minimumNote)} {text(process.config.minimumNote) && text(process.config.refundNote) && ( | )} {text(process.config.refundNote)} )} {!scheduleRows.length && !c && !steps.length && ( 出摊服务信息正在完善中 )} ); } function Profile({ workspace }: { workspace: RuntimeWorkspace }) { const brand = workspace.brand; const p = presentation(workspace, "profile"); const credentials = workspace.trustItems.filter((item) => item.type === "credential"); return ( {text(brand.avatarUrl) && } {p.badge && {p.badge}} {text(brand.founder) || text(brand.name)} {text(brand.title) && {text(brand.title)}} {p.storyLead && {p.storyLead}} {text(brand.description) && {text(brand.description)}} {credentials.map((item) => rows(item.config.standards).length ? ( {rows(item.config.standards).map((standard, index) => ( {standard.title} {standard.detail} ))} ) : ( {item.title} {item.summary && {item.summary}} {item.content} ), )} {workspace.trustItems .filter((item) => item.type === "case") .map((item) => ( {item.title} {item.summary && {item.summary}} {rows(item.config.entries).length ? ( {rows(item.config.entries).map((entry, index) => ( {entry.badge} {entry.title} {entry.detail} {entry.result && {entry.result}} ))} ) : ( {item.content} )} ))} {workspace.trustItems .filter((item) => item.type === "promise") .map((item) => ( {item.title} {item.summary && {item.summary}} {rows(item.config.commitments).length ? ( {rows(item.config.commitments).map((entry, index) => ( {entry.label}: {entry.detail} {entry.highlight && {entry.highlight}} ))} ) : ( {item.content} )} ))} {text(brand.contactPhone) && ( )} {text(brand.contactWechat) && ( )} navigate("records")}> {p.recordsTitle || "我的咨询记录"} 查看记录 › ); } const formTargets: Record = { inquiry: "acheng-campus-food.inquiry.booking", success: "acheng-campus-food.success.successCopy", records: "acheng-campus-food.records.recordsCopy", }; export function TemplatePage({ workspace, page, children, offeringId }: TemplateProps) { if (page === "home") return ; if (page === "service") return ; if (page === "profile") return ; if (page === "offerings") return ; if (page === "detail") return ; return ( {children} ); } function OfferingList({ workspace }: { workspace: RuntimeWorkspace }) { const p = presentation(workspace, "offerings"); const [category, setCategory] = useState("all"); const [query, setQuery] = useState(""); const list = workspace.offerings.map(offering); const categories = [...new Set(list.map((item) => item.category).filter(Boolean))]; const filtered = list.filter( (item) => (category === "all" || item.category === category) && [item.name, item.desc, ...item.keywords] .join(" ") .toLowerCase() .includes(query.trim().toLowerCase()), ); return ( {categories.map((value) => ( ))} {p.title || "套餐餐品"} {p.subtitle && {p.subtitle}} setQuery(event.detail.value)} /> {p.menuTip && {p.menuTip}} {filtered.length ? ( filtered.map((item) => ( navigate("detail", { id: item.id })} > {item.category} {item.name} {item.desc} {item.priceRange} {p.detailAction || "查看详情 ›"} )) ) : ( 没有找到相关餐品,换个词试试 )} ); } function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string }) { const found = workspace.offerings.find((item) => item.id === id); if (!found) return ( 未找到该餐品 ); const item = offering(found); const p = presentation(workspace, "detail"); return ( {item.category} · {item.area} {item.name} {item.series} {p.priceLabel || "参考价格"} {item.priceRange} {p.spaceLabel} {text(item.presentation.spaceType)} {p.backgroundTitle || "餐品说明"} {item.details.background || item.desc} {item.details.designConcept && ( {p.conceptTitle} {item.details.designConcept} )} {item.details.crafts.length > 0 && ( {p.craftsTitle} {item.details.crafts.map((craft, index) => ( 0{index + 1} {craft} ))} )} {item.details.materialsList.length > 0 && ( {p.materialsTitle} {item.details.materialsList.map((material, index) => ( {material.name} {material.spec} ))} )} {item.keywords.map((key, index) => ( {key} ))} {p.inquiryHint} ); }