setRewardGoods.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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:'id'}">商品编码</th>
  43. <th lay-data="{field:'name'}">商品名称</th>
  44. <th lay-data="{field:'price', edit: 'text'}">价值(元)</th>
  45. <th lay-data="{field:'number', edit: 'text'}">更改总数量</th>
  46. <th lay-data="{field:'operation'}">操作</th>
  47. </tr>
  48. </thead>
  49. <tbody id="goods">
  50. </tbody>
  51. </table>
  52. </div>
  53. <div class="total ft16">
  54. 合计:【<span> 当前总数量:<i class="totalNum">0</i> </span>】
  55. </div>
  56. <div class="towbtn">
  57. <input type="button" id="settlement" value="确认设置">
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </form>
  64. </div>
  65. <script>
  66. var form;
  67. layui.config(
  68. {
  69. base: '../script/lib/layui/admin/' //静态资源所在路径
  70. ,version: true
  71. }).extend(
  72. {
  73. index: 'lib/index', //主入口模块
  74. formSelects: 'plugin/formselects/formselects'
  75. }).use(['index', 'contlist', 'table', 'form', 'formSelects','layer'], function()
  76. {
  77. var table = layui.table;
  78. form = layui.form;
  79. var formSelects = layui.formSelects;
  80. form.render();
  81. });
  82. $(function()
  83. {
  84. $("#settlement").click(function(){
  85. var url = '<{$submit}>';
  86. var reward_give_id = '<{$reward_give_id}>';
  87. var link = '<{$link}>';
  88. layui.layer.confirm('确定进行此项设置吗?', function() {
  89. var goods_string = JSON.stringify(goods);
  90. var data = {};
  91. data = {reward_give_id:reward_give_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. $("#goods").on("keyup", ".goods_num", function() {
  106. var num = parseInt($(this).val());
  107. if (!num || num <= 0) {
  108. num = 0;
  109. $(this).val(0);
  110. }
  111. var id = $(this).parent().attr('value');
  112. goods[id].total = num;
  113. setTotal();
  114. });
  115. })
  116. var goods = {};
  117. var del_goods = {};
  118. mini.parse();
  119. var tree = mini.get("tree1");
  120. for (var i in tree.data) {
  121. if (typeof(tree.data[i].children) == 'object') {
  122. if (tree.data[i].children.length > 0) {
  123. for (var j in tree.data[i].children) {
  124. if(tree.data[i].children[j].select == 1) {
  125. setGoods(tree.data[i].children[j]);
  126. }
  127. }
  128. } else if(tree.data[i].select == 1) {
  129. setGoods(tree.data[i]);
  130. }
  131. }
  132. }
  133. function search()
  134. {
  135. var key = mini.get("key").getValue();
  136. if (key == "") {
  137. tree.clearFilter();
  138. } else {
  139. key = key.toLowerCase();
  140. tree.filter(function (node) {
  141. var name = node.name ? node.name.toLowerCase() : "";
  142. if (name.indexOf(key) != -1) {
  143. return true;
  144. }
  145. });
  146. }
  147. }
  148. function onKeyEnter(e)
  149. {
  150. search();
  151. }
  152. function onNodeClick()
  153. {
  154. var tree=mini.get("tree1");
  155. node=tree.getSelectedNode();
  156. if(node.end) {
  157. setGoods(node);
  158. }
  159. }
  160. function setGoods(node)
  161. {
  162. if (node.id) {
  163. var key = node.id;
  164. if (!goods[key] || (goods[key] && goods[key].del == 2)) {
  165. goods[key] = node;
  166. goods[key].price = parseFloat(goods[key].price);
  167. goods[key].price_type = parseInt(goods[key].price_type);
  168. goods[key].total = parseFloat(goods[key].total);
  169. goods[key].total = goods[key].total > 0 ? goods[key].total : 1;
  170. goods[key].num = 0;
  171. goods[key].del = 1;
  172. create(node);
  173. setTotal();
  174. } else if(node.price_type < 4) {
  175. add(key);
  176. }
  177. }
  178. }
  179. function get(key)
  180. {
  181. return $('#goods_' + key);
  182. }
  183. function create(node)
  184. {
  185. if (!get(node.id).length) {
  186. var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
  187. addtr += '<td class="goods_id">'+node.id+'</td>';
  188. addtr += '<td class="goods_name">'+node.name+'</td>';
  189. addtr += '<td class="goods_price">'+node.price+'</td>';
  190. 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>';
  191. if (node.total <= 0) {
  192. addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
  193. } else {
  194. addtr += '<td></td>';
  195. }
  196. addtr += '</tr>';
  197. $("#goods").append(addtr);
  198. }
  199. }
  200. function add(id)
  201. {
  202. goods[id].total += 1;
  203. get(id).find('.goods_num').val(goods[id].total);
  204. setTotal();
  205. }
  206. function dec(id)
  207. {
  208. goods[id].total -= 1;
  209. if (goods[id].total < 1) {
  210. goods[id].total = 0;
  211. }
  212. get(id).find('.goods_num').val(goods[id].total);
  213. setTotal();
  214. }
  215. function del(id)
  216. {
  217. if (confirm('确定删除吗?')) {
  218. goods[id].del = 2;
  219. get(id).remove();
  220. setTotal();
  221. }
  222. }
  223. function setTotal()
  224. {
  225. var cash = 0;
  226. var num = 0;
  227. var total = 0;
  228. for (var i in goods) {
  229. //num += goods[i].num;
  230. total += goods[i].total;
  231. }
  232. //$(".totalQuantity").html(num);
  233. $(".totalNum").html(total);
  234. }
  235. </script>
  236. </body>
  237. </html>