import streamlit as st # 菜单 menu = { "牛排": 50, "鸡肉": 35, "虾仁": 40, "炒面": 20, "饺子": 15 } # 页面标题 st.title("欢迎来到餐厅点餐小程序") # 商家编辑菜单 if st.sidebar.checkbox("编辑菜单"): menu = {} st.write("请编辑菜单:") while True: dish_name = st.text_input("请输入菜名") if not dish_name: break price = st.number_input("请输入价格", min_value=0) if price == 0: break menu[dish_name] = price st.write("已更新菜单:") st.write(menu) # 选择菜品,并提交订单 st.subheader("请选择您需要的菜品及数量") order_dict = {} for dish, price in menu.items(): quantity = st.number_input(f"{dish}({price}元)", value=0, step=1) if quantity > 0: order_dict[dish] = {"price": price, "quantity": quantity} if st.button("提交订单"): if order_dict: st.success("订单已提交") # 生成订单号 order_id = "123456789" st.write(f"订单号:{order_id}") # 展示订单详情 st.subheader("订单详情") total_price = 0 for dish, values in order_dict.items(): price = values["price"] quantity = values["quantity"] dish_total_price = price*quantity total_price += dish_total_price st.write(f"{dish} x {quantity}: {dish_total_price}元") st.write(f"总价:{total_price}元") # 支付 payment_method = st.selectbox("请选择支付方式", ["微信支付", "支付宝支付", "银行卡支付"]) if st.button("支付"): st.success("支付成功") st.write("请等待配送") else: st.warning("您还没有选择任何菜品") # 商家查看订单 st.subheader("商家查看订单") if st.button("查看订单"): st.write("订单详情") st.write(order_dict) import streamlit as st # 菜单 menu = { "牛排": 50, "鸡肉": 35, "虾仁": 40, "炒面": 20, "饺子": 15 } # 页面标题 st.title("欢迎来到餐厅点餐小程序") # 商家编辑菜单 if st.sidebar.checkbox("编辑菜单"): menu = {} st.write("请编辑菜单:") while True: dish_name = st.text_input("请输入菜名") if not dish_name: break price = st.number_input("请输入价格", min_value=0) if price == 0: break menu[dish_name] = price st.write("已更新菜单:") st.write(menu) # 选择菜品,并提交订单 st.subheader("请选择您需要的菜品及数量") order_dict = {} for dish, price in menu.items(): quantity = st.number_input(f"{dish}({price}元)", value=0, step=1) if quantity > 0: order_dict[dish] = {"price": price, "quantity": quantity} if st.button("提交订单"): if order_dict: st.success("订单已提交") # 生成订单号 order_id = "123456789" st.write(f"订单号:{order_id}") # 展示订单详情 st.subheader("订单详情") total_price = 0 for dish, values in order_dict.items(): price = values["price"] quantity = values["quantity"] dish_total_price = price*quantity total_price += dish_total_price st.write(f"{dish} x {quantity}: {dish_total_price}元") st.write(f"总价:{total_price}元") # 支付 payment_method = st.selectbox("请选择支付方式", ["微信支付", "支付宝支付", "银行卡支付"]) if st.button("支付"): st.success("支付成功") st.write("请等待配送") else: st.warning("您还没有选择任何菜品") # 商家查看订单 st.subheader("商家查看订单") if st.button("查看订单"): st.write("订单详情") st.write(order_dict)