setOrderGoods.html 8.9 KB

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