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

893 lines
30 KiB
HTML

<!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;
}
.tabs {
background: #fff;
margin: 12px 0;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
overflow: hidden;
}
.tab-buttons {
display: flex;
background: #f8f9fa;
}
.tab-button {
flex: 1;
padding: 16px;
background: none;
border: none;
font-size: 16px;
color: #666;
cursor: pointer;
transition: all 0.3s ease;
position: relative;
}
.tab-button.active {
color: #007AFF;
background: #fff;
}
.tab-button.active::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 3px;
background: #007AFF;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.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);
}
.switch {
position: relative;
display: inline-block;
width: 50px;
height: 28px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 28px;
}
.slider:before {
position: absolute;
content: "";
height: 22px;
width: 22px;
left: 3px;
bottom: 3px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #007AFF;
}
input:checked + .slider:before {
transform: translateX(22px);
}
.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-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="tabs">
<div class="tab-buttons">
<button class="tab-button active" onclick="switchTab(event, 'points-discount')">积分优惠</button>
<button class="tab-button" onclick="switchTab(event, 'double-points')">双倍积分</button>
</div>
</div>
<div id="points-discount" class="tab-content active">
<div class="filter-section">
<div class="filter-row">
<label class="filter-label">商铺</label>
<select class="filter-select" id="storeSelect1">
<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="productId1" placeholder="请输入商品ID">
</div>
<div class="filter-row">
<label class="filter-label">商品名称</label>
<input type="text" class="filter-input" id="productName1" placeholder="请输入商品名称">
</div>
<div class="filter-buttons">
<button class="btn btn-primary" onclick="searchProducts(1)">查询</button>
<button class="btn btn-secondary" onclick="resetFilters(1)">重置</button>
</div>
</div>
<div class="product-list" id="productList1">
<div class="loading" id="loading1">加载中...</div>
</div>
</div>
<div id="double-points" class="tab-content">
<div class="filter-section">
<div class="filter-row">
<label class="filter-label">商铺</label>
<select class="filter-select" id="storeSelect2">
<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="productId2" placeholder="请输入商品ID">
</div>
<div class="filter-row">
<label class="filter-label">商品名称</label>
<input type="text" class="filter-input" id="productName2" placeholder="请输入商品名称">
</div>
<div class="filter-row">
<label class="filter-label">是否启用双倍积分</label>
<select class="filter-select" id="doublePointsFilter">
<option value="all">全部</option>
<option value="enabled">启用</option>
<option value="disabled">关闭</option>
</select>
</div>
<div class="filter-buttons">
<button class="btn btn-primary" onclick="searchProducts(2)">查询</button>
<button class="btn btn-secondary" onclick="resetFilters(2)">重置</button>
</div>
</div>
<div class="product-list" id="productList2">
<div class="loading" id="loading2">加载中...</div>
</div>
</div>
</div>
<button class="add-button" onclick="showAddModal()" id="addButton1" style="display: block;">+</button>
<button class="add-button" onclick="showAddModal()" id="addButton2" style="display: none;">+</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>
<select class="filter-select" id="modalPoints">
<option value="">请选择积分使用模式</option>
<option value="积分换购">积分换购</option>
<option value="积分优惠购">积分优惠购</option>
</select>
</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 pointsDiscountProducts = [
{
id: '001',
name: '黑木耳',
spec: '小份',
store: '生生蔬菜店',
price: 5.00,
originalStatus: '上架',
pointsMode: '积分换购',
stock: 10,
enabled: true
},
{
id: '002',
name: '黑木耳',
spec: '大份',
store: '生生蔬菜店',
price: 8.00,
originalStatus: '上架',
pointsMode: '积分优惠购',
stock: 10,
enabled: true
},
{
id: '003',
name: '番茄',
spec: '无',
store: '生生蔬菜店',
price: 3.50,
originalStatus: '下架',
pointsMode: '积分换购',
stock: 2,
enabled: false
}
];
// 双倍积分商品数据
let doublePointsProducts = [
{
id: '001',
name: '黑木耳',
store: '生生蔬菜店',
price: 5.00,
originalStatus: '上架',
enabled: true
},
{
id: '002',
name: '黑木耳',
store: '生生蔬菜店',
price: 8.00,
originalStatus: '上架',
enabled: true
},
{
id: '003',
name: '番茄',
store: '生生蔬菜店',
price: 3.50,
originalStatus: '下架',
enabled: false
},
{
id: '004',
name: '冬瓜',
store: '生生蔬菜店',
price: 12.00,
originalStatus: '上架',
enabled: true
},
{
id: '005',
name: '土豆',
store: '生生蔬菜店',
price: 6.00,
originalStatus: '上架',
enabled: true
},
{
id: '006',
name: '白萝卜',
store: '生生蔬菜店',
price: 4.50,
originalStatus: '上架',
enabled: true
}
];
let currentTab = 1; // 1: 积分优惠, 2: 双倍积分
let currentEditId = null;
// 渲染积分优惠商品
function renderPointsDiscountProducts(productsToRender = pointsDiscountProducts) {
const productList = document.getElementById('productList1');
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-id">ID: ${product.id}</div>
</div>
<div class="product-name">${product.name}</div>
<div class="product-info">
<div class="info-item">
<span class="info-label">规格名称</span>
<span class="info-value">${product.spec}</span>
</div>
<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.toFixed(2)}</span>
</div>
<div class="info-item">
<span class="info-label">原有商品状态</span>
<span class="info-value">${product.originalStatus}</span>
</div>
<div class="info-item">
<span class="info-label">积分使用模式</span>
<span class="info-value">${product.pointsMode}</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>
<label class="switch">
<input type="checkbox" ${product.enabled ? 'checked' : ''} onchange="toggleProduct(1, ${index})">
<span class="slider"></span>
</label>
</div>
</div>
<div class="product-actions">
<button class="btn-small btn-success" onclick="editProduct(1, ${index})">编辑</button>
</div>
</div>
`).join('');
}
// 渲染双倍积分商品
function renderDoublePointsProducts(productsToRender = doublePointsProducts) {
const productList = document.getElementById('productList2');
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-id">ID: ${product.id}</div>
</div>
<div class="product-name">${product.name}</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.toFixed(2)}</span>
</div>
<div class="info-item">
<span class="info-label">原有商品状态</span>
<span class="info-value">${product.originalStatus}</span>
</div>
<div class="info-item">
<span class="info-label">是否启用</span>
<label class="switch">
<input type="checkbox" ${product.enabled ? 'checked' : ''} onchange="toggleProduct(2, ${index})">
<span class="slider"></span>
</label>
</div>
</div>
</div>
`).join('');
}
function searchProducts(tabIndex) {
if (tabIndex === 1) {
const storeFilter = document.getElementById('storeSelect1').value;
const idFilter = document.getElementById('productId1').value.toLowerCase();
const nameFilter = document.getElementById('productName1').value.toLowerCase();
const filteredProducts = pointsDiscountProducts.filter(product => {
const matchStore = !storeFilter || product.store === storeFilter;
const matchId = !idFilter || product.id.toLowerCase().includes(idFilter);
const matchName = !nameFilter || product.name.toLowerCase().includes(nameFilter);
return matchStore && matchId && matchName;
});
renderPointsDiscountProducts(filteredProducts);
} else {
const storeFilter = document.getElementById('storeSelect2').value;
const idFilter = document.getElementById('productId2').value.toLowerCase();
const nameFilter = document.getElementById('productName2').value.toLowerCase();
const enabledFilter = document.getElementById('doublePointsFilter').value;
const filteredProducts = doublePointsProducts.filter(product => {
const matchStore = !storeFilter || product.store === storeFilter;
const matchId = !idFilter || product.id.toLowerCase().includes(idFilter);
const matchName = !nameFilter || product.name.toLowerCase().includes(nameFilter);
let matchEnabled = true;
if (enabledFilter === 'enabled') {
matchEnabled = product.enabled;
} else if (enabledFilter === 'disabled') {
matchEnabled = !product.enabled;
}
return matchStore && matchId && matchName && matchEnabled;
});
renderDoublePointsProducts(filteredProducts);
}
}
function resetFilters(tabIndex) {
if (tabIndex === 1) {
document.getElementById('storeSelect1').value = '';
document.getElementById('productId1').value = '';
document.getElementById('productName1').value = '';
renderPointsDiscountProducts();
} else {
document.getElementById('storeSelect2').value = '';
document.getElementById('productId2').value = '';
document.getElementById('productName2').value = '';
document.getElementById('doublePointsFilter').value = 'all';
renderDoublePointsProducts();
}
}
function switchTab(evt, tabName) {
const tabcontent = document.getElementsByClassName("tab-content");
for (let i = 0; i < tabcontent.length; i++) {
tabcontent[i].classList.remove("active");
}
const tablinks = document.getElementsByClassName("tab-button");
for (let i = 0; i < tablinks.length; i++) {
tablinks[i].classList.remove("active");
}
document.getElementById(tabName).classList.add("active");
evt.currentTarget.classList.add("active");
// 切换添加按钮的显示
if (tabName === 'points-discount') {
document.getElementById('addButton1').style.display = 'block';
document.getElementById('addButton2').style.display = 'none';
currentTab = 1;
} else {
document.getElementById('addButton1').style.display = 'none';
document.getElementById('addButton2').style.display = 'block';
currentTab = 2;
}
}
function toggleProduct(tabIndex, index) {
if (tabIndex === 1) {
pointsDiscountProducts[index].enabled = !pointsDiscountProducts[index].enabled;
renderPointsDiscountProducts();
} else {
doublePointsProducts[index].enabled = !doublePointsProducts[index].enabled;
renderDoublePointsProducts();
}
}
function editProduct(tabIndex, index) {
if (tabIndex === 1) {
const product = pointsDiscountProducts[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.pointsMode;
document.getElementById('modalStock').value = product.stock;
currentEditId = index;
document.getElementById('productModal').style.display = 'block';
} else {
alert('双倍积分功能暂无编辑功能');
}
}
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 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 pointsMode = document.getElementById('modalPoints').value;
const stock = parseInt(document.getElementById('modalStock').value);
if (!name || !store || !price || !pointsMode || !stock) {
alert('请填写所有必填字段');
return;
}
if (currentEditId !== null) {
pointsDiscountProducts[currentEditId] = {
...pointsDiscountProducts[currentEditId],
name, store, price, pointsMode, stock
};
} else {
const newId = String(Math.max(...pointsDiscountProducts.map(p => parseInt(p.id))) + 1).padStart(3, '0');
pointsDiscountProducts.push({
id: newId,
name,
spec: '无',
store,
price,
originalStatus: '上架',
pointsMode,
stock,
enabled: true
});
}
hideModal();
renderPointsDiscountProducts();
}
document.addEventListener('click', function(e) {
const modal = document.getElementById('productModal');
if (e.target === modal) {
hideModal();
}
});
setTimeout(() => {
renderPointsDiscountProducts();
renderDoublePointsProducts();
}, 500);
</script>
</body>
</html>