merchant-promotion-ui-demo.html 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>商家促销管理 - 操作演示</title>
  7. <style>
  8. * { margin: 0; padding: 0; box-sizing: border-box; }
  9. body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background: #f0f2f5; color: #333; }
  10. /* Layout */
  11. .app { max-width: 900px; margin: 0 auto; min-height: 100vh; }
  12. .header { background: #fff; padding: 16px 20px; border-bottom: 1px solid #e8e8e8; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 100; }
  13. .header h1 { font-size: 18px; font-weight: 600; }
  14. .header .store-name { font-size: 13px; color: #999; }
  15. /* Content */
  16. .content { padding: 16px; }
  17. /* Button */
  18. .btn { padding: 8px 20px; border-radius: 6px; border: none; cursor: pointer; font-size: 14px; font-weight: 500; transition: all 0.2s; }
  19. .btn-primary { background: #ff6b35; color: #fff; }
  20. .btn-primary:hover { background: #e55a2b; }
  21. .btn-default { background: #fff; color: #666; border: 1px solid #d9d9d9; }
  22. .btn-default:hover { border-color: #ff6b35; color: #ff6b35; }
  23. .btn-danger { background: #fff; color: #ff4d4f; border: 1px solid #ff4d4f; }
  24. .btn-danger:hover { background: #fff1f0; }
  25. .btn-sm { padding: 4px 12px; font-size: 12px; }
  26. .btn:disabled { opacity: 0.5; cursor: not-allowed; }
  27. /* Card */
  28. .card { background: #fff; border-radius: 8px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
  29. .card-header { padding: 14px 16px; border-bottom: 1px solid #f0f0f0; display: flex; justify-content: space-between; align-items: center; }
  30. .card-header h3 { font-size: 15px; font-weight: 600; }
  31. .card-body { padding: 16px; }
  32. /* Status Tags */
  33. .tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; }
  34. .tag-active { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
  35. .tag-pending { background: #fff7e6; color: #fa8c16; border: 1px solid #ffd591; }
  36. .tag-expired { background: #f5f5f5; color: #999; border: 1px solid #d9d9d9; }
  37. /* Promotion List Item */
  38. .promo-item { padding: 14px 16px; border-bottom: 1px solid #f5f5f5; display: flex; justify-content: space-between; align-items: center; }
  39. .promo-item:last-child { border-bottom: none; }
  40. .promo-info { flex: 1; }
  41. .promo-info .name { font-size: 14px; font-weight: 500; margin-bottom: 4px; }
  42. .promo-info .detail { font-size: 12px; color: #999; }
  43. .promo-info .detail span { margin-right: 12px; }
  44. .promo-type-icon { display: inline-block; width: 22px; height: 22px; border-radius: 4px; text-align: center; line-height: 22px; font-size: 12px; color: #fff; margin-right: 6px; vertical-align: middle; }
  45. .type-manjian { background: #ff6b35; }
  46. .type-zhekou { background: #2196f3; }
  47. .type-ban { background: #9c27b0; }
  48. .type-xinke { background: #43e97b; }
  49. /* Modal / Drawer */
  50. .drawer-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); z-index: 200; display: none; }
  51. .drawer-overlay.show { display: block; }
  52. .drawer { position: fixed; right: -600px; top: 0; bottom: 0; width: 580px; max-width: 100%; background: #fff; z-index: 201; transition: right 0.3s ease; display: flex; flex-direction: column; }
  53. .drawer.show { right: 0; }
  54. .drawer-header { padding: 16px 20px; border-bottom: 1px solid #e8e8e8; display: flex; justify-content: space-between; align-items: center; }
  55. .drawer-header h2 { font-size: 17px; font-weight: 600; }
  56. .drawer-close { font-size: 20px; cursor: pointer; color: #999; background: none; border: none; padding: 4px; }
  57. .drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
  58. .drawer-footer { padding: 14px 20px; border-top: 1px solid #e8e8e8; display: flex; justify-content: flex-end; gap: 10px; }
  59. /* Form */
  60. .form-group { margin-bottom: 20px; }
  61. .form-label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 8px; color: #333; }
  62. .form-label .required { color: #ff4d4f; margin-right: 2px; }
  63. .form-hint { font-size: 12px; color: #999; margin-top: 4px; }
  64. .form-input { width: 100%; padding: 8px 12px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 14px; outline: none; transition: border-color 0.2s; }
  65. .form-input:focus { border-color: #ff6b35; box-shadow: 0 0 0 2px rgba(255,107,53,0.1); }
  66. /* Type Selector */
  67. .type-selector { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
  68. .type-card { border: 2px solid #e8e8e8; border-radius: 8px; padding: 14px 10px; text-align: center; cursor: pointer; transition: all 0.2s; }
  69. .type-card:hover { border-color: #ff6b35; }
  70. .type-card.selected { border-color: #ff6b35; background: #fff8f0; }
  71. .type-card .icon { font-size: 24px; margin-bottom: 6px; }
  72. .type-card .label { font-size: 13px; font-weight: 500; }
  73. .type-card .desc { font-size: 11px; color: #999; margin-top: 2px; }
  74. .type-card.disabled { opacity: 0.4; cursor: not-allowed; position: relative; }
  75. .type-card.disabled::after { content: '已互斥'; position: absolute; top: 4px; right: 4px; font-size: 10px; background: #ff4d4f; color: #fff; padding: 1px 5px; border-radius: 3px; }
  76. /* Tiers (满减) */
  77. .tier-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
  78. .tier-row .tier-text { font-size: 14px; color: #666; white-space: nowrap; }
  79. .tier-input { width: 80px; padding: 6px 10px; border: 1px solid #d9d9d9; border-radius: 4px; font-size: 14px; text-align: center; outline: none; }
  80. .tier-input:focus { border-color: #ff6b35; }
  81. .tier-remove { cursor: pointer; color: #ff4d4f; font-size: 18px; background: none; border: none; padding: 2px 6px; }
  82. .add-tier { color: #ff6b35; cursor: pointer; font-size: 13px; background: none; border: none; padding: 4px 0; }
  83. .add-tier:hover { text-decoration: underline; }
  84. /* Product Selector */
  85. .product-select-area { border: 1px solid #e8e8e8; border-radius: 8px; overflow: hidden; }
  86. .product-search { padding: 10px 12px; border-bottom: 1px solid #f0f0f0; }
  87. .product-search input { width: 100%; border: none; outline: none; font-size: 13px; padding: 4px 0; }
  88. .product-list { max-height: 320px; overflow-y: auto; }
  89. .product-item { display: flex; align-items: center; padding: 10px 12px; border-bottom: 1px solid #f5f5f5; transition: background 0.15s; }
  90. .product-item:hover { background: #fafafa; }
  91. .product-item.selected { background: #fff8f0; }
  92. .product-check { width: 18px; height: 18px; border-radius: 3px; border: 1px solid #d9d9d9; margin-right: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all 0.15s; }
  93. .product-item.selected .product-check { background: #ff6b35; border-color: #ff6b35; }
  94. .product-check::after { content: '✓'; color: #fff; font-size: 12px; font-weight: 700; display: none; }
  95. .product-item.selected .product-check::after { display: block; }
  96. .product-img { width: 40px; height: 40px; border-radius: 4px; background: #f5f5f5; margin-right: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
  97. .product-meta { flex: 1; min-width: 0; }
  98. .product-meta .pname { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  99. .product-meta .pprice { font-size: 12px; color: #999; }
  100. .product-rate { width: 72px; text-align: center; }
  101. .product-rate input { width: 52px; padding: 4px 6px; border: 1px solid #d9d9d9; border-radius: 4px; font-size: 13px; text-align: center; outline: none; }
  102. .product-rate input:focus { border-color: #ff6b35; }
  103. .product-rate span { font-size: 11px; color: #999; }
  104. .product-result { display: inline-block; padding: 2px 8px; background: #fff2e8; border-radius: 4px; font-size: 12px; color: #ff6b35; font-weight: 500; min-width: 50px; text-align: center; }
  105. /* Selected summary */
  106. .selected-summary { margin-top: 12px; padding: 12px; background: #fafafa; border-radius: 6px; }
  107. .selected-summary .title { font-size: 13px; font-weight: 500; margin-bottom: 8px; color: #666; }
  108. .selected-item { display: flex; align-items: center; padding: 6px 0; font-size: 13px; }
  109. .selected-item .sname { flex: 1; }
  110. .selected-item .srate { color: #ff6b35; font-weight: 500; margin-right: 8px; }
  111. .selected-item .sresult { color: #666; }
  112. .selected-item .sremove { color: #ff4d4f; cursor: pointer; margin-left: 8px; }
  113. /* Mutex Warning */
  114. .mutex-warning { background: #fff7e6; border: 1px solid #ffd591; border-radius: 6px; padding: 10px 14px; margin-bottom: 16px; display: flex; align-items: flex-start; gap: 8px; }
  115. .mutex-warning .icon { font-size: 16px; flex-shrink: 0; }
  116. .mutex-warning .text { font-size: 13px; color: #ad6800; line-height: 1.6; }
  117. /* Step indicator */
  118. .steps { display: flex; margin-bottom: 20px; }
  119. .step { flex: 1; text-align: center; position: relative; }
  120. .step .step-dot { width: 28px; height: 28px; border-radius: 50%; background: #e8e8e8; color: #999; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
  121. .step.active .step-dot { background: #ff6b35; color: #fff; }
  122. .step.done .step-dot { background: #52c41a; color: #fff; }
  123. .step .step-label { font-size: 12px; color: #999; display: block; }
  124. .step.active .step-label { color: #ff6b35; font-weight: 500; }
  125. .step::after { content: ''; position: absolute; top: 14px; left: 55%; right: -45%; height: 2px; background: #e8e8e8; }
  126. .step:last-child::after { display: none; }
  127. .step.done::after { background: #52c41a; }
  128. /* Empty state */
  129. .empty { text-align: center; padding: 40px 20px; color: #999; }
  130. .empty .icon { font-size: 48px; margin-bottom: 12px; }
  131. .empty p { font-size: 14px; margin-bottom: 16px; }
  132. /* Toast */
  133. .toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background: #52c41a; color: #fff; padding: 10px 24px; border-radius: 6px; font-size: 14px; z-index: 300; display: none; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
  134. .toast.show { display: block; animation: fadeInOut 2s ease; }
  135. @keyframes fadeInOut { 0% { opacity: 0; transform: translateX(-50%) translateY(-10px); } 15% { opacity: 1; transform: translateX(-50%) translateY(0); } 80% { opacity: 1; } 100% { opacity: 0; } }
  136. /* Tabs */
  137. .tabs { display: flex; border-bottom: 2px solid #f0f0f0; margin-bottom: 16px; }
  138. .tab-btn { padding: 10px 20px; font-size: 14px; color: #666; cursor: pointer; border: none; background: none; position: relative; font-weight: 500; }
  139. .tab-btn.active { color: #ff6b35; }
  140. .tab-btn.active::after { content: ''; position: absolute; bottom: -2px; left: 0; right: 0; height: 2px; background: #ff6b35; }
  141. .tab-panel { display: none; }
  142. .tab-panel.active { display: block; }
  143. /* Coupon batch card */
  144. .coupon-card { border: 1px solid #e8e8e8; border-radius: 8px; padding: 14px 16px; margin-bottom: 10px; position: relative; }
  145. .coupon-card::before { content: ''; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; background: #ff6b35; border-radius: 0 2px 2px 0; }
  146. .coupon-card .coupon-name { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
  147. .coupon-card .coupon-info { font-size: 12px; color: #999; display: flex; gap: 16px; }
  148. .coupon-card .coupon-stock { margin-top: 8px; }
  149. .stock-bar { height: 4px; background: #f0f0f0; border-radius: 2px; margin-top: 4px; }
  150. .stock-fill { height: 100%; background: #ff6b35; border-radius: 2px; transition: width 0.3s; }
  151. /* Divider */
  152. .divider { border: none; border-top: 1px dashed #e8e8e8; margin: 16px 0; }
  153. </style>
  154. </head>
  155. <body>
  156. <div class="app">
  157. <div class="header">
  158. <div>
  159. <h1>营销管理</h1>
  160. <span class="store-name">🍔 好味道快餐店</span>
  161. </div>
  162. <button class="btn btn-primary" onclick="openDrawer('promotion')">+ 创建促销活动</button>
  163. </div>
  164. <div class="content">
  165. <!-- Tabs -->
  166. <div class="tabs">
  167. <button class="tab-btn active" onclick="switchMainTab('promotions')">促销活动</button>
  168. <button class="tab-btn" onclick="switchMainTab('coupons')">优惠券管理</button>
  169. </div>
  170. <!-- Promotions Tab -->
  171. <div id="panel-promotions" class="tab-panel active">
  172. <div class="mutex-warning">
  173. <span class="icon">⚠️</span>
  174. <div class="text">
  175. <strong>互斥规则:</strong>满减、折扣商品、第二份半价三种活动同一时间只能开启一种。新客立减可与以上任意一种叠加使用。
  176. </div>
  177. </div>
  178. <div class="card">
  179. <div class="card-header">
  180. <h3>活动列表</h3>
  181. </div>
  182. <div id="promo-list">
  183. <div class="promo-item">
  184. <div class="promo-info">
  185. <div class="name"><span class="promo-type-icon type-manjian">减</span> 全场满减</div>
  186. <div class="detail"><span>满20减5 / 满40减12 / 满60减20</span><span>2026-06-01 ~ 2026-06-30</span></div>
  187. </div>
  188. <div style="display:flex;align-items:center;gap:8px;">
  189. <span class="tag tag-active">进行中</span>
  190. <button class="btn btn-sm btn-danger" onclick="endPromo(this)">结束</button>
  191. </div>
  192. </div>
  193. <div class="promo-item">
  194. <div class="promo-info">
  195. <div class="name"><span class="promo-type-icon type-xinke">新</span> 新客立减</div>
  196. <div class="detail"><span>新客立减3元</span><span>2026-06-01 ~ 2026-06-30</span></div>
  197. </div>
  198. <div style="display:flex;align-items:center;gap:8px;">
  199. <span class="tag tag-active">进行中</span>
  200. <button class="btn btn-sm btn-danger" onclick="endPromo(this)">结束</button>
  201. </div>
  202. </div>
  203. </div>
  204. </div>
  205. <div class="card">
  206. <div class="card-header"><h3>已结束活动</h3></div>
  207. <div>
  208. <div class="promo-item" style="opacity:0.5">
  209. <div class="promo-info">
  210. <div class="name"><span class="promo-type-icon type-zhekou">折</span> 夏日折扣</div>
  211. <div class="detail"><span>3个商品参加折扣</span><span>2026-05-01 ~ 2026-05-15</span></div>
  212. </div>
  213. <span class="tag tag-expired">已结束</span>
  214. </div>
  215. </div>
  216. </div>
  217. </div>
  218. <!-- Coupons Tab -->
  219. <div id="panel-coupons" class="tab-panel">
  220. <div class="card">
  221. <div class="card-header">
  222. <h3>优惠券列表</h3>
  223. <button class="btn btn-primary btn-sm" onclick="openDrawer('coupon')">+ 创建优惠券</button>
  224. </div>
  225. <div id="coupon-list">
  226. <div class="coupon-card">
  227. <div class="coupon-name">满30减5优惠券(同享券)</div>
  228. <div class="coupon-info">
  229. <span>满减券 / 同享</span>
  230. <span>有效期 7天</span>
  231. <span>已领 45/100</span>
  232. </div>
  233. <div class="coupon-stock">
  234. <div class="stock-bar"><div class="stock-fill" style="width:45%"></div></div>
  235. </div>
  236. </div>
  237. <div class="coupon-card">
  238. <div class="coupon-name">宫保鸡丁5折券</div>
  239. <div class="coupon-info">
  240. <span>商品券 / 折扣券</span>
  241. <span>有效期 30天</span>
  242. <span>已领 23/50</span>
  243. </div>
  244. <div class="coupon-stock">
  245. <div class="stock-bar"><div class="stock-fill" style="width:46%"></div></div>
  246. </div>
  247. </div>
  248. </div>
  249. </div>
  250. </div>
  251. </div>
  252. </div>
  253. <!-- Drawer Overlay -->
  254. <div class="drawer-overlay" id="drawer-overlay" onclick="closeDrawer()"></div>
  255. <!-- Drawer -->
  256. <div class="drawer" id="drawer">
  257. <div class="drawer-header">
  258. <h2 id="drawer-title">创建促销活动</h2>
  259. <button class="drawer-close" onclick="closeDrawer()">✕</button>
  260. </div>
  261. <div class="drawer-body" id="drawer-body">
  262. <!-- Dynamic content -->
  263. </div>
  264. <div class="drawer-footer" id="drawer-footer">
  265. <button class="btn btn-default" onclick="closeDrawer()">取消</button>
  266. <button class="btn btn-primary" id="drawer-confirm" onclick="confirmCreate()">确认创建</button>
  267. </div>
  268. </div>
  269. <!-- Toast -->
  270. <div class="toast" id="toast"></div>
  271. <script>
  272. // Products data
  273. const products = [
  274. { id: 1, name: '宫保鸡丁', price: 20, emoji: '🍗' },
  275. { id: 2, name: '麻婆豆腐', price: 18, emoji: '🥘' },
  276. { id: 3, name: '可乐', price: 6, emoji: '🥤' },
  277. { id: 4, name: '雪碧', price: 6, emoji: '🧊' },
  278. { id: 5, name: '薯条', price: 8, emoji: '🍟' },
  279. { id: 6, name: '鸡腿饭', price: 25, emoji: '🍚' },
  280. { id: 7, name: '酸辣汤', price: 12, emoji: '🍲' },
  281. { id: 8, name: '鸡蛋炒饭', price: 15, emoji: '🍳' },
  282. { id: 9, name: '红烧肉', price: 28, emoji: '🥩' },
  283. { id: 10, name: '青菜', price: 10, emoji: '🥬' },
  284. ];
  285. let currentType = null;
  286. let selectedProducts = {};
  287. let drawerMode = '';
  288. function switchMainTab(name) {
  289. document.querySelectorAll('.tab-btn').forEach((b, i) => b.classList.toggle('active', ['promotions','coupons'][i] === name));
  290. document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
  291. document.getElementById('panel-' + name).classList.add('active');
  292. }
  293. function openDrawer(mode) {
  294. drawerMode = mode;
  295. currentType = null;
  296. selectedProducts = {};
  297. document.getElementById('drawer-overlay').classList.add('show');
  298. document.getElementById('drawer').classList.add('show');
  299. document.getElementById('drawer-title').textContent = mode === 'promotion' ? '创建促销活动' : '创建优惠券';
  300. renderDrawerContent();
  301. }
  302. function closeDrawer() {
  303. document.getElementById('drawer-overlay').classList.remove('show');
  304. document.getElementById('drawer').classList.remove('show');
  305. }
  306. function renderDrawerContent() {
  307. const body = document.getElementById('drawer-body');
  308. if (drawerMode === 'promotion') {
  309. renderPromotionForm(body);
  310. } else {
  311. renderCouponForm(body);
  312. }
  313. }
  314. function renderPromotionForm(body) {
  315. body.innerHTML = `
  316. <div class="steps" id="form-steps">
  317. <div class="step active" id="step1"><span class="step-dot">1</span><span class="step-label">选择类型</span></div>
  318. <div class="step" id="step2"><span class="step-dot">2</span><span class="step-label">设置规则</span></div>
  319. <div class="step" id="step3"><span class="step-dot">3</span><span class="step-label">确认提交</span></div>
  320. </div>
  321. <div id="step-content">
  322. ${renderStep1()}
  323. </div>
  324. `;
  325. }
  326. function renderStep1() {
  327. const hasActive = { manjian: true, zhekou: false, ban: false }; // simulate: 满减 is active
  328. return `
  329. <div class="form-group">
  330. <label class="form-label"><span class="required">*</span> 选择促销类型</label>
  331. <div class="type-selector">
  332. <div class="type-card ${currentType==='manjian'?'selected':''} ${hasActive.manjian?'disabled':''}"
  333. onclick="${hasActive.manjian?'':'selectType(\"manjian\")'}">
  334. <div class="icon">📦</div>
  335. <div class="label">满减</div>
  336. <div class="desc">订单满X减Y</div>
  337. ${hasActive.manjian?'<div style="font-size:10px;color:#999;margin-top:4px">已有进行中活动</div>':''}
  338. </div>
  339. <div class="type-card ${currentType==='zhekou'?'selected':''} ${hasActive.zhekou?'disabled':''}"
  340. onclick="${hasActive.zhekou?'':'selectType(\"zhekou\")'}">
  341. <div class="icon">🏷️</div>
  342. <div class="label">折扣商品</div>
  343. <div class="desc">指定商品打折</div>
  344. ${hasActive.zhekou?'<div style="font-size:10px;color:#999;margin-top:4px">与满减互斥</div>':''}
  345. </div>
  346. <div class="type-card ${currentType==='ban'?'selected':''} ${hasActive.ban?'disabled':''}"
  347. onclick="${hasActive.ban?'':'selectType(\"ban\")'}">
  348. <div class="icon">🔄</div>
  349. <div class="label">第二份半价</div>
  350. <div class="desc">买2件第2件半价</div>
  351. ${hasActive.ban?'<div style="font-size:10px;color:#999;margin-top:4px">与满减互斥</div>':''}
  352. </div>
  353. <div class="type-card ${currentType==='xinke'?'selected':''}" onclick="selectType('xinke')">
  354. <div class="icon">🆕</div>
  355. <div class="label">新客立减</div>
  356. <div class="desc">首次下单减X元</div>
  357. </div>
  358. </div>
  359. </div>
  360. <div style="text-align:right;margin-top:20px;">
  361. <button class="btn btn-primary" onclick="goStep2()" ${currentType?'':'disabled'} id="next-step1">下一步 →</button>
  362. </div>
  363. `;
  364. }
  365. function selectType(type) {
  366. currentType = type;
  367. renderDrawerContent();
  368. }
  369. function goStep2() {
  370. if (!currentType) return;
  371. document.getElementById('step1').className = 'step done';
  372. document.getElementById('step2').className = 'step active';
  373. const content = document.getElementById('step-content');
  374. content.innerHTML = renderStep2Content();
  375. }
  376. function renderStep2Content() {
  377. let html = '';
  378. if (currentType === 'manjian') {
  379. html = renderManjianForm();
  380. } else if (currentType === 'zhekou') {
  381. html = renderZhekouForm();
  382. } else if (currentType === 'ban') {
  383. html = renderBanForm();
  384. } else if (currentType === 'xinke') {
  385. html = renderXinkeForm();
  386. }
  387. html += `
  388. <hr class="divider">
  389. <div class="form-group">
  390. <label class="form-label">活动时间</label>
  391. <div style="display:flex;gap:10px;align-items:center;">
  392. <input type="date" class="form-input" style="width:auto" value="2026-06-01">
  393. <span>~</span>
  394. <input type="date" class="form-input" style="width:auto" value="2026-06-30">
  395. </div>
  396. </div>
  397. <div style="display:flex;justify-content:space-between;margin-top:20px;">
  398. <button class="btn btn-default" onclick="goBackStep1()">← 上一步</button>
  399. <button class="btn btn-primary" onclick="goStep3()">下一步 →</button>
  400. </div>
  401. `;
  402. return html;
  403. }
  404. function renderManjianForm() {
  405. return `
  406. <div class="form-group">
  407. <label class="form-label"><span class="required">*</span> 设置满减档位</label>
  408. <div class="form-hint" style="margin-bottom:12px">建议根据客单价分布设置2-3个档位,每个档位自动匹配最优</div>
  409. <div id="tier-list">
  410. <div class="tier-row" data-tier="0">
  411. <span class="tier-text">满</span>
  412. <input class="tier-input" type="number" placeholder="20" value="20">
  413. <span class="tier-text">减</span>
  414. <input class="tier-input" type="number" placeholder="5" value="5">
  415. <span class="tier-text">元</span>
  416. </div>
  417. <div class="tier-row" data-tier="1">
  418. <span class="tier-text">满</span>
  419. <input class="tier-input" type="number" placeholder="40" value="40">
  420. <span class="tier-text">减</span>
  421. <input class="tier-input" type="number" placeholder="12" value="12">
  422. <span class="tier-text">元</span>
  423. <button class="tier-remove" onclick="removeTier(this)">✕</button>
  424. </div>
  425. </div>
  426. <button class="add-tier" onclick="addTier()">+ 添加档位</button>
  427. </div>
  428. `;
  429. }
  430. function renderZhekouForm() {
  431. return `
  432. <div class="mutex-warning" style="margin-bottom:16px;">
  433. <span class="icon">💡</span>
  434. <div class="text">
  435. <strong>操作说明:</strong>从下方商品列表中勾选要参加折扣的商品,<strong>每个商品可以设置不同的折扣率</strong>。
  436. 用户下单时,参加折扣的商品按折扣价计算,未参加的商品仍按原价。折扣商品和满减活动互斥,用户系统自动选最优。
  437. </div>
  438. </div>
  439. <div class="form-group">
  440. <label class="form-label"><span class="required">*</span> 选择折扣商品并设置折扣率</label>
  441. <div class="product-select-area">
  442. <div class="product-search">
  443. <input type="text" placeholder="🔍 搜索商品名称..." oninput="filterProducts(this.value)">
  444. </div>
  445. <div class="product-list" id="product-list">
  446. ${products.map(p => renderProductItem(p)).join('')}
  447. </div>
  448. </div>
  449. <div class="selected-summary" id="selected-summary" style="display:none;">
  450. <div class="title">已选商品(点击折扣率可修改)</div>
  451. <div id="selected-items"></div>
  452. </div>
  453. </div>
  454. `;
  455. }
  456. function renderProductItem(p) {
  457. const sel = selectedProducts[p.id];
  458. return `
  459. <div class="product-item ${sel?'selected':''}" id="pitem-${p.id}">
  460. <div class="product-check" onclick="toggleProduct(${p.id})">${sel?'✓':''}</div>
  461. <div class="product-img">${p.emoji}</div>
  462. <div class="product-meta">
  463. <div class="pname">${p.name}</div>
  464. <div class="pprice">原价 ¥${p.price}</div>
  465. </div>
  466. <div class="product-rate" id="prate-${p.id}" style="${sel?'':'opacity:0.3;pointer-events:none'}">
  467. <input type="number" value="${sel?sel.rate:7}" min="1" max="9" step="0.1" onchange="updateRate(${p.id}, this.value)" style="width:48px"> <span>折</span>
  468. </div>
  469. <div class="product-result" id="presult-${p.id}">${sel?'¥'+(p.price*sel.rate/10).toFixed(1):'-'}</div>
  470. </div>
  471. `;
  472. }
  473. function toggleProduct(id) {
  474. if (selectedProducts[id]) {
  475. delete selectedProducts[id];
  476. } else {
  477. const p = products.find(x => x.id === id);
  478. selectedProducts[id] = { rate: 7 }; // default 7折
  479. }
  480. refreshProductUI();
  481. }
  482. function updateRate(id, val) {
  483. const rate = parseFloat(val) || 7;
  484. selectedProducts[id].rate = rate;
  485. refreshProductUI();
  486. }
  487. function refreshProductUI() {
  488. const list = document.getElementById('product-list');
  489. list.innerHTML = products.map(p => renderProductItem(p)).join('');
  490. updateSelectedSummary();
  491. }
  492. function updateSelectedSummary() {
  493. const summary = document.getElementById('selected-summary');
  494. const items = document.getElementById('selected-items');
  495. const ids = Object.keys(selectedProducts);
  496. if (ids.length === 0) {
  497. summary.style.display = 'none';
  498. return;
  499. }
  500. summary.style.display = 'block';
  501. items.innerHTML = ids.map(id => {
  502. const p = products.find(x => x.id == id);
  503. const rate = selectedProducts[id].rate;
  504. const result = (p.price * rate / 10).toFixed(1);
  505. return `
  506. <div class="selected-item">
  507. <span class="sname">${p.emoji} ${p.name}(原价¥${p.price})</span>
  508. <span class="srate">${rate}折</span>
  509. <span class="sresult">→ ¥${result}</span>
  510. <span class="sremove" onclick="toggleProduct(${p.id})">移除</span>
  511. </div>
  512. `;
  513. }).join('');
  514. }
  515. function filterProducts(keyword) {
  516. const filtered = products.filter(p => p.name.includes(keyword));
  517. document.getElementById('product-list').innerHTML = filtered.map(p => renderProductItem(p)).join('');
  518. updateSelectedSummary();
  519. }
  520. function renderBanForm() {
  521. return `
  522. <div class="mutex-warning" style="margin-bottom:16px;">
  523. <span class="icon">💡</span>
  524. <div class="text">
  525. <strong>操作说明:</strong>从商品列表中勾选参加"第二份半价"的商品。用户买2件同一商品时,第2件自动半价。
  526. </div>
  527. </div>
  528. <div class="form-group">
  529. <label class="form-label"><span class="required">*</span> 选择参加第二份半价的商品</label>
  530. <div class="product-select-area">
  531. <div class="product-list" id="product-list">
  532. ${products.map(p => {
  533. const sel = selectedProducts[p.id];
  534. return `
  535. <div class="product-item ${sel?'selected':''}" id="pitem-${p.id}">
  536. <div class="product-check" onclick="toggleBanProduct(${p.id})">${sel?'✓':''}</div>
  537. <div class="product-img">${p.emoji}</div>
  538. <div class="product-meta">
  539. <div class="pname">${p.name}</div>
  540. <div class="pprice">原价 ¥${p.price} → 第2件 ¥${(p.price*0.5).toFixed(1)}</div>
  541. </div>
  542. </div>
  543. `;
  544. }).join('')}
  545. </div>
  546. </div>
  547. </div>
  548. `;
  549. }
  550. function toggleBanProduct(id) {
  551. if (selectedProducts[id]) {
  552. delete selectedProducts[id];
  553. } else {
  554. selectedProducts[id] = true;
  555. }
  556. document.getElementById('product-list').innerHTML = products.map(p => {
  557. const sel = selectedProducts[p.id];
  558. return `
  559. <div class="product-item ${sel?'selected':''}" id="pitem-${p.id}">
  560. <div class="product-check" onclick="toggleBanProduct(${p.id})">${sel?'✓':''}</div>
  561. <div class="product-img">${p.emoji}</div>
  562. <div class="product-meta">
  563. <div class="pname">${p.name}</div>
  564. <div class="pprice">原价 ¥${p.price} → 第2件 ¥${(p.price*0.5).toFixed(1)}</div>
  565. </div>
  566. </div>
  567. `;
  568. }).join('');
  569. }
  570. function renderXinkeForm() {
  571. return `
  572. <div class="form-group">
  573. <label class="form-label"><span class="required">*</span> 新客立减金额</label>
  574. <div style="display:flex;align-items:center;gap:8px;">
  575. <span style="font-size:14px;color:#666;">首次在本店下单减</span>
  576. <input class="tier-input" type="number" value="3" style="width:80px">
  577. <span style="font-size:14px;color:#666;">元</span>
  578. </div>
  579. <div class="form-hint">建议设置2-5元,可与满减/折扣/第二份半价叠加使用</div>
  580. </div>
  581. `;
  582. }
  583. function addTier() {
  584. const list = document.getElementById('tier-list');
  585. const count = list.children.length;
  586. const row = document.createElement('div');
  587. row.className = 'tier-row';
  588. row.dataset.tier = count;
  589. row.innerHTML = `
  590. <span class="tier-text">满</span>
  591. <input class="tier-input" type="number" placeholder="60">
  592. <span class="tier-text">减</span>
  593. <input class="tier-input" type="number" placeholder="20">
  594. <span class="tier-text">元</span>
  595. <button class="tier-remove" onclick="removeTier(this)">✕</button>
  596. `;
  597. list.appendChild(row);
  598. }
  599. function removeTier(btn) {
  600. btn.parentElement.remove();
  601. }
  602. function goBackStep1() {
  603. document.getElementById('step1').className = 'step active';
  604. document.getElementById('step2').className = 'step';
  605. document.getElementById('step-content').innerHTML = renderStep1();
  606. }
  607. function goStep3() {
  608. document.getElementById('step2').className = 'step done';
  609. document.getElementById('step3').className = 'step active';
  610. document.getElementById('step-content').innerHTML = renderStep3();
  611. document.getElementById('drawer-footer').innerHTML = `
  612. <button class="btn btn-default" onclick="goBackStep2()">上一步</button>
  613. <button class="btn btn-primary" onclick="confirmCreate()">✓ 确认创建</button>
  614. `;
  615. }
  616. function renderStep3() {
  617. let summary = '';
  618. const typeNames = { manjian: '满减活动', zhekou: '折扣商品', ban: '第二份半价', xinke: '新客立减' };
  619. summary += `<div style="margin-bottom:12px;font-size:15px;font-weight:600;">📋 创建确认</div>`;
  620. summary += `<div style="font-size:14px;margin-bottom:4px;"><strong>类型:</strong>${typeNames[currentType]}</div>`;
  621. if (currentType === 'manjian') {
  622. summary += `<div style="font-size:14px;margin-bottom:4px;"><strong>档位:</strong></div>`;
  623. summary += `<div style="background:#fafafa;padding:10px;border-radius:6px;margin-bottom:12px;">`;
  624. document.querySelectorAll('.tier-row').forEach(row => {
  625. const inputs = row.querySelectorAll('.tier-input');
  626. summary += `<div style="font-size:13px;padding:2px 0;">满 <strong>${inputs[0].value}</strong> 减 <strong style="color:#ff6b35">${inputs[1].value}</strong> 元</div>`;
  627. });
  628. summary += `</div>`;
  629. } else if (currentType === 'zhekou') {
  630. const ids = Object.keys(selectedProducts);
  631. summary += `<div style="font-size:14px;margin-bottom:4px;"><strong>折扣商品(${ids.length}个):</strong></div>`;
  632. summary += `<div style="background:#fafafa;padding:10px;border-radius:6px;margin-bottom:12px;">`;
  633. ids.forEach(id => {
  634. const p = products.find(x => x.id == id);
  635. const rate = selectedProducts[id].rate;
  636. summary += `<div style="font-size:13px;padding:2px 0;">${p.emoji} ${p.name}:原价¥${p.price} → <strong style="color:#ff6b35">${rate}折 ¥${(p.price*rate/10).toFixed(1)}</strong></div>`;
  637. });
  638. summary += `</div>`;
  639. } else if (currentType === 'ban') {
  640. const ids = Object.keys(selectedProducts);
  641. summary += `<div style="font-size:14px;margin-bottom:4px;"><strong>参加商品(${ids.length}个):</strong></div>`;
  642. summary += `<div style="background:#fafafa;padding:10px;border-radius:6px;margin-bottom:12px;">`;
  643. ids.forEach(id => {
  644. const p = products.find(x => x.id == id);
  645. summary += `<div style="font-size:13px;padding:2px 0;">${p.emoji} ${p.name}:买2件 = ¥${p.price} + ¥${(p.price*0.5).toFixed(1)} = <strong style="color:#ff6b35">¥${(p.price*1.5).toFixed(1)}</strong></div>`;
  646. });
  647. summary += `</div>`;
  648. } else if (currentType === 'xinke') {
  649. summary += `<div style="font-size:14px;margin-bottom:4px;">新客首次下单减 <strong style="color:#ff6b35">3元</strong></div>`;
  650. }
  651. summary += `<div style="font-size:14px;"><strong>活动时间:</strong>2026-06-01 ~ 2026-06-30</div>`;
  652. summary += `<div class="mutex-warning" style="margin-top:16px;">
  653. <span class="icon">⚠️</span>
  654. <div class="text">
  655. ${currentType === 'xinke' ? '新客立减可与满减/折扣/第二份半价叠加使用' : '创建此活动后,由于互斥规则,与当前进行中的<strong>满减活动</strong>将需要二选一。请确认是否继续。'}
  656. </div>
  657. </div>`;
  658. return summary;
  659. }
  660. function goBackStep2() {
  661. document.getElementById('step2').className = 'step active';
  662. document.getElementById('step3').className = 'step';
  663. document.getElementById('step-content').innerHTML = renderStep2Content();
  664. document.getElementById('drawer-footer').innerHTML = `
  665. <button class="btn btn-default" onclick="closeDrawer()">取消</button>
  666. <button class="btn btn-primary" onclick="goStep3()">下一步 →</button>
  667. `;
  668. }
  669. function confirmCreate() {
  670. closeDrawer();
  671. showToast('✓ 促销活动创建成功!');
  672. }
  673. function endPromo(btn) {
  674. if (confirm('确定要结束此活动吗?结束后不可恢复。')) {
  675. const item = btn.closest('.promo-item');
  676. item.querySelector('.tag').className = 'tag tag-expired';
  677. item.querySelector('.tag').textContent = '已结束';
  678. item.style.opacity = '0.5';
  679. btn.remove();
  680. }
  681. }
  682. function showToast(msg) {
  683. const toast = document.getElementById('toast');
  684. toast.textContent = msg;
  685. toast.classList.add('show');
  686. setTimeout(() => toast.classList.remove('show'), 2000);
  687. }
  688. // Coupon form
  689. function renderCouponForm(body) {
  690. body.innerHTML = `
  691. <div class="form-group">
  692. <label class="form-label"><span class="required">*</span> 优惠券名称</label>
  693. <input class="form-input" placeholder="如:满30减5优惠券" value="满30减5优惠券">
  694. </div>
  695. <div class="form-group">
  696. <label class="form-label"><span class="required">*</span> 券类型</label>
  697. <div style="display:flex;gap:10px;">
  698. <div class="type-card selected" style="flex:1" onclick="selectCouponType(this, 'manjian')">
  699. <div class="label">满减券</div>
  700. <div class="desc">满X减Y元</div>
  701. </div>
  702. <div class="type-card" style="flex:1" onclick="selectCouponType(this, 'shangpin')">
  703. <div class="label">商品券</div>
  704. <div class="desc">指定商品折扣/兑换</div>
  705. </div>
  706. </div>
  707. </div>
  708. <div id="coupon-rule-area">
  709. <div class="form-group">
  710. <label class="form-label">同享/互斥</label>
  711. <div style="display:flex;gap:10px;">
  712. <label style="display:flex;align-items:center;gap:6px;cursor:pointer;font-size:14px;">
  713. <input type="radio" name="mutex" value="0" checked> 同享券(可与满减叠加)
  714. </label>
  715. <label style="display:flex;align-items:center;gap:6px;cursor:pointer;font-size:14px;">
  716. <input type="radio" name="mutex" value="1"> 互斥券(不可与满减叠加)
  717. </label>
  718. </div>
  719. </div>
  720. <div class="form-group">
  721. <label class="form-label"><span class="required">*</span> 使用门槛</label>
  722. <div style="display:flex;align-items:center;gap:8px;">
  723. <span style="font-size:14px;color:#666;">满</span>
  724. <input class="tier-input" type="number" value="30" style="width:80px">
  725. <span style="font-size:14px;color:#666;">元可用,减</span>
  726. <input class="tier-input" type="number" value="5" style="width:80px">
  727. <span style="font-size:14px;color:#666;">元</span>
  728. </div>
  729. </div>
  730. </div>
  731. <hr class="divider">
  732. <div class="form-group">
  733. <label class="form-label"><span class="required">*</span> 发放总量</label>
  734. <input class="form-input" type="number" value="100" style="width:200px">
  735. <div class="form-hint">每个用户限领1张</div>
  736. </div>
  737. <div class="form-group">
  738. <label class="form-label"><span class="required">*</span> 领取时间</label>
  739. <div style="display:flex;gap:10px;align-items:center;">
  740. <input type="date" class="form-input" style="width:auto" value="2026-06-01">
  741. <span>~</span>
  742. <input type="date" class="form-input" style="width:auto" value="2026-06-30">
  743. </div>
  744. </div>
  745. <div class="form-group">
  746. <label class="form-label"><span class="required">*</span> 领取后有效天数</label>
  747. <div style="display:flex;gap:10px;align-items:center;">
  748. <input class="form-input" type="number" value="7" style="width:100px">
  749. <span style="font-size:14px;color:#666;">天</span>
  750. </div>
  751. </div>
  752. <div class="mutex-warning">
  753. <span class="icon">💡</span>
  754. <div class="text">
  755. 发放方式:<strong>店内领券</strong> — 用户进入店铺时可在领券区看到并领取,下单时手动选择使用。
  756. </div>
  757. </div>
  758. `;
  759. }
  760. function selectCouponType(el, type) {
  761. el.parentElement.querySelectorAll('.type-card').forEach(c => c.classList.remove('selected'));
  762. el.classList.add('selected');
  763. const area = document.getElementById('coupon-rule-area');
  764. if (type === 'shangpin') {
  765. area.innerHTML = `
  766. <div class="form-group">
  767. <label class="form-label">商品券类型</label>
  768. <div style="display:flex;gap:10px;">
  769. <label style="display:flex;align-items:center;gap:6px;cursor:pointer;font-size:14px;">
  770. <input type="radio" name="sp_type" value="discount" checked> 折扣券(指定商品X折)
  771. </label>
  772. <label style="display:flex;align-items:center;gap:6px;cursor:pointer;font-size:14px;">
  773. <input type="radio" name="sp_type" value="exchange"> 抵用券(指定商品免费兑换)
  774. </label>
  775. </div>
  776. </div>
  777. <div class="form-group">
  778. <label class="form-label"><span class="required">*</span> 选择适用商品</label>
  779. <div class="product-select-area">
  780. <div class="product-list" style="max-height:200px;">
  781. ${products.slice(0,6).map(p => `
  782. <div class="product-item" onclick="this.classList.toggle('selected');this.querySelector('.product-check').innerHTML=this.classList.contains('selected')?'✓':'';">
  783. <div class="product-check"></div>
  784. <div class="product-img">${p.emoji}</div>
  785. <div class="product-meta">
  786. <div class="pname">${p.name}</div>
  787. <div class="pprice">¥${p.price}</div>
  788. </div>
  789. </div>
  790. `).join('')}
  791. </div>
  792. </div>
  793. </div>
  794. <div class="form-group">
  795. <label class="form-label"><span class="required">*</span> 折扣率</label>
  796. <div style="display:flex;align-items:center;gap:8px;">
  797. <input class="tier-input" type="number" value="5" step="0.1" style="width:80px">
  798. <span style="font-size:14px;color:#666;">折</span>
  799. </div>
  800. </div>
  801. `;
  802. } else {
  803. area.innerHTML = `
  804. <div class="form-group">
  805. <label class="form-label">同享/互斥</label>
  806. <div style="display:flex;gap:10px;">
  807. <label style="display:flex;align-items:center;gap:6px;cursor:pointer;font-size:14px;">
  808. <input type="radio" name="mutex" value="0" checked> 同享券(可与满减叠加)
  809. </label>
  810. <label style="display:flex;align-items:center;gap:6px;cursor:pointer;font-size:14px;">
  811. <input type="radio" name="mutex" value="1"> 互斥券(不可与满减叠加)
  812. </label>
  813. </div>
  814. </div>
  815. <div class="form-group">
  816. <label class="form-label"><span class="required">*</span> 使用门槛</label>
  817. <div style="display:flex;align-items:center;gap:8px;">
  818. <span style="font-size:14px;color:#666;">满</span>
  819. <input class="tier-input" type="number" value="30" style="width:80px">
  820. <span style="font-size:14px;color:#666;">元可用,减</span>
  821. <input class="tier-input" type="number" value="5" style="width:80px">
  822. <span style="font-size:14px;color:#666;">元</span>
  823. </div>
  824. </div>
  825. `;
  826. }
  827. }
  828. </script>
  829. </body>
  830. </html>