demo.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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="scripts/miniui/themes/default/miniui.css">
  9. <link rel="stylesheet" href="layui/css/layui.css" />
  10. <link rel="stylesheet" href="css/common.css">
  11. </head>
  12. <body style="background: #F6F7F9;">
  13. <div class="main">
  14. <div class="layui-row">
  15. <div class="main_left layui-col-xs12 layui-col-md3">
  16. <div class="layui-row">
  17. <div class="top">
  18. <i class="layui-icon layui-icon-app"></i>商品列表
  19. </div>
  20. <div class="left_main">
  21. <input id="key" class="mini-textbox" placeholder="请输入商品名称" onenter="onKeyEnter"/>
  22. <a class="mini-button" onclick="search()">查询</a>
  23. <ul id="tree1" class="mini-tree" url="data/tree.json" showTreeIcon="true" textField="name" idField="id" expandOnLoad="true" onNodeClick="onNodeClick">
  24. </ul>
  25. </div>
  26. </div>
  27. </div>
  28. <div class="main_right layui-col-xs12 layui-col-md9">
  29. <div class="layui-row">
  30. <div class="top">
  31. <label>商品编码:</label>
  32. <div class="layui-input-inline">
  33. <input type="text" name="title" required lay-verify="required" placeholder="扫码或手动输入商品编码" autocomplete="off" class="layui-input">
  34. </div>
  35. <div class="layui-input-inline">
  36. <button class="layui-btn layui-btn-primary" style="vertical-align: middle;margin-bottom: 2px;">添加</button>
  37. </div>
  38. </div>
  39. <div class="goods_list">
  40. <table class="layui-table">
  41. <thead>
  42. <tr>
  43. <th lay-data="{field:'id'}">商品编码</th>
  44. <th lay-data="{field:'name'}">商品名称</th>
  45. <th lay-data="{field:'price', edit: 'text'}">零售价(元)</th>
  46. <th lay-data="{field:'number', edit: 'text'}">数量</th>
  47. <th lay-data="{field:'integral'}">积分</th>
  48. <!--<th lay-data="{field:'staff', edit: 'text'}">提成员工</th>-->
  49. <th lay-data="{field:'remarks', edit: 'text'}">备注</th>
  50. <th lay-data="{field:'operation'}">操作</th>
  51. </tr>
  52. </thead>
  53. <tbody id="myTbody">
  54. </tbody>
  55. </table>
  56. </div>
  57. <div class="total ft16">
  58. 合计:【<span> 消费总金额:<i class="totalMoney">0.00</i> </span>】【<span> 消费总数量:<i class="totalQuantity">0</i> </span>】【 <span> 总积分:<i class="totalIntegral">0</i> </span>】
  59. </div>
  60. <table class="reading layui-table" lay-even="">
  61. <tbody>
  62. <tr>
  63. <td>会员查找</td>
  64. <td colspan="3">
  65. <div class="layui-input-inline">
  66. <input type="text" class="layui-input" placeholder="扫描或者手动输入会员卡号" />
  67. </div>
  68. <button class="card_reading layui-btn">读卡</button>
  69. <a href="#" class="registration layui-btn layui-btn-primary">会员登记</a>
  70. </td>
  71. </tr>
  72. <tr>
  73. <td>会员卡号:</td>
  74. <td></td>
  75. <td>会员姓名:</td>
  76. <td></td>
  77. </tr>
  78. <tr>
  79. <td>会员级别:</td>
  80. <td></td>
  81. <td>有效期:</td>
  82. <td></td>
  83. </tr>
  84. <tr>
  85. <td>可用积分:</td>
  86. <td></td>
  87. <td>可用储值:</td>
  88. <td></td>
  89. </tr>
  90. </tbody>
  91. </table>
  92. <div class="towbtn">
  93. <input type="submit" id="settlement" value="结算">
  94. <input type="reset" value="清空" />
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. <div class="mask_box">
  101. <div class="mask"></div>
  102. <div class="box">
  103. <div class="box_top">结算</div>
  104. <div class="box_block box_block1">
  105. <div class="block_left"><label for="">应付金额:</label></div>
  106. <div class="block_right"><input type="text" class="layui-input" value="23131" readonly style="border: none;" /></div>
  107. </div>
  108. <div class="box_block box_block2">
  109. <div class="block_left"><input type="checkbox" name="" />优惠券:</div>
  110. <div class="block_right">
  111. <select class="layui-select" name="" id="">
  112. <option value="0">请选择</option>
  113. <option value="1">1</option>
  114. <option value="2">2</option>
  115. <option value="3">3</option>
  116. <option value="4">4</option>
  117. </select>
  118. </div>
  119. <div class="block_left">还需支付:</div>
  120. <div class="block_right"><input type="text" class="layui-input" value="32432" readonly style="border: none;" /></div>
  121. </div>
  122. <div class="box_block box_block3">
  123. <div class="block_left"><input type="radio" name="payment" /><label for="use_coupon">现金支付:</label></div>
  124. <div class="block_right">
  125. <input type="text" class="layui-input" />
  126. </div>
  127. <br style="clear: both;">
  128. <div class="block_left"><input type="radio" name="payment" /><label for="use_coupon">移动支付:</label></div>
  129. <div class="block_right">
  130. <input type="text" class="layui-input" />
  131. </div>
  132. <br style="clear: both;">
  133. <div class="block_left"><input type="radio" name="payment" /><label for="use_coupon">其他支付:</label></div>
  134. <div class="block_right">
  135. <input type="text" class="layui-input" />
  136. </div>
  137. </div>
  138. <div class="remark_mess">
  139. <div class="block_left">
  140. 备注:
  141. </div>
  142. <div class="block_right">
  143. <textarea class="layui-textarea" name="" rows="" cols="" maxlength="200" placeholder="最多输入200字符"></textarea>
  144. </div>
  145. <br style="clear: both;">
  146. <div class="block_left">
  147. 交易时间:
  148. </div>
  149. <div class="block_right">
  150. <input type="text" value="2018-11-23 08:23:43" class="layui-input" readonly style="border: none;" />
  151. </div>
  152. </div>
  153. <div class="bot">
  154. <input type="submit" value="提交">
  155. <input type="text" value="取消">
  156. </div>
  157. </div>
  158. </div>
  159. <script src="http://www.jq22.com/jquery/jquery-2.1.1.js"></script>
  160. <script src="scripts/miniui/miniui.js"></script>
  161. <script src="layui/layui.js"></script>
  162. <script>
  163. $(function() {
  164. $("#settlement").click(function(){
  165. $(".mask_box").show();
  166. })
  167. $(".bot input:nth-child(2)").click(function(){
  168. $(".mask_box").hide();
  169. })
  170. })
  171. /*miniui - tree 插件 - 开始*/
  172. mini.parse();
  173. var tree = mini.get("tree1");
  174. function search() {
  175. var key = mini.get("key").getValue();
  176. if (key == "") {
  177. tree.clearFilter();
  178. } else {
  179. key = key.toLowerCase();
  180. tree.filter(function (node) {
  181. var name = node.name ? node.name.toLowerCase() : "";
  182. if (name.indexOf(key) != -1) {
  183. return true;
  184. }
  185. });
  186. }
  187. }
  188. function onKeyEnter(e) {
  189. search();
  190. }
  191. var totalQuantity = 0; //总数量
  192. var totalMoney = 0; //总金额
  193. var totalIntegral = 0; //总积分
  194. function onNodeClick(){
  195. //获取选中节点的值
  196. var flag = false;
  197. var tree=mini.get("tree1");
  198. node=tree.getSelectedNode();
  199. if(node.end){
  200. /*树结构选中商品,table列表变化 - 开始*/
  201. totalQuantity++;
  202. $('.totalQuantity').html(totalQuantity);
  203. this_price = node.price; //获取单价
  204. this_price = parseFloat(this_price);
  205. totalMoney += this_price;
  206. $('.totalMoney').html(totalMoney.toFixed(2));
  207. this_integral = node.integral; //获取积分
  208. this_integral = parseFloat(this_integral);
  209. totalIntegral += this_integral;
  210. $('.totalIntegral').html(totalIntegral.toFixed(0));
  211. /*树结构选中商品,table列表变化 - 结束*/
  212. if($("#myTbody tr").length <= 0){
  213. var addtr = '<tr class="mytr">';
  214. addtr += '<td>'+node.id+'</td>';
  215. addtr += '<td>'+node.name+'</td>' ;
  216. addtr += '<td class="kbj danjia">'+node.price+'</td>';
  217. addtr += '<td class="numberTd"><div class="jiajian"><span class="jian" onclick="num_sub(this)">-</span><input type="text" value="1" class="num"><span class="jia" onclick="num_add(this)">+</span></div></td>';
  218. addtr += '<td class="jifen">'+node.integral+'</td>';
  219. addtr += '<td class="kbj remarks"></td>';
  220. addtr += '<td><button class="delete_btn">删除</button></td>';
  221. addtr += '</tr>';
  222. $("#myTbody").append(addtr);
  223. return;
  224. }else{
  225. $("#myTbody tr").each(function () {
  226. //找到商品的名称与上面获取到的商品名称进行对比
  227. if ($(this).children("td:eq(0)").html() == node.id) {
  228. //找到此商品的数量
  229. var count = parseInt($(this).children("td:eq(3)").find("input").val());
  230. count++;
  231. $(this).children("td:eq(3)").find("input").val(count); //对商品的数量进行重新赋值
  232. flag = true;
  233. return false;
  234. }else {
  235. flag = false;
  236. }
  237. })
  238. }
  239. //如果为默认值也就是说里面没有此商品,所以添加此商品。
  240. if (flag == false) {
  241. var addtr = '<tr class="mytr">';
  242. addtr += '<td>'+node.id+'</td>';
  243. addtr += '<td>'+node.name+'</td>' ;
  244. addtr += '<td class="danjia">'+node.price+'</td>';
  245. addtr += '<td><div class="jiajian"><span class="jian" onclick="num_sub(this)">-</span><input type="text" value="1" class="num"><span class="jia" onclick="num_add(this)">+</span></div></td>';
  246. addtr += '<td class="jifen">'+node.integral+'</td>';
  247. addtr += '<td class="remarks"></td>';
  248. addtr += '<td><button class="delete_btn">删除</button></td>';
  249. addtr += '</tr>';
  250. $("#myTbody").append(addtr);
  251. }
  252. }
  253. }
  254. /*miniui - tree 插件 - 结束*/
  255. //加的效果
  256. function num_add(on_this){
  257. var totalQuantity = 0; //总数量
  258. var totalMoney = 0; //总金额
  259. var totalIntegral = 0; //总积分
  260. $("#myTbody tr").each(function(){
  261. //获取当前行的单价
  262. this_price = $(this).children(".danjia").text();
  263. this_price = parseFloat(this_price);
  264. //获取当前行的积分
  265. this_integral = $(this).children(".jifen").text();
  266. this_integral = parseFloat(this_integral);
  267. //获取当前行的数量
  268. this_num = $(this).find(".num").val();
  269. this_num = parseInt(this_num);
  270. //获取当前行的总价格、总积分
  271. var trmoney = this_price*this_num;
  272. var trIntegral = this_integral*this_num;
  273. //总金额、总数量、总积分
  274. totalQuantity += this_num*1; //总数量
  275. totalMoney += trmoney*1 //总金额
  276. totalIntegral += trIntegral*1 //总积分
  277. })
  278. $(".totalQuantity").html(totalQuantity);
  279. $(".totalMoney").html(totalMoney);
  280. $(".totalIntegral").html(totalIntegral);
  281. this_price = $(on_this).parents("td").siblings("td.danjia").text();//获取单价
  282. this_price = parseFloat(this_price);
  283. console.log(totalMoney);
  284. totalMoney += this_price;
  285. $('.totalMoney').html(totalMoney.toFixed(2));
  286. console.log(totalMoney);
  287. this_integral = $(on_this).parents("td").siblings("td.jifen").text();//获取积分
  288. this_integral = parseFloat(this_integral);
  289. totalIntegral += this_integral;
  290. $('.totalIntegral').html(totalIntegral.toFixed(0));
  291. //当前商品数量
  292. this_num = $(on_this).siblings('.num');
  293. var get_this_num = parseInt(this_num.val())+1;
  294. this_num.val(get_this_num);
  295. totalQuantity++;
  296. $('.totalQuantity').html(totalQuantity);
  297. }
  298. //减的效果
  299. function num_sub(on_this){
  300. var totalQuantity = 0; //总数量
  301. var totalMoney = 0; //总金额
  302. var totalIntegral = 0; //总积分
  303. $("#myTbody tr").each(function(){
  304. //获取当前行的单价
  305. this_price = $(this).children(".danjia").text();
  306. this_price = parseFloat(this_price);
  307. //获取当前行的积分
  308. this_integral = $(this).children(".jifen").text();
  309. this_integral = parseFloat(this_integral);
  310. //获取当前行的数量
  311. this_num = $(this).find(".num").val();
  312. this_num = parseInt(this_num);
  313. //获取当前行的总价格、总积分
  314. var trmoney = this_price*this_num;
  315. var trIntegral = this_integral*this_num;
  316. //总金额、总数量、总积分
  317. totalQuantity += this_num*1; //总数量
  318. totalMoney += trmoney*1 //总金额
  319. totalIntegral += trIntegral*1 //总积分
  320. })
  321. $(".totalQuantity").html(totalQuantity);
  322. $(".totalMoney").html(totalMoney);
  323. $(".totalIntegral").html(totalIntegral);
  324. //当前商品数量
  325. this_num = $(on_this).siblings('.num');
  326. if(this_num.val() <= 1){
  327. this_num.siblings('.jian').removeAttr('onclick');
  328. return;
  329. }else{
  330. var get_this_num = this_num.val()-1;
  331. this_num.val(get_this_num);
  332. this_price = $(on_this).parents("td").siblings("td.danjia").text();//获取单价
  333. totalMoney -= this_price;
  334. $('.totalMoney').html(totalMoney.toFixed(2));
  335. this_integral = $(on_this).parents("td").siblings("td.jifen").text();//获取积分
  336. totalIntegral -= this_integral;
  337. $('.totalIntegral').html(totalIntegral.toFixed(0));
  338. totalQuantity--;
  339. $('.totalQuantity').html(totalQuantity);
  340. }
  341. }
  342. //输入商品数量时改变合计的内容
  343. $("#myTbody").on("keyup",".num",function(){
  344. if($(this).val()==''){
  345. $(this).val('1');
  346. }
  347. $(this).val($(this).val().replace(/\D|^0/g,''));
  348. setTotal();
  349. })
  350. //点击 - 备注 - 可编辑
  351. $("#myTbody").on("click","td.remarks",function(){
  352. if(!$(this).is('.bj')){
  353. $(this).addClass('bj').html('<textarea class="layui-textarea" value="'+$(this).val()+'" />').find('textarea').focus().blur(function(){$(this).parent().removeClass('bj').html($(this).val())});
  354. }
  355. })
  356. //点击 - 单价 - 可编辑
  357. $("#myTbody").on("click","td.danjia",function(){
  358. if(!$(this).is('.bj')){
  359. var currentPrice = $(this).html();
  360. $(this).focus();
  361. $(this).addClass('bj').html('<input type="tel" class="layui-input" value="'+$(this).text()+'" />').find('input').focus().blur();
  362. }
  363. })
  364. //输入商品价格时改变合计的内容
  365. $("#myTbody").on("change",".danjia input",function(){
  366. var $this = $(this).val();
  367. var reg = /^(([1-9]+)|([0-9]+\.[0-9]{1,2}))$/;
  368. if(!reg.test($this)){
  369. alert("请输入非负浮点数");
  370. $(this).parent().removeClass('bj').html($this||"1.00");
  371. $(this).val(currentPrice);
  372. }else{
  373. $(this).parent().removeClass('bj').html($this||"1.00");
  374. setTotal();
  375. }
  376. })
  377. //table tr 点击删除
  378. $("#myTbody").on("click",".delete_btn",function(){
  379. if($("#myTbody tr").length < 1){
  380. $(".totalQuantity").html("0");
  381. $(".totalMoney").html("0");
  382. $(".totalIntegral").html("0");
  383. return;
  384. }
  385. $(this).parents("#myTbody tr").remove();
  386. setTotal();
  387. })
  388. function setTotal(){
  389. var totalQuantity = 0; //总数量
  390. var totalMoney = 0; //总金额
  391. var totalIntegral = 0; //总积分
  392. $("#myTbody tr").each(function(){
  393. //获取当前行的单价
  394. this_price = $(this).children(".danjia").text();
  395. this_price = parseFloat(this_price);
  396. //获取当前行的积分
  397. this_integral = $(this).children(".jifen").text();
  398. this_integral = parseFloat(this_integral);
  399. //获取当前行的数量
  400. this_num = $(this).find(".num").val();
  401. this_num = parseInt(this_num);
  402. //获取当前行的总价格、总积分
  403. var trmoney = this_price*this_num;
  404. var trIntegral = this_integral*this_num;
  405. //总金额、总数量、总积分
  406. totalQuantity += this_num*1; //总数量
  407. totalMoney += trmoney*1 //总金额
  408. totalIntegral += trIntegral*1 //总积分
  409. })
  410. $(".totalQuantity").html(totalQuantity);
  411. $(".totalMoney").html(totalMoney);
  412. $(".totalIntegral").html(totalIntegral);
  413. }
  414. </script>
  415. </body>
  416. </html>