商品选择功能测试示例.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>商品选择功能测试示例</title>
  6. <style>
  7. body {
  8. font-family: Arial, sans-serif;
  9. max-width: 800px;
  10. margin: 50px auto;
  11. padding: 20px;
  12. }
  13. .demo-section {
  14. margin: 30px 0;
  15. padding: 20px;
  16. border: 1px solid #ddd;
  17. border-radius: 5px;
  18. }
  19. .demo-title {
  20. font-size: 18px;
  21. font-weight: bold;
  22. margin-bottom: 15px;
  23. color: #333;
  24. }
  25. .demo-button {
  26. background: #5cb85c;
  27. color: white;
  28. border: none;
  29. padding: 10px 20px;
  30. border-radius: 4px;
  31. cursor: pointer;
  32. margin-right: 10px;
  33. margin-bottom: 10px;
  34. }
  35. .demo-button:hover {
  36. background: #449d44;
  37. }
  38. .demo-button.primary {
  39. background: #337ab7;
  40. }
  41. .demo-button.primary:hover {
  42. background: #286090;
  43. }
  44. .demo-button.warning {
  45. background: #f0ad4e;
  46. }
  47. .demo-button.warning:hover {
  48. background: #ec971f;
  49. }
  50. .code-block {
  51. background: #f8f8f8;
  52. border: 1px solid #ddd;
  53. border-radius: 4px;
  54. padding: 15px;
  55. margin: 10px 0;
  56. font-family: 'Courier New', monospace;
  57. font-size: 14px;
  58. overflow-x: auto;
  59. }
  60. .selected-goods {
  61. background: #f9f9f9;
  62. border: 1px solid #ddd;
  63. border-radius: 4px;
  64. padding: 15px;
  65. margin: 10px 0;
  66. min-height: 50px;
  67. }
  68. .feature-list {
  69. list-style-type: none;
  70. padding: 0;
  71. }
  72. .feature-list li {
  73. padding: 5px 0;
  74. border-bottom: 1px solid #eee;
  75. }
  76. .feature-list li:before {
  77. content: "✓ ";
  78. color: #5cb85c;
  79. font-weight: bold;
  80. }
  81. .comparison-table {
  82. width: 100%;
  83. border-collapse: collapse;
  84. margin: 15px 0;
  85. }
  86. .comparison-table th, .comparison-table td {
  87. border: 1px solid #ddd;
  88. padding: 10px;
  89. text-align: left;
  90. }
  91. .comparison-table th {
  92. background: #f5f5f5;
  93. font-weight: bold;
  94. }
  95. .highlight {
  96. background: #ffffcc;
  97. padding: 2px 4px;
  98. border-radius: 2px;
  99. }
  100. </style>
  101. </head>
  102. <body>
  103. <h1>商品选择功能测试示例</h1>
  104. <div class="demo-section">
  105. <div class="demo-title">功能概述</div>
  106. <p>新的商品选择功能完全通过操作列的选择按钮来实现单选和多选,提供更直观的用户体验。</p>
  107. <h3>主要特性:</h3>
  108. <ul class="feature-list">
  109. <li>去除了传统的checkbox/radio选择方式</li>
  110. <li>通过操作列的按钮实现选择功能</li>
  111. <li>单选模式:蓝色按钮,点击即选择并关闭</li>
  112. <li>多选模式:绿色/红色按钮,支持多次选择</li>
  113. <li>支持最大选择数量限制</li>
  114. <li>状态在搜索、分页后保持不变</li>
  115. </ul>
  116. </div>
  117. <div class="demo-section">
  118. <div class="demo-title">单选模式 vs 多选模式对比</div>
  119. <table class="comparison-table">
  120. <thead>
  121. <tr>
  122. <th>特性</th>
  123. <th>单选模式</th>
  124. <th>多选模式</th>
  125. </tr>
  126. </thead>
  127. <tbody>
  128. <tr>
  129. <td>按钮颜色</td>
  130. <td><span class="highlight">蓝色</span></td>
  131. <td><span class="highlight">绿色(未选)/ 红色(已选)</span></td>
  132. </tr>
  133. <tr>
  134. <td>按钮图标</td>
  135. <td>✓ 选择</td>
  136. <td>+ 选择 / - 取消选择</td>
  137. </tr>
  138. <tr>
  139. <td>操作方式</td>
  140. <td>点击直接完成选择</td>
  141. <td>点击切换选择状态</td>
  142. </tr>
  143. <tr>
  144. <td>确认按钮</td>
  145. <td>隐藏(不需要)</td>
  146. <td>显示(需要确认)</td>
  147. </tr>
  148. <tr>
  149. <td>数量限制</td>
  150. <td>固定1个</td>
  151. <td>可配置最大数量</td>
  152. </tr>
  153. <tr>
  154. <td>适用场景</td>
  155. <td>奖品选择等</td>
  156. <td>活动商品、优惠券商品等</td>
  157. </tr>
  158. </tbody>
  159. </table>
  160. </div>
  161. <div class="demo-section">
  162. <div class="demo-title">1. 单选模式示例</div>
  163. <p>适用于奖品选择等只需选择一个商品的场景。</p>
  164. <button class="demo-button primary" onclick="openSingleSelect()">
  165. 打开单选模式 (奖品选择)
  166. </button>
  167. <div class="code-block">
  168. // JavaScript 调用代码
  169. Fast.api.open('shop/goods/select?selectMode=single', '选择奖品', {
  170. callback: function(data) {
  171. if (data.length > 0) {
  172. var goods = data[0];
  173. console.log('选中的奖品:', goods);
  174. // 处理选中的奖品
  175. }
  176. }
  177. });
  178. </div>
  179. <div class="selected-goods" id="single-result">
  180. 选择结果将显示在这里...
  181. </div>
  182. </div>
  183. <div class="demo-section">
  184. <div class="demo-title">2. 多选模式示例</div>
  185. <p>适用于营销活动参与商品、优惠券适用商品等需要选择多个商品的场景。</p>
  186. <button class="demo-button" onclick="openMultiSelect()">
  187. 打开多选模式 (无限制)
  188. </button>
  189. <button class="demo-button warning" onclick="openMultiSelectWithLimit()">
  190. 打开多选模式 (最多3个)
  191. </button>
  192. <div class="code-block">
  193. // 多选模式(无限制)
  194. Fast.api.open('shop/goods/select?selectMode=multiple', '选择商品', {
  195. callback: function(data) {
  196. console.log('选中的商品列表:', data);
  197. }
  198. });
  199. // 多选模式(最多3个)
  200. Fast.api.open('shop/goods/select?selectMode=multiple&maxSelect=3', '选择商品(最多3个)', {
  201. callback: function(data) {
  202. console.log('选中的商品列表:', data);
  203. }
  204. });
  205. </div>
  206. <div class="selected-goods" id="multi-result">
  207. 选择结果将显示在这里...
  208. </div>
  209. </div>
  210. <div class="demo-section">
  211. <div class="demo-title">3. 使用封装方法</div>
  212. <p>在activity.js中提供了封装好的方法,可以直接调用。</p>
  213. <div class="code-block">
  214. // 奖品商品选择(单选)
  215. Controller.api.selectPrizeGoods('#prize-goods-container');
  216. // 任务商品选择(多选)
  217. Controller.api.selectTaskGoods('#task-goods-container');
  218. // 通用商品选择
  219. Controller.api.selectGoods({
  220. mode: 'single', // 'single' 或 'multiple'
  221. title: '选择商品',
  222. container: '#selected-goods',
  223. maxSelect: 0, // 最大选择数量,0表示无限制
  224. callback: function(data) {
  225. // 处理选中的商品
  226. }
  227. });
  228. </div>
  229. </div>
  230. <div class="demo-section">
  231. <div class="demo-title">界面特性说明</div>
  232. <h3>选择模式提示</h3>
  233. <ul>
  234. <li><strong>单选模式</strong>:页面顶部显示"单击任意商品的'选择'按钮即可完成选择"</li>
  235. <li><strong>多选模式</strong>:页面顶部显示"点击商品的'选择'按钮添加到选择列表,绿色表示可选择,红色表示已选择"</li>
  236. </ul>
  237. <h3>按钮状态</h3>
  238. <ul>
  239. <li><strong>单选按钮</strong>:蓝色背景,白色文字,带勾选图标</li>
  240. <li><strong>多选按钮(未选择)</strong>:绿色背景,白色文字,带加号图标</li>
  241. <li><strong>多选按钮(已选择)</strong>:红色背景,白色文字,带减号图标</li>
  242. <li><strong>禁用状态</strong>:半透明显示,无法点击</li>
  243. </ul>
  244. <h3>确认按钮</h3>
  245. <ul>
  246. <li><strong>单选模式</strong>:隐藏确认按钮,点击选择按钮直接完成选择</li>
  247. <li><strong>多选模式</strong>:显示确认按钮,显示已选择数量,如"确认选择 (3)"</li>
  248. </ul>
  249. </div>
  250. <script>
  251. // 模拟选择器函数(实际环境中这些由FastAdmin提供)
  252. function openSingleSelect() {
  253. document.getElementById('single-result').innerHTML =
  254. '<div style="color: #337ab7;"><strong>模拟选择结果:</strong><br>' +
  255. '商品名称: 热卖厨邦酱油410ml特级生抽黄豆造美味鲜酱油<br>' +
  256. '商品ID: 40<br>' +
  257. '价格: ¥7.00<br>' +
  258. '<em>实际使用时,单选模式点击选择按钮会直接关闭弹窗并返回选中商品。</em></div>';
  259. }
  260. function openMultiSelect() {
  261. document.getElementById('multi-result').innerHTML =
  262. '<div style="color: #5cb85c;"><strong>模拟选择结果:</strong><br>' +
  263. '已选择 2 个商品:<br>' +
  264. '1. 热卖厨邦酱油410ml特级生抽黄豆造美味鲜酱油 (¥7.00)<br>' +
  265. '2. 虚州卡密 (¥111.00)<br>' +
  266. '<em>实际使用时,多选模式可以选择多个商品,点击确认按钮完成选择。</em></div>';
  267. }
  268. function openMultiSelectWithLimit() {
  269. document.getElementById('multi-result').innerHTML =
  270. '<div style="color: #f0ad4e;"><strong>模拟选择结果(限制3个):</strong><br>' +
  271. '已选择 3 个商品:<br>' +
  272. '1. 热卖厨邦酱油410ml特级生抽黄豆造美味鲜酱油 (¥7.00)<br>' +
  273. '2. 虚州卡密 (¥111.00)<br>' +
  274. '3. 打底裤 (¥89.00)<br>' +
  275. '<em>已达到最大选择数量,其他商品的选择按钮将被禁用。</em></div>';
  276. }
  277. </script>
  278. </body>
  279. </html>