优惠券选择功能测试示例.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. body {
  9. font-family: "Microsoft YaHei", Arial, sans-serif;
  10. margin: 20px;
  11. background-color: #f5f5f5;
  12. }
  13. .container {
  14. max-width: 1200px;
  15. margin: 0 auto;
  16. background: white;
  17. padding: 20px;
  18. border-radius: 8px;
  19. box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  20. }
  21. .header {
  22. text-align: center;
  23. margin-bottom: 30px;
  24. padding-bottom: 20px;
  25. border-bottom: 2px solid #3c8dbc;
  26. }
  27. .header h1 {
  28. color: #333;
  29. margin-bottom: 10px;
  30. }
  31. .header p {
  32. color: #666;
  33. font-size: 14px;
  34. }
  35. .demo-section {
  36. margin-bottom: 30px;
  37. padding: 20px;
  38. border: 1px solid #e5e5e5;
  39. border-radius: 5px;
  40. background-color: #fafafa;
  41. }
  42. .demo-section h3 {
  43. color: #3c8dbc;
  44. margin-top: 0;
  45. margin-bottom: 15px;
  46. font-size: 18px;
  47. }
  48. .demo-section p {
  49. color: #666;
  50. margin-bottom: 15px;
  51. line-height: 1.6;
  52. }
  53. .demo-buttons {
  54. margin-bottom: 15px;
  55. }
  56. .demo-button {
  57. display: inline-block;
  58. padding: 8px 16px;
  59. margin: 5px 10px 5px 0;
  60. background-color: #3c8dbc;
  61. color: white;
  62. text-decoration: none;
  63. border-radius: 4px;
  64. border: none;
  65. cursor: pointer;
  66. font-size: 14px;
  67. transition: background-color 0.3s;
  68. }
  69. .demo-button:hover {
  70. background-color: #2980b9;
  71. color: white;
  72. text-decoration: none;
  73. }
  74. .demo-button.secondary {
  75. background-color: #5cb85c;
  76. }
  77. .demo-button.secondary:hover {
  78. background-color: #449d44;
  79. }
  80. .demo-button.warning {
  81. background-color: #f0ad4e;
  82. }
  83. .demo-button.warning:hover {
  84. background-color: #ec971f;
  85. }
  86. .code-section {
  87. background-color: #f8f8f8;
  88. border: 1px solid #e5e5e5;
  89. border-radius: 4px;
  90. padding: 15px;
  91. margin-top: 10px;
  92. }
  93. .code-section h4 {
  94. color: #333;
  95. margin-top: 0;
  96. margin-bottom: 10px;
  97. font-size: 14px;
  98. }
  99. .code-section code {
  100. background-color: #f5f5f5;
  101. padding: 2px 4px;
  102. border-radius: 3px;
  103. font-family: "Courier New", monospace;
  104. font-size: 13px;
  105. }
  106. .code-section pre {
  107. background-color: #2d3748;
  108. color: #e2e8f0;
  109. padding: 15px;
  110. border-radius: 4px;
  111. overflow-x: auto;
  112. margin: 10px 0;
  113. font-family: "Courier New", monospace;
  114. font-size: 13px;
  115. line-height: 1.4;
  116. }
  117. .feature-list {
  118. list-style: none;
  119. padding: 0;
  120. }
  121. .feature-list li {
  122. padding: 8px 0;
  123. border-bottom: 1px solid #e5e5e5;
  124. position: relative;
  125. padding-left: 25px;
  126. }
  127. .feature-list li:before {
  128. content: "✓";
  129. position: absolute;
  130. left: 0;
  131. color: #5cb85c;
  132. font-weight: bold;
  133. }
  134. .feature-list li:last-child {
  135. border-bottom: none;
  136. }
  137. .alert {
  138. padding: 15px;
  139. margin-bottom: 20px;
  140. border: 1px solid transparent;
  141. border-radius: 4px;
  142. }
  143. .alert-info {
  144. color: #31708f;
  145. background-color: #d9edf7;
  146. border-color: #bce8f1;
  147. }
  148. .alert-success {
  149. color: #3c763d;
  150. background-color: #dff0d8;
  151. border-color: #d6e9c6;
  152. }
  153. table {
  154. width: 100%;
  155. border-collapse: collapse;
  156. margin-top: 15px;
  157. }
  158. table th,
  159. table td {
  160. border: 1px solid #ddd;
  161. padding: 8px;
  162. text-align: left;
  163. }
  164. table th {
  165. background-color: #f2f2f2;
  166. font-weight: bold;
  167. }
  168. table tr:nth-child(even) {
  169. background-color: #f9f9f9;
  170. }
  171. </style>
  172. </head>
  173. <body>
  174. <div class="container">
  175. <div class="header">
  176. <h1>优惠券选择功能测试示例</h1>
  177. <p>演示优惠券选择功能的不同调用模式和参数配置</p>
  178. </div>
  179. <div class="alert alert-info">
  180. <strong>说明:</strong>此页面为功能演示,实际使用时需要在FastAdmin后台环境中调用相应的API接口。
  181. </div>
  182. <!-- 单选模式 -->
  183. <div class="demo-section">
  184. <h3>1. 单选模式(默认模式)</h3>
  185. <p>单选模式下,用户点击优惠券行的"选择"按钮即可直接选择该优惠券并关闭弹窗。这是优惠券选择的默认模式。</p>
  186. <div class="demo-buttons">
  187. <button class="demo-button" onclick="simulateCall('single1')">基础单选</button>
  188. <button class="demo-button" onclick="simulateCall('single2')">指定单选模式</button>
  189. </div>
  190. <div class="code-section">
  191. <h4>调用代码:</h4>
  192. <pre>// 基础单选(默认)
  193. Fast.api.open('shop/coupon/select', '选择优惠券');
  194. // 明确指定单选模式
  195. Fast.api.open('shop/coupon/select?selectMode=single', '选择优惠券');</pre>
  196. </div>
  197. <ul class="feature-list">
  198. <li>点击"选择"按钮直接完成选择</li>
  199. <li>不显示确认按钮</li>
  200. <li>按钮颜色为蓝色</li>
  201. <li>自动检查优惠券状态(过期/停用的优惠券不可选)</li>
  202. </ul>
  203. </div>
  204. <!-- 多选模式 -->
  205. <div class="demo-section">
  206. <h3>2. 多选模式</h3>
  207. <p>多选模式下,用户可以选择多个优惠券,绿色按钮表示可选择,红色按钮表示已选择,最后需要点击"确认选择"按钮完成操作。</p>
  208. <div class="demo-buttons">
  209. <button class="demo-button secondary" onclick="simulateCall('multiple1')">基础多选</button>
  210. <button class="demo-button secondary" onclick="simulateCall('multiple2')">限制3个</button>
  211. <button class="demo-button secondary" onclick="simulateCall('multiple3')">限制5个</button>
  212. </div>
  213. <div class="code-section">
  214. <h4>调用代码:</h4>
  215. <pre>// 基础多选(无数量限制)
  216. Fast.api.open('shop/coupon/select?selectMode=multiple', '选择优惠券');
  217. // 限制最多选择3个
  218. Fast.api.open('shop/coupon/select?selectMode=multiple&maxSelect=3', '选择优惠券');
  219. // 限制最多选择5个
  220. Fast.api.open('shop/coupon/select?selectMode=multiple&maxSelect=5', '选择优惠券');</pre>
  221. </div>
  222. <ul class="feature-list">
  223. <li>绿色按钮表示可选择,红色按钮表示已选择</li>
  224. <li>显示确认按钮和选择数量</li>
  225. <li>支持最大选择数量限制</li>
  226. <li>达到限制后其他选择按钮自动禁用</li>
  227. <li>支持状态恢复(刷新后保持选择状态)</li>
  228. </ul>
  229. </div>
  230. <!-- 优惠券状态检查 -->
  231. <div class="demo-section">
  232. <h3>3. 优惠券状态检查</h3>
  233. <p>系统自动检查优惠券的可用状态,不可用的优惠券将显示为灰色按钮且不能点击。</p>
  234. <div class="alert alert-success">
  235. <strong>状态检查规则:</strong><br>
  236. • <code>expired = true</code> - 优惠券已过期<br>
  237. • <code>is_open != 1</code> - 优惠券已停用
  238. </div>
  239. <table>
  240. <thead>
  241. <tr>
  242. <th>优惠券状态</th>
  243. <th>按钮颜色</th>
  244. <th>是否可选</th>
  245. <th>提示信息</th>
  246. </tr>
  247. </thead>
  248. <tbody>
  249. <tr>
  250. <td>正常(未过期且开启)</td>
  251. <td>蓝色(单选)/ 绿色(多选)</td>
  252. <td>✓ 可选</td>
  253. <td>点击选择该优惠券</td>
  254. </tr>
  255. <tr>
  256. <td>已过期</td>
  257. <td>灰色</td>
  258. <td>✗ 不可选</td>
  259. <td>优惠券不可用</td>
  260. </tr>
  261. <tr>
  262. <td>已停用</td>
  263. <td>灰色</td>
  264. <td>✗ 不可选</td>
  265. <td>优惠券不可用</td>
  266. </tr>
  267. </tbody>
  268. </table>
  269. </div>
  270. <!-- 显示信息 -->
  271. <div class="demo-section">
  272. <h3>4. 优惠券信息显示</h3>
  273. <p>优惠券选择界面显示完整的优惠券信息,便于用户做出准确的选择。</p>
  274. <table>
  275. <thead>
  276. <tr>
  277. <th>显示列</th>
  278. <th>内容说明</th>
  279. <th>示例</th>
  280. </tr>
  281. </thead>
  282. <tbody>
  283. <tr>
  284. <td>优惠券信息</td>
  285. <td>名称、使用条件、时间信息</td>
  286. <td>新用户专享券<br>满100元,减20元<br>领取: 2024-01-01 | 使用: 30天</td>
  287. </tr>
  288. <tr>
  289. <td>使用条件</td>
  290. <td>使用条件描述</td>
  291. <td>新用户专享</td>
  292. </tr>
  293. <tr>
  294. <td>发放/已领</td>
  295. <td>发放数量和已领取数量</td>
  296. <td>发放: 1000<br>已领: 256</td>
  297. </tr>
  298. <tr>
  299. <td>状态</td>
  300. <td>优惠券当前状态</td>
  301. <td>正常 / 已过期 / 停用</td>
  302. </tr>
  303. <tr>
  304. <td>选择</td>
  305. <td>选择操作按钮</td>
  306. <td>选择 / 操作</td>
  307. </tr>
  308. </tbody>
  309. </table>
  310. </div>
  311. <!-- 回调数据格式 -->
  312. <div class="demo-section">
  313. <h3>5. 回调数据格式</h3>
  314. <p>选择完成后,回调函数会返回选中的优惠券数据数组。</p>
  315. <div class="code-section">
  316. <h4>回调函数示例:</h4>
  317. <pre>Fast.api.open('shop/coupon/select?selectMode=multiple', '选择优惠券', {
  318. callback: function(data) {
  319. console.log('选中的优惠券:', data);
  320. // data是数组,包含选中的优惠券对象
  321. data.forEach(function(coupon) {
  322. console.log('优惠券ID:', coupon.id);
  323. console.log('优惠券名称:', coupon.name);
  324. console.log('使用条件:', coupon.condition_name);
  325. console.log('结果数据:', coupon.result_data);
  326. });
  327. }
  328. });</pre>
  329. </div>
  330. <div class="code-section">
  331. <h4>优惠券对象结构:</h4>
  332. <pre>{
  333. "id": 1,
  334. "name": "新用户专享券",
  335. "condition_name": "新用户专享",
  336. "result": 1,
  337. "result_data": {
  338. "money": "100.00",
  339. "number": "20.00"
  340. },
  341. "give_num": 1000,
  342. "received_num": 256,
  343. "is_open": 1,
  344. "expired": false,
  345. "receive_times": "2024-01-01 - 2024-12-31",
  346. "use_times": "30",
  347. "mode": "fixation"
  348. }</pre>
  349. </div>
  350. </div>
  351. </div>
  352. <script>
  353. function simulateCall(type) {
  354. var calls = {
  355. 'single1': "Fast.api.open('shop/coupon/select', '选择优惠券');",
  356. 'single2': "Fast.api.open('shop/coupon/select?selectMode=single', '选择优惠券');",
  357. 'multiple1': "Fast.api.open('shop/coupon/select?selectMode=multiple', '选择优惠券');",
  358. 'multiple2': "Fast.api.open('shop/coupon/select?selectMode=multiple&maxSelect=3', '选择优惠券');",
  359. 'multiple3': "Fast.api.open('shop/coupon/select?selectMode=multiple&maxSelect=5', '选择优惠券');"
  360. };
  361. alert('模拟调用:\n\n' + calls[type] + '\n\n实际使用时需要在FastAdmin后台环境中调用。');
  362. }
  363. </script>
  364. </body>
  365. </html>