setGoods.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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="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 link = '<{$link}>';
  98. var give = $('#give').val();
  99. layui.layer.confirm('确定进行此项设置吗?', function() {
  100. var goods_string = JSON.stringify(goods);
  101. var data = {};
  102. data = {role_id:role_id, give:give, goods:goods_string,link:link};
  103. $.post(url, data, function(t) {
  104. t = JSON.parse(t);
  105. if (t.status == 1) {
  106. layui.layer.alert('商品权益设置成功', function(index){
  107. location.reload();
  108. layer.close(index);
  109. });
  110. } else {
  111. layui.layer.alert(t.msg);
  112. }
  113. });
  114. });
  115. })
  116. $("#goods").on("keyup", ".goods_num", function() {
  117. var num = parseInt($(this).val());
  118. if (!num || num <= 0) {
  119. num = 0;
  120. $(this).val(0);
  121. }
  122. var id = $(this).parent().attr('value');
  123. goods[id].total = num;
  124. setTotal();
  125. });
  126. })
  127. var goods = {};
  128. var del_goods = {};
  129. mini.parse();
  130. var tree = mini.get("tree1");
  131. for (var i in tree.data) {
  132. if (typeof(tree.data[i].children) == 'object') {
  133. if (tree.data[i].children.length > 0) {
  134. for (var j in tree.data[i].children) {
  135. if(tree.data[i].children[j].select == 1) {
  136. setGoods(tree.data[i].children[j]);
  137. }
  138. }
  139. } else if(tree.data[i].select == 1) {
  140. setGoods(tree.data[i]);
  141. }
  142. }
  143. }
  144. function search()
  145. {
  146. var key = mini.get("key").getValue();
  147. if (key == "") {
  148. tree.clearFilter();
  149. } else {
  150. key = key.toLowerCase();
  151. tree.filter(function (node) {
  152. var name = node.name ? node.name.toLowerCase() : "";
  153. if (name.indexOf(key) != -1) {
  154. return true;
  155. }
  156. });
  157. }
  158. }
  159. function onKeyEnter(e)
  160. {
  161. search();
  162. }
  163. function onNodeClick()
  164. {
  165. var tree=mini.get("tree1");
  166. node=tree.getSelectedNode();
  167. if(node.end) {
  168. setGoods(node);
  169. }
  170. }
  171. function setGoods(node)
  172. {
  173. if (node.id) {
  174. var key = node.id;
  175. if (!goods[key] || (goods[key] && goods[key].del == 2)) {
  176. goods[key] = node;
  177. goods[key].price = parseFloat(goods[key].price);
  178. goods[key].price_type = parseInt(goods[key].price_type);
  179. goods[key].total = parseFloat(goods[key].total);
  180. goods[key].total = goods[key].total > 0 ? goods[key].total : 1;
  181. goods[key].num = 0;
  182. goods[key].del = 1;
  183. create(node);
  184. setTotal();
  185. } else if(node.price_type < 4) {
  186. add(key);
  187. }
  188. }
  189. }
  190. function get(key)
  191. {
  192. return $('#goods_' + key);
  193. }
  194. function create(node)
  195. {
  196. if (!get(node.id).length) {
  197. var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
  198. addtr += '<td class="goods_id">'+node.id+'</td>';
  199. addtr += '<td class="goods_name">'+node.name+'</td>';
  200. addtr += '<td class="goods_price">'+node.price+'</td>';
  201. 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>';
  202. if (node.total <= 0) {
  203. addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
  204. } else {
  205. addtr += '<td></td>';
  206. }
  207. addtr += '</tr>';
  208. $("#goods").append(addtr);
  209. }
  210. }
  211. function add(id)
  212. {
  213. goods[id].total += 1;
  214. get(id).find('.goods_num').val(goods[id].total);
  215. setTotal();
  216. }
  217. function dec(id)
  218. {
  219. goods[id].total -= 1;
  220. if (goods[id].total < 1) {
  221. goods[id].total = 0;
  222. }
  223. get(id).find('.goods_num').val(goods[id].total);
  224. setTotal();
  225. }
  226. function del(id)
  227. {
  228. if (confirm('确定删除吗?')) {
  229. goods[id].del = 2;
  230. get(id).remove();
  231. setTotal();
  232. }
  233. }
  234. function setTotal()
  235. {
  236. var cash = 0;
  237. var num = 0;
  238. var total = 0;
  239. for (var i in goods) {
  240. //num += goods[i].num;
  241. total += goods[i].total;
  242. }
  243. //$(".totalQuantity").html(num);
  244. $(".totalNum").html(total);
  245. }
  246. function setShop()
  247. {
  248. var give = $('#give').val();
  249. if (!give) {
  250. layui.layer.alert('请选择赠送类型');
  251. return;
  252. }
  253. layui.layer.confirm('确定切换赠送类型吗?切换后现在选择的商品都将清空', function() {
  254. location.href = '<{$host}>&give=' + give;
  255. });
  256. }
  257. </script>
  258. </body>
  259. </html>