set_seller_goods.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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'}">商品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 id = '<{$id}>';
  124. var role = '<{$role}>';
  125. layui.layer.confirm('确定进行此项设置吗?', function() {
  126. var goods_string = JSON.stringify(goods);
  127. var data = {};
  128. data = {id:id, role:role, goods:goods_string};
  129. $.post(url, data, function(t) {
  130. t = JSON.parse(t);
  131. if (t.status == 1) {
  132. layui.layer.alert('商品设置成功', function(index){
  133. if (t.data == 'refer') {
  134. history.back();
  135. } else {
  136. location.href = t.data;
  137. }
  138. layer.close(index);
  139. });
  140. } else {
  141. layui.layer.alert(t.msg);
  142. }
  143. });
  144. });
  145. })
  146. $("#goods").on("keyup", ".goods_num", function() {
  147. var num = parseFloat($(this).val());
  148. if (num < 0) {
  149. num = 0;
  150. $(this).val(0);
  151. }
  152. var id = $(this).parent().attr('value');
  153. goods[id].num = num;
  154. setTotal();
  155. });
  156. $("#goods").on("keyup", ".goods_min", function() {
  157. var min = parseFloat($(this).val());
  158. if (min < 0) {
  159. min = 1;
  160. $(this).val(1);
  161. }
  162. var id = $(this).parent().attr('value');
  163. goods[id].min = min;
  164. setTotal();
  165. });
  166. })
  167. function search()
  168. {
  169. var key = mini.get("key").getValue();
  170. if (key == "") {
  171. tree.clearFilter();
  172. } else {
  173. key = key.toLowerCase();
  174. tree.filter(function (node) {
  175. var name = node.name ? node.name.toLowerCase() : "";
  176. if (name.indexOf(key) != -1) {
  177. return true;
  178. }
  179. });
  180. }
  181. }
  182. function onKeyEnter(e)
  183. {
  184. search();
  185. }
  186. function onNodeClick()
  187. {
  188. var tree=mini.get("tree1");
  189. node=tree.getSelectedNode();
  190. if(node.end) {
  191. setGoods(node);
  192. }
  193. }
  194. function setVal(e)
  195. {
  196. mini.get(e).setValue('');
  197. }
  198. function searchGoods()
  199. {
  200. var key = mini.get("search_key").getValue();
  201. if (key == "") {
  202. $(".mytr").show();
  203. } else {
  204. key = key.toLowerCase();
  205. $(".mytr").show();
  206. $(".goods_name").each(function(t) {
  207. var name = $(this).html();
  208. name = name.toLowerCase();
  209. if (name.indexOf(key) == -1) {
  210. $(this).parent().hide();
  211. }
  212. });
  213. }
  214. }
  215. // 一键添加
  216. function addGoods()
  217. {
  218. var key = mini.get("key").getValue();
  219. if (key == '请输入商品名称') {
  220. key = '';
  221. }
  222. if (key) {
  223. key = key.toLowerCase();
  224. }
  225. for (var i in tree.data) {
  226. if (typeof(tree.data[i].children) == 'object') {
  227. if (tree.data[i].children.length > 0) {
  228. for (var j in tree.data[i].children) {
  229. if (key) {
  230. var name = tree.data[i].children[j].name;
  231. if (name.indexOf(key) != -1) {
  232. setGoods(tree.data[i].children[j]);
  233. }
  234. } else {
  235. setGoods(tree.data[i].children[j]);
  236. }
  237. }
  238. } else {
  239. if (key) {
  240. var name = tree.data[i].name;
  241. if (name.indexOf(key) != -1) {
  242. setGoods(tree.data[i]);
  243. }
  244. } else {
  245. setGoods(tree.data[i]);
  246. }
  247. }
  248. }
  249. }
  250. }
  251. // 一键删除
  252. function delGoods()
  253. {
  254. if (confirm('确定删除吗?')) {
  255. var key = mini.get("key").getValue();
  256. if (key == '请输入商品名称') {
  257. key = '';
  258. }
  259. if (key) {
  260. key = key.toLowerCase();
  261. }
  262. for (var i in tree.data) {
  263. if (typeof(tree.data[i].children) == 'object') {
  264. if (tree.data[i].children.length > 0) {
  265. for (var j in tree.data[i].children) {
  266. if (key) {
  267. var name = tree.data[i].children[j].name;
  268. if (name.indexOf(key) != -1) {
  269. unsetGoods(tree.data[i].children[j]);
  270. }
  271. } else {
  272. unsetGoods(tree.data[i].children[j]);
  273. }
  274. }
  275. } else {
  276. if (key) {
  277. var name = tree.data[i].name;
  278. if (name.indexOf(key) != -1) {
  279. unsetGoods(tree.data[i]);
  280. }
  281. } else {
  282. unsetGoods(tree.data[i]);
  283. }
  284. }
  285. }
  286. }
  287. setTotal();
  288. }
  289. }
  290. function unsetGoods(node)
  291. {
  292. if (node.id) {
  293. if (goods[node.id]) {
  294. goods[node.id].del = 2;
  295. goods[node.id].num = 0;
  296. goods[node.id].total = 0;
  297. get(node.id).remove();
  298. }
  299. }
  300. }
  301. function setGoods(node)
  302. {
  303. if (node.id) {
  304. var key = node.id;
  305. if (!goods[key] || (goods[key] && goods[key].del == 2)) {
  306. goods[key] = node;
  307. goods[key].price = parseFloat(goods[key].price);
  308. goods[key].type = parseInt(goods[key].type);
  309. goods[key].total = parseFloat(goods[key].total);
  310. goods[key].min = goods[key].min ? parseFloat(goods[key].min) : 1;
  311. goods[key].num = 0;
  312. goods[key].del = 1;
  313. create(node);
  314. setTotal();
  315. } else if(node.type < 4) {
  316. add(key);
  317. }
  318. }
  319. }
  320. function get(key)
  321. {
  322. return $('#goods_' + key);
  323. }
  324. function create(node)
  325. {
  326. if (!get(node.id).length) {
  327. var select = '';
  328. var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
  329. addtr += '<td class="goods_id">'+node.id+'</td>';
  330. addtr += '<td class="goods_name">'+node.name+'</td>';
  331. if (node.stock == 1) {
  332. addtr += '<td class="goods_total">'+node.total+'</td>';
  333. } else {
  334. addtr += '<td class="goods_total"> - </td>';
  335. }
  336. addtr += '<td class="goods_prices">'+node.price+'</td>';
  337. var commission_price = 0;
  338. var commission_string = '';
  339. if (commission == 0) {
  340. commission_string = '0';
  341. } else {
  342. if (!node.commission) {
  343. node.commission = '0';
  344. }
  345. commission_string = node.commission;
  346. if (node.commission.indexOf('%') > -1) {
  347. node.commission = node.commission.replace('%', '');
  348. node.commission = parseFloat(node.commission);
  349. commission_price = (node.commission/100) * parseFloat(node.price);
  350. } else {
  351. commission_price = parseFloat(node.commission);
  352. }
  353. if (commission) {
  354. commission_string += '+' + commission;
  355. if (commission.indexOf('%') > -1) {
  356. var commission_temp = commission.replace('%', '');
  357. commission_temp = parseFloat(commission_temp);
  358. commission_price += (commission_temp/100) * parseFloat(node.price);
  359. } else {
  360. commission_price += parseFloat(commission);
  361. }
  362. commission_price = commission_price.toFixed(2);
  363. commission_string += '=' + commission_price;
  364. }
  365. }
  366. addtr += '<td class="goods_commission"><span>'+commission_string+'</span></td>';
  367. addtr += '<td class="goods_prices">'+node.buy_price+'</td>';
  368. 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>';
  369. if (node.total <= 0 || node.stock != 1) {
  370. addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
  371. } else {
  372. addtr += '<td></td>';
  373. }
  374. addtr += '</tr>';
  375. $("#goods").append(addtr);
  376. form.render();
  377. //$('.goods_price_template').change();
  378. }
  379. }
  380. function setPrice(e, id)
  381. {
  382. var val = e.val().split('_');
  383. goods[id].price_template_id = val[0];
  384. e.parent().find('span').html(val[1]);
  385. //goods[id].min = val[2];
  386. //e.parent().parent().find('.goods_min').val(val[2]);
  387. }
  388. function add(id)
  389. {
  390. goods[id].num += 1;
  391. get(id).find('.goods_num').val(goods[id].num);
  392. setTotal();
  393. }
  394. function dec(id)
  395. {
  396. goods[id].num -= 1;
  397. if (goods[id].num < 1) {
  398. goods[id].num = 0;
  399. }
  400. get(id).find('.goods_num').val(goods[id].num);
  401. setTotal();
  402. }
  403. function addMin(id)
  404. {
  405. goods[id].min += 1;
  406. get(id).find('.goods_min').val(goods[id].min);
  407. setTotal();
  408. }
  409. function decMin(id)
  410. {
  411. goods[id].min -= 1;
  412. if (goods[id].min < 1) {
  413. goods[id].min = 0;
  414. }
  415. get(id).find('.goods_min').val(goods[id].min);
  416. setTotal();
  417. }
  418. function del(id)
  419. {
  420. //if (confirm('确定删除吗?')) {
  421. goods[id].del = 2;
  422. goods[id].num = 0;
  423. get(id).remove();
  424. setTotal();
  425. //}
  426. }
  427. function setTotal()
  428. {
  429. var cash = 0;
  430. var total = 0;
  431. for (var i in goods) {
  432. total += goods[i].total;
  433. }
  434. $(".totalNum").html(total);
  435. }
  436. function setShop()
  437. {
  438. var shop_id = $('.xm-select-parent[fs_id="shop_id"] span[fsw="xm-select"]').attr('value');
  439. if (!shop_id) {
  440. layui.layer.alert('请选择门店');
  441. return;
  442. }
  443. layui.layer.confirm('确定切换门店吗?切换后现在选择的商品都将清空', function() {
  444. location.href = '<{$host}>&id=' + shop_id;
  445. });
  446. }
  447. </script>
  448. </body>
  449. </html>