1229 lines
45 KiB
HTML
1229 lines
45 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;
|
||
}
|
||
|
||
.product-info-section {
|
||
background: #f8f9fa;
|
||
padding: 16px;
|
||
border-radius: 8px;
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
.info-row {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
padding: 8px 0;
|
||
border-bottom: 1px solid #e9ecef;
|
||
}
|
||
|
||
.info-row:last-child {
|
||
border-bottom: none;
|
||
}
|
||
|
||
.info-label {
|
||
font-size: 14px;
|
||
color: #666;
|
||
font-weight: 500;
|
||
}
|
||
|
||
.info-value {
|
||
font-size: 14px;
|
||
color: #333;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.required {
|
||
color: #ff4757;
|
||
}
|
||
|
||
.quantity-control {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0;
|
||
border: 1px solid #ddd;
|
||
border-radius: 6px;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.quantity-btn {
|
||
width: 40px;
|
||
height: 48px;
|
||
border: none;
|
||
background: #f8f9fa;
|
||
color: #333;
|
||
font-size: 18px;
|
||
cursor: pointer;
|
||
transition: all 0.2s ease;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.quantity-btn:hover {
|
||
background: #e9ecef;
|
||
}
|
||
|
||
.quantity-btn:active {
|
||
background: #dee2e6;
|
||
}
|
||
|
||
.quantity-input {
|
||
border: none;
|
||
text-align: center;
|
||
flex: 1;
|
||
min-width: 60px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.quantity-input:focus {
|
||
outline: none;
|
||
border: none;
|
||
}
|
||
|
||
.radio-group {
|
||
display: flex;
|
||
gap: 24px;
|
||
}
|
||
|
||
.radio-option {
|
||
display: flex;
|
||
align-items: center;
|
||
cursor: pointer;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.radio-option input[type="radio"] {
|
||
width: 18px;
|
||
height: 18px;
|
||
margin-right: 8px;
|
||
accent-color: #007AFF;
|
||
}
|
||
|
||
.radio-text {
|
||
color: #333;
|
||
user-select: none;
|
||
}
|
||
|
||
.info-display {
|
||
padding: 12px;
|
||
background: #f8f9fa;
|
||
border: 1px solid #e9ecef;
|
||
border-radius: 6px;
|
||
color: #333;
|
||
font-weight: 500;
|
||
}
|
||
|
||
@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 id="addMode" style="display: none;">
|
||
<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" onchange="updatePointsMode()">
|
||
<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 id="editModeExchange" style="display: none;">
|
||
<div class="product-info-section">
|
||
<div class="info-row">
|
||
<span class="info-label">商品ID:</span>
|
||
<span class="info-value" id="displayProductId"></span>
|
||
</div>
|
||
<div class="info-row">
|
||
<span class="info-label">商品名称:</span>
|
||
<span class="info-value" id="displayProductName"></span>
|
||
</div>
|
||
<div class="info-row">
|
||
<span class="info-label">归属摊位:</span>
|
||
<span class="info-value" id="displayStore"></span>
|
||
</div>
|
||
<div class="info-row">
|
||
<span class="info-label">规格名称:</span>
|
||
<span class="info-value" id="displaySpec"></span>
|
||
</div>
|
||
<div class="info-row">
|
||
<span class="info-label">SKU-ID:</span>
|
||
<span class="info-value" id="displaySkuId"></span>
|
||
</div>
|
||
<div class="info-row">
|
||
<span class="info-label">商品原价:</span>
|
||
<span class="info-value" id="displayPrice"></span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="filter-row">
|
||
<label class="filter-label">添加库存(负数代表减少库存) <span class="required">*</span></label>
|
||
<div class="quantity-control">
|
||
<button type="button" class="quantity-btn" onclick="changeQuantity('modalStockEdit', -1)">-</button>
|
||
<input type="number" class="filter-input quantity-input" id="modalStockEdit" value="10">
|
||
<button type="button" class="quantity-btn" onclick="changeQuantity('modalStockEdit', 1)">+</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="filter-row">
|
||
<label class="filter-label">积分类型</label>
|
||
<div class="info-display">积分换购</div>
|
||
</div>
|
||
|
||
<div class="filter-row">
|
||
<label class="filter-label">兑换所需积分设置 <span class="required">*</span></label>
|
||
<div class="quantity-control">
|
||
<button type="button" class="quantity-btn" onclick="changeQuantity('modalPoints', -1)">-</button>
|
||
<input type="number" class="filter-input quantity-input" id="modalPointsRequired" value="1" min="1">
|
||
<button type="button" class="quantity-btn" onclick="changeQuantity('modalPointsRequired', 1)">+</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="filter-row">
|
||
<label class="filter-label">最低兑换金额(商业支付最少0.01元)</label>
|
||
<input type="text" class="filter-input" id="modalMinAmount" value="0.01元" readonly>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 编辑模式 - 积分优惠购 -->
|
||
<div id="editModeDiscount" style="display: none;">
|
||
<div class="product-info-section">
|
||
<div class="info-row">
|
||
<span class="info-label">商品ID:</span>
|
||
<span class="info-value" id="displayProductIdDiscount"></span>
|
||
</div>
|
||
<div class="info-row">
|
||
<span class="info-label">商品名称:</span>
|
||
<span class="info-value" id="displayProductNameDiscount"></span>
|
||
</div>
|
||
<div class="info-row">
|
||
<span class="info-label">归属摊位:</span>
|
||
<span class="info-value" id="displayStoreDiscount"></span>
|
||
</div>
|
||
<div class="info-row">
|
||
<span class="info-label">规格名称:</span>
|
||
<span class="info-value" id="displaySpecDiscount"></span>
|
||
</div>
|
||
<div class="info-row">
|
||
<span class="info-label">商品原价:</span>
|
||
<span class="info-value" id="displayPriceDiscount"></span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="filter-row">
|
||
<label class="filter-label">添加库存(负数代表减少库存) <span class="required">*</span></label>
|
||
<div class="quantity-control">
|
||
<button type="button" class="quantity-btn" onclick="changeQuantity('modalStockEditDiscount', -1)">-</button>
|
||
<input type="number" class="filter-input quantity-input" id="modalStockEditDiscount" value="10">
|
||
<button type="button" class="quantity-btn" onclick="changeQuantity('modalStockEditDiscount', 1)">+</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="filter-row">
|
||
<label class="filter-label">积分类型</label>
|
||
<div class="info-display">积分优惠购</div>
|
||
</div>
|
||
|
||
<div class="filter-row">
|
||
<label class="filter-label">积分抵扣金额设置 <span class="required">*</span></label>
|
||
<input type="number" step="0.01" class="filter-input" id="modalDiscountAmount" placeholder="请输入积分抵扣金额" min="0.01">
|
||
</div>
|
||
|
||
<div class="filter-row">
|
||
<label class="filter-label">所需积分数量 <span class="required">*</span></label>
|
||
<div class="quantity-control">
|
||
<button type="button" class="quantity-btn" onclick="changeQuantity('modalDiscountPoints', -1)">-</button>
|
||
<input type="number" class="filter-input quantity-input" id="modalDiscountPoints" value="100" min="1">
|
||
<button type="button" class="quantity-btn" onclick="changeQuantity('modalDiscountPoints', 1)">+</button>
|
||
</div>
|
||
</div>
|
||
</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,
|
||
skuId: '19410514277450383601',
|
||
pointsRequired: 50,
|
||
discountAmount: null,
|
||
discountPoints: null
|
||
},
|
||
{
|
||
id: '002',
|
||
name: '黑木耳',
|
||
spec: '大份',
|
||
store: '生生蔬菜店',
|
||
price: 8.00,
|
||
originalStatus: '上架',
|
||
pointsMode: '积分优惠购',
|
||
stock: 10,
|
||
enabled: true,
|
||
skuId: '19410514277450383602',
|
||
pointsRequired: null,
|
||
discountAmount: 2.00,
|
||
discountPoints: 100
|
||
},
|
||
{
|
||
id: '003',
|
||
name: '番茄',
|
||
spec: '无',
|
||
store: '生生蔬菜店',
|
||
price: 3.50,
|
||
originalStatus: '下架',
|
||
pointsMode: '积分换购',
|
||
stock: 2,
|
||
enabled: false,
|
||
skuId: '19410514277450383603',
|
||
pointsRequired: 35,
|
||
discountAmount: null,
|
||
discountPoints: null
|
||
}
|
||
];
|
||
|
||
// 双倍积分商品数据
|
||
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('addMode').style.display = 'none';
|
||
document.getElementById('editModeExchange').style.display = 'none';
|
||
document.getElementById('editModeDiscount').style.display = 'none';
|
||
|
||
if (product.pointsMode === '积分换购') {
|
||
// 显示积分换购编辑模式
|
||
document.getElementById('editModeExchange').style.display = 'block';
|
||
|
||
// 填充商品信息
|
||
document.getElementById('displayProductId').textContent = product.id;
|
||
document.getElementById('displayProductName').textContent = product.name;
|
||
document.getElementById('displayStore').textContent = product.store;
|
||
document.getElementById('displaySpec').textContent = product.spec;
|
||
document.getElementById('displaySkuId').textContent = product.skuId;
|
||
document.getElementById('displayPrice').textContent = `¥${product.price.toFixed(2)}`;
|
||
|
||
// 设置可编辑字段
|
||
document.getElementById('modalStockEdit').value = product.stock;
|
||
document.getElementById('modalPointsRequired').value = product.pointsRequired || 1;
|
||
} else {
|
||
// 显示积分优惠购编辑模式
|
||
document.getElementById('editModeDiscount').style.display = 'block';
|
||
|
||
// 填充商品信息
|
||
document.getElementById('displayProductIdDiscount').textContent = product.id;
|
||
document.getElementById('displayProductNameDiscount').textContent = product.name;
|
||
document.getElementById('displayStoreDiscount').textContent = product.store;
|
||
document.getElementById('displaySpecDiscount').textContent = product.spec;
|
||
document.getElementById('displayPriceDiscount').textContent = `¥${product.price.toFixed(2)}`;
|
||
|
||
// 设置可编辑字段
|
||
document.getElementById('modalStockEditDiscount').value = product.stock;
|
||
document.getElementById('modalDiscountAmount').value = product.discountAmount || '';
|
||
document.getElementById('modalDiscountPoints').value = product.discountPoints || 100;
|
||
}
|
||
|
||
currentEditId = index;
|
||
document.getElementById('productModal').style.display = 'block';
|
||
} else {
|
||
alert('双倍积分功能暂无编辑功能');
|
||
}
|
||
}
|
||
|
||
function showAddModal() {
|
||
document.getElementById('modalTitle').textContent = '添加商品';
|
||
|
||
// 显示添加模式,隐藏编辑模式
|
||
document.getElementById('addMode').style.display = 'block';
|
||
document.getElementById('editModeExchange').style.display = 'none';
|
||
document.getElementById('editModeDiscount').style.display = 'none';
|
||
|
||
// 清空表单
|
||
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() {
|
||
if (currentEditId !== null) {
|
||
// 编辑模式
|
||
const product = pointsDiscountProducts[currentEditId];
|
||
|
||
if (product.pointsMode === '积分换购') {
|
||
// 积分换购模式
|
||
const stock = parseInt(document.getElementById('modalStockEdit').value);
|
||
const pointsRequired = parseInt(document.getElementById('modalPointsRequired').value);
|
||
|
||
if (stock === null || stock === undefined || !pointsRequired) {
|
||
alert('请填写所有必填字段');
|
||
return;
|
||
}
|
||
|
||
pointsDiscountProducts[currentEditId] = {
|
||
...product,
|
||
stock,
|
||
pointsRequired
|
||
};
|
||
} else {
|
||
// 积分优惠购模式
|
||
const stock = parseInt(document.getElementById('modalStockEditDiscount').value);
|
||
const discountAmount = parseFloat(document.getElementById('modalDiscountAmount').value);
|
||
const discountPoints = parseInt(document.getElementById('modalDiscountPoints').value);
|
||
|
||
if (stock === null || stock === undefined || !discountAmount || !discountPoints) {
|
||
alert('请填写所有必填字段');
|
||
return;
|
||
}
|
||
|
||
pointsDiscountProducts[currentEditId] = {
|
||
...product,
|
||
stock,
|
||
discountAmount,
|
||
discountPoints
|
||
};
|
||
}
|
||
} else {
|
||
// 添加模式
|
||
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;
|
||
}
|
||
|
||
const newId = String(Math.max(...pointsDiscountProducts.map(p => parseInt(p.id))) + 1).padStart(3, '0');
|
||
const newSkuId = `1941051427745038360${newId}`;
|
||
|
||
pointsDiscountProducts.push({
|
||
id: newId,
|
||
name,
|
||
spec: '无',
|
||
store,
|
||
price,
|
||
originalStatus: '上架',
|
||
pointsMode,
|
||
stock,
|
||
enabled: true,
|
||
skuId: newSkuId,
|
||
pointsRequired: pointsMode === '积分换购' ? Math.floor(price * 10) : null,
|
||
discountAmount: pointsMode === '积分优惠购' ? Math.floor(price * 0.2 * 100) / 100 : null,
|
||
discountPoints: pointsMode === '积分优惠购' ? 100 : null
|
||
});
|
||
}
|
||
|
||
hideModal();
|
||
renderPointsDiscountProducts();
|
||
}
|
||
|
||
// 数量控制函数
|
||
function changeQuantity(inputId, change) {
|
||
const input = document.getElementById(inputId);
|
||
const currentValue = parseInt(input.value) || 0;
|
||
// 对于库存设置允许负数,其他字段保持最小值限制
|
||
if (inputId.includes('Stock')) {
|
||
input.value = currentValue + change;
|
||
} else {
|
||
const newValue = Math.max(0, currentValue + change);
|
||
input.value = newValue;
|
||
}
|
||
}
|
||
|
||
// 更新积分模式函数(用于添加模式)
|
||
function updatePointsMode() {
|
||
// 预留函数,可以在选择积分模式时进行相关处理
|
||
}
|
||
|
||
document.addEventListener('click', function(e) {
|
||
const modal = document.getElementById('productModal');
|
||
if (e.target === modal) {
|
||
hideModal();
|
||
}
|
||
});
|
||
|
||
setTimeout(() => {
|
||
renderPointsDiscountProducts();
|
||
renderDoublePointsProducts();
|
||
}, 500);
|
||
</script>
|
||
</body>
|
||
</html> |