Files
g.hnyhua.cn/Mtxfw.shop/Sell/myShoppingCart.aspx
2026-02-07 15:48:27 +08:00

211 lines
7.7 KiB
Plaintext

<%@ Page Title="" Language="C#" MasterPageFile="~/Telesa.Master" AutoEventWireup="true" CodeBehind="myShoppingCart.aspx.cs" Inherits="Mtxfw.shop.myShoppingCart" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MyHead" runat="server">
<link href="/css/shop_cart.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
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) {
var Price = $("#Price" + cartid);
var Num = $("#Num" + cartid);
var Num2 = $("#Num2" + cartid);
var SubTotal = $("#SubTotal" + cartid);
var tr = $("#tr" + cartid);
var Nums = $(".cart_table .ProdNum");
var cart_Total = $("#cart_Total");
var cart_Total2 = $("#cart_Total2");
var b = true;
if (IsNumber(Num.val())) {
alert('请输入正确的购买数量');
Num.val(Num2.val());
SubTotal.html("¥" + changeTwoDecimal_f((parseFloat(Price.html().replace("¥", "").replace(",", "")) * parseInt(Num.val()))));
b = false;
}
if (Num.val().toString().substring(0,1)=="0") {
alert('购买数量必须大于0');
Num.val(Num2.val());
SubTotal.html("¥" + changeTwoDecimal_f((parseFloat(Price.html().replace("¥", "").replace(",", "")) * parseInt(Num.val()))));
b = false;
}
if (parseInt(Num.val()) > TotalNum) {
alert('购买数量不能大于' + TotalNum);
Num.val(Num2.val());
SubTotal.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;
Nums.each(function (i) {
var dPrice = parseFloat($("#Price" + Nums[i].id.replace("Num", "")).html().replace("¥", "").replace(",", ""));
var dNum = parseInt($(this).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));
cart_Total2.html("¥" + changeTwoDecimal_f(NumTotal));
$.post("/Ajax.ashx", { action: 'updatecart', ProductID: strProdId, Num: Num.val(), selcolor:escape(selcolor)}, function (data) {
switch (data) {
case "0": alert('参数错误!'); break;
//case "1": alert('参数00!'); break;
}
});
}
}
function delcart() {
var cart_Total = $("#cart_Total");
var checks = $(".cart_table .checks");
var NumTotal = parseFloat($("#cart_Total").html().replace("¥", ""));
var strProdId = "", selcolor="";
var ifchecked = 0;
for (var i = 0; i < checks.length; i++) {
if (typeof ($(checks[i]).attr("checked")) != "undefined") {
var strA = $(checks[i]).val().split("|");
var tr = $("#tr" + strA[0]);
var trr = $("#trr" + strA[0]);
var dPrice = parseFloat($("#Price" + strA[0]).html().replace("¥", ""));
var dNum = parseInt($("#Num" + strA[0]).val());
NumTotal = NumTotal - dPrice * dNum;
tr.hide();
if (trr.length > 0) {
trr.hide();
}
strProdId += strA[1] + ",";
var color = $("#selcolor" + strA[0]).val();
selcolor += (color==""?"":escape(color)) + ",";
ifchecked += 1;
}
}
if (strProdId == "") {
alert('请先选择');
} else {
$.post("/Ajax.ashx", { action: 'updatecart', ProductID: strProdId, Num: 0, selcolor: selcolor });
cart_Total.html("¥" + changeTwoDecimal_f(NumTotal));
if (checks.length == ifchecked) {
var trdel = $("#trdel td");
trdel.css("background-color", "#ffffff");
trdel.html("<span class=\"Cart_FH\">购物车为空,<A href=\"/\">返回商城购物</A></span>");
}
}
}
function Shop_Pay() {
var checks = document.getElementsByName("checks");
var Achecks = "";
var ifchecked = false;
for (var i = 0; i < checks.length; i++) {
if (checks[i].checked == true) {
var strA = checks[i].value.split("|");
if (Achecks == "") {
Achecks = Achecks + "," + strA[1] + ",";
} else {
Achecks = Achecks + strA[1] + ",";
}
ifchecked = true;
}
}
if (ifchecked == false) {
alert('你木有选择');
} else {
location.replace("/Sell/UserQRGM.aspx?CartID=" + Achecks);
}
}
function UserQRGM() {
var checks = document.getElementsByName("qrshdz");
if (checks.length != 0) {
var Achecks = "";
var ifchecked = false;
for (var i = 0; i < checks.length; i++) {
if (checks[i].checked == true) {
ifchecked = true;
}
}
if (ifchecked == false) {
alert('你木有选择配送地址');
checks[0].focus();
return false;
}
}
else {
alert('你木有配送地址,请先添加配送地址');
return false;
}
}
function changeTwoDecimal_f(x) {
var f_x = parseFloat(x);
if (isNaN(f_x)) {
alert('function:changeTwoDecimal->parameter error');
return false;
}
var f_x = Math.round(x * 100) / 100;
var s_x = f_x.toString();
var pos_decimal = s_x.indexOf('.');
if (pos_decimal < 0) {
pos_decimal = s_x.length;
s_x += '.';
}
while (s_x.length <= pos_decimal + 2) {
s_x += '0';
}
return s_x;
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MyContent" runat="server">
<div class="contentWrapper">
<form runat="server" id="MyForm">
<div id="main">
<div id="Location"><div class="title">当前位置: <a href="/">首页</a> &gt; 购物车</div></div>
<table cellSpacing="0" class="cart_table" align="center">
<tr bgColor="#E2F2FF">
<td width="40" align="center">选择</td>
<td align="center">商品名称</td>
<td align="center" class="hide300">商品单价</td>
<td align="center">商品数量</td>
<td align="center">商品小计</td>
</tr>
<%=ShowConent%>
</TABLE>
</div>
</form>
</div>
</asp:Content>