setGoods.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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="javascript:history.back()">返回上一页</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="top">
  39. <label>选择赠送类型:</label>
  40. <div class="layui-input-inline">
  41. <div><select name="give" id="give" lay-verify=""><{foreach($search as $k => $v):}><option value="<{$k}>" <{if($give == $k):}>selected<{endif}>><{$v}></option><{endforeach}></select></div>
  42. </div>
  43. <div class="layui-input-inline">
  44. <button class="layui-btn layui-btn-button" type="button" style="vertical-align: middle;margin-bottom: 2px;" onclick="setShop()">确认选择</button>
  45. </div>
  46. </div>
  47. <div class="goods_list" style="height:645px;">
  48. <table class="layui-table">
  49. <thead>
  50. <tr>
  51. <th lay-data="{field:'id'}">商品编码</th>
  52. <th lay-data="{field:'name'}">商品名称</th>
  53. <th lay-data="{field:'price', edit: 'text'}">销售价(元)</th>
  54. <th lay-data="{field:'number', edit: 'text'}">更改总数量</th>
  55. <th lay-data="{field:'operation'}">操作</th>
  56. </tr>
  57. </thead>
  58. <tbody id="goods">
  59. </tbody>
  60. </table>
  61. </div>
  62. <div class="total ft16">
  63. 合计:【<span> 当前总数量:<i class="totalNum">0</i> </span>
  64. </div>
  65. <div class="towbtn">
  66. <input type="button" id="settlement" value="确认设置">
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </form>
  73. </div>
  74. <script>
  75. var form;
  76. layui.config(
  77. {
  78. base: '../script/lib/layui/admin/' //静态资源所在路径
  79. ,version: true
  80. }).extend(
  81. {
  82. index: 'lib/index', //主入口模块
  83. formSelects: 'plugin/formselects/formselects'
  84. }).use(['index', 'contlist', 'table', 'form', 'formSelects','layer'], function()
  85. {
  86. var table = layui.table;
  87. form = layui.form;
  88. var formSelects = layui.formSelects;
  89. $('#give').val('<{$give}>');
  90. form.render();
  91. });
  92. $(function()
  93. {
  94. $("#settlement").click(function(){
  95. var url = '<{$submit}>';
  96. var role_id = '<{$role_id}>';
  97. var give = $('#give').val();
  98. layui.layer.confirm('确定进行此项设置吗?', function() {
  99. var goods_string = JSON.stringify(goods);
  100. var data = {};
  101. data = {role_id:role_id, give:give, goods:goods_string};
  102. $.post(url, data, function(t) {
  103. t = JSON.parse(t);
  104. if (t.status == 1) {
  105. layui.layer.alert('商品权益设置成功', function(index){
  106. location.reload();
  107. layer.close(index);
  108. });
  109. } else {
  110. layui.layer.alert(t.msg);
  111. }
  112. });
  113. });
  114. })
  115. $("#goods").on("keyup", ".goods_num", function() {
  116. var num = parseInt($(this).val());
  117. if (!num || num <= 0) {
  118. num = 0;
  119. $(this).val(0);
  120. }
  121. var id = $(this).parent().attr('value');
  122. goods[id].total = num;
  123. setTotal();
  124. });
  125. })
  126. var goods = {};
  127. var del_goods = {};
  128. mini.parse();
  129. var tree = mini.get("tree1");
  130. for (var i in tree.data) {
  131. if (typeof(tree.data[i].children) == 'object') {
  132. if (tree.data[i].children.length > 0) {
  133. for (var j in tree.data[i].children) {
  134. if(tree.data[i].children[j].select == 1) {
  135. setGoods(tree.data[i].children[j]);
  136. }
  137. }
  138. } else if(tree.data[i].select == 1) {
  139. setGoods(tree.data[i]);
  140. }
  141. }
  142. }
  143. function search()
  144. {
  145. var key = mini.get("key").getValue();
  146. if (key == "") {
  147. tree.clearFilter();
  148. } else {
  149. key = key.toLowerCase();
  150. tree.filter(function (node) {
  151. var name = node.name ? node.name.toLowerCase() : "";
  152. if (name.indexOf(key) != -1) {
  153. return true;
  154. }
  155. });
  156. }
  157. }
  158. function onKeyEnter(e)
  159. {
  160. search();
  161. }
  162. function onNodeClick()
  163. {
  164. var tree=mini.get("tree1");
  165. node=tree.getSelectedNode();
  166. if(node.end) {
  167. setGoods(node);
  168. }
  169. }
  170. function setGoods(node)
  171. {
  172. if (node.id) {
  173. var key = node.id;
  174. if (!goods[key] || (goods[key] && goods[key].del == 2)) {
  175. goods[key] = node;
  176. goods[key].price = parseFloat(goods[key].price);
  177. goods[key].price_type = parseInt(goods[key].price_type);
  178. goods[key].total = parseFloat(goods[key].total);
  179. goods[key].total = goods[key].total > 0 ? goods[key].total : 1;
  180. goods[key].num = 0;
  181. goods[key].del = 1;
  182. create(node);
  183. setTotal();
  184. } else if(node.price_type < 4) {
  185. add(key);
  186. }
  187. }
  188. }
  189. function get(key)
  190. {
  191. return $('#goods_' + key);
  192. }
  193. function create(node)
  194. {
  195. if (!get(node.id).length) {
  196. var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
  197. addtr += '<td class="goods_id">'+node.id+'</td>';
  198. addtr += '<td class="goods_name">'+node.name+'</td>';
  199. addtr += '<td class="goods_price">'+node.price+'</td>';
  200. addtr += '<td><div class="jiajian" value='+node.id+'><span class="jian" onclick="dec(\''+node.id+'\')">-</span><input type="text" value="'+node.total+'" class="goods_num"><span class="jia" onclick="add(\''+node.id+'\')">+</span></div></td>';
  201. if (node.total <= 0) {
  202. addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
  203. } else {
  204. addtr += '<td></td>';
  205. }
  206. addtr += '</tr>';
  207. $("#goods").append(addtr);
  208. }
  209. }
  210. function add(id)
  211. {
  212. goods[id].total += 1;
  213. get(id).find('.goods_num').val(goods[id].total);
  214. setTotal();
  215. }
  216. function dec(id)
  217. {
  218. goods[id].total -= 1;
  219. if (goods[id].total < 1) {
  220. goods[id].total = 0;
  221. }
  222. get(id).find('.goods_num').val(goods[id].total);
  223. setTotal();
  224. }
  225. function del(id)
  226. {
  227. if (confirm('确定删除吗?')) {
  228. goods[id].del = 2;
  229. get(id).remove();
  230. setTotal();
  231. }
  232. }
  233. function setTotal()
  234. {
  235. var cash = 0;
  236. var num = 0;
  237. var total = 0;
  238. for (var i in goods) {
  239. //num += goods[i].num;
  240. total += goods[i].total;
  241. }
  242. //$(".totalQuantity").html(num);
  243. $(".totalNum").html(total);
  244. }
  245. function setShop()
  246. {
  247. var give = $('#give').val();
  248. if (!give) {
  249. layui.layer.alert('请选择赠送类型');
  250. return;
  251. }
  252. layui.layer.confirm('确定切换赠送类型吗?切换后现在选择的商品都将清空', function() {
  253. location.href = '<{$host}>&give=' + give;
  254. });
  255. }
  256. </script>
  257. </body>
  258. </html>