set_servicer_goods.html 14 KB

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