setMemberGoods.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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:'name'}">商品名称</th>
  43. <th lay-data="{field:'price', edit: 'text'}">价值(元)</th>
  44. <th lay-data="{field:'number', edit: 'text'}">更改剩余数量</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. <table class="reading layui-table" lay-even="">
  56. <tbody>
  57. <tr>
  58. <td>备注(本次调整说明):</td>
  59. <td><textarea class="layui-textarea" name="desc" id="desc" rows="" cols="" maxlength="200" placeholder="请输入备注"></textarea></td>
  60. </tr>
  61. </tbody>
  62. </table>
  63. <div class="towbtn">
  64. <input type="button" id="settlement" value="确认修改权益">
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </form>
  71. </div>
  72. <script>
  73. var form;
  74. layui.config(
  75. {
  76. base: '../script/lib/layui/admin/' //静态资源所在路径
  77. ,version: true
  78. }).extend(
  79. {
  80. index: 'lib/index', //主入口模块
  81. formSelects: 'plugin/formselects/formselects'
  82. }).use(['index', 'contlist', 'table', 'form', 'formSelects','layer'], function()
  83. {
  84. var table = layui.table;
  85. form = layui.form;
  86. var formSelects = layui.formSelects;
  87. form.render();
  88. });
  89. $(function()
  90. {
  91. $("#settlement").click(function(){
  92. var url = '<{$submit}>';
  93. var mid = '<{$mid}>';
  94. var link = '<{$link}>';
  95. var search_api_mid = '<{$search_api_mid}>';
  96. layui.layer.confirm('确定进行此项设置吗?', function() {
  97. var desc = $('#desc').val();
  98. var goods_string = JSON.stringify(goods);
  99. var data = {};
  100. data = {mid:mid,search_api_mid:search_api_mid, desc:desc, goods:goods_string,link:link};
  101. $.post(url, data, function(t) {
  102. t = JSON.parse(t);
  103. if (t.status == 1) {
  104. layui.layer.alert('权益调整成功', function(index){
  105. location.href = t.data;
  106. layer.close(index);
  107. });
  108. } else {
  109. layui.layer.alert(t.msg);
  110. }
  111. });
  112. });
  113. })
  114. $("#goods").on("keyup", ".goods_num", function() {
  115. var num = parseInt($(this).val());
  116. if (!num || num <= 0) {
  117. num = 0;
  118. $(this).val(0);
  119. }
  120. var id = $(this).parent().attr('value');
  121. goods[id].total = num;
  122. if (goods[id].total == 0) {
  123. get(id).find('.delete_btn').show();
  124. } else {
  125. get(id).find('.delete_btn').hide();
  126. }
  127. setTotal();
  128. });
  129. $("#goods").on("keyup", ".goods_set_price", function() {
  130. var num = parseFloat($(this).val());
  131. if (!num || num <= 0) {
  132. num = 0;
  133. $(this).val(0);
  134. }
  135. var id = $(this).parent().attr('value');
  136. goods[id].price = num;
  137. setTotal();
  138. });
  139. })
  140. var goods = {};
  141. var del_goods = {};
  142. mini.parse();
  143. var tree = mini.get("tree1");
  144. for (var i in tree.data) {
  145. if (typeof(tree.data[i].children) == 'object') {
  146. if (tree.data[i].children.length > 0) {
  147. for (var j in tree.data[i].children) {
  148. if(tree.data[i].children[j].select == 1) {
  149. setGoods(tree.data[i].children[j]);
  150. }
  151. }
  152. } else if(tree.data[i].select == 1) {
  153. setGoods(tree.data[i]);
  154. }
  155. }
  156. }
  157. function search()
  158. {
  159. var key = mini.get("key").getValue();
  160. if (key == "") {
  161. tree.clearFilter();
  162. } else {
  163. key = key.toLowerCase();
  164. tree.filter(function (node) {
  165. var name = node.name ? node.name.toLowerCase() : "";
  166. if (name.indexOf(key) != -1) {
  167. return true;
  168. }
  169. });
  170. }
  171. }
  172. function onKeyEnter(e)
  173. {
  174. search();
  175. }
  176. function onNodeClick()
  177. {
  178. var tree=mini.get("tree1");
  179. node=tree.getSelectedNode();
  180. if(node.end) {
  181. setGoods(node);
  182. }
  183. }
  184. function setGoods(node)
  185. {
  186. if (node.id) {
  187. var key = node.id;
  188. if (!goods[key] || (goods[key] && goods[key].del == 2)) {
  189. goods[key] = node;
  190. goods[key].price = parseFloat(goods[key].price);
  191. goods[key].price_type = parseInt(goods[key].price_type);
  192. goods[key].total = parseFloat(goods[key].total);
  193. goods[key].total = goods[key].total >= 0 ? goods[key].total : 1;
  194. goods[key].num = 0;
  195. goods[key].del = 1;
  196. create(node);
  197. setTotal();
  198. } else if(node.price_type < 4) {
  199. add(key);
  200. }
  201. }
  202. }
  203. function get(key)
  204. {
  205. return $('#goods_' + key);
  206. }
  207. function create(node)
  208. {
  209. if (!get(node.id).length) {
  210. var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
  211. //addtr += '<td class="goods_id">'+node.id+'</td>';
  212. addtr += '<td class="goods_name">'+node.name+'</td>';
  213. if (node.name.indexOf('自定义面值卡') != -1) {
  214. addtr += '<td class="goods_price"><div class="jiajian" value='+node.id+'><input type="text" style="width: 122px;" value="'+node.price+'" class="goods_set_price"></div></td>';
  215. } else {
  216. addtr += '<td class="goods_price">'+node.price+'</td>';
  217. }
  218. if (node.id.indexOf('_2') != -1 && node.id.indexOf('-') != -1) {
  219. //addtr += '<td><input type="hidden" value="'+node.total+'" class="goods_num">'+node.total+'</td>';
  220. addtr += '<td><div class="jiajian" value='+node.id+'><span class="jian" onclick="dec(\''+node.id+'\')">-</span><input type="text" disabled value="'+node.total+'" class="goods_num" data-min="'+node.total+'" ><span class="jia" onclick="add(\''+node.id+'\')">+</span></div></td>';
  221. } else {
  222. 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" data-min="0"><span class="jia" onclick="add(\''+node.id+'\')">+</span></div></td>';
  223. }
  224. if (node.total <= 0) {
  225. addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
  226. } else {
  227. addtr += '<td><a class="delete_btn" style="display:none" onclick="del(\''+node.id+'\')">删除</a></td>';
  228. }
  229. addtr += '</tr>';
  230. $("#goods").append(addtr);
  231. }
  232. }
  233. function add(id)
  234. {
  235. goods[id].total += 1;
  236. get(id).find('.delete_btn').hide();
  237. get(id).find('.goods_num').val(goods[id].total);
  238. setTotal();
  239. }
  240. function dec(id)
  241. {
  242. var e = get(id).find('.goods_num');
  243. if (e.attr('data-min')) {
  244. var min = parseInt(e.attr('data-min'));
  245. if (goods[id].total <= min) {
  246. //alert('无法减少');
  247. return;
  248. }
  249. }
  250. goods[id].total -= 1;
  251. if (goods[id].total < 1) {
  252. goods[id].total = 0;
  253. }
  254. if (goods[id].total == 0) {
  255. get(id).find('.delete_btn').show();
  256. } else {
  257. get(id).find('.delete_btn').hide();
  258. }
  259. e.val(goods[id].total);
  260. setTotal();
  261. }
  262. function del(id)
  263. {
  264. if (confirm('确定删除吗?')) {
  265. goods[id].del = 2;
  266. get(id).remove();
  267. setTotal();
  268. }
  269. }
  270. function setTotal()
  271. {
  272. var cash = 0;
  273. var num = 0;
  274. var total = 0;
  275. for (var i in goods) {
  276. //num += goods[i].num;
  277. total += goods[i].total;
  278. }
  279. //$(".totalQuantity").html(num);
  280. $(".totalNum").html(total);
  281. }
  282. function setShop()
  283. {
  284. var give = $('#give').val();
  285. if (!give) {
  286. layui.layer.alert('请选择赠送类型');
  287. return;
  288. }
  289. layui.layer.confirm('确定切换赠送类型吗?切换后现在选择的商品都将清空', function() {
  290. location.href = '<{$host}>&give=' + give;
  291. });
  292. }
  293. </script>
  294. </body>
  295. </html>