setGoods.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. name = name.toLowerCase();
  230. if (name.indexOf(key) == -1) {
  231. $(this).parent().hide();
  232. }
  233. });
  234. }
  235. }
  236. // 一键添加
  237. function addGoods()
  238. {
  239. var key = mini.get("key").getValue();
  240. if (key == '请输入商品名称') {
  241. key = '';
  242. }
  243. if (key) {
  244. key = key.toLowerCase();
  245. }
  246. for (var i in tree.data) {
  247. if (typeof(tree.data[i].children) == 'object') {
  248. if (tree.data[i].children.length > 0) {
  249. for (var j in tree.data[i].children) {
  250. if (key) {
  251. var name = tree.data[i].children[j].name;
  252. if (name.indexOf(key) != -1) {
  253. setGoods(tree.data[i].children[j]);
  254. }
  255. } else {
  256. setGoods(tree.data[i].children[j]);
  257. }
  258. }
  259. } else {
  260. if (key) {
  261. var name = tree.data[i].name;
  262. if (name.indexOf(key) != -1) {
  263. setGoods(tree.data[i]);
  264. }
  265. } else {
  266. setGoods(tree.data[i]);
  267. }
  268. }
  269. }
  270. }
  271. }
  272. // 一键删除
  273. function delGoods()
  274. {
  275. if (confirm('确定删除吗?')) {
  276. var key = mini.get("key").getValue();
  277. if (key == '请输入商品名称') {
  278. key = '';
  279. }
  280. if (key) {
  281. key = key.toLowerCase();
  282. }
  283. for (var i in tree.data) {
  284. if (typeof(tree.data[i].children) == 'object') {
  285. if (tree.data[i].children.length > 0) {
  286. for (var j in tree.data[i].children) {
  287. if (key) {
  288. var name = tree.data[i].children[j].name;
  289. if (name.indexOf(key) != -1) {
  290. unsetGoods(tree.data[i].children[j]);
  291. }
  292. } else {
  293. unsetGoods(tree.data[i].children[j]);
  294. }
  295. }
  296. } else {
  297. if (key) {
  298. var name = tree.data[i].name;
  299. if (name.indexOf(key) != -1) {
  300. unsetGoods(tree.data[i]);
  301. }
  302. } else {
  303. unsetGoods(tree.data[i]);
  304. }
  305. }
  306. }
  307. }
  308. setTotal();
  309. }
  310. }
  311. function unsetGoods(node)
  312. {
  313. if (node.id) {
  314. if (goods[node.id]) {
  315. delete goods[node.id];
  316. get(node.id).remove();
  317. }
  318. }
  319. }
  320. function setGoods(node)
  321. {
  322. if (node.id && node.end) {
  323. var key = node.id;
  324. if (!goods[key]) {
  325. goods[key] = node;
  326. goods[key].price = parseFloat(goods[key].price);
  327. goods[key].num = 1;
  328. create(node);
  329. setTotal();
  330. } else {
  331. //add(key);
  332. }
  333. }
  334. }
  335. function get(key)
  336. {
  337. return $('#goods_' + key);
  338. }
  339. function create(node)
  340. {
  341. if (!get(node.id).length) {
  342. var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
  343. addtr += '<td class="goods_id">'+node.id+'</td>';
  344. addtr += '<td class="goods_name">'+node.name+'</td>';
  345. 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>';
  346. addtr += '<td><button class="delete_btn" onclick="del(\''+node.id+'\')">删除</button></td>';
  347. addtr += '</tr>';
  348. $("#goods").append(addtr);
  349. }
  350. }
  351. function add(id)
  352. {
  353. if (goods[id].num >= goods[id].total) {
  354. goods[id].num = goods[id].total;
  355. layer.msg('库存不足');
  356. } else {
  357. goods[id].num += 1;
  358. }
  359. get(id).find('.goods_num').val(goods[id].num);
  360. setTotal();
  361. }
  362. function dec(id)
  363. {
  364. goods[id].num -= 1;
  365. if (goods[id].num < 1) {
  366. goods[id].num = 1;
  367. }
  368. get(id).find('.goods_num').val(goods[id].num);
  369. setTotal();
  370. }
  371. function del(id)
  372. {
  373. delete goods[id];
  374. get(id).remove();
  375. setTotal();
  376. }
  377. function setTotal()
  378. {
  379. var cash = 0;
  380. var num = 0;
  381. for (var i in goods) {
  382. num += goods[i].num;
  383. }
  384. $(".totalQuantity").html(num);
  385. //$(".totalMoney").html(cash.toFixed(2));
  386. }
  387. </script>
  388. </body>
  389. </html>