<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link href="css/mui.min.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="css/app.css" />
<link rel="stylesheet" type="text/css" href="css/shopping-cart.css">
<script type="text/javascript">
var i = 0;
var money = 0;
var cart_money = new Object();
var cart_id = new Object();
var cart_id_copy = new Object();
</script>
</head>
<body style="background-color:#f5f5f5">
<div class="mui-bar mui-bar-nav" style="background-color: #1b82d2;">
<h1 class="mui-title" style="color: #ffffff;font-size:20px;">商品消费</h1>
</div>
<div style="height:26px;"></div>
<form method="post" name="cart_form" target="_self" id="cart_form" action="">
<div class="commodity_list_box">
<div class="commodity_box">
<div class="commodity_list">
<ul class="commodity_list_term">
<li class="select">
<div class="mui-row" style="padding-top:10px;">
<div class="mui-col-sm-5 mui-col-xs-5" style="font-size:18px;left:15px;">
<img src="image/pig.jpg" />
</div>
<em aem="0" cart_id="84" style="top:57px"></em>
<div class="mui-col-sm-7 mui-col-xs-7" style="font-size:18px;right:8px;top:-5px;">
<div class="div_center" >
<h4>猪肉 5斤</h4>
<span>
日期:<label class="mr-6">11月5日-12月11日</label> <br>
猪肉类型:<label >种猪</label>
</span>
<p class="now_value"><i>¥</i><b class="qu_su">100.00</b></p>
</div>
<div class="div_right" style="right:-5px;bottom:1px;">
<i onclick="reducew(this)">-</i>
<span class="zi">1</span>
<input type="hidden" value="84">
<i onclick="plusw(this)">+</i>
</div>
</div>
</div>
</li>
<li class="select">
<div class="mui-row" style="padding-top:10px;">
<div class="mui-col-sm-5 mui-col-xs-5" style="font-size:18px;left:15px;">
<img src="image/niu.jpg" />
</div>
<em aem="0" cart_id="84" style="top:57px"></em>
<div class="mui-col-sm-7 mui-col-xs-7" style="font-size:18px;right:8px;top:-5px;">
<div class="div_center" >
<h4>牛肉 15斤</h4>
<span>
日期:<label class="mr-6">8月5日-0月15日</label> <br>
牛肉类型:<label >种牛</label>
</span>
<p class="now_value"><i>¥</i><b class="qu_su">10.00</b></p>
</div>
<div class="div_right" style="right:-5px;bottom:1px;">
<i onclick="reducew(this)">-</i>
<span class="zi">1</span>
<input type="hidden" value="84">
<i onclick="plusw(this)">+</i>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="settle_box" style="bottom:0px;">
<ul class="all_check select">
<li><span id="all_pitch_on"></span><div>全选</div></li>
</ul>
<ul class="total_amount">
<li style="display: flex;">合计:<p id="total_price">¥<b>0</b></p></li>
<li style="display: flex;">
<a class="settle_btn" href="javascript:void(0);" id="confirm_cart">结算</a>
</li>
</ul>
<a class="settle_btn" href="javascript:void(0);" id="confirm_cart1" onclick="big_cart_remove()">删除</a>
</div>
</form>
<script src="js/mui.min.js"></script>
<script src="js/jquery.min.js"></script>
<script>
var noX = 0;
var allThis = $(".commodity_box .select em");
function reduceMod(e, totalH, mod, noX) {
var tn = e.siblings().find(".qu_su").text();
var tn1 = e.siblings().find(".zi").text();
if(mod != 2) {
var Total = parseFloat(totalH) - (tn * tn1);
$("#total_price b").text(Total.toFixed(2));
} else {
var Total = parseFloat(totalH) - parseFloat(tn);
$("#total_price b").text(Total.toFixed(2));
}
};
function plusMod(e, totalH, mod) {
var tn = e.siblings().find(".qu_su").text();
var tn1 = e.siblings().find(".zi").text();
if(mod != 2) {
var Total = parseFloat(totalH) + (tn * tn1);
$("#total_price b").text(Total.toFixed(2));
} else {
var Total = parseFloat(totalH) + (parseFloat(tn) + (noX - 1));
$("#total_price b").text(Total.toFixed(2));
}
};
function commodityPlusMod(e, totalH) {
var qu = e.parents(".commodity_list").find(".pitch_on").parent().find(".qu_su");
var quj = e.parents(".commodity_list").find(".pitch_on").parent().find(".zi");
var Total = 0;
var erTotal = true;
for(var i = 0; i < qu.length; i++) {
var n = qu.eq(i).text();
var n1 = quj.eq(i).text();
if(erTotal) {
Total = parseFloat(totalH) + (parseFloat(n) * parseFloat(n1));
if(Total < 0)
Total = 0;
erTotal = false;
} else {
Total = parseFloat(Total) + (parseFloat(n) * parseFloat(n1));
if(Total < 0)
Total = 0;
}
}
$("#total_price b").text(Total.toFixed(2));
};
var plus;
function commodityReduceMod(e, totalH) {
var qu = e.parents(".commodity_list").find(".pitch_on").parent().find(".qu_su");
var quj = e.parents(".commodity_list").find(".pitch_on").parent().find(".zi");
var Total = 0;
var erTotal = true;
for(var i = 0; i < qu.length; i++) {
var n = qu.eq(i).text();
var n1 = quj.eq(i).text();
if(erTotal) {
Total = parseFloat(totalH) - (parseFloat(n) * parseFloat(n1));
plus = parseFloat(n) * parseFloat(n1);
if(Total < 0)
Total = 0;
erTotal = false;
} else {
Total = parseFloat(Total) - (parseFloat(n) * parseFloat(n1));
plus = parseFloat(n) * parseFloat(n1);
if(Total < 0)
Total = 0;
}
$("#total_price b").text(Total.toFixed(2));
}
return plus;
};
function commodityWhole() {
var je = $(".commodity_box .select .qu_su");
var je1 = $(".commodity_box .select .zi");
var TotalJe = 0;
for(var i = 0; i < je.length; i++) {
var n = je.eq(i).text();
var n1 = je1.eq(i).text();
TotalJe = TotalJe + (parseFloat(n) * parseFloat(n1));
}
$("#total_price b").text(TotalJe.toFixed(2));
};
$(".select em").click(function() {
var su = $(this).attr("aem");
var carts_id = $(this).attr("cart_id");
var totalH = $("#total_price b").text();
if(su == 0) {
if($(this).hasClass("pitch_on")) {
$(this).parents("ul").siblings(".select").find("em").removeClass("pitch_on");
$("#all_pitch_on").removeClass("pitch_on");
$(this).removeClass("pitch_on");
reduceMod($(this), totalH);
cart_id[carts_id] = "";
delete cart_id[carts_id];
} else {
$(this).addClass("pitch_on");
var n = $(this).parents("ul").children().find(".pitch_on");
var n1 = $(this).parents("ul").children();
plusMod($(this), totalH, 0, noX);
cart_id[carts_id] = "";
if(n.length == n1.length) {
$(this).parents("ul").siblings(".select").find("em").addClass("pitch_on");
}
var fot = $(".commodity_list_box .pitch_on");
var fot1 = $(".commodity_list_box em");
if(fot.length == fot1.length)
$("#all_pitch_on").addClass("pitch_on");
}
} else {
if($(this).hasClass("pitch_on")) {
$("#all_pitch_on").removeClass("pitch_on");
$(this).removeClass("pitch_on");
commodityReduceMod($(this), totalH);
$(this).parent().siblings("ul").find("span").removeClass("pitch_on");
delete cart_id[carts_id];
} else {
commodityReduceMod($(this), totalH);
$(this).addClass("pitch_on");
$(this).parent().siblings("ul").find("span").addClass("pitch_on");
if(plus != NaN && plus != undefined) {
totalH = parseFloat(totalH) - parseFloat(plus);
}
commodityPlusMod($(this), totalH);
cart_id[carts_id] = "";
var fot = $(".commodity_list_box .pitch_on");
var fot1 = $(".commodity_list_box span");
if(fot.length == fot1.length)
$("#all_pitch_on").addClass("pitch_on");
}
}
number();
});
var bot = 0;
$("#all_pitch_on").click(function() {
if(bot == 0) {
$(this).addClass("pitch_on");
allThis.removeClass("pitch_on");
allThis.addClass("pitch_on");
commodityWhole();
bot = 1;
for(var key in cart_id_copy) {
cart_id[key] = "";
}
} else {
$(this).removeClass("pitch_on");
allThis.removeClass("pitch_on");
$("#total_price b").text("0");
bot = 0;
for(var key in cart_id) {
delete cart_id[key];
}
}
number();
});
function number() {
var num = 0;
for(var key in cart_id) {
num++;
}
}
var topb = 0;
$("#rem_s").click(function() {
if(topb == 0) {
$(this).text("完成");
$(".total_amount").hide();
$("#confirm_cart").hide();
$("#confirm_cart1").show();
topb = 1;
} else {
topb = 0;
$(this).text("编辑");
$(".total_amount").show();
$("#confirm_cart").show();
$("#confirm_cart1").hide();
allThis.removeClass("pitch_on");
$("#all_pitch_on").removeClass("pitch_on");
$("#total_price b").text("0");
}
});
function reducew(obj) {
var $this = $(obj);
var totalH = $("#total_price b").text();
var ise = $this.siblings("span").text();
var gc_id = $this.siblings("input").val();
if(noX <= 0) {
noX = 0;
} else {
noX--;
};
if(parseInt(ise) <= 1) {
$this.siblings("span").text("1");
} else {
var n = parseInt(ise) - 1;
$this.siblings("span").text(n);
if($this.parent().parent().children("em").hasClass("pitch_on")) {
var mo = $this.parent().parent().children("em");
reduceMod(mo, totalH, 2, noX);
noX = 0;
}
}
};
function plusw(obj) {
var $this = $(obj);
var totalH = $("#total_price b").text();
var ise = $this.siblings("span").text();
var gc_id = $this.siblings("input").val();
var n = parseInt(ise) + 1;
noX++;
$this.siblings("span").text(n);
if($this.parent().parent().children("em").hasClass("pitch_on")) {
var mo = $this.parent().parent().children("em");
plusMod(mo, totalH, 2, noX);
noX = 0;
}
}
function big_cart_remove() {
$(".commodity_list_term .pitch_on").parent().remove();
$(".commodity_list > em.pitch_on").parents(".commodity_box").remove();
}
</script>
</body>
</html>
界面效果:
app.css和shopping-cart.css文件链接
|