setGoods.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
  6. <meta name="author" content="siweiyong 2602812659@qq.com"/>
  7. <title>设置商品</title>
  8. <link rel="stylesheet" href="../script/lib/miniui/themes/default/miniui.css">
  9. <link rel="stylesheet" href="../script/lib/layui/css/layui.css" />
  10. <link rel="stylesheet" href="../script/lib/cashier/common.css">
  11. <link rel="stylesheet" href="../script/lib/layui/admin/modules/plugin/formselects/formselects.css" media="all" />
  12. <script src="../script/lib/jquery/jquery.min.js"></script>
  13. <script src="../script/lib/miniui/miniui.js"></script>
  14. <script src="../script/lib/layui/layui.js"></script>
  15. <script><{Dever::script()}></script>
  16. <script src="../script/dever/core.js"></script>
  17. </head>
  18. <body style="background: #F6F7F9;">
  19. <div class="main">
  20. <form class="layui-form" lay-filter="form">
  21. <div class="layui-row">
  22. <div class="main_left layui-col-xs12 layui-col-md3">
  23. <div class="layui-row">
  24. <div class="top">
  25. <i class="layui-icon layui-icon-app"></i>商品列表
  26. <!-- <a class="mini-button" onclick="location.href='<{$link}>'">返回上一页</a> -->
  27. </div>
  28. <div class="left_main">
  29. <input id="key" class="mini-textbox" placeholder="请输入商品名称" onenter="onKeyEnter"/>
  30. <a class="mini-button" onclick="search()">查询</a>
  31. <ul id="tree1" class="mini-tree" url="<{$url}>" showTreeIcon="true" textField="name" idField="id" expandOnLoad="true" onNodeClick="onNodeClick">
  32. </ul>
  33. </div>
  34. </div>
  35. </div>
  36. <div class="main_right layui-col-xs12 layui-col-md9">
  37. <div class="layui-row">
  38. <div class="goods_list" style="height:645px;">
  39. <table class="layui-table">
  40. <thead>
  41. <tr>
  42. <th lay-data="{field:'cate'}">商品分类</th>
  43. <th lay-data="{field:'id'}">商品编码</th>
  44. <th lay-data="{field:'name'}">商品名称</th>
  45. <th lay-data="{field:'operation'}">操作</th>
  46. </tr>
  47. </thead>
  48. <tbody id="goods">
  49. </tbody>
  50. </table>
  51. </div>
  52. <div class="total ft16">
  53. 合计:【<span> 当前选择商品数:<i class="totalNum">0</i> </span>】
  54. </div>
  55. <div class="towbtn">
  56. <input type="button" id="settlement" value="确认设置">
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. </form>
  63. </div>
  64. <script>
  65. var form;
  66. layui.config(
  67. {
  68. base: '../script/lib/layui/admin/' //静态资源所在路径
  69. ,version: true
  70. }).extend(
  71. {
  72. index: 'lib/index', //主入口模块
  73. formSelects: 'plugin/formselects/formselects'
  74. }).use(['index', 'contlist', 'table', 'form', 'formSelects','layer'], function()
  75. {
  76. var table = layui.table;
  77. form = layui.form;
  78. var formSelects = layui.formSelects;
  79. $('#give').val('<{$give}>');
  80. form.render();
  81. });
  82. $(function()
  83. {
  84. $("#settlement").click(function(){
  85. var url = '<{$submit}>';
  86. var discount_id = '<{$discount_id}>';
  87. var link = '<{$link}>';
  88. layui.layer.confirm('确定进行此项设置吗?', function() {
  89. var goods_string = JSON.stringify(goods);
  90. var data = {};
  91. data = {discount_id:discount_id, goods:goods_string,link:link};
  92. $.post(url, data, function(t) {
  93. t = JSON.parse(t);
  94. if (t.status == 1) {
  95. layui.layer.alert('折扣商品设置成功', function(index){
  96. location.reload();
  97. layer.close(index);
  98. });
  99. } else {
  100. layui.layer.alert(t.msg);
  101. }
  102. });
  103. });
  104. })
  105. })
  106. var goods = {};
  107. var del_goods = {};
  108. mini.parse();
  109. var tree = mini.get("tree1");
  110. for (var i in tree.data) {
  111. if (typeof(tree.data[i].children) == 'object') {
  112. if (tree.data[i].children.length > 0) {
  113. for (var j in tree.data[i].children) {
  114. if(tree.data[i].children[j].select == 1) {
  115. setGoods(tree.data[i].children[j]);
  116. }
  117. }
  118. } else if(tree.data[i].select == 1) {
  119. setGoods(tree.data[i]);
  120. }
  121. }
  122. }
  123. function search()
  124. {
  125. var key = mini.get("key").getValue();
  126. if (key == "") {
  127. tree.clearFilter();
  128. } else {
  129. key = key.toLowerCase();
  130. tree.filter(function (node) {
  131. var name = node.name ? node.name.toLowerCase() : "";
  132. if (name.indexOf(key) != -1) {
  133. return true;
  134. }
  135. });
  136. }
  137. }
  138. function onKeyEnter(e)
  139. {
  140. search();
  141. }
  142. function onNodeClick()
  143. {
  144. var tree=mini.get("tree1");
  145. node=tree.getSelectedNode();
  146. if(node.end) {
  147. setGoods(node);
  148. }
  149. }
  150. function setGoods(node)
  151. {
  152. if (node.id) {
  153. var key = node.id;
  154. if (!goods[key] || (goods[key] && goods[key].del == 2)) {
  155. goods[key] = node;
  156. goods[key].num = 0;
  157. goods[key].del = 1;
  158. create(node);
  159. setTotal();
  160. }
  161. }
  162. }
  163. function get(key)
  164. {
  165. return $('#goods_' + key);
  166. }
  167. function create(node)
  168. {
  169. if (!get(node.id).length) {
  170. var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
  171. addtr += '<td class="goods_class">'+node.class_name+'</td>';
  172. addtr += '<td class="goods_id">'+node.id+'</td>';
  173. addtr += '<td class="goods_name">'+node.name+'</td>';
  174. addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
  175. addtr += '</tr>';
  176. $("#goods").append(addtr);
  177. }
  178. }
  179. function del(id)
  180. {
  181. if (confirm('确定删除吗?')) {
  182. goods[id].del = 2;
  183. get(id).remove();
  184. setTotal();
  185. }
  186. }
  187. function setTotal()
  188. {
  189. var total = 0;
  190. for (var i in goods) {
  191. if (goods[i].del == 1) {
  192. total += 1;
  193. }
  194. }
  195. //$(".totalQuantity").html(num);
  196. $(".totalNum").html(total);
  197. }
  198. </script>
  199. </body>
  200. </html>