set_supplier_goods.html 15 KB

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