setGoods.html 14 KB

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