feat: 后台支持切换行业模板

This commit is contained in:
que01 committed 2026-09-19 12:38:31 +08:00
1 parent 8d93f34260
commit e807bba1cb
1 file changed
+2 -2
+2 -2
View File
@@ -11,7 +11,7 @@ export class AdminDashboard {
const { root, client } = this.options;
const [bookings, unread, brand, services] = await Promise.all([client.listAdminBookings(), client.getAdminUnreadCount(), client.getAdminBrand(), client.listServices()]);
this.bookings = bookings;
root.innerHTML = `<h1>品牌后台</h1><p>未读订单:${unread.count}</p><section><h2>品牌配置</h2><label>品牌名 <input id="brand-name" value="${brand.name}"></label><label>品牌简介 <textarea id="brand-description">${brand.description ?? ""}</textarea></label><label>联系电话 <input id="brand-phone" value="${brand.contactPhone ?? ""}"></label><label>微信号 <input id="brand-wechat" value="${brand.contactWechat ?? ""}"></label><button id="save-brand">保存品牌配置</button></section><section><h2>服务配置</h2><ul id="services">${services.map((item) => `<li><input data-service-name="${item.id}" value="${item.name}"><input data-service-price="${item.id}" value="${item.priceText ?? ""}"><button data-service-save="${item.id}">保存</button></li>`).join("")}</ul></section><label>状态 <select id="status"><option value="">全部</option><option>received</option><option>contacting</option><option>confirmed</option><option>completed</option><option>cancelled</option></select></label><button id="refresh">刷新</button><ul id="bookings">${this.listHtml()}</ul><section id="detail">选择订单查看详情</section>`;
root.innerHTML = `<h1>品牌后台</h1><p>未读订单:${unread.count}</p><section><h2>品牌配置</h2><label>行业模板 <select id="brand-template"><option value="food" ${brand.templateKey === "food" ? "selected" : ""}>餐饮</option><option value="personal" ${brand.templateKey === "personal" ? "selected" : ""}>个人品牌</option></select></label><label>品牌名 <input id="brand-name" value="${brand.name}"></label><label>品牌简介 <textarea id="brand-description">${brand.description ?? ""}</textarea></label><label>联系电话 <input id="brand-phone" value="${brand.contactPhone ?? ""}"></label><label>微信号 <input id="brand-wechat" value="${brand.contactWechat ?? ""}"></label><button id="save-brand">保存品牌配置</button></section><section><h2>服务配置</h2><ul id="services">${services.map((item) => `<li><input data-service-name="${item.id}" value="${item.name}"><input data-service-price="${item.id}" value="${item.priceText ?? ""}"><button data-service-save="${item.id}">保存</button></li>`).join("")}</ul></section><label>状态 <select id="status"><option value="">全部</option><option>received</option><option>contacting</option><option>confirmed</option><option>completed</option><option>cancelled</option></select></label><button id="refresh">刷新</button><ul id="bookings">${this.listHtml()}</ul><section id="detail">选择订单查看详情</section>`;
root.querySelector("#refresh")?.addEventListener("click", () => void this.load());
root.querySelector("#status")?.addEventListener("change", () => void this.filter());
root.querySelector("#save-brand")?.addEventListener("click", () => void this.saveBrand());
@@ -23,7 +23,7 @@ export class AdminDashboard {
private async filter(): Promise<void> { const status = (this.options.root.querySelector("#status") as HTMLSelectElement).value as BookingStatus | ""; this.bookings = await this.options.client.listAdminBookings(status ? { status } : {}); const list = this.options.root.querySelector("#bookings"); if (list) list.innerHTML = this.listHtml(); }
private select(id: string | undefined): void { this.selected = this.bookings.find((item) => item.id === id); if (!this.selected) return; const detail = this.options.root.querySelector("#detail"); if (!detail) return; detail.innerHTML = `<h2>${this.selected.bookingNo}</h2><p>客户:${this.selected.customerName}</p><select id="detail-status"><option>received</option><option>contacting</option><option>confirmed</option><option>completed</option><option>cancelled</option></select><textarea id="note" placeholder="内部备注">${this.selected.adminNote ?? ""}</textarea><button id="save">保存</button>`; detail.querySelector("#save")?.addEventListener("click", () => void this.save()); }
private async save(): Promise<void> { if (!this.selected) return; const detail = this.options.root.querySelector("#detail")!; const status = (detail.querySelector("#detail-status") as HTMLSelectElement).value as BookingStatus; const note = (detail.querySelector("#note") as HTMLTextAreaElement).value; this.selected = await this.options.client.updateAdminBookingStatus(this.selected.id, status, note); await this.load(); }
private async saveBrand(): Promise<void> { const root = this.options.root; await this.options.client.updateAdminBrand({ name: (root.querySelector("#brand-name") as HTMLInputElement).value, description: (root.querySelector("#brand-description") as HTMLTextAreaElement).value, contactPhone: (root.querySelector("#brand-phone") as HTMLInputElement).value, contactWechat: (root.querySelector("#brand-wechat") as HTMLInputElement).value }); }
private async saveBrand(): Promise<void> { const root = this.options.root; await this.options.client.updateAdminBrand({ templateKey: (root.querySelector("#brand-template") as HTMLSelectElement).value as "food" | "personal", name: (root.querySelector("#brand-name") as HTMLInputElement).value, description: (root.querySelector("#brand-description") as HTMLTextAreaElement).value, contactPhone: (root.querySelector("#brand-phone") as HTMLInputElement).value, contactWechat: (root.querySelector("#brand-wechat") as HTMLInputElement).value }); }
private async saveService(id: string | undefined): Promise<void> { if (!id) return; const root = this.options.root; await this.options.client.updateAdminService(id, { name: (root.querySelector(`[data-service-name="${id}"]`) as HTMLInputElement).value, priceText: (root.querySelector(`[data-service-price="${id}"]`) as HTMLInputElement).value }); }
}