car.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
  6. <meta name="apple-mobile-web-app-capable" content="yes">
  7. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  8. <meta name="format-detection" content="telephone=no">
  9. <title>购物车</title>
  10. <link rel="stylesheet" href="/static/index/css/cart.css" />
  11. <link rel="stylesheet" href="/static/css/Font-Awesome/css/font-awesome.min.css">
  12. <link rel="stylesheet" href="/static/css/common.css" />
  13. <link rel="stylesheet" href="/static/index/css/cartStyle.css" />
  14. <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
  15. </head>
  16. <style>
  17. .cart2-middle-goods:last-child{
  18. margin-bottom: 10rem;
  19. }
  20. .cart2-bottom-total span{
  21. height: 3rem!important;
  22. line-height: 3rem!important;
  23. font-size: 0.95rem!important;
  24. }
  25. .cart2-bottom-total{
  26. height: 3rem!important;
  27. border-bottom: 0!important;
  28. }
  29. .base-price em,.base-price i{
  30. font-weight: bold;
  31. }
  32. .cart2-bottom-total em{
  33. font-size: 0.95rem!important;
  34. font-weight: bold;
  35. }
  36. .product_name{
  37. display: inline-block;
  38. width: 13.45rem;
  39. font-size: 0.9rem;
  40. color: #666;
  41. }
  42. .quantity {
  43. display: inline-block;
  44. min-width: 6.86rem;
  45. height: 2.24rem;
  46. background-color: #F5F5F5;
  47. float: right!important;
  48. border: 1px solid #ccc;
  49. text-align: center;
  50. line-height: 2.24rem;
  51. font-size: 1.09rem;
  52. border-radius: 0.08rem;
  53. }
  54. .quantity em:first-child {
  55. border-right: 1px solid #ccc;
  56. background: url('/static/images/minus1.svg') no-repeat center center;
  57. background-size: 1.51rem 1.51rem;
  58. background-color: #fff;
  59. /* background-size: contain; */
  60. float: left;
  61. cursor: pointer;
  62. background-size: 50% 100%;
  63. display: inline-block;
  64. width: 2.18rem;
  65. height: 100%;
  66. font-size: 1.09rem;
  67. letter-spacing: -0.06rem;
  68. color: #ff0000;
  69. justify-content: center;
  70. align-items: center;
  71. }
  72. .quantity em:last-child {
  73. border-left: 1px solid #ccc;
  74. background: url('/static/images/plus1.svg') no-repeat center center;
  75. background-size: 1.51rem 1.51rem;
  76. background-color: #fff;
  77. float: right;
  78. cursor: pointer;
  79. background-size: 50% 100%;
  80. display: inline-block;
  81. width: 2.18rem;
  82. height: 100%;
  83. font-size: 1.09rem;
  84. letter-spacing: -0.06rem;
  85. color: #ff0000;
  86. justify-content: center;
  87. align-items: center;
  88. }
  89. .cart2-middle .cart2-middle-goods .goods-right,.cart2-middle .cart2-middle-goods .goods-left{
  90. height: 6.3rem!important;
  91. }
  92. .base-price{
  93. line-height: 2.24rem;
  94. padding: 0.4rem;
  95. }
  96. .cart2-middle-goods .goods-left img{
  97. border-radius: 0!important;
  98. }
  99. .cart2-bottom-total .select{
  100. font-size: 0.95rem;
  101. }
  102. .cart2-bottom-total .pay{
  103. font-size: 0.9rem!important;
  104. }
  105. .cart2-middle{
  106. margin: 0!important;
  107. padding-bottom: 7rem;
  108. }
  109. .cart2-middle-goods .goods-right>span:nth-child(1) em{
  110. width: 3rem!important;
  111. height: 3rem!important;
  112. background-size: 1.5rem!important;
  113. }
  114. .cart2-bottom-nav{
  115. box-shadow: none;
  116. }
  117. .cart2-middle .cart2-middle-goods{
  118. border-top: 0!important;
  119. border-bottom: 1px solid #eee!important;
  120. }
  121. </style>
  122. <body>
  123. <div class="dialog" style="position: fixed;top: 0rem;width: 25rem;height: 56rem;background: rgba(0,0,0,0.2);z-index: 999;display: none"></div>
  124. <!--cart1购物车1页面-->
  125. <div class="cart1" style="display:block;">
  126. <!--<div class="cart1-top"></div>-->
  127. <div class="cart2-middle">
  128. </div>
  129. <div class="cart1-middle" style="display: none">
  130. <div class="cart1-middle-icon"><em></em></div>
  131. <div class="cart1-middle-tips">购物车空着呢,快去挑选商品吧</div>
  132. <div class="cart1-middle-btn"><a href="/index/index/commodity">去本店逛逛→</a></div>
  133. </div>
  134. <div class="cart1-bottom" style="box-shadow: 0 1px 4px rgba(55, 55, 55, 0.1);">
  135. <div class="cart2-bottom" style="margin-bottom: 3.8rem;">
  136. <div class="cart2-bottom-total">
  137. <span class="select selected"><em></em>全选</span>
  138. <span>商品合计:<em>¥<e class="total_price">0.00</e></em></span>
  139. <span class="pay" style="box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1);">结算(<em class="count" style="color: #fff">0</em>)</span>
  140. </div>
  141. </div>
  142. </div>
  143. {include file='Index/footer'}
  144. </div>
  145. <ul style=" position: fixed;
  146. top: 14rem;
  147. left: 2rem;
  148. width: 21rem;
  149. height: 11rem;display: none;z-index: 10000;border-radius: 1rem;
  150. background: #fff;" class="dialogs">
  151. <li style=" text-align: center;
  152. height: 4rem;
  153. line-height: 4rem;border-top-left-radius: 1rem;
  154. border-top-right-radius: 1rem; color: #EB3E2D;">确定删除?</li>
  155. <li class="product-name" style=" width: 80%;
  156. margin-left: 10%;
  157. text-align: center;
  158. height: 4rem; "></li>
  159. <li style=" height: 3rem;">
  160. <p style="width: 50%;
  161. text-align: center;
  162. border-top: 1px solid #ccc;
  163. height: 3rem;
  164. line-height: 3rem;border-right: 1px solid #ccc;color: #EB3E2D;" data-action="1" class="chooses">确定</p>
  165. <p style=" width: 50%;
  166. float: right;
  167. position: relative;
  168. top: -3rem;
  169. text-align: center;
  170. height: 3rem;
  171. border-top: 1px solid #ccc;
  172. line-height: 3rem;" data-action="2" class="chooses">取消</p>
  173. </li>
  174. </ul>
  175. <script src="/static/index/js/common.js"></script>
  176. <script src="/static/layer/layer.js"></script>
  177. </body>
  178. </html>
  179. <script>
  180. $(".bot3").attr("src","/static/index/images/nav_icon33.png");
  181. $(".bottom3 span").css('color','#dc3b32');
  182. $(function(){
  183. // alert(11);
  184. $("span.select").trigger("click");
  185. });
  186. /*单击删除图标删除效果*/
  187. $(function(){
  188. var id;
  189. // var len = $('.cart2-middle').children('.cart2-middle-goods').length;
  190. $("body").on("click",".delete",function(){
  191. $('.dialog').show();
  192. $('.dialogs').show();
  193. var producNaem = $(this).parent().find('.product_name').html();
  194. $(".product-name").html(producNaem);
  195. id = $(this).data('id');
  196. });
  197. $(".chooses").click(function () {
  198. var action = $(this).data('action');
  199. var len = $('.cart2-middle').children('.cart2-middle-goods').length;
  200. if(action == 1){
  201. if(len == 1){
  202. $('.cart2-middle').hide();
  203. $('.cart1-bottom').hide();
  204. $('.cart1-middle').show();
  205. }
  206. $.ajax({
  207. url: '/index/OrderInterfaces/deleteCar',
  208. type: 'GET',
  209. async:false,
  210. data:{id:id},
  211. dataType:'json',
  212. success: function (res) {
  213. if(res.code==400){
  214. layer.msg("<span style='color: #fff'>"+res.msg+"</span>");
  215. setTimeout(function () {
  216. window.location.reload();
  217. },1000);
  218. }
  219. if(res.code == 200){
  220. layer.msg("<span style='color: #fff'>"+res.msg+"</span>");
  221. setTimeout(function () {
  222. window.location.reload();
  223. },1000);
  224. }
  225. }
  226. });
  227. }
  228. $('.dialog').hide();
  229. $('.dialogs').hide();
  230. })
  231. $.ajax({
  232. url: '/index/OrderInterfaces/car',
  233. type: 'GET',
  234. async:false,
  235. data:{},
  236. dataType:'json',
  237. success: function (res) {
  238. var html="";
  239. var data = res.data;
  240. // console.log(data);
  241. if(data.length == 0){
  242. $('.cart2-middle').hide();
  243. $('.cart1-bottom').hide();
  244. $('.cart1-middle').show();
  245. }else{
  246. $.each(data,function (i,v) {
  247. html+="<div class='cart2-middle-goods'>";
  248. html+="<div class='goods-left'>";
  249. html+="<em class='select selected'></em>";
  250. if(v.images!=null&&v.images!=""){
  251. $.each(v.images,function (is,vs) {
  252. if(is==0){
  253. html+="<img src={$host}"+vs+" alt='' />";
  254. }
  255. })
  256. }else{
  257. html+="<img src='' alt='' />";
  258. }
  259. html+="</div>";
  260. html+="<div class='goods-right'>";
  261. if(v.type_name==11){
  262. html+="<span><span class='product_name'>"+v.product_name+"</span><em class='delete' data-doctorno='"+v.doctor_no+"' data-id="+v.id+" data-productid="+v.product_id+"></em></span>";
  263. }else{
  264. html+="<span><span class='product_name'>"+"【"+v.type_name+"】"+v.product_name+"</span><em class='delete' data-doctorno='"+v.doctor_no+"' data-id="+v.id+" data-productid="+v.product_id+"></em></span>";
  265. }
  266. html+="<div class='base-price' style='width: 9rem;'><i style='font-size:0.9rem;line-height:2.24rem;color:#FE2A36;'>¥</i><em class='price' style='width: 8rem;font-size: 0.9rem;color:#FE2A36;'>"+v.sales_price+"</em></div>";
  267. html+="<span style='border:0;height: 0;'>";
  268. html+="<em class='hidePrice' hidden=''>"+v.sales_price+"</em>";
  269. html+="</span>";
  270. html+="</div>";
  271. html+="<div style='clear: both;'></div>";
  272. html+="<div style='padding:0.4rem 1rem;border-top: 1px solid #eee;overflow:hidden;'>";
  273. html+="<span class='quantity'><em class='minus'></em><i class='chooseNum'>"+v.number+"</i><em class='plus'></em></span>";
  274. html+="</div>";
  275. html+="</div>";
  276. })
  277. $('.cart2-middle').html(html);
  278. }
  279. }
  280. });
  281. })
  282. var arr = new Array();
  283. function car() {
  284. arr = new Array();
  285. var le = $('.selected').length;
  286. var total_price = 0;
  287. var count = 0;
  288. if(le!=0){
  289. for (var i=0 ;i<le;i++){
  290. var price = $('.selected').eq(i).parent().parent().find('.price').html();
  291. var coun = $('.selected').eq(i).parent().parent().find('.chooseNum').html();
  292. var id = $('.selected').eq(i).parent().parent().find('.delete').data('productid');
  293. var doctorNo = $('.selected').eq(i).parent().parent().find('.delete').data('doctorno');
  294. if(price != undefined){
  295. total_price = price*coun*1+total_price*1;
  296. total_price = total_price.toFixed(2);
  297. count = coun*1+count*1;
  298. arr[id]=coun+"/"+doctorNo+"/"+price;
  299. }
  300. }
  301. }
  302. var count = parseFormatNum(count,0);
  303. var trotal_price = parseFormatNum(total_price,2);
  304. $('.total_price').html(trotal_price);
  305. $('.count').html(count);
  306. }
  307. /*商品加减计件*/
  308. $(function(){
  309. car();
  310. var price;
  311. $("body").on("click",".plus",function(){
  312. price = $(this).parent().siblings(".hidePrice").text();
  313. var num = $(this).siblings("i").html();
  314. // if(num > 10 || num == 10){
  315. // layer.msg('单次购买不可超过10');
  316. // return false;
  317. // }
  318. num++;
  319. $(this).siblings("i").html(num);
  320. car();
  321. /*console.log(num);*/
  322. });
  323. $("body").on("click",".minus",function(){
  324. price = $(this).parent().siblings(".hidePrice").text();
  325. var num = $(this).siblings("i").html();
  326. if(num==1){
  327. return false;
  328. }
  329. num--;
  330. // $(this).parent().siblings(".price").html(num*price);
  331. $(this).siblings("i").html(num);
  332. car();
  333. });
  334. });
  335. /*点击选中效果*/
  336. $(function(){
  337. $('span.select').find('em').trigger('click');
  338. $("span.select").click(function(){
  339. if($(this).hasClass("selected")){
  340. $(".select").removeClass("selected");
  341. }else{
  342. $(".select").addClass("selected");
  343. }
  344. car();
  345. });
  346. $("em.select").click(function(){
  347. $(this).toggleClass("selected");
  348. if($("em.selected").length == $("em.select").length){
  349. $("span.select").addClass("selected");
  350. }else{
  351. $("span.select").removeClass("selected");
  352. }
  353. car();
  354. });
  355. });
  356. /**
  357. * 付款
  358. */
  359. $('.pay').click(function () {
  360. var total_price = $('.total_price').html();
  361. var count = $('.count').html();
  362. $.ajax({
  363. url: '/index/OrderInterfaces/insertOrder',
  364. type: 'GET',
  365. async:false,
  366. data:{total_price:total_price,arr:arr,count:count},
  367. dataType:'json',
  368. success: function (res) {
  369. if(res.code == 200){
  370. window.location.href="{:url('/index/order/orderDetail')}";//订单详情页面
  371. }else{
  372. layer.msg("<span style='color: #fff'>"+res.msg+"</span>");
  373. }
  374. }
  375. });
  376. console.log(arr);
  377. })
  378. // function checkcar() {
  379. // var len = $('.chooseNum').length;
  380. // for (var i = 0;i<len ;i++){
  381. // var num = $('.chooseNum').eq(i).html();
  382. // var nums = parseFormatNum(num,0);
  383. // $('.chooseNum').eq(i).html(nums);
  384. // }
  385. // }
  386. function parseFormatNum(number,n){
  387. if(n != 0 ){
  388. n = (n > 0 && n <= 20) ? n : 2;
  389. }
  390. number = parseFloat((number + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
  391. var sub_val = number.split(".")[0].split("").reverse();
  392. var sub_xs = number.split(".")[1];
  393. var show_html = "";
  394. for (i = 0; i < sub_val.length; i++){
  395. show_html += sub_val[i] + ((i + 1) % 3 == 0 && (i + 1) != sub_val.length ? "," : "");
  396. }
  397. if(n == 0 ){
  398. return show_html.split("").reverse().join("");
  399. }else{
  400. return show_html.split("").reverse().join("") + "." + sub_xs;
  401. }
  402. }
  403. </script>