请帮我设计一个具有会员机制的超市收银系统的HTML界面
时间: 2024-03-05 09:48:38 浏览: 174
好的,下面是一个简单的超市收银系统的 HTML 界面设计,包含了会员登录、商品选择和结算等基本功能。
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>超市收银系统</title>
<style>
/* 页面样式 */
body {
font-family: Arial, Helvetica, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
}
h1, h2 {
color: #333;
text-align: center;
}
form {
border: 1px solid #ccc;
padding: 10px;
margin: 20px auto;
max-width: 600px;
background-color: #fff;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
input[type="text"], input[type="password"], select {
display: block;
width: 100%;
padding: 8px;
margin-bottom: 10px;
border-radius: 4px;
border: 1px solid #ccc;
box-sizing: border-box;
font-size: 16px;
}
input[type="submit"], button {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
float: right;
}
input[type="submit"]:hover, button:hover {
background-color: #45a049;
}
table {
border-collapse: collapse;
width: 100%;
margin-top: 20px;
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #4CAF50;
color: white;
}
.total {
font-size: 24px;
font-weight: bold;
margin-top: 20px;
text-align: right;
}
</style>
</head>
<body>
<h1>超市收银系统</h1>
<!-- 会员登录表单 -->
<form id="login-form">
<h2>会员登录</h2>
<label for="username">用户名:</label>
<input type="text" id="username" name="username" required>
<label for="password">密码:</label>
<input type="password" id="password" name="password" required>
<input type="submit" value="登录">
</form>
<!-- 商品选择表单 -->
<form id="goods-form">
<h2>商品选择</h2>
<label for="goods">商品:</label>
<select id="goods" name="goods">
<option value="">请选择</option>
<option value="1">商品1</option>
<option value="2">商品2</option>
<option value="3">商品3</option>
</select>
<label for="quantity">数量:</label>
<input type="text" id="quantity" name="quantity" value="1" required>
<button id="add-btn" type="button">添加</button>
</form>
<!-- 商品列表 -->
<table id="goods-table">
<thead>
<tr>
<th>商品名称</th>
<th>单价(元)</th>
<th>数量</th>
<th>小计(元)</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<!-- 商品列表内容通过 JavaScript 动态添加 -->
</tbody>
</table>
<!-- 结算 -->
<div class="total">总计:0.00 元</div>
<button id="checkout-btn" type="button">结算</button>
<!-- JavaScript 代码 -->
<script>
// 商品列表数组
var goodsList = [];
// 获取表单元素
var loginForm = document.getElementById("login-form");
var goodsForm = document.getElementById("goods-form");
var goodsTable = document.getElementById("goods-table");
var addBtn = document.getElementById("add-btn");
var checkoutBtn = document.getElementById("checkout-btn");
// 会员登录表单提交事件
loginForm.addEventListener("submit", function(event) {
event.preventDefault();
// TODO: 处理会员登录逻辑
});
// 商品选择表单提交事件
goodsForm.addEventListener("submit", function(event) {
event.preventDefault();
// 获取商品信息
var goodsId = goodsForm.goods.value;
var quantity = parseInt(goodsForm.quantity.value);
var goodsName = goodsForm.goods.options[goodsForm.goods.selectedIndex].text;
var goodsPrice = 0.00; // TODO: 根据商品 ID 获取商品单价
// 添加到商品列表
if (goodsId && quantity) {
var subtotal = (goodsPrice * quantity).toFixed(2);
var row = document.createElement("tr");
row.innerHTML = "<td>" + goodsName + "</td><td>" + goodsPrice.toFixed(2) + "</td><td>" + quantity + "</td><td>" + subtotal + "</td><td><button class='delete-btn' type='button'>删除</button></td>";
goodsTable.querySelector("tbody").appendChild(row);
goodsList.push({
id: goodsId,
name: goodsName,
price: goodsPrice,
quantity: quantity,
subtotal: subtotal
});
updateTotal();
// 绑定删除按钮事件
row.querySelector(".delete-btn").addEventListener("click", function() {
var index = Array.from(goodsTable.querySelectorAll("tbody tr")).indexOf(row);
goodsList.splice(index, 1);
row.remove();
updateTotal();
});
}
});
// 结算按钮点击事件
checkoutBtn.addEventListener("click", function() {
// TODO: 处理结算逻辑
});
// 更新商品总计
function updateTotal() {
var total = goodsList.reduce(function(sum, goods) {
return sum + parseFloat(goods.subtotal);
}, 0.00);
document.querySelector(".total").textContent = "总计:" + total.toFixed(2) + " 元";
}
</script>
</body>
</html>
```
上述代码包含了会员登录、商品选择和结算等基本功能,具体实现需要根据业务逻辑进行调整和完善。
阅读全文