dm-design/商家端APP/1 工作台/1.1 会员管理/1.1.3 积分商城/积分商城.html

572 lines
18 KiB
HTML
Raw Normal View History

2025-08-06 08:38:43 +00:00
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>积分商城</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background-color: #f5f5f5;
color: #333;
line-height: 1.6;
}
.container {
max-width: 100%;
padding: 0 16px;
}
.header {
background: #fff;
padding: 16px 0;
border-bottom: 1px solid #e0e0e0;
position: sticky;
top: 0;
z-index: 100;
}
.header h1 {
text-align: center;
font-size: 18px;
font-weight: 600;
color: #333;
}
.filter-section {
background: #fff;
margin: 12px 0;
padding: 16px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.filter-row {
margin-bottom: 16px;
}
.filter-row:last-child {
margin-bottom: 0;
}
.filter-label {
display: block;
font-size: 14px;
color: #666;
margin-bottom: 8px;
}
.filter-input, .filter-select {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 16px;
background: #fff;
}
.filter-input:focus, .filter-select:focus {
outline: none;
border-color: #007AFF;
}
.filter-buttons {
display: flex;
gap: 12px;
margin-top: 16px;
}
.btn {
flex: 1;
padding: 12px;
border: none;
border-radius: 6px;
font-size: 16px;
cursor: pointer;
transition: all 0.3s ease;
}
.btn-primary {
background: #007AFF;
color: #fff;
}
.btn-primary:active {
background: #0056CC;
}
.btn-secondary {
background: #f0f0f0;
color: #333;
}
.btn-secondary:active {
background: #e0e0e0;
}
.btn-success {
background: #34C759;
color: #fff;
}
.btn-success:active {
background: #28A745;
}
.btn-danger {
background: #FF3B30;
color: #fff;
}
.btn-danger:active {
background: #D70015;
}
.add-button {
position: fixed;
bottom: 24px;
right: 24px;
width: 56px;
height: 56px;
background: #34C759;
color: #fff;
border: none;
border-radius: 50%;
font-size: 24px;
cursor: pointer;
box-shadow: 0 4px 12px rgba(52, 199, 89, 0.4);
z-index: 1000;
transition: all 0.3s ease;
}
.add-button:active {
transform: scale(0.95);
}
.product-list {
margin-bottom: 80px;
}
.product-card {
background: #fff;
margin: 12px 0;
padding: 16px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.product-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
}
.product-id {
font-size: 14px;
color: #666;
font-weight: 600;
}
.product-checkbox {
width: 20px;
height: 20px;
}
.product-name {
font-size: 16px;
font-weight: 600;
color: #333;
margin-bottom: 8px;
}
.product-info {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
margin-bottom: 16px;
}
.info-item {
background: #f8f8f8;
padding: 8px 12px;
border-radius: 4px;
}
.info-label {
font-size: 12px;
color: #666;
display: block;
}
.info-value {
font-size: 14px;
color: #333;
font-weight: 600;
}
.product-actions {
display: flex;
gap: 8px;
}
.btn-small {
flex: 1;
padding: 8px 16px;
border: none;
border-radius: 4px;
font-size: 14px;
cursor: pointer;
transition: all 0.3s ease;
}
.empty-state {
text-align: center;
padding: 60px 20px;
color: #999;
}
.empty-state img {
width: 120px;
height: 120px;
margin-bottom: 16px;
opacity: 0.5;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
z-index: 2000;
}
.modal-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #fff;
width: 90%;
max-width: 400px;
border-radius: 12px;
padding: 24px;
max-height: 80vh;
overflow-y: auto;
}
.modal-header {
text-align: center;
font-size: 18px;
font-weight: 600;
margin-bottom: 24px;
}
.modal-body .filter-row {
margin-bottom: 20px;
}
.modal-buttons {
display: flex;
gap: 12px;
margin-top: 24px;
}
.loading {
text-align: center;
padding: 40px;
color: #666;
}
@media (min-width: 768px) {
.container {
max-width: 800px;
margin: 0 auto;
}
.filter-section {
padding: 24px;
}
.product-info {
grid-template-columns: repeat(3, 1fr);
}
}
</style>
</head>
<body>
<div class="header">
<div class="container">
<h1>积分商城</h1>
</div>
</div>
<div class="container">
<div class="filter-section">
<div class="filter-row">
<label class="filter-label">商铺</label>
<select class="filter-select" id="storeSelect">
<option value="">请选择商铺</option>
<option value="生生蔬菜店">生生蔬菜店</option>
</select>
</div>
<div class="filter-row">
<label class="filter-label">商品ID</label>
<input type="text" class="filter-input" id="productId" placeholder="请输入商品ID">
</div>
<div class="filter-row">
<label class="filter-label">商品名称</label>
<input type="text" class="filter-input" id="productName" placeholder="请输入商品名称">
</div>
<div class="filter-buttons">
<button class="btn btn-primary" onclick="searchProducts()">查询</button>
<button class="btn btn-secondary" onclick="resetFilters()">重置</button>
</div>
</div>
<div class="product-list" id="productList">
<div class="loading" id="loading">加载中...</div>
</div>
</div>
<button class="add-button" onclick="showAddModal()">+</button>
<div class="modal" id="productModal">
<div class="modal-content">
<div class="modal-header" id="modalTitle">添加商品</div>
<div class="modal-body">
<div class="filter-row">
<label class="filter-label">商品名称</label>
<input type="text" class="filter-input" id="modalProductName" placeholder="请输入商品名称">
</div>
<div class="filter-row">
<label class="filter-label">归属店铺</label>
<select class="filter-select" id="modalStore">
<option value="">请选择店铺</option>
<option value="生生蔬菜店">生生蔬菜店</option>
</select>
</div>
<div class="filter-row">
<label class="filter-label">商品价格</label>
<input type="number" step="0.01" class="filter-input" id="modalPrice" placeholder="请输入商品价格">
</div>
<div class="filter-row">
<label class="filter-label">兑换积分</label>
<input type="number" class="filter-input" id="modalPoints" placeholder="请输入兑换积分">
</div>
<div class="filter-row">
<label class="filter-label">剩余兑换库存</label>
<input type="number" class="filter-input" id="modalStock" placeholder="请输入库存数量">
</div>
</div>
<div class="modal-buttons">
<button class="btn btn-secondary" onclick="hideModal()">取消</button>
<button class="btn btn-primary" onclick="saveProduct()">保存</button>
</div>
</div>
</div>
<script>
let products = [
{
name: '黑木耳100g',
store: '生生蔬菜店',
price: 5.50,
points: 1,
stock: 10,
exchanged: 0,
createdTime: '2024-01-15 09:30:00'
},
{
name: '苦瓜200g',
store: '生生蔬菜店',
price: 3.80,
points: 1,
stock: 10,
exchanged: 0,
createdTime: '2024-01-16 14:20:00'
},
{
name: '番茄500g',
store: '生生蔬菜店',
price: 8.90,
points: 2,
stock: 2,
exchanged: 0,
createdTime: '2024-01-17 10:45:00'
}
];
let currentEditId = null;
function renderProducts(productsToRender = products) {
const productList = document.getElementById('productList');
if (productsToRender.length === 0) {
productList.innerHTML = `
<div class="empty-state">
<div>暂无商品数据</div>
</div>
`;
return;
}
productList.innerHTML = productsToRender.map((product, index) => `
<div class="product-card">
<div class="product-header">
<div class="product-name">${product.name}</div>
<input type="checkbox" class="product-checkbox">
</div>
<div class="product-info">
<div class="info-item">
<span class="info-label">归属店铺</span>
<span class="info-value">${product.store}</span>
</div>
<div class="info-item">
<span class="info-label">商品价格</span>
<span class="info-value">¥${product.price}</span>
</div>
<div class="info-item">
<span class="info-label">兑换积分</span>
<span class="info-value">${product.points}</span>
</div>
<div class="info-item">
<span class="info-label">剩余库存</span>
<span class="info-value">${product.stock}</span>
</div>
<div class="info-item">
<span class="info-label">已兑换数量</span>
<span class="info-value">${product.exchanged}</span>
</div>
<div class="info-item">
<span class="info-label">成为积分商品时间</span>
<span class="info-value">${product.createdTime}</span>
</div>
</div>
<div class="product-actions">
<button class="btn-small btn-success" onclick="editProduct(${index})">编辑</button>
<button class="btn-small btn-danger" onclick="deleteProduct(${index})">删除</button>
</div>
</div>
`).join('');
}
function searchProducts() {
const storeFilter = document.getElementById('storeSelect').value;
const idFilter = document.getElementById('productId').value.toLowerCase();
const nameFilter = document.getElementById('productName').value.toLowerCase();
const filteredProducts = products.filter(product => {
const matchStore = !storeFilter || product.store === storeFilter;
const matchName = !nameFilter || product.name.toLowerCase().includes(nameFilter);
return matchStore && matchName;
});
renderProducts(filteredProducts);
}
function resetFilters() {
document.getElementById('storeSelect').value = '';
document.getElementById('productId').value = '';
document.getElementById('productName').value = '';
renderProducts();
}
function showAddModal() {
document.getElementById('modalTitle').textContent = '添加商品';
document.getElementById('modalProductName').value = '';
document.getElementById('modalStore').value = '';
document.getElementById('modalPrice').value = '';
document.getElementById('modalPoints').value = '';
document.getElementById('modalStock').value = '';
currentEditId = null;
document.getElementById('productModal').style.display = 'block';
}
function editProduct(index) {
const product = products[index];
if (!product) return;
document.getElementById('modalTitle').textContent = '编辑商品';
document.getElementById('modalProductName').value = product.name;
document.getElementById('modalStore').value = product.store;
document.getElementById('modalPrice').value = product.price;
document.getElementById('modalPoints').value = product.points;
document.getElementById('modalStock').value = product.stock;
currentEditId = index;
document.getElementById('productModal').style.display = 'block';
}
function deleteProduct(index) {
if (confirm('确定要删除这个商品吗?')) {
products.splice(index, 1);
renderProducts();
}
}
function hideModal() {
document.getElementById('productModal').style.display = 'none';
currentEditId = null;
}
function saveProduct() {
const name = document.getElementById('modalProductName').value;
const store = document.getElementById('modalStore').value;
const price = parseFloat(document.getElementById('modalPrice').value);
const points = parseInt(document.getElementById('modalPoints').value);
const stock = parseInt(document.getElementById('modalStock').value);
if (!name || !store || !price || !points || !stock) {
alert('请填写所有必填字段');
return;
}
if (currentEditId !== null) {
products[currentEditId] = {
...products[currentEditId],
name, store, price, points, stock
};
} else {
const now = new Date();
const createdTime = now.getFullYear() + '-' +
String(now.getMonth() + 1).padStart(2, '0') + '-' +
String(now.getDate()).padStart(2, '0') + ' ' +
String(now.getHours()).padStart(2, '0') + ':' +
String(now.getMinutes()).padStart(2, '0') + ':' +
String(now.getSeconds()).padStart(2, '0');
products.push({
name, store, price, points, stock, exchanged: 0, createdTime
});
}
hideModal();
renderProducts();
}
document.addEventListener('click', function(e) {
const modal = document.getElementById('productModal');
if (e.target === modal) {
hideModal();
}
});
setTimeout(() => {
renderProducts();
}, 500);
</script>
</body>
</html>