| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679 |
- <!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", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; background: #f5f5f5; color: #333; padding: 16px; max-width: 480px; margin: 0 auto; }
- .page-title { text-align: center; font-size: 20px; font-weight: 700; margin: 12px 0 20px; color: #333; }
- /* Category Section */
- .category { background: #fff; border-radius: 12px; margin-bottom: 16px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
- .category-header { padding: 14px 16px; display: flex; align-items: center; gap: 10px; }
- .category-header .icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 18px; color: #fff; flex-shrink: 0; }
- .category-header .info h3 { font-size: 16px; font-weight: 600; }
- .category-header .info p { font-size: 12px; color: #999; margin-top: 2px; }
- .cat-order .icon { background: linear-gradient(135deg, #ff6b35, #ff4500); }
- .cat-item .icon { background: linear-gradient(135deg, #4facfe, #2196f3); }
- .cat-delivery .icon { background: linear-gradient(135deg, #43e97b, #38b249); }
- .cat-coupon .icon { background: linear-gradient(135deg, #fa709a, #e91e63); }
- /* Promo Card */
- .promo-card { padding: 12px 16px; border-top: 1px solid #f0f0f0; }
- .promo-card .promo-title { font-size: 14px; font-weight: 600; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
- .promo-card .promo-title .badge { font-size: 10px; padding: 1px 6px; border-radius: 3px; color: #fff; font-weight: 500; }
- .badge-auto { background: #ff6b35; }
- .badge-select { background: #2196f3; }
- .badge-manual { background: #e91e63; }
- .promo-card .promo-desc { font-size: 12px; color: #666; margin-bottom: 8px; line-height: 1.6; }
- .promo-card .example { background: #fff8f0; border-radius: 8px; padding: 10px 12px; font-size: 12px; }
- .cat-item .promo-card .example { background: #f0f7ff; }
- .cat-delivery .promo-card .example { background: #f0fff4; }
- .cat-coupon .promo-card .example { background: #fff0f5; }
- .example .label { color: #999; margin-bottom: 4px; }
- .example .calc { color: #333; line-height: 1.8; }
- .example .calc .price { color: #ff4500; font-weight: 600; }
- .example .calc .line-through { text-decoration: line-through; color: #999; }
- .example .calc .highlight { background: #fff3cd; padding: 0 3px; border-radius: 2px; }
- /* Interactive Demo */
- .demo-section { background: #fff; border-radius: 12px; margin-bottom: 16px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
- .demo-header { padding: 14px 16px; background: linear-gradient(135deg, #667eea, #764ba2); color: #fff; }
- .demo-header h3 { font-size: 16px; font-weight: 600; }
- .demo-header p { font-size: 12px; opacity: 0.8; margin-top: 2px; }
- /* Order Items */
- .order-items { padding: 12px 16px; }
- .order-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid #f5f5f5; font-size: 13px; }
- .order-item:last-child { border-bottom: none; }
- .order-item .name { flex: 1; }
- .order-item .item-price { color: #333; font-weight: 500; min-width: 60px; text-align: right; }
- .order-item .item-final { color: #ff4500; font-weight: 600; min-width: 60px; text-align: right; }
- .order-item .item-tag { font-size: 10px; padding: 1px 5px; border-radius: 3px; color: #fff; margin-left: 6px; }
- .item-tag-discount { background: #2196f3; }
- .item-tag-normal { background: #ccc; }
- /* Calculation Steps */
- .calc-steps { padding: 0 16px 16px; }
- .calc-step { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 13px; }
- .calc-step .step-label { color: #666; display: flex; align-items: center; gap: 6px; }
- .calc-step .step-label .step-icon { width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; color: #fff; flex-shrink: 0; }
- .step-order { background: #ff6b35; }
- .step-item { background: #2196f3; }
- .step-delivery { background: #43e97b; }
- .step-coupon { background: #e91e63; }
- .calc-step .step-value { font-weight: 500; }
- .step-minus { color: #ff4500; }
- .step-plus { color: #333; }
- .calc-divider { border-top: 1px dashed #ddd; margin: 6px 0; }
- .calc-total { display: flex; justify-content: space-between; padding: 8px 0; font-size: 16px; font-weight: 700; }
- .calc-total .total-price { color: #ff4500; }
- /* Toggle switches */
- .toggle-section { padding: 12px 16px; background: #fafafa; border-top: 1px solid #f0f0f0; }
- .toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: 13px; }
- .toggle-row .toggle-info { display: flex; align-items: center; gap: 6px; }
- .toggle-row .toggle-info .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
- .toggle { width: 44px; height: 24px; border-radius: 12px; background: #ddd; position: relative; cursor: pointer; transition: background 0.2s; flex-shrink: 0; }
- .toggle.active { background: #4facfe; }
- .toggle .knob { width: 20px; height: 20px; border-radius: 50%; background: #fff; position: absolute; top: 2px; left: 2px; transition: left 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
- .toggle.active .knob { left: 22px; }
- /* Tabs */
- .tabs { display: flex; border-bottom: 1px solid #f0f0f0; }
- .tab { flex: 1; text-align: center; padding: 12px 0; font-size: 14px; color: #999; cursor: pointer; position: relative; transition: color 0.2s; }
- .tab.active { color: #ff6b35; font-weight: 600; }
- .tab.active::after { content: ''; position: absolute; bottom: 0; left: 30%; right: 30%; height: 3px; background: #ff6b35; border-radius: 2px; }
- .tab-content { display: none; }
- .tab-content.active { display: block; }
- /* Stack diagram */
- .stack-diagram { padding: 16px; }
- .stack-bar { display: flex; align-items: center; margin-bottom: 8px; }
- .stack-bar .bar-label { width: 80px; font-size: 11px; color: #666; text-align: right; padding-right: 10px; flex-shrink: 0; }
- .stack-bar .bar-track { flex: 1; height: 28px; background: #f5f5f5; border-radius: 6px; position: relative; overflow: hidden; }
- .stack-bar .bar-fill { height: 100%; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 11px; color: #fff; font-weight: 600; transition: width 0.5s ease; }
- .bar-original { background: linear-gradient(90deg, #b0b0b0, #999); }
- .bar-promo { background: linear-gradient(90deg, #ff6b35, #ff4500); }
- .bar-discount { background: linear-gradient(90deg, #4facfe, #2196f3); }
- .bar-delivery { background: linear-gradient(90deg, #43e97b, #38b249); }
- .bar-coupon { background: linear-gradient(90deg, #fa709a, #e91e63); }
- .bar-final { background: linear-gradient(90deg, #667eea, #764ba2); }
- .note { font-size: 11px; color: #999; padding: 0 16px 12px; line-height: 1.6; }
- /* Exclusive table */
- .mutex-table { padding: 12px 16px; }
- .mutex-table table { width: 100%; border-collapse: collapse; font-size: 11px; }
- .mutex-table th { background: #f8f8f8; padding: 6px 4px; text-align: center; border: 1px solid #eee; font-weight: 600; color: #333; }
- .mutex-table td { padding: 6px 4px; text-align: center; border: 1px solid #eee; }
- .mutex-yes { color: #43e97b; font-weight: 700; }
- .mutex-no { color: #ff4500; font-weight: 700; }
- .mutex-self { color: #ccc; }
- </style>
- </head>
- <body>
- <div class="page-title">美团商家促销类型解析</div>
- <!-- Tabs -->
- <div class="category">
- <div class="tabs">
- <div class="tab active" onclick="switchTab('overview')">类型总览</div>
- <div class="tab" onclick="switchTab('demo')">算价演示</div>
- <div class="tab" onclick="switchTab('mutex')">互斥规则</div>
- </div>
- <!-- Tab 1: Overview -->
- <div id="tab-overview" class="tab-content active">
- <!-- Order Level -->
- <div class="category cat-order">
- <div class="category-header">
- <div class="icon">📦</div>
- <div class="info">
- <h3>订单级促销</h3>
- <p>作用在"订单总价"上</p>
- </div>
- </div>
- <div class="promo-card">
- <div class="promo-title">满减活动 <span class="badge badge-auto">自动生效</span></div>
- <div class="promo-desc">订单金额达到X元自动减免Y元,可设多档位。全场商品参与,不需要选商品。</div>
- <div class="example">
- <div class="label">📋 示例</div>
- <div class="calc">
- 满减档位:满20减5 / 满40减12 / 满60减20<br>
- 订单商品合计 <span class="price">¥45</span> → 命中"满40减12"<br>
- 实付商品金额 = 45 - 12 = <span class="price">¥33</span>
- </div>
- </div>
- </div>
- <div class="promo-card">
- <div class="promo-title">门店新客立减 <span class="badge badge-auto">自动生效</span></div>
- <div class="promo-desc">首次在本店下单的用户,订单总价直接减X元。仅限新客。</div>
- <div class="example">
- <div class="label">📋 示例</div>
- <div class="calc">
- 新客立减 <span class="price">¥3</span><br>
- 新客下单 ¥45 → 实付 = 45 - 3 = <span class="price">¥42</span>
- </div>
- </div>
- </div>
- </div>
- <!-- Item Level -->
- <div class="category cat-item">
- <div class="category-header">
- <div class="icon">🏷️</div>
- <div class="info">
- <h3>商品级促销</h3>
- <p>作用在"指定商品单价"上</p>
- </div>
- </div>
- <div class="promo-card">
- <div class="promo-title">折扣商品 <span class="badge badge-select">选商品</span></div>
- <div class="promo-desc">商家选择特定商品设折扣价。只有被选中的商品打折,其他商品原价。自动创建"折扣"专区。</div>
- <div class="example">
- <div class="label">📋 示例</div>
- <div class="calc">
- 宫保鸡丁 原价 <span class="line-through">¥20</span> → 7折 = <span class="price">¥14</span><br>
- 麻婆豆腐 原价 ¥18(未设折扣,原价)<br>
- 订单合计 = 14 + 18 = <span class="price">¥32</span>
- </div>
- </div>
- </div>
- <div class="promo-card">
- <div class="promo-title">第二份半价 <span class="badge badge-select">选商品</span></div>
- <div class="promo-desc">选择特定商品,买2件时第2件半价。按商品单独计算。</div>
- <div class="example">
- <div class="label">📋 示例</div>
- <div class="calc">
- 可乐 原价 ¥6,买2件<br>
- = 6 + 6×0.5 = <span class="price">¥9</span>(省¥3)<br>
- 不是对订单总价打折,是这1件商品的价格变了
- </div>
- </div>
- </div>
- <div class="promo-card">
- <div class="promo-title">爆品特价 <span class="badge badge-select">选商品</span></div>
- <div class="promo-desc">选择特定商品设超低特价引流,可与满减/折扣同享(独特优势)。</div>
- <div class="example">
- <div class="label">📋 示例</div>
- <div class="calc">
- 招牌鸡腿饭 原价 <span class="line-through">¥25</span> → 爆品价 <span class="price">¥9.9</span><br>
- 爆品价 ¥9.9 仍然计入满减的订单金额
- </div>
- </div>
- </div>
- </div>
- <!-- Delivery Level -->
- <div class="category cat-delivery">
- <div class="category-header">
- <div class="icon">🛵</div>
- <div class="info">
- <h3>配送费级促销</h3>
- <p>作用在"配送费"上</p>
- </div>
- </div>
- <div class="promo-card">
- <div class="promo-title">减配送费 <span class="badge badge-auto">自动生效</span></div>
- <div class="promo-desc">商家固定补贴X元配送费,所有用户自动享受。</div>
- <div class="example">
- <div class="label">📋 示例</div>
- <div class="calc">
- 配送费 ¥5 → 商家补贴 ¥2 → 用户付 <span class="price">¥3</span><br>
- 与商品价格无关,只扣配送费
- </div>
- </div>
- </div>
- <div class="promo-card">
- <div class="promo-title">满减运费 <span class="badge badge-auto">自动生效</span></div>
- <div class="promo-desc">订单金额满X元免配送费。与"减配送费"互斥二选一。</div>
- <div class="example">
- <div class="label">📋 示例</div>
- <div class="calc">
- 满30元免配送费<br>
- 订单 ¥35 → 配送费 <span class="price">¥0</span><br>
- 订单 ¥25 → 配送费 ¥5(未达标)
- </div>
- </div>
- </div>
- </div>
- <!-- Coupon Level -->
- <div class="category cat-coupon">
- <div class="category-header">
- <div class="icon">🎫</div>
- <div class="info">
- <h3>优惠券类(商家券)</h3>
- <p>用户需先领券,下单时手动选择使用</p>
- </div>
- </div>
- <div class="promo-card">
- <div class="promo-title">满减券 <span class="badge badge-manual">用户选券</span></div>
- <div class="promo-desc">分"同享券"(可与满减叠加)和"互斥券"(不可与满减/折扣叠加)。作用在订单总价上。</div>
- <div class="example">
- <div class="label">📋 示例</div>
- <div class="calc">
- 满30减5元券(同享券)<br>
- 满减后 ¥33 → 再扣券 → <span class="price">¥28</span>
- </div>
- </div>
- </div>
- <div class="promo-card">
- <div class="promo-title">商品券 <span class="badge badge-manual">用户选券</span></div>
- <div class="promo-desc">只能用于指定商品。分"折扣券"(指定商品X折)和"抵用券"(指定商品免费兑换)。</div>
- <div class="example">
- <div class="label">📋 示例</div>
- <div class="calc">
- 抵用券:免费兑换1杯可乐(原价¥6)<br>
- 折扣券:宫保鸡丁5折券(¥20 → <span class="price">¥10</span>)
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- Tab 2: Demo -->
- <div id="tab-demo" class="tab-content">
- <div class="demo-section">
- <div class="demo-header">
- <h3>💰 算价演示</h3>
- <p>开启/关闭不同促销,看价格怎么变</p>
- </div>
- <div class="toggle-section">
- <div class="toggle-row">
- <div class="toggle-info">
- <div class="dot" style="background:#ff6b35"></div>
- <span>满减(满40减12)</span>
- </div>
- <div class="toggle active" onclick="toggle(this, 'manjian')"><div class="knob"></div></div>
- </div>
- <div class="toggle-row">
- <div class="toggle-info">
- <div class="dot" style="background:#2196f3"></div>
- <span>折扣(宫保鸡丁7折)</span>
- </div>
- <div class="toggle" onclick="toggle(this, 'zhekou')"><div class="knob"></div></div>
- </div>
- <div class="toggle-row">
- <div class="toggle-info">
- <div class="dot" style="background:#43e97b"></div>
- <span>减配送费(减¥2)</span>
- </div>
- <div class="toggle active" onclick="toggle(this, 'delivery')"><div class="knob"></div></div>
- </div>
- <div class="toggle-row">
- <div class="toggle-info">
- <div class="dot" style="background:#e91e63"></div>
- <span>商家满减券(满30减5)</span>
- </div>
- <div class="toggle active" onclick="toggle(this, 'coupon')"><div class="knob"></div></div>
- </div>
- </div>
- <div class="order-items">
- <div class="order-item">
- <span class="name">🍗 宫保鸡丁</span>
- <span class="item-price" id="item1-price">¥20</span>
- <span class="item-final" id="item1-final">¥20</span>
- <span class="item-tag item-tag-normal" id="item1-tag">原价</span>
- </div>
- <div class="order-item">
- <span class="name">🥘 麻婆豆腐</span>
- <span class="item-price">¥18</span>
- <span class="item-final">¥18</span>
- </div>
- <div class="order-item">
- <span class="name">🥤 可乐×2</span>
- <span class="item-price">¥12</span>
- <span class="item-final">¥12</span>
- </div>
- <div class="order-item">
- <span class="name">📦 餐盒费</span>
- <span class="item-price">¥3</span>
- <span class="item-final">¥3</span>
- </div>
- </div>
- <div class="calc-steps">
- <div class="calc-step">
- <span class="step-label"><span class="step-icon step-order">📦</span> 商品原价合计</span>
- <span class="step-value" id="step-original">¥53</span>
- </div>
- <div class="calc-step" id="row-zhekou">
- <span class="step-label"><span class="step-icon step-item">🏷️</span> 折扣(宫保鸡丁7折)</span>
- <span class="step-value step-minus" id="step-zhekou">—</span>
- </div>
- <div class="calc-step" id="row-discount-subtotal">
- <span class="step-label" style="color:#999; font-size:12px;"> 折扣后小计</span>
- <span class="step-value" id="step-discount-subtotal" style="color:#999; font-size:12px;">—</span>
- </div>
- <div class="calc-step" id="row-manjian">
- <span class="step-label"><span class="step-icon step-order">📦</span> 满减(满40减12)</span>
- <span class="step-value step-minus" id="step-manjian">-¥12</span>
- </div>
- <div class="calc-step" id="row-coupon">
- <span class="step-label"><span class="step-icon step-coupon">🎫</span> 商家满减券(满30减5)</span>
- <span class="step-value step-minus" id="step-coupon">-¥5</span>
- </div>
- <div class="calc-divider"></div>
- <div class="calc-step">
- <span class="step-label">商品实付</span>
- <span class="step-value" id="step-item-total">¥36</span>
- </div>
- <div class="calc-step" id="row-delivery">
- <span class="step-label"><span class="step-icon step-delivery">🛵</span> 配送费(原¥5,减¥2)</span>
- <span class="step-value step-plus" id="step-delivery">+¥3</span>
- </div>
- <div class="calc-divider"></div>
- <div class="calc-total">
- <span>实付金额</span>
- <span class="total-price" id="step-total">¥39</span>
- </div>
- </div>
- </div>
- <!-- Stack Diagram -->
- <div class="category">
- <div class="category-header">
- <div class="icon">📊</div>
- <div class="info">
- <h3>价格叠加图</h3>
- <p>各层级优惠怎么从原价扣到实付</p>
- </div>
- </div>
- <div class="stack-diagram">
- <div class="stack-bar">
- <span class="bar-label">商品原价</span>
- <div class="bar-track"><div class="bar-fill bar-original" id="bar-original" style="width:100%">¥53</div></div>
- </div>
- <div class="stack-bar" id="bar-zhekou-row">
- <span class="bar-label">商品折扣</span>
- <div class="bar-track"><div class="bar-fill bar-discount" id="bar-zhekou" style="width:0%"></div></div>
- </div>
- <div class="stack-bar" id="bar-manjian-row">
- <span class="bar-label">订单满减</span>
- <div class="bar-track"><div class="bar-fill bar-promo" id="bar-manjian" style="width:22%">-¥12</div></div>
- </div>
- <div class="stack-bar" id="bar-coupon-row">
- <span class="bar-label">商家券</span>
- <div class="bar-track"><div class="bar-fill bar-coupon" id="bar-coupon" style="width:9%">-¥5</div></div>
- </div>
- <div class="stack-bar" id="bar-delivery-row">
- <span class="bar-label">配送费</span>
- <div class="bar-track"><div class="bar-fill bar-delivery" id="bar-delivery" style="width:5%">+¥3</div></div>
- </div>
- <div class="stack-bar">
- <span class="bar-label" style="font-weight:700;">实付</span>
- <div class="bar-track"><div class="bar-fill bar-final" id="bar-final" style="width:73%">¥39</div></div>
- </div>
- </div>
- <div class="note">
- 💡 每一层作用在不同的价格基础上:商品折扣改单价 → 满减看折后订单总额 → 券再扣 → 配送费单独加
- </div>
- </div>
- </div>
- <!-- Tab 3: Mutex -->
- <div id="tab-mutex" class="tab-content">
- <div class="category">
- <div class="category-header">
- <div class="icon">⚠️</div>
- <div class="info">
- <h3>互斥规则</h3>
- <p>哪些促销不能同时使用</p>
- </div>
- </div>
- <div class="mutex-table">
- <table>
- <tr>
- <th></th>
- <th>满减</th>
- <th>折扣</th>
- <th>第二份<br>半价</th>
- <th>新客<br>立减</th>
- <th>减配<br>送费</th>
- <th>满减<br>运费</th>
- </tr>
- <tr>
- <th>满减</th>
- <td class="mutex-self">—</td>
- <td class="mutex-no">✗</td>
- <td class="mutex-no">✗</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- </tr>
- <tr>
- <th>折扣</th>
- <td class="mutex-no">✗</td>
- <td class="mutex-self">—</td>
- <td class="mutex-no">✗</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- </tr>
- <tr>
- <th>第二份半价</th>
- <td class="mutex-no">✗</td>
- <td class="mutex-no">✗</td>
- <td class="mutex-self">—</td>
- <td class="mutex-no">✗</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- </tr>
- <tr>
- <th>新客立减</th>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-no">✗</td>
- <td class="mutex-self">—</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- </tr>
- <tr>
- <th>减配送费</th>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-self">—</td>
- <td class="mutex-no">✗</td>
- </tr>
- <tr>
- <th>满减运费</th>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-yes">✓</td>
- <td class="mutex-no">✗</td>
- <td class="mutex-self">—</td>
- </tr>
- </table>
- </div>
- <div class="note">
- ✓ = 可同时使用 ✗ = 互斥不可同时使用<br><br>
- 💡 核心互斥链:满减 ↔ 折扣 ↔ 第二份半价(三选一)<br>
- 💡 配送费互斥:减配送费 ↔ 满减运费(二选一)<br>
- 💡 满赠、售卖代金券、下单返券与所有活动同享
- </div>
- </div>
- </div>
- </div>
- <script>
- // State
- const state = {
- manjian: true,
- zhekou: false,
- delivery: true,
- coupon: true
- };
- // Prices
- const ORIGINAL_PRICE = { chicken: 20, tofu: 18, cola: 12, box: 3 }; // cola = 6*2
- const DELIVERY_FEE = 5;
- const MANJIAN_THRESHOLD = 40;
- const MANJIAN_AMOUNT = 12;
- const ZHEKOU_RATE = 0.7;
- const DELIVERY_DISCOUNT = 2;
- const COUPON_THRESHOLD = 30;
- const COUPON_AMOUNT = 5;
- function toggle(el, key) {
- // 满减和折扣互斥
- if (key === 'manjian' && !state.manjian) {
- state.zhekou = false;
- document.querySelectorAll('.toggle')[1].classList.remove('active');
- }
- if (key === 'zhekou' && !state.zhekou) {
- state.manjian = false;
- document.querySelectorAll('.toggle')[0].classList.remove('active');
- }
- state[key] = !state[key];
- el.classList.toggle('active');
- recalculate();
- }
- function recalculate() {
- let chicken = ORIGINAL_PRICE.chicken;
- let itemDiscount = 0;
- // 折扣
- if (state.zhekou) {
- chicken = Math.round(ORIGINAL_PRICE.chicken * ZHEKOU_RATE * 10) / 10;
- itemDiscount = ORIGINAL_PRICE.chicken - chicken;
- document.getElementById('item1-final').textContent = '¥' + chicken;
- document.getElementById('item1-tag').textContent = '7折';
- document.getElementById('item1-tag').className = 'item-tag item-tag-discount';
- } else {
- document.getElementById('item1-final').textContent = '¥' + ORIGINAL_PRICE.chicken;
- document.getElementById('item1-tag').textContent = '原价';
- document.getElementById('item1-tag').className = 'item-tag item-tag-normal';
- }
- let subtotal = chicken + ORIGINAL_PRICE.tofu + ORIGINAL_PRICE.cola + ORIGINAL_PRICE.box;
- // 满减
- let manjianAmount = 0;
- if (state.manjian && subtotal >= MANJIAN_THRESHOLD) {
- manjianAmount = MANJIAN_AMOUNT;
- }
- // 券
- let couponAmount = 0;
- let afterManjian = subtotal - manjianAmount;
- if (state.coupon && afterManjian >= COUPON_THRESHOLD) {
- couponAmount = COUPON_AMOUNT;
- }
- let itemTotal = subtotal - manjianAmount - couponAmount;
- // 配送费
- let deliveryPay = DELIVERY_FEE;
- if (state.delivery) {
- deliveryPay = DELIVERY_FEE - DELIVERY_DISCOUNT;
- }
- let total = itemTotal + deliveryPay;
- // Update UI
- document.getElementById('step-original').textContent = '¥' + ORIGINAL_PRICE.chicken;
- if (state.zhekou) {
- document.getElementById('row-zhekou').style.display = 'flex';
- document.getElementById('row-discount-subtotal').style.display = 'flex';
- document.getElementById('step-zhekou').textContent = '-¥' + itemDiscount.toFixed(1);
- document.getElementById('step-discount-subtotal').textContent = '¥' + subtotal;
- document.getElementById('step-original').textContent = '¥' + (ORIGINAL_PRICE.chicken + ORIGINAL_PRICE.tofu + ORIGINAL_PRICE.cola + ORIGINAL_PRICE.box);
- } else {
- document.getElementById('row-zhekou').style.display = 'none';
- document.getElementById('row-discount-subtotal').style.display = 'none';
- }
- if (state.manjian && manjianAmount > 0) {
- document.getElementById('row-manjian').style.display = 'flex';
- document.getElementById('step-manjian').textContent = '-¥' + manjianAmount;
- } else {
- document.getElementById('row-manjian').style.display = state.manjian ? 'flex' : 'none';
- document.getElementById('step-manjian').textContent = state.manjian ? '未达到¥' + MANJIAN_THRESHOLD : '';
- document.getElementById('step-manjian').style.color = state.manjian && manjianAmount === 0 ? '#999' : '#ff4500';
- }
- if (state.coupon) {
- document.getElementById('row-coupon').style.display = 'flex';
- document.getElementById('step-coupon').textContent = couponAmount > 0 ? '-¥' + couponAmount : '未达到¥' + COUPON_THRESHOLD;
- document.getElementById('step-coupon').style.color = couponAmount > 0 ? '#ff4500' : '#999';
- } else {
- document.getElementById('row-coupon').style.display = 'none';
- }
- document.getElementById('step-item-total').textContent = '¥' + itemTotal;
- if (state.delivery) {
- document.getElementById('row-delivery').style.display = 'flex';
- document.getElementById('step-delivery').textContent = '+¥' + deliveryPay + '(原¥' + DELIVERY_FEE + ')';
- } else {
- document.getElementById('row-delivery').style.display = 'flex';
- document.getElementById('step-delivery').textContent = '+¥' + DELIVERY_FEE;
- }
- document.getElementById('step-total').textContent = '¥' + total;
- // Update bars
- let maxVal = ORIGINAL_PRICE.chicken + ORIGINAL_PRICE.tofu + ORIGINAL_PRICE.cola + ORIGINAL_PRICE.box + DELIVERY_FEE;
- document.getElementById('bar-original').style.width = ((subtotal + itemDiscount) / maxVal * 100) + '%';
- document.getElementById('bar-original').textContent = '¥' + (subtotal + itemDiscount);
- if (state.zhekou) {
- document.getElementById('bar-zhekou-row').style.display = 'flex';
- document.getElementById('bar-zhekou').style.width = (itemDiscount / maxVal * 100) + '%';
- document.getElementById('bar-zhekou').textContent = '-¥' + itemDiscount.toFixed(1);
- } else {
- document.getElementById('bar-zhekou-row').style.display = 'none';
- }
- if (state.manjian && manjianAmount > 0) {
- document.getElementById('bar-manjian-row').style.display = 'flex';
- document.getElementById('bar-manjian').style.width = (manjianAmount / maxVal * 100) + '%';
- document.getElementById('bar-manjian').textContent = '-¥' + manjianAmount;
- } else {
- document.getElementById('bar-manjian-row').style.display = 'none';
- }
- if (state.coupon && couponAmount > 0) {
- document.getElementById('bar-coupon-row').style.display = 'flex';
- document.getElementById('bar-coupon').style.width = (couponAmount / maxVal * 100) + '%';
- document.getElementById('bar-coupon').textContent = '-¥' + couponAmount;
- } else {
- document.getElementById('bar-coupon-row').style.display = 'none';
- }
- document.getElementById('bar-delivery').style.width = (deliveryPay / maxVal * 100) + '%';
- document.getElementById('bar-delivery').textContent = '+¥' + deliveryPay;
- document.getElementById('bar-final').style.width = (total / maxVal * 100) + '%';
- document.getElementById('bar-final').textContent = '¥' + total;
- }
- function switchTab(name) {
- document.querySelectorAll('.tab').forEach((t, i) => {
- t.classList.toggle('active', ['overview', 'demo', 'mutex'][i] === name);
- });
- document.querySelectorAll('.tab-content').forEach(tc => tc.classList.remove('active'));
- document.getElementById('tab-' + name).classList.add('active');
- }
- // Init
- recalculate();
- </script>
- </body>
- </html>
|