set_price_goods.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. </div>
  27. <div class="left_main">
  28. <input id="key" class="mini-textbox" onenter="onKeyEnter" value="请输入商品名称" onclick="setVal('key')"/>
  29. <a class="mini-button" onclick="search()">查询</a>
  30. <button class="layui-btn layui-btn-button" type="button" style="vertical-align: middle;margin-bottom: 2px;" onclick="addGoods()">一键添加</button>
  31. <button class="layui-btn layui-btn-button" type="button" style="vertical-align: middle;margin-bottom: 2px;" onclick="delGoods()">一键删除</button>
  32. <ul id="tree1" class="mini-tree" url="<{$url}>" showTreeIcon="true" textField="name" idField="id" expandOnLoad="true" onNodeClick="onNodeClick">
  33. </ul>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="main_right layui-col-xs12 layui-col-md9">
  38. <div class="layui-row">
  39. <div class="top">
  40. <div class="layui-input-inline" style="margin-left:20px">
  41. <input id="search_key" class="mini-textbox" value="请输入商品名称" onclick="setVal('search_key')"/>
  42. <a class="mini-button" onclick="searchGoods()">搜索</a>
  43. </div>
  44. </div>
  45. <div class="goods_list" style="height:645px;">
  46. <table class="layui-table">
  47. <thead>
  48. <tr>
  49. <!--<th lay-data="{field:'id'}" width="15%">商品编码</th>-->
  50. <th lay-data="{field:'name'}" width="15%">商品名称</th>
  51. <{if($type == 1):}>
  52. <th lay-data="{field:'price', edit: 'text'}" width="10%">原销售价</th>
  53. <th lay-data="{field:'price', edit: 'text'}" width="10%">销售调价</th>
  54. <th lay-data="{field:'price', edit: 'text'}" width="10%">新销售价</th>
  55. <th lay-data="{field:'buy_price', edit: 'text'}" width="10%">原采购价</th>
  56. <th lay-data="{field:'buy_price', edit: 'text'}" width="10%">采购调价</th>
  57. <th lay-data="{field:'buy_price', edit: 'text'}" width="10%">新采购价</th>
  58. <{else:}>
  59. <th lay-data="{field:'price', edit: 'text'}" width="15%">原销售价</th>
  60. <th lay-data="{field:'price', edit: 'text'}" width="15%">新销售价</th>
  61. <th lay-data="{field:'buy_price', edit: 'text'}" width="15%">原采购价</th>
  62. <th lay-data="{field:'buy_price', edit: 'text'}" width="15%">新采购价</th>
  63. <{endif;}>
  64. <th lay-data="{field:'operation'}" width="15%">操作</th>
  65. </tr>
  66. </thead>
  67. <tbody id="goods">
  68. </tbody>
  69. </table>
  70. </div>
  71. <div class="towbtn">
  72. <input type="button" id="settlement" value="确认设置">
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </form>
  79. </div>
  80. <script>
  81. var form;
  82. var goods = {};
  83. var del_goods = {};
  84. var tree = {};
  85. var type = "<{$type}>";
  86. var num = "<{$num}>";
  87. layui.config(
  88. {
  89. base: '../script/lib/layui/admin/' //静态资源所在路径
  90. ,version: true
  91. }).extend(
  92. {
  93. index: 'lib/index', //主入口模块
  94. formSelects: 'plugin/formselects/formselects'
  95. }).use(['index', 'contlist', 'table', 'form', 'formSelects','layer'], function()
  96. {
  97. var table = layui.table;
  98. form = layui.form;
  99. var formSelects = layui.formSelects;
  100. mini.parse();
  101. tree = mini.get("tree1");
  102. for (var i in tree.data) {
  103. if (typeof(tree.data[i].children) == 'object') {
  104. if (tree.data[i].children.length > 0) {
  105. for (var j in tree.data[i].children) {
  106. if(tree.data[i].children[j].select == 1) {
  107. setGoods(tree.data[i].children[j]);
  108. }
  109. }
  110. } else if(tree.data[i].select == 1) {
  111. setGoods(tree.data[i]);
  112. }
  113. }
  114. }
  115. });
  116. $(function()
  117. {
  118. $("#settlement").click(function(){
  119. var url = '<{$submit}>';
  120. var price_rule_id = '<{$price_rule_id}>';
  121. layui.layer.confirm('确定进行此项设置吗?', function() {
  122. var goods_string = JSON.stringify(goods);
  123. var data = {};
  124. data = {price_rule_id:price_rule_id, goods:goods_string};
  125. $.post(url, data, function(t) {
  126. t = JSON.parse(t);
  127. if (t.status == 1) {
  128. layui.layer.alert('商品设置成功', function(index){
  129. if (t.data == 'refer') {
  130. history.back();
  131. } else {
  132. location.href = t.data;
  133. }
  134. layer.close(index);
  135. });
  136. } else {
  137. layui.layer.alert(t.msg);
  138. }
  139. });
  140. });
  141. });
  142. $("#goods").on("keyup", ".goods_price", function() {
  143. var num = $(this).find('input').val();
  144. var id = $(this).parent().attr('value');
  145. goods[id].price = num;
  146. setTotal();
  147. goods[id].new_price = getPrice(goods[id].old_price, goods[id].price);
  148. $(this).parent().find('.goods_new_price').html(goods[id].new_price);
  149. });
  150. $("#goods").on("keyup", ".goods_buy_price", function() {
  151. var num = $(this).find('input').val();
  152. var id = $(this).parent().attr('value');
  153. goods[id].buy_price = num;
  154. setTotal();
  155. goods[id].new_buy_price = getPrice(goods[id].old_buy_price, goods[id].buy_price);
  156. $(this).parent().find('.goods_new_buy_price').html(goods[id].new_buy_price);
  157. });
  158. })
  159. function onNodeClick()
  160. {
  161. var tree=mini.get("tree1");
  162. node=tree.getSelectedNode();
  163. if(node.end) {
  164. setGoods(node);
  165. }
  166. }
  167. function setVal(e)
  168. {
  169. mini.get(e).setValue('');
  170. }
  171. function searchGoods()
  172. {
  173. var key = mini.get("search_key").getValue();
  174. if (key == "") {
  175. $(".mytr").show();
  176. } else {
  177. key = key.toLowerCase();
  178. $(".mytr").show();
  179. $(".goods_name").each(function(t) {
  180. var name = $(this).html();
  181. name = name.toLowerCase();
  182. if (name.indexOf(key) == -1) {
  183. $(this).parent().hide();
  184. }
  185. });
  186. }
  187. }
  188. // 一键添加
  189. function addGoods()
  190. {
  191. var key = mini.get("key").getValue();
  192. if (key == '请输入商品名称') {
  193. key = '';
  194. }
  195. if (key) {
  196. key = key.toLowerCase();
  197. }
  198. for (var i in tree.data) {
  199. if (typeof(tree.data[i].children) == 'object') {
  200. if (tree.data[i].children.length > 0) {
  201. for (var j in tree.data[i].children) {
  202. if (key) {
  203. var name = tree.data[i].children[j].name;
  204. if (name.indexOf(key) != -1) {
  205. setGoods(tree.data[i].children[j]);
  206. }
  207. } else {
  208. setGoods(tree.data[i].children[j]);
  209. }
  210. }
  211. } else {
  212. if (key) {
  213. var name = tree.data[i].name;
  214. if (name.indexOf(key) != -1) {
  215. setGoods(tree.data[i]);
  216. }
  217. } else {
  218. setGoods(tree.data[i]);
  219. }
  220. }
  221. }
  222. }
  223. }
  224. // 一键删除
  225. function delGoods()
  226. {
  227. if (confirm('确定删除吗?')) {
  228. var key = mini.get("key").getValue();
  229. if (key == '请输入商品名称') {
  230. key = '';
  231. }
  232. if (key) {
  233. key = key.toLowerCase();
  234. }
  235. for (var i in tree.data) {
  236. if (typeof(tree.data[i].children) == 'object') {
  237. if (tree.data[i].children.length > 0) {
  238. for (var j in tree.data[i].children) {
  239. if (key) {
  240. var name = tree.data[i].children[j].name;
  241. if (name.indexOf(key) != -1) {
  242. unsetGoods(tree.data[i].children[j]);
  243. }
  244. } else {
  245. unsetGoods(tree.data[i].children[j]);
  246. }
  247. }
  248. } else {
  249. if (key) {
  250. var name = tree.data[i].name;
  251. if (name.indexOf(key) != -1) {
  252. unsetGoods(tree.data[i]);
  253. }
  254. } else {
  255. unsetGoods(tree.data[i]);
  256. }
  257. }
  258. }
  259. }
  260. setTotal();
  261. }
  262. }
  263. function unsetGoods(node)
  264. {
  265. if (node.id) {
  266. if (goods[node.id]) {
  267. goods[node.id].del = 2;
  268. goods[node.id].num = 0;
  269. goods[node.id].total = 0;
  270. get(node.id).remove();
  271. }
  272. }
  273. }
  274. function setGoods(node)
  275. {
  276. if (node.id) {
  277. var key = node.id;
  278. if (!goods[key] || (goods[key] && goods[key].del == 2)) {
  279. goods[key] = node;
  280. goods[key].type = parseInt(goods[key].type);
  281. goods[key].total = parseFloat(goods[key].total);
  282. goods[key].min = goods[key].min ? parseFloat(goods[key].min) : 1;
  283. goods[key].num = 0;
  284. goods[key].del = 1;
  285. create(node);
  286. setTotal();
  287. } else if(node.type < 4) {
  288. add(key);
  289. }
  290. }
  291. }
  292. function get(key)
  293. {
  294. return $('#goods_' + key);
  295. }
  296. function create(node)
  297. {
  298. if (!get(node.id).length) {
  299. var select = '';
  300. var addtr = '<tr class="mytr" id="goods_'+node.id+'" value="'+node.id+'">';
  301. //addtr += '<td class="goods_id">'+node.id+'</td>';
  302. addtr += '<td class="goods_name">'+node.name+'</td>';
  303. addtr += '<td class="goods_old_price">'+node.old_price+'</td>';
  304. addtr += '<td class="goods_price"><span><input type="text" value="'+node.price+'" class="layui-input"></span></td>';
  305. if (type == 1) {
  306. node.new_price = getPrice(node.old_price, node.price);
  307. addtr += '<td class="goods_new_price">'+node.new_price+'</td>';
  308. }
  309. addtr += '<td class="goods_old_buy_price">'+node.old_buy_price+'</td>';
  310. addtr += '<td class="goods_buy_price"><span><input type="text" value="'+node.buy_price+'" class="layui-input"></span></td>';
  311. if (type == 1) {
  312. node.new_buy_price = getPrice(node.old_buy_price, node.buy_price);
  313. addtr += '<td class="goods_new_buy_price">'+node.new_buy_price+'</td>';
  314. }
  315. addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
  316. addtr += '</tr>';
  317. $("#goods").append(addtr);
  318. form.render();
  319. //$('.goods_price_template').change();
  320. }
  321. }
  322. function getPrice(price, num)
  323. {
  324. if (num.indexOf('%') > -1) {
  325. num = num.replace('%', '');
  326. price = parseFloat(price) + parseFloat(price * (num/100));
  327. } else {
  328. // 数字
  329. price = parseFloat(price) + parseFloat(num);
  330. }
  331. price = price.toFixed(2);
  332. return price;
  333. }
  334. function del(id)
  335. {
  336. if (confirm('确定删除吗?')) {
  337. goods[id].del = 2;
  338. goods[id].num = 0;
  339. get(id).remove();
  340. setTotal();
  341. }
  342. }
  343. function setTotal()
  344. {
  345. return;
  346. }
  347. function add(id)
  348. {
  349. }
  350. </script>
  351. </body>
  352. </html>