set_seller_goods.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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 style="display:none;">
  41. <label>选择商品分类:</label>
  42. <div class="layui-input-inline">
  43. <div><select xm-select="shop_id" xm-select-skin="normal" xm-select-search="<{$search}>" xm-select-search-type="dl" xm-select-radio="" class="update_value form-control layui-input layui-select" name="shop_id" id="shop_id" ></select></div>
  44. </div>
  45. <div class="layui-input-inline">
  46. <button class="layui-btn layui-btn-button" type="button" style="vertical-align: middle;margin-bottom: 2px;" onclick="setShop()">确认选择</button>
  47. </div>
  48. </div>
  49. <div class="layui-input-inline" style="margin-left:20px">
  50. <input id="search_key" class="mini-textbox" value="请输入商品名称" onclick="setVal('search_key')"/>
  51. <a class="mini-button" onclick="searchGoods()">搜索</a>
  52. </div>
  53. </div>
  54. <div class="goods_list" style="height:645px;">
  55. <table class="layui-table">
  56. <thead>
  57. <tr>
  58. <!--<th lay-data="{field:'id'}">商品编码</th>-->
  59. <th lay-data="{field:'name'}">商品名称</th>
  60. <th lay-data="{field:'total', edit: 'text'}">当前库存</th>
  61. <th lay-data="{field:'price', edit: 'text'}">销售价</th>
  62. <th lay-data="{field:'commission', edit: 'text'}">销售佣金</th>
  63. <th lay-data="{field:'buy_price', edit: 'text'}">采购价</th>
  64. <th lay-data="{field:'number', edit: 'text'}">采购起订数</th>
  65. <th lay-data="{field:'operation'}">操作</th>
  66. </tr>
  67. </thead>
  68. <tbody id="goods">
  69. </tbody>
  70. </table>
  71. </div>
  72. <div class="total ft16">
  73. 合计:【<span> 当前总库存:<i class="totalNum">0</i> </span>】
  74. </div>
  75. <div class="towbtn">
  76. <input type="button" id="settlement" value="确认设置">
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. </form>
  83. </div>
  84. <script>
  85. var form;
  86. var goods = {};
  87. var del_goods = {};
  88. var tree = {};
  89. var commission = '<{$info["commission"]}>';
  90. layui.config(
  91. {
  92. base: '../script/lib/layui/admin/' //静态资源所在路径
  93. ,version: true
  94. }).extend(
  95. {
  96. index: 'lib/index', //主入口模块
  97. formSelects: 'plugin/formselects/formselects'
  98. }).use(['index', 'contlist', 'table', 'form', 'formSelects','layer'], function()
  99. {
  100. var table = layui.table;
  101. form = layui.form;
  102. var formSelects = layui.formSelects;
  103. mini.parse();
  104. tree = mini.get("tree1");
  105. for (var i in tree.data) {
  106. if (typeof(tree.data[i].children) == 'object') {
  107. if (tree.data[i].children.length > 0) {
  108. for (var j in tree.data[i].children) {
  109. if(tree.data[i].children[j].select == 1) {
  110. setGoods(tree.data[i].children[j]);
  111. }
  112. }
  113. } else if(tree.data[i].select == 1) {
  114. setGoods(tree.data[i]);
  115. }
  116. }
  117. }
  118. });
  119. $(function()
  120. {
  121. $("#settlement").click(function(){
  122. var url = '<{$submit}>';
  123. var seller_id = '<{$seller_id}>';
  124. layui.layer.confirm('确定进行此项设置吗?', function() {
  125. var goods_string = JSON.stringify(goods);
  126. var data = {};
  127. data = {seller_id:seller_id, goods:goods_string};
  128. $.post(url, data, function(t) {
  129. t = JSON.parse(t);
  130. if (t.status == 1) {
  131. layui.layer.alert('商品设置成功', function(index){
  132. if (t.data == 'refer') {
  133. history.back();
  134. } else {
  135. location.href = t.data;
  136. }
  137. layer.close(index);
  138. });
  139. } else {
  140. layui.layer.alert(t.msg);
  141. }
  142. });
  143. });
  144. })
  145. $("#goods").on("keyup", ".goods_num", function() {
  146. var num = parseFloat($(this).val());
  147. if (num < 0) {
  148. num = 0;
  149. $(this).val(0);
  150. }
  151. var id = $(this).parent().attr('value');
  152. goods[id].num = num;
  153. setTotal();
  154. });
  155. $("#goods").on("keyup", ".goods_min", function() {
  156. var min = parseFloat($(this).val());
  157. if (min < 0) {
  158. min = 1;
  159. $(this).val(1);
  160. }
  161. var id = $(this).parent().attr('value');
  162. goods[id].min = min;
  163. setTotal();
  164. });
  165. })
  166. function search()
  167. {
  168. var key = mini.get("key").getValue();
  169. if (key == "") {
  170. tree.clearFilter();
  171. } else {
  172. key = key.toLowerCase();
  173. tree.filter(function (node) {
  174. var name = node.name ? node.name.toLowerCase() : "";
  175. if (name.indexOf(key) != -1) {
  176. return true;
  177. }
  178. });
  179. }
  180. }
  181. function onKeyEnter(e)
  182. {
  183. search();
  184. }
  185. function onNodeClick()
  186. {
  187. var tree=mini.get("tree1");
  188. node=tree.getSelectedNode();
  189. if(node.end) {
  190. setGoods(node);
  191. }
  192. }
  193. function setVal(e)
  194. {
  195. mini.get(e).setValue('');
  196. }
  197. function searchGoods()
  198. {
  199. var key = mini.get("search_key").getValue();
  200. if (key == "") {
  201. $(".mytr").show();
  202. } else {
  203. key = key.toLowerCase();
  204. $(".mytr").show();
  205. $(".goods_name").each(function(t) {
  206. var name = $(this).html();
  207. name = name.toLowerCase();
  208. if (name.indexOf(key) == -1) {
  209. $(this).parent().hide();
  210. }
  211. });
  212. }
  213. }
  214. // 一键添加
  215. function addGoods()
  216. {
  217. var key = mini.get("key").getValue();
  218. if (key == '请输入商品名称') {
  219. key = '';
  220. }
  221. if (key) {
  222. key = key.toLowerCase();
  223. }
  224. for (var i in tree.data) {
  225. if (typeof(tree.data[i].children) == 'object') {
  226. if (tree.data[i].children.length > 0) {
  227. for (var j in tree.data[i].children) {
  228. if (key) {
  229. var name = tree.data[i].children[j].name;
  230. if (name.indexOf(key) != -1) {
  231. setGoods(tree.data[i].children[j]);
  232. }
  233. } else {
  234. setGoods(tree.data[i].children[j]);
  235. }
  236. }
  237. } else {
  238. if (key) {
  239. var name = tree.data[i].name;
  240. if (name.indexOf(key) != -1) {
  241. setGoods(tree.data[i]);
  242. }
  243. } else {
  244. setGoods(tree.data[i]);
  245. }
  246. }
  247. }
  248. }
  249. }
  250. // 一键删除
  251. function delGoods()
  252. {
  253. if (confirm('确定删除吗?')) {
  254. var key = mini.get("key").getValue();
  255. if (key == '请输入商品名称') {
  256. key = '';
  257. }
  258. if (key) {
  259. key = key.toLowerCase();
  260. }
  261. for (var i in tree.data) {
  262. if (typeof(tree.data[i].children) == 'object') {
  263. if (tree.data[i].children.length > 0) {
  264. for (var j in tree.data[i].children) {
  265. if (key) {
  266. var name = tree.data[i].children[j].name;
  267. if (name.indexOf(key) != -1) {
  268. unsetGoods(tree.data[i].children[j]);
  269. }
  270. } else {
  271. unsetGoods(tree.data[i].children[j]);
  272. }
  273. }
  274. } else {
  275. if (key) {
  276. var name = tree.data[i].name;
  277. if (name.indexOf(key) != -1) {
  278. unsetGoods(tree.data[i]);
  279. }
  280. } else {
  281. unsetGoods(tree.data[i]);
  282. }
  283. }
  284. }
  285. }
  286. setTotal();
  287. }
  288. }
  289. function unsetGoods(node)
  290. {
  291. if (node.id) {
  292. if (goods[node.id]) {
  293. goods[node.id].del = 2;
  294. goods[node.id].num = 0;
  295. goods[node.id].total = 0;
  296. get(node.id).remove();
  297. }
  298. }
  299. }
  300. function setGoods(node)
  301. {
  302. if (node.id) {
  303. var key = node.id;
  304. if (!goods[key] || (goods[key] && goods[key].del == 2)) {
  305. goods[key] = node;
  306. goods[key].price = parseFloat(goods[key].price);
  307. goods[key].type = parseInt(goods[key].type);
  308. goods[key].total = parseFloat(goods[key].total);
  309. goods[key].min = goods[key].min ? parseFloat(goods[key].min) : 1;
  310. goods[key].num = 0;
  311. goods[key].del = 1;
  312. create(node);
  313. setTotal();
  314. } else if(node.type < 4) {
  315. add(key);
  316. }
  317. }
  318. }
  319. function get(key)
  320. {
  321. return $('#goods_' + key);
  322. }
  323. function create(node)
  324. {
  325. if (!get(node.id).length) {
  326. var select = '';
  327. var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
  328. //addtr += '<td class="goods_id">'+node.id+'</td>';
  329. addtr += '<td class="goods_name">'+node.name+'</td>';
  330. if (node.stock == 1) {
  331. addtr += '<td class="goods_total">'+node.total+'</td>';
  332. } else {
  333. addtr += '<td class="goods_total"> - </td>';
  334. }
  335. addtr += '<td class="goods_prices">'+node.price+'</td>';
  336. var commission_price = 0;
  337. var commission_string = '';
  338. if (commission == 'n') {
  339. commission_string = '0';
  340. } else {
  341. if (!node.commission) {
  342. node.commission = '0';
  343. }
  344. commission_string = node.commission;
  345. if (node.commission.indexOf('%') > -1) {
  346. node.commission = node.commission.replace('%', '');
  347. node.commission = parseFloat(node.commission);
  348. commission_price = (node.commission/100) * parseFloat(node.price);
  349. } else {
  350. commission_price = parseFloat(node.commission);
  351. }
  352. if (commission != 0) {
  353. commission_string += '+' + commission;
  354. if (commission.indexOf('%') > -1) {
  355. var commission_temp = commission.replace('%', '');
  356. commission_temp = parseFloat(commission_temp);
  357. commission_price += (commission_temp/100) * parseFloat(node.price);
  358. } else {
  359. commission_price += parseFloat(commission);
  360. }
  361. commission_price = commission_price.toFixed(2);
  362. commission_string += '=' + commission_price;
  363. }
  364. }
  365. addtr += '<td class="goods_commission"><span>'+commission_string+'</span></td>';
  366. addtr += '<td class="goods_prices">'+node.buy_price+'</td>';
  367. addtr += '<td><div class="jiajian" value='+node.id+'><span class="jian" onclick="decMin(\''+node.id+'\')">-</span><input type="text" value="'+node.min+'" class="goods_min"><span class="jia" onclick="addMin(\''+node.id+'\')">+</span></div></td>';
  368. if (node.total <= 0 || node.stock != 1) {
  369. addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
  370. } else {
  371. addtr += '<td></td>';
  372. }
  373. addtr += '</tr>';
  374. $("#goods").append(addtr);
  375. form.render();
  376. //$('.goods_price_template').change();
  377. }
  378. }
  379. function setPrice(e, id)
  380. {
  381. var val = e.val().split('_');
  382. goods[id].price_template_id = val[0];
  383. e.parent().find('span').html(val[1]);
  384. //goods[id].min = val[2];
  385. //e.parent().parent().find('.goods_min').val(val[2]);
  386. }
  387. function add(id)
  388. {
  389. goods[id].num += 1;
  390. get(id).find('.goods_num').val(goods[id].num);
  391. setTotal();
  392. }
  393. function dec(id)
  394. {
  395. goods[id].num -= 1;
  396. if (goods[id].num < 1) {
  397. goods[id].num = 0;
  398. }
  399. get(id).find('.goods_num').val(goods[id].num);
  400. setTotal();
  401. }
  402. function addMin(id)
  403. {
  404. goods[id].min += 1;
  405. get(id).find('.goods_min').val(goods[id].min);
  406. setTotal();
  407. }
  408. function decMin(id)
  409. {
  410. goods[id].min -= 1;
  411. if (goods[id].min < 1) {
  412. goods[id].min = 0;
  413. }
  414. get(id).find('.goods_min').val(goods[id].min);
  415. setTotal();
  416. }
  417. function del(id)
  418. {
  419. //if (confirm('确定删除吗?')) {
  420. goods[id].del = 2;
  421. goods[id].num = 0;
  422. get(id).remove();
  423. setTotal();
  424. //}
  425. }
  426. function setTotal()
  427. {
  428. var cash = 0;
  429. var total = 0;
  430. for (var i in goods) {
  431. total += goods[i].total;
  432. }
  433. $(".totalNum").html(total);
  434. }
  435. function setShop()
  436. {
  437. var shop_id = $('.xm-select-parent[fs_id="shop_id"] span[fsw="xm-select"]').attr('value');
  438. if (!shop_id) {
  439. layui.layer.alert('请选择门店');
  440. return;
  441. }
  442. layui.layer.confirm('确定切换门店吗?切换后现在选择的商品都将清空', function() {
  443. location.href = '<{$host}>&id=' + shop_id;
  444. });
  445. }
  446. </script>
  447. </body>
  448. </html>