Files
g.hnyhua.cn/Mtxfw.VipSite/mobile/shop_cart.html
2026-02-07 15:48:27 +08:00

468 lines
20 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>购物车</title>
<link rel="stylesheet" type="text/css" href="/css/api.css" />
<link rel="stylesheet" type="text/css" href="/css/content.css" />
<script type="text/javascript" src="/scripts/jquery-2.0.2.min.js"></script>
<script type="text/javascript" src="/scripts/jquery.cookie.min.js"></script>
<!--<script type="text/javascript" src="/scripts/iscroll.js"></script>-->
<script type="text/javascript" src="/script/main.js?t=0"></script>
<script type="text/javascript" src="/layer/layer.js"></script>
<script type="text/javascript" src="/Scripts/long.js"></script>
<script type="text/javascript" src="/script/moment.js"></script>
<script type="text/javascript" src="/Scripts/TouchSlide.1.1.js"></script>
<script type="text/javascript" src="/script/api.js"></script>
<style type="text/css">
html, body {
overflow: hidden;
}
#wrapper {
flex: 1;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.pullDown {
position: absolute;
top: -1.25rem;
left: 0;
width: 100%;
z-index: 100;
text-align: center;
display: none;
}
.pullUp {
position: absolute;
bottom: -1.25rem;
left: 0;
width: 100%;
z-index: 100;
text-align: center;
display: none;
}
.pullDown.loading, .pullUp.loading, .pullDown.refresh, .pullUp.refresh {
display: block;
}
</style>
<script type="text/javascript">
var userId = null;
var LoginId = null;
var CartId = null;
var search_keyword = null;
var pullDown = 1; // 下拉刷新避免多次执行
var pullUp = 1; // 上拉加载避免多次执行
var downHeight = 0;
var upHeight = 0;
var isload = true;//设置是否终止滚动加载
var curScrollHeight = 0;//当前滚动位置
var curCount = 1;//计数器,防止滚动时重复执行加载下一页
$(document).ready(function () {
userId = getlocalStorage("userId");
LoginId = getlocalStorage("LoginId");
CartId = getlocalStorage("CartId");
opentimes = setInterval(function () {
var selectqydatas = getlocalStorage("shop_view_refresh");
if (selectqydatas != null) {
rdata();
clearlocalStorage("shop_view_refresh");
}
}, 1000);
rdata(1);
});
function onScroll() {
if (myScroll != null) {
myScroll.destroy();
myScroll = null;
}
myScroll = new IScroll('#wrapper', {
probeType: 2,
fadeScrollbars: false
});
myScroll.on('scroll', function () {
var y = myScroll.y;
downHeight = $(".pullDown").height();
upHeight = $(".pullUp").height();
// 下拉加载
if (y >= downHeight && pullDown) {
$(".pullDown").addClass("refresh").html("松开刷新...");
myScroll.minScrollY = downHeight;
pullDown = 0;
}
if (y <= downHeight && y >= 0 && !pullDown) {
$(".pullDown").removeClass("refresh").html("下拉刷新...");
pullDown = 1;
myScroll.minScrollY = 0;
}
// 上拉刷新
var maxHeight = myScroll.maxScrollY;
if (y < (maxHeight - upHeight) && pullUp) {
$(".pullUp").addClass("loading").html("松开加载...");
myScroll.maxScrollY = maxHeight - upHeight;
pullUp = 0;
}
if (y > maxHeight && y < (maxHeight + upHeight) && !pullUp) {
$(".pullUp").removeClass("loading").html("上拉加载...");
myScroll.maxScrollY = maxHeight + upHeight;
pullUp = 1;
}
});
myScroll.on('scrollEnd', function () {
if ($(".pullDown").hasClass("refresh")) {
$(".pullDown").text("正在刷新...");
opentimes = setTimeout(function () {
clearInterval(opentimes);
rdata(1);
$(".pullDown").removeClass("refresh").html("下拉刷新...");
pullDown = 1;
myScroll.refresh();
}, 2000);
}
if ($(".pullUp").hasClass("loading")) {
$(".pullUp").text("正在加载...");
opentimes = setTimeout(function () {
clearInterval(opentimes);
rdata(0);
myScroll.refresh();
}, 1000);
}
});
myScroll.on('refresh', function () {
$(".pullUp").removeClass("loading").html("上拉加载...");
pullUp = 1;
});
}
function onScroll0() {
isload = true;//设置是否终止滚动加载
curScrollHeight = 0;//当前滚动位置
curCount = 1;//计数器,防止滚动时重复执行加载下一页
$("#wrapper").scroll(function () {
var pageHeight = $("#sysnew").height();
var showHeight = $("#wrapper").height();
var scrollHeight = $("#wrapper").scrollTop();
if (curScrollHeight - scrollHeight < 10 && curScrollHeight > 0) {
if (curCount == 1 && isload) {
rdata(0);
}
curCount++; //加载下一页后计数器+1
}
if (curScrollHeight < scrollHeight) {
curScrollHeight = pageHeight - showHeight;//滚动到页面底部时,重设当前滚动位置
curCount = 1;
}
});
}
function rdata(ag) {
$(".ajaxLoader").removeClass("uhide");
$.ajax({
type: 'GET',
url: "/apiajax.ashx",
data: "&action=getshopcart&CartId=" + CartId + "&userId=" + (userId != null ? userId : "") + "&LoginId=" + (LoginId != null ? LoginId : ""),
dataType: "JSON",
error: function (xhr) {
tishi3("发生错误:" + JSON.stringify(xhr));
},
success: function (data) {
if (data.status == 1) {
var html = "";
if (data.productlist.length > 0) {
html += "<div class=\"productlist\"><ul>";
var list = data.productlist;
for (j = 0; j < list.length; j++) {
html += "<li id=\"cartbox" + j + "\" color=\"" + list[j].selcolor + " \"guige=\"" + list[j].guige + "\">";
html += "<span class=\"limg\"><img onclick=\"ondetail(" + list[j].prodid + ")\" src=\"" + list[j].prodimg + "\" /></span>";
html += "<span class=\"rname\"><span class=\"prodName\" onclick=\"ondetail(" + list[j].prodid + ")\">" + list[j].prodName + list[j].selcolor + "</span>";
html += "<span class=\"je ulev-4\">单价:<em id=\"Price" + j + "\">" + list[j].prodPrice + "</em>&nbsp;小计:";
html += "<em id='SubTotal" + j + "'>" + list[j].SubTotal + "</em></span><span class=\"tnum\">";
html += "<span class=\"input_del\" title='点击一次数量减1' onclick=\"updatenum(2,'" + j + "','" + list[j].prodid + "'," + list[j].TotalNum + ",'" + list[j].selcolor + "','" + list[j].guige + "')\"></span>";
html += "<input name='Nums' id='Num" + j + "' type=\"text\" class=\"input_text\" onblur=\"updatenum(0,'" + j + "','" + list[j].prodid + "'," + list[j].TotalNum + ",'" + list[j].selcolor + "','" + list[j].guige + "')\" value=\"" + list[j].prodNum + "\"/>";
html += "<input name='Nums' id='Num2" + j + "' type=\"hidden\" value=\"" + list[j].prodNum + "\"/>";
html += "<span class=\"input_add\" title='点击一次数量加1' onclick=\"updatenum(1,'" + j + "','" + list[j].prodid + "'," + list[j].TotalNum + ",'" + list[j].selcolor + "','" + list[j].guige + "')\"></span>";
html += "<span class=\"Inventory\">库存:" + list[j].TotalNum + "</span></span></span><i onclick=\"delcart('" + list[j].prodid + "'," + j + ")\">x</i>";
html += "</li>";
}
html += "</ul></div>";
} else {
html += "<div class=\"ub ub-ac ub-pc ub-ver\" onclick='closeWin()' >"
+ "<img src=\"../image/noon.png\" style=\"margin-top:10em\"/>"
+ "<div class=\"ub\" style=\"color:red;margin-top:0.8em\">"
+ "您的购物车中还没有商品哦,马上去选购吧!"
+ "</div>"
+ "</div>";
$("#footer").css("display", "none");
}
$(".floor-product").html(html);
$("#cart_Total").html("¥" + data.ZSubTotal + "");
$(".ajaxLoader").addClass("uhide");
} else {
tishi3(data.msg);
$(".ajaxLoader").addClass("uhide");
if (data.msg == "您未登录") {
clearlocalStorage("userId");
clearlocalStorage("LoginId");
onlink("/");
}
}
}
});
}
function IsNumber(what) {
var text1 = "1234567890";
for (i = 0; i <= what.length - 1; i++) {
char1 = what.charAt(i);
index = text1.indexOf(char1);
if (index == -1) {
return true;
}
}
return false;
}
function updatenum(t, cartid, strProdId, TotalNum, selcolor, guige) {
var Price = $("#Price" + cartid);
var Num = $("#Num" + cartid);
var Num2 = $("#Num2" + cartid);
var SubTotal = $("#SubTotal" + cartid);
var Nums = $(".productlist .input_text");
var b = true;
if (IsNumber($(Num).val())) {
tishi3("请输入正确的购买数量");
$(Num).val($(Num2).val());
$("#cart_Total").html("¥" + changeTwoDecimal_f(parseFloat($(Price).html().replace("¥", "").replace(",", "")) * parseInt($(Num).val())));
b = false;
}
if ($(Num).val().toString().substring(0, 1) == "0") {
tishi3("购买数量必须大于0");
$(Num).val($(Num2).val());
$("#cart_Total").html("¥" + changeTwoDecimal_f(parseFloat($(Price).html().replace("¥", "").replace(",", "")) * parseInt($(Num).val())));
b = false;
}
if (parseInt($(Num).val()) > TotalNum) {
tishi3("购买数量不能大于" + TotalNum);
$(Num).val($(Num2).val());
$("#cart_Total").html("¥" + changeTwoDecimal_f(parseFloat($(Price).html().replace("¥", "").replace(",", "")) * parseInt($(Num).val())));
b = false;
}
if (b) {
if (t == 1) {
if (parseInt($(Num).val()) < TotalNum) {
$(Num).val(parseInt($(Num).val()) + 1);
$(Num2).val(parseInt($(Num2).val()) + 1);
}
}
if (t == 2) {
if (parseInt($(Num).val()) < 2) {
$(Num).val(parseInt($(Num).val()));
$(Num2).val(parseInt($(Num2).val()));
}
else {
$(Num).val(parseInt($(Num).val()) - 1);
$(Num2).val(parseInt($(Num2).val()) - 1);
}
}
var NumTotal = 0.00;
for (var i = 0; i < Nums.length; i++) {
var dPrice = parseFloat($("#Price" + Nums[i].id.replace("Num", "")).html().replace("¥", "").replace(",", ""));
var dNum = parseInt($(Nums[i]).val());
NumTotal = NumTotal + dPrice * dNum;
$(Num2).val($(Num).val());
};
$(SubTotal).html("¥" + changeTwoDecimal_f((parseFloat($(Price).html().replace("¥", "").replace(",", "")) * parseInt($(Num).val()))));
$("#cart_Total").html("¥" + changeTwoDecimal_f(NumTotal));
var datas = {
action: "updatecart",
CartId: CartId,
viewId: strProdId,
num: $(Num).val(),
selcolor: selcolor,
guige: guige
}
$.ajax({
type: 'POST',
url: "/apiajax.ashx?ifweb=1",
data: datas,
dataType: "json",
error: function (xhr) {
tishi3("发生错误:" + JSON.stringify(xhr));
},
success: function (data) {
if (data.status == '1') {
setlocalStorage("shop_view_refresh", 1);
if (data.cartcount == 0) {
var html = "";
html += "<div class=\"ub ub-ac ub-pc ub-ver\" onclick='appcan.window.open(\"shop\", \"../shop.html\", 10)' >"
+ "<img src=\"../image/noon.png\" style=\"margin-top:10em\"/>"
+ "<div class=\"ub\" style=\"color:red;margin-top:0.8em\">"
+ "您的购物车中还没有商品哦,马上去选购吧!"
+ "</div>"
+ "</div>";
$(".floor-product").html();
$("footer").css("display", "none");
}
} else {
tishi3('获取失败');
}
}
});
}
}
function delcart(strProdId, cid) {
if (strProdId == "") {
tishi3("请先选择");
} else {
var selcolor = $("#cartbox" + cid).attr("color");
var guige = $("#cartbox" + cid).attr("guige");
var datas = {
action: "updatecart",
CartId: CartId,
viewId: strProdId,
num: 0,
selcolor: selcolor,
guige: guige
}
$.ajax({
type: 'POST',
url: "/apiajax.ashx?ifweb=1",
data: datas,
dataType: "json",
error: function (xhr) {
tishi3("发生错误:" + JSON.stringify(xhr));
},
success: function (data) {
if (data.status == '1') {
var Price = parseFloat($("#SubTotal" + cid).html().replace("¥", ""));
var cart_Total = $("#cart_Total");
var NumTotal = parseFloat($(cart_Total).html().replace("¥", "")) - Price;
$(cart_Total).html("¥" + changeTwoDecimal_f(NumTotal));
$("#cartbox" + cid).css("display", "none");
setlocalStorage("shop_view_refresh", 1);
if (data.cartcount == 0) {
var html = "";
html += "<div class=\"ub ub-ac ub-pc ub-ver\" onclick='appcan.window.open(\"shop\", \"../shop.html\", 10)' >"
+ "<img src=\"../image/noon.png\" style=\"margin-top:10em\"/>"
+ "<div class=\"ub\" style=\"color:red;margin-top:0.8em\">"
+ "您的购物车中还没有商品哦,马上去选购吧!"
+ "</div>"
+ "</div>";
$(".floor-product").html(html);
$("footer").css("display", "none");
}
} else {
tishi3('删除失败');
}
}
});
}
}
function Shop_Pay() {
var userId = getlocalStorage("userId");
if (userId != null) {
onlink("shop_qygm.html");
} else {
onlink("/");
}
}
function ondetail(id) {
onlink("shop_view.html?id=" + id);
}
</script>
</head>
<body class="wrap">
<header>
<div class="ub">
<div class="nav-btn" id="nav-left" style=" margin:0; padding:0; padding-top:0.2em; min-width:3em" onclick="closeWin()">
<img src="../image/faifei.png" style="margin-left:0; margin-top:0em; height:1.2em;width:1.2em;" />
</div>
<h1 class="ub-f1">
购物车
</h1>
<div class="nav-btn blue" id="nav-right" style=" margin:0; padding:0; min-width:3em; ">
</div>
</div>
</header>
<section class="ub-f1" id="wrapper">
<div id="wrapper_content">
<p class="pullDown">下拉刷新...</p>
<div class="clear"></div>
<div style="padding:0 0.8em;">
<div class="floor-product">
</div>
<div class="clear"></div>
<div class="more_box"></div>
</div>
<div class="clear"></div>
<p class="pullUp">上拉加载...</p>
</div>
</section>
<footer class="" style=" width:100%; padding:0;background-color:#fff;border:0;">
<div class="cartbox">
<div class="cartmbox">
<div class="leftbox">
总价(不含运费)
<span class="cart_Total" id="cart_Total"></span>
</div>
<div class="rightbox">
<input id="doPurchaseBtn" type="button" onclick="Shop_Pay();" value="去结算" class="input_shopdh">
</div>
</div>
</div>
</footer>
<div class="ajaxLoader ub ub-ac uhide" onclick="reload()">
<div class="ub ub-ac ub-ver"><img src="image/load.gif" /><br>正在加载...</div>
</div>
</body>
</html>