cookie做订单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=utf-8"%>
<%@ include file="/WEB-INF/jsp/include.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>爱玛客微信订货</title>
<link href="${rootUrl }css/mui.min.css" rel="stylesheet" />
<link rel="stylesheet" href="${rootUrl }css/font-awesome.min.css" />
<link href="${rootUrl }css/an-app.css" rel="stylesheet" />
<script src="${rootUrl }js/jquery/jquery.js" type="text/javascript"></script>
<style>
.mui-row.mui-fullscreen>[class*="mui-col-"] {
height: 100%;
}
.mui-col-xs-3,
.mui-control-content {
overflow-y: auto;
height: 100%;
}
.mui-segmented-control .mui-control-item {
width: 100%;
}
.mui-search .mui-placeholder .mui-icon {
color: #f7f7f7;
}
.an-top-bg .mui-search:before{ margin-top:-10px;}
.an-top-bg{ height:110px;}
.an-order-main{top:110px;}
.an-top-select{display: inline-block; margin-top: 5px; text-align: center; width: auto;
right: 50px; left: 10px; position: absolute;}
.an-top-select input[type=search]{ margin:6px 0; height:29px; background-color:rgba(0,0,0,0.2);}
.an-top-bg .mui-input-row.mui-search .mui-icon-clear{top:10px;}
.mui-search .mui-placeholder .mui-icon{padding-top:10px; padding-bottom:10px;}
.an-top-bg .mui-btn-link{color: #FFFFFF;margin-top: 5px; line-height:44px; font-size:16px; padding:0 10px;}
</style>
</head>
<body>
<!--主界面部分-->
<div class="an-order">
<!-- <div class="an-top-bg"> -->
<div class="mui-inner-wrap">
<header class="mui-bar mui-bar-nav">
<a class="mui-icon mui-icon-left-nav mui-pull-left goBack"></a>
<h1 class="mui-title">
<img class="an-logo" src="${rootUrl }img/logo.png" />
<span>${school.nameZH } </span>
</h1>
<a class="mui-icon mui-pull-right searchGo"><i class="fa fa-search" aria-hidden="true"></i></a>
</header>
<!-- 主图切换 -->
<div class="an-index-banner">
<div id="slider" class="mui-slider" >
<div class="mui-slider-group mui-slider-loop">
<!-- 额外增加的一个节点(循环轮播:第一个节点是最后一张轮播) -->
<!-- 第一张 -->
<input name="openid" value="${member.openid }" type="text" id="openid"/>
<input name="kongxc_wx_fen_diancanUrl" value="${kongxc_wx_fen_diancanUrl }" type="text" id="kongxc_wx_fen_diancanUrl"/>
<c:forEach items="${themeList }" var="vo">
<div class="mui-slider-item">
<a href="javascript:void (0);" onclick="theme(this,'${vo.id}');">
<img src="${rootUrl }attachFiles/theme/${school.code }/${vo.themeImg}" height="173px"/>
</a>
</div>
</c:forEach>
</div>
<div class="mui-slider-indicator">
<div class="mui-indicator mui-active"></div>
<div class="mui-indicator"></div>
</div>
</div>
</div>
<!-- 主图切换 end-->
<!-- 点餐和外卖切换 -->
<div>
<div id="segmentedControl" class="mui-slider-indicator mui-segmented-control mui-segmented-control-inverted an-order-topnav">
<a class="mui-control-item mui-active" href="#item1"></a>
</div>
</div>
<div>
<div id="item1" class="mui-control-content mui-active">
<div class="an-order-dc" id="an-heig">
<div class="mui-content mui-row mui-fullscreen">
<div class="mui-col-xs-3">
<div id="segmentedControls" class="mui-segmented-control mui-segmented-control-inverted mui-segmented-control-vertical">
<c:forEach items="${list }" var="vo" varStatus="voStatus">
<a class="mui-control-item <c:if test="${voStatus.count == 1}">mui-active</c:if>" href="#'${vo.id }'" id="${vo.id }" >${vo.nameZH }</a>
</c:forEach>
</div>
</div>
<div id="segmentedControlContents" class="mui-col-xs-9" style="border-left: 1px solid #c8c7cc;">
<c:forEach items="${list }" var="vo" varStatus="voStatus">
<div id="'${vo.id }'" class="mui-control-content <c:if test="${voStatus.count == 1}">mui-active</c:if>">
<ul class="mui-table-view">
<c:forEach items="${vo.foodBaseInfo }" var="food">
<li class="mui-table-view-cell">
<!-- 一道菜 -->
<div class="an-cai clearfix">
<a class="an-cai-left clickPhoto" href="javascript:void (0);" data-option="${food.id }" data-option_price="${food.priceStr }" onclick="detail(this,'${food.id }',${food.priceStr });">
<img src="${rootUrl }attachFiles/food/${food.foodPic }" />
</a>
<div class="an-cai-body">
<h4 style="font-size: 12px;">
<a href="javascript:void (0);" onclick="detail(this,'${food.id }',${food.priceStr });">${food.nameZH }</a>
<c:if test="${food.foodType != null && food.foodType !=''&& food.foodType =='2'}">
<img src="${rootUrl }attachFiles/productLogo/xp.jpg" height="25px" width="25px" />
</c:if>
<c:if test="${food.foodType != null && food.foodType !=''&& food.foodType =='3'}">
<img src="${rootUrl }attachFiles/productLogo/bm.jpg" height="25px" width="25px" />
</c:if>
</h4>
<div class="clearfix">
<div class="an-pull-left">
<p style="font-size: 8px;"><s>¥${food.marketPriceStr }</s> <c:if test="${food.maxNumStr !='0' }"></c:if>库存量:${food.maxNumStr }</p>
<p class="color-1" style="font-weight:bold;">¥${food.priceStr }</p>
</div>
<div class="an-order-number-add">
<c:if test="${food.maxNumStr !='0' }">
<div class="mui-numbox" data-numbox-min='0' data-numbox-max='99'>
<button class="mui-btn mui-btn-numbox-minus jian" type="button" onclick="getJian('${food.id }','${food.nameZH }',${food.priceStr });"><span class="mui-icon mui-icon-minus"></span></button>
<input class="mui-input-numbox number" id="foodNumber" data="${food.id }" type="number" readonly="readonly" name="${food.id }" value=""/>
<button class="mui-btn mui-btn-numbox-plus jia" type="button" onclick="getJia('${food.id }','${food.nameZH }',${food.priceStr });"><i class="fa fa-plus-circle" aria-hidden="true"></i></button>
</div>
</c:if>
<c:if test="${food.maxNumStr =='0' }">
<p style="font-size: 8px; color: red;font-weight: bold;" align="right">已售完</p></c:if>
</div>
</div>
</div>
</div>
<!-- 一道菜 end-->
</li>
</c:forEach>
</ul>
</div>
</c:forEach>
<c:if test="${orderTime eq null || orderTime.status !='1'}">
<br />
<br />
<font color="red" size="5" >商家还未开启售货</font><br /><br /></c:if>
</div>
</div>
</div>
</div>
</div>
<!-- </div> -->
<!-- 正文内容部分 end-->
<!-- 购物车 -->
<div id="an-order-car" class="an-order-busket mui-card">
<div class="mui-card-header">购物车
<%-- <h4 class="color-1" >总金额:¥<span class="an-order-number" id="totalMoney2">${totalMoney }</span></h4> --%>
<a class="mui-badge" id="delAll"><i class="fa fa-trash-o" aria-hidden="true"></i> 清空</a>
</div>
<div class="mui-card-content">
<div class="mui-card-content-inner">
<div class="an-order-busket-items">
<form class="mui-input-group" id="myCar">
</form>
</div>
</div>
</div>
</div>
<!-- 下单 -->
<div class="an-order-bot">
<div class="an-bott-hang">
<div class="an-order-gwc">
<i class="fa shopping-cart" aria-hidden="true">
<span class="an-order-number" id="totalNum">${totalQuantity }</span>
</i>
</div>
<div class="an-order-bot-txt">
<h4 class="color-1" >¥<span class="an-order-number" id="totalMoney">${totalMoney }</span></h4>
<p>配送费以订单为准</p>
</div>
</div>
<div class="an-order-btn">
<a href="" class="settlement" id="settlement">提交订单</a>
<!-- <a href="" class="settlement1" id="" onclick="test();">提交--订单</a> -->
</div>
</div>
<!-- 下单 end-->
</div>
<script src="${rootUrl }js/mui.min.js"></script>
<script type="text/javascript">
function detail(obj , id , priceStr ){
var openid = $("#openid").val();
$(obj).attr("href","${rootUrl }app/common/wx/product/getCoudetail?id="+id+"&price="+priceStr+"&openid="+openid);
document.location.href=obj.href;
}
function theme(obj , id ){
var openid = $("#openid").val();
$(obj).attr("href","${rootUrl }app/common/wx/product/theme?id="+id+"&openid="+openid);
document.location.href=obj.href;
}
</script>
<script type="text/javascript">
window.onload=function(){
//给主体div框架高度赋值
map_height=document.documentElement.clientHeight;//获取页面可见高度
document.getElementById("an-heig").style.height= map_height - 192 + "px";
//初始化map
ProIDList = cookie.Get("carList"); //车内商品ID列表
var _TotaPri = 0.0;
if(ProIDList != null && ProIDList != 'null' && ProIDList != ''){
if(ProIDList.lastIndexOf("&") != -1) {
var _arr = ProIDList.split("&");
for(var i = 0 ; i< _arr.length; i++){
var arr_Eve = _arr[i].split("|");
var _id = arr_Eve[0].substr(0,_arr[0].indexOf("="));
var _Num = arr_Eve[1];
var _PriOne = arr_Eve[4];
var _TempPri = parseFloat(_PriOne)*parseInt(_Num);
_TotaPri += parseFloat(_TempPri);
map.put(_id,_Num);
var nameList = document.getElementsByName(_id);
for(var len = 0; len < nameList.length ; len++){
nameList[len].value = _Num;
};
};
}else{
var arrOne = ProIDList.split("|");
var _id = arrOne[0].substr(0,arrOne[0].indexOf("="));
var _Num = arrOne[1];
var _PriOne = arrOne[4];
var _TempPri = parseFloat(_PriOne)*parseInt(_Num);
_TotaPri += parseFloat(_TempPri);
map.put(_id,_Num);
var nameList = document.getElementsByName(_id);
for(var len = 0; len < nameList.length ; len++){
nameList[len].value = _Num;
};
};
};
//-------对商品总价进行操作----------
$("#totalMoney").text(_TotaPri.toFixed(2));
//-------对商品总数进行操作----------
var TotalPro = cookie.Get("TotalPro"); //当前车内含有商品的总数
if(TotalPro != null && TotalPro != 'null' && TotalPro != '' ){
$("#totalNum").text(TotalPro);
}else{
$("#totalNum").text(0);
};
};
</script>
<script type="text/javascript">
mui('body').on('tap','#delAll',function(){
cookie.Del("carList","/");
cookie.Set("TotalPro",0,2,"/");//更新购物车清单
var totalNum = cookie.Get("TotalPro");
$("#totalNum").text(totalNum);
});
// 点击其他地方,隐藏购物车
mui('body').on('tap','.mui-backdrop-action',function(){
var myCar = $('#myCar');
myCar.empty();
document.getElementById("an-order-car").style.display="none";
document.getElementById("an-order-ying").style.display="none";
});
mui('body').on('tap','a',function(){
if($(this).hasClass('searchGo')){
var openid = $('#openid').val();
$(this).attr("href","${rootUrl }app/common/wx/product/searchName?openid="+openid);
document.location.href=this.href;
}
if($(this).hasClass('goBack')){
var kongxc_wx_fen_diancanUrl = $('#kongxc_wx_fen_diancanUrl').val();
var openid = $('#openid').val();
$(this).attr("href",kongxc_wx_fen_diancanUrl+"/app/common/wx/index/manage?openid="+openid);
document.location.href=this.href;
};
if($(this).hasClass('settlement')){
var totalMoney= $("#totalMoney").text();
if(totalMoney > 0){
// ----------
ProIDList = cookie.Get("carList"); //车内商品ID列表
var _detl ='' ;
if(ProIDList != null && ProIDList != 'null' && ProIDList != ''){
if(ProIDList.lastIndexOf("&") != -1) {
var _arr = ProIDList.split("&");
for(var i = 0 ; i< _arr.length; i++){
var arr_Eve = _arr[i].split("|");
var _id = arr_Eve[0].substr(0,_arr[0].indexOf("="));
var _Num = arr_Eve[1];
if(i == 0){
_detl = _id+","+_Num;
}else{
_detl += "@"+_id+","+_Num;
};
};
}else{
var arrOne = ProIDList.split("|");
var _id = arrOne[0].substr(0,arrOne[0].indexOf("="));
var _Num = arrOne[1];
_detl = _id+","+_Num;
};
};
var openid = $('#openid').val();
map.put("totalMoney",totalMoney);
$(this).attr("href","${rootUrl }app/common/wx/product/submit?openid="+openid+"&ProIDList="+_detl+"&totalMoney="+totalMoney);
cookie.Del("carList","/");
cookie.Set("TotalPro",0,2,"/");//更新购物车清单
document.location.href=this.href;
}else{
mui.toast("你还未下单");
};
};
document.location.href=this.href;
});
mui('body').on('tap','.clickPhoto',function(){
var id = this.getAttribute("data-option");
var priceStr = this.getAttribute("data-option_price");
var openid = $("#openid").val();
var uri = "${rootUrl }app/common/wx/product/getCoudetail?id="+id+"&price="+priceStr+"&openid="+openid;
setInterval(function (){
document.location.href=uri;
},500);
});
document.getElementById("an-heig").addEventListener("swipeup",function(){
console.log("你正在向上滑动");
});
var map = new Map();
function getJia(id ,name ,price){
if(Common.checkHasOne(id)){//如果cookie内没有
Common.intoCar(id,'1',name,'i',price);
}else{
ProIDList = cookie.Get("carList"); //车内商品ID列表
if(ProIDList.lastIndexOf("&") != -1) {
var _arr = ProIDList.split("&");
var _SubInd = Common.getSubPlace(ProIDList,id);//获取该物品在COOKIE数组中的下标位置
var arr_ = _arr[_SubInd].split("|");
var _Num = parseInt(arr_[1]);
var _AftNum = _Num + 1;
Common.updateQuantity(id,_AftNum);
}else{
var arrOne = ProIDList.split("|");
var _Num = parseInt(arrOne[1]) ;
var _AftNum = _Num +1;
Common.updateQuantity(id,_AftNum);
};
var TotalPro = cookie.Get("TotalPro");
cookie.Set("TotalPro",parseInt(TotalPro)+1,2,"/");//更新Cookies中的个数
};
//-----------对总价操作-------------------
var _TemPri = $("#totalMoney").text();
var _TotPri = parseFloat(_TemPri);
_TotPri += price;
$("#totalMoney").text(_TotPri.toFixed(2));
//--------对map进行操作,对加减的显示框进行操作----
var _NamList = document.getElementsByName(id);
if(map.containsKey(id)){
var _AftNum = parseInt(map.get(id))+1;
map.remove(id);
map.put(id,_AftNum);
for(var len = 0; len < _NamList.length ; len++){
_NamList[len].value = _AftNum;
};
}else{
map.put(id,1);
for(var len = 0; len < _NamList.length ; len++){
_NamList[len].value = 1;
};
};
//-----------对总量进行操作-----------------
var totalNum = cookie.Get("TotalPro"); //当前车内含有商品的总数
$("#totalNum").text(totalNum);
}
//----------------------减--------------------------
function getJian(id ,name,price){
if(!Common.checkHasOne(id)){
ProIDList = cookie.Get("carList"); //车内商品ID列表
var TotalPro = cookie.Get("TotalPro"); //当前车内含有商品的总数
//----------------对价格进行操作---------------
var totalPrice = 0.0;
var totalMoney = $("#totalMoney").text();
totalPrice = parseFloat(totalMoney) - parseFloat(price);
$("#totalMoney").text(totalPrice.toFixed(2));
if(ProIDList.lastIndexOf("&") != -1) {
var _arr = ProIDList.split("&");
var _SubInd = Common.getSubPlace(ProIDList,id);//获取该物品在COOKIE数组中的下标位置
var arr_Eve = _arr[_SubInd].split("|");
var _AftNum = parseInt(arr_Eve[1])-1;
if(_AftNum == 0){
Common.reMoveOne(id);
}else{
cookie.Set("TotalPro",parseInt(TotalPro)-1,2,"/");//更新Cookies中的个数
Common.updateQuantity(id,_AftNum);
};
}else{
//如果cookie内有
var arrOne = ProIDList.split("|");
var _AftNum = parseInt(arrOne[1])-1;
if(_AftNum == 0){
Common.reMoveOne(id);
}else{
cookie.Set("TotalPro",parseInt(TotalPro)-1,2,"/");//更新Cookies中的个数
Common.updateQuantity(id,_AftNum);
};
};
//----------------对map进行操作,对input输入框操作----------------------
var _AftNum = parseInt(map.get(id))-1;
map.remove(id);
map.put(id,_AftNum);
var _NamList = document.getElementsByName(id);
for(var len = 0; len < _NamList.length;len++){
_NamList[len].value =_AftNum;
};
//-------------对总数进行操作---------------
var totalNum = cookie.Get("TotalPro"); //当前车内含有商品的总数
$("#totalNum").text(totalNum);
};
};
//----------------------购物车--------------------------
// 点击购物车图标出现购物车内容
mui('.an-order-bot').on('tap','.an-order-gwc',function(){
var sty = document.getElementById("an-order-car").style.display;
if(sty =="" ||sty =='none'){
ProIDList = cookie.Get("carList"); //车内商品ID列表
if(ProIDList != null && ProIDList !='null' && ProIDList != ''){
var myCar = $('#myCar');
if(ProIDList.lastIndexOf("&") != -1) {
var json = ProIDList.split("&");
for(var i = 0 ; i< json.length; i++){
var detail = json[i].split("|");
myCar.append(
'<div class="mui-input-row">'+
'<label>'+unescape(detail[2])+'</label>'+
'<div class="an-order-busket-money">¥'+detail[4]+'</div>'+
"<div class='mui-numbox' data-numbox-min='0' data-numbox-max='99' >" +
"<button class='mui-btn mui-btn-numbox-minus jian' type='button' onclick='getJian("+'"'+detail[0].substr(0,detail[0].indexOf("="))+'"'+","+'"'+detail[2]+'"'+","+detail[4]+");' >-</button>" +
"<input class='mui-input-numbox' type='number' value='"+detail[1]+"' name='"+detail[0].substr(0,detail[0].indexOf("="))+"'readonly='readonly' />" +
"<button class='mui-btn mui-btn-numbox-plus jia' type='button' onclick='getJia("+'"'+detail[0].substr(0,detail[0].indexOf("="))+'"'+","+'"'+detail[2]+'"'+","+detail[4]+");' >+</button>" +
"</div>"+
"</div>");
mui('.mui-numbox').numbox();
};
}else{
var detail = ProIDList.split("|");
myCar.append(
'<div class="mui-input-row">'+
'<label>'+unescape(detail[2])+'</label>'+
'<div class="an-order-busket-money">¥'+detail[4]+'</div>'+
"<div class='mui-numbox' data-numbox-min='0' data-numbox-max='99' >" +
"<button class='mui-btn mui-btn-numbox-minus jian' type='button' onclick='getJian("+'"'+detail[0].substr(0,detail[0].indexOf("="))+'"'+","+'"'+detail[2]+'"'+","+detail[4]+");' >-</button>" +
"<input class='mui-input-numbox' type='number' value='"+detail[1]+"' name='"+detail[0].substr(0,detail[0].indexOf("="))+"'readonly='readonly' />" +
"<button class='mui-btn mui-btn-numbox-plus jia' type='button' onclick='getJia("+'"'+detail[0].substr(0,detail[0].indexOf("="))+'"'+","+'"'+detail[2]+'"'+","+detail[4]+");' >+</button>" +
"</div>"+
"</div>");
mui('.mui-numbox').numbox();
};
}
document.getElementById("an-order-car").style.display="block";
document.getElementById("an-order-ying").style.display="block";
}
if(sty == 'block'){
var myCar = $('#myCar');
myCar.empty();
document.getElementById("an-order-car").style.display="none";
document.getElementById("an-order-ying").style.display="none";
};
});
//----------------------Map--------------------------
function Map(){
this.elements = new Array();
//删除MAP所有元素
this.clear = function() {
this.elements = new Array();
}
//向MAP中增加元素(key, value)
this.put = function(_key, _value) {
this.elements.push( {
key : _key,
value : _value
});
}
//删除指定KEY的元素,成功返回True,失败返回False
this.remove = function(_key) {
var bln = false;
try {
for (var i = 0; i < this.elements.length; i++) {
if (this.elements[i].key == _key) {
this.elements.splice(i, 1);
return true;
};
};
} catch (e) {
bln = false;
}
return bln;
}
//获取指定KEY的元素值VALUE,失败返回NULL
this.get = function(_key) {
try {
for (var i = 0; i < this.elements.length; i++) {
if (this.elements[i].key == _key) {
return this.elements[i].value;
};
};
} catch (e) {
return null;
};
}
//判断MAP中是否含有指定KEY的元素
this.containsKey = function(_key) {
var bln = false;
try {
for (var i = 0; i < this.elements.length; i++) {
if (this.elements[i].key == _key) {
bln = true;
};
};
} catch (e) {
bln = false;
}
return bln;
}
//获取MAP中所有VALUE的数组(ARRAY)
this.values = function() {
var arr = new Array();
for (var i = 0; i < this.elements.length; i++) {
arr.push(this.elements[i].value);
}
return arr;
}
//获取MAP中所有KEY的数组(ARRAY)
this.keys = function() {
var arr = new Array();
for (var i = 0; i < this.elements.length; i++) {
arr.push(this.elements[i].key);
}
return arr;
};
};
</script>
<div id="an-order-ying" class="mui-backdrop mui-active mui-backdrop-action" style=" display: none;"></div>
</body>
</html>
<script type="text/javascript">
/*mui('body').on('tap','a',function(){
if($(this).hasClass('settlement1')){
cookie.Del("carList","/");
cookie.Set("TotalPro",0,2,"/");//更新购物车清单
alert("-=-=-");
Common.intoCar('3','3','name3','img3','3');
Common.intoCar('4','4','name4','img4','4');
Common.intoCar('1','1','name1','img1','1');
Common.intoCar('2','2','name2','img2','2');
Common.reMoveOne('1');
Common.updateQuantity("3","120000");
};
}); */
var Common = {
//移除数组中指定项
delArr:function(ar,n) { //n表示第几项,从0开始算起。
if(n<0) //如果n<0,则不进行任何操作。
return ar;
else{
return ar.slice(0,n).concat(ar.slice(n+1,ar.length));
}
},
//添加至购物车
intoCar:function(proid,quantity,proname,imgurl,_price) {
if(proid != "" && proname != "") {
var ProIDList = cookie.Get("carList"); //车内商品ID列表
if(ProIDList!=null && ProIDList!="" && ProIDList!="null")
{
if(Common.hasOne(proid))//如果购物车内没有
{
ProIDList += "&"+proid+"="+proid+"|"+quantity+"|"+proname+"|"+imgurl+"|"+_price;
// ProIDList += "&"+proid+"="+proid+"|"+quantity+"|"+escape(proname)+"|"+escape(imgurl)+"|"+_price;
cookie.Set("carList",ProIDList,2,"/");//更新购物车清单
TotalPro = cookie.Get("TotalPro"); //当前车内含有商品的总数
TotalPro++; //总数+1
cookie.Set("TotalPro",TotalPro,2,"/");
}
else
{
alert("SystemError,购物车中已含有此数量的商品");
}
}
else {
ProIDList=proid+"="+proid+"|"+quantity+"|"+proname+"|"+imgurl+"|"+_price;
// ProIDList=proid+"="+proid+"|"+quantity+"|"+escape(proname)+"|"+escape(imgurl)+"|"+_price;
cookie.Set("carList",ProIDList,2,"/");//更新购物车清单
cookie.Set("TotalPro",1,2,"/");
}
ProIDList = cookie.Get("carList"); //车内商品ID列表
}
}, //添加物品结束
//重置购物车内个数
reloadcar:function()
{
var t = cookie.Get("TotalPro");
if(t!=""&&t!="null")
document.getElementById("cart_num").innerText="(" + cookie.Get("TotalPro") + ")";
else
document.getElementById("cart_num").innerText="(0)";
}, //重置结束
//检验购物车内是否已经含有该商品
hasOne:function(pid){
ProIDList = cookie.Get("carList"); //车内商品ID列表
if(ProIDList.lastIndexOf("&") != -1){
var arr=ProIDList.split("&");
for(var i=0;i<arr.length;i++)
{
// alert(arr[i].indexOf("="));
if(arr[i].substring(0,arr[i].indexOf("=")) ==pid)
{
return false;
}
}
}else if(ProIDList!="null" && ProIDList!="")
{
if(ProIDList.substr(0,ProIDList.indexOf("="))==pid)
return false;
}
return true;
}, //检测结束
//检验购物车内是否已经含有该商品
checkHasOne:function(pid){
ProIDList = cookie.Get("carList"); //车内商品ID列表
if(ProIDList != null && ProIDList != 'null' && ProIDList.lastIndexOf("&") != -1){
var arr=ProIDList.split("&");
for(var i=0;i<arr.length;i++)
{
if(arr[i].substring(0,arr[i].indexOf("=")) ==pid)
{
return false;
}
}
}else if(ProIDList!="null" && ProIDList!="" && ProIDList != null)
{
if(ProIDList.substr(0,ProIDList.indexOf("="))==pid){
return false;
}
}
return true;
}, //检测结束
//移除某商品
reMoveOne:function(proid){
var ProIDList1 = cookie.Get("carList");
if(!Common.hasOne(proid)){
if(ProIDList1.lastIndexOf("&") != -1){
var arr=ProIDList1.split("&");
for(var i=arr.length-1;i>=0;i--){
if(arr[i].substr(0,arr[i].indexOf("="))==proid) {
arr.splice(i,1);
var tempStr=arr.join("&");
cookie.Set("carList",tempStr,2,"/");//更新购物车清单
var t=cookie.Get("TotalPro");
cookie.Set("TotalPro",t-1,2,"/");//更新Cookies中的个数
return;
}
}
} else{
cookie.Del("carList","/");
cookie.Set("TotalPro",0,2,"/");//更新购物车清单
// var totalNum = cookie.Get("TotalPro"); //当前车内含有商品的总数
// alert(totalNum);
}
}
}, //移除物品结束
//修改某物品数量
updateQuantity:function(proid,quantity){
ProIDList = cookie.Get("carList"); //车内商品ID列表
if(ProIDList.lastIndexOf("&") != -1) {
var arr=ProIDList.split("&");
var sub=Common.getSubPlace(ProIDList,proid);//获取该物品在COOKIE数组中的下标位置
var arr2=arr[sub].split("|");
arr2[1]=quantity;
var tempStr=arr2.join("|");//由数组重组字符串
arr[sub] = tempStr;
var newProList = arr.join("&");//由数组重组字符串
cookie.Set("carList",newProList,2,"/");//更新购物车清单
// alert(newProList);
} else {
var arr=ProIDList.split("|");
arr[1]=quantity;
var newProList=arr.join("|");
cookie.Set("carList",newProList,2,"/");//更新购物车清单
// alert(newProList);
}
}, //修改物品结束
//返回指定物品所在数组的下标位置
getSubPlace:function(list,proid){
var arr=list.split("&");
for(var i=0;i<arr.length;i++){
if(arr[i].substr(0,arr[i].indexOf("="))==proid) {
return i;
}
}
} //返回下标结束
};
</script>
<script type="text/javascript">
/**//*
by 码农.KEN (2007-11-9)
*/
var cookie={
//读取COOKIES,n为COOKIE名
Get:function(n){
var re=new RegExp(n+'=([^;]*);?','gi');
var r=re.exec(document.cookie)||[];
return (r.length>1?r[1]:null);
},
Get1:function(n){
var re=new RegExp(n+'=([^;]*);?','gi');
var r=re.exec(document.cookie)||[];
return unescape(r.length>1?r[1]:null);
},
//写入COOKIES,n为Cookie名,v为value
Set:function(n,v,e,p,d,s){
// alert(n+"========="+v);
var t=new Date;
if(e){
// 8.64e7 一天 3.6e6 一小时
t.setTime(t.getTime() + (e*3.6e6));
}
document.cookie=n+'='+v+'; '+(!e?'':'; expires='+t.toUTCString())+(!p?'':'; path='+p)+(!d?'':'; domain='+d)+(!s?'':'; secure'); // Set cookie
// var ProIDList3 = cookie.Get("carList");
// alert(ProIDList3+"--00");
},
Set1:function(n,v,e,p,d,s){
var t=new Date;
if(e){
// 8.64e7 一天 3.6e6 一小时
t.setTime(t.getTime() + (e*8.64e7));
}
document.cookie=n+'='+escape(v)+'; '+(!e?'':'; expires='+t.toUTCString())+(!p?'':'; path='+p)+(!d?'':'; domain='+d)+(!s?'':'; secure'); // Set cookie
},
Del:function(n,p,d){
var t=cookie.Get(n);
document.cookie=n+'='+(!p?'':'; path='+p)+(!d?'':'; domain='+d)+'; expires=Thu, 01-Jan-70 00:00:01 GMT';
return t;
},
DelCookie:function(NameOfCookie){
if (cookie.getCookie(NameOfCookie))
{
document.cookie = NameOfCookie+"="+";expires=Thu, 01-Jan-70 00:00:01 GMT";
// document.cookie = NameOfCookie+"="+";expires=Thu, 01-Jan-70 00:00:01 GMT";
var ProIDList3 = cookie.Get("carList");
alert(ProIDList3+"--00");
var ProIDList4 = cookie.Get("TotalPro");
alert(ProIDList4+"--11");
}
},
getCookie:function (NameOfCookie) {
if (document.cookie.length > 0)
{
begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
{
begin += NameOfCookie.length+1;//cookie值的初始位置
end = document.cookie.indexOf(";", begin);//结束位置
if (end == -1) end = document.cookie.length;//没有;则end为字符串结束位置
// document.write(document.cookie.substring(begin, end));
return unescape(document.cookie.substring(begin, end));
}
}
return null;
}
};
//var TotalPro = cookie.Get("TotalPro"); //当前车内含有商品的总数
</script>
cookie做订单的更多相关文章
- Safari无痕模式是不能只使用localStorage存储数据要用Cookie做补丁
safari 无痕浏览情况测试(部分手机) 1.测试机型 iPhone7 Plus 版本 11.3 iPhone6 Plus 版本 11.3.1 iPhone6 版本 10.2.1 iP ...
- 使用页面Cookie做ABTest测试
背景介绍: 公司为了提升网站销售,做了2种不同风格的Bug页面,需要测试哪个页面的销售效果更好,使用了ABTest. 原理: 当用户访问www.website.com/buy.php时,生成一个随机数 ...
- 用redis和cookie做单用户登录
因为公司的项目需要用到单用户登录,于是今天用redis和cookie给系统添加了单用户登录功能,再次简单记录一下. 单用户登录是为了防止同一账户在不同电脑和不同浏览器里面同时登录.所以我这边的思路是: ...
- 分享一个关于Cookie做的实验结果
实验本身是很枯燥的,我尽量把它讲的有趣些. 起因 去网上搜了下关于Cookie的介绍,看了好几篇都长得很一样,阉割一下内容不外乎说是"不同浏览器限制cookie数不同,大致在30-50这个范 ...
- 针对不同的Cookie做页面缓存
有时我们需要为PC浏览器及移动浏览器生成不同的页面,为了提高性能,不能每次请求都去判断User-Agent,通常用一个 Cookie 标记一下客户端是否是移动客户端,这样只需要读取这个 Cookie ...
- destoon系统开发-最新利用浏览器的cookie 做历史浏览记录
注意: 代码 放在要显示的为 (一般放在详情页),注意本教程不入库,直接利用浏览器的 cookie 缓存判断 <!--历史浏览记录 S--> <div class=&quo ...
- Django学习笔记(5)——cookie和session
一,前言 1.1,什么是会话跟踪技术 在JavaWeb中,客户向某一服务器发出第一个请求开始,会话就开始了,直到客户关闭了浏览器会话结束.在一个会话的多个请求中共享数据,这就是会话跟踪技术. 例如在一 ...
- Python学习笔记整理总结【Django】:模板语言、分页、Cookie、Session
一.模板语言 1.在前段展示:对象/字典/元组 class Business(models.Model): # id #用默认的自增id列 即:Business中有3列数据(id, caption, ...
- HTTP Session、Cookie机制详解
一.什么是http session,有什么用 HTTP协议本身是无状态的,本身并不能支持服务端保存客户端的状态信息,于是,Web Server中引入了session的概念,用来保存客户端的状态信息. ...
随机推荐
- 学习Microsoft SQL Server 2008技术内幕:T-SQL语法基础
第 2 章: 单表查询 use TSQLFundamentals2008; select * from Sales.orders; select empid, year(orderdate) as o ...
- msgfmt: command not found
sudo apt-get install gettext
- webpack-dev-server最简单的应用
1.安装 npm install webpack-dev-server --save-dev 2.再exports后加多一个对象即可 devServer: { contentBase: ". ...
- Flask+uwsgi+Nginx环境搭建
开源软件准备需要的软件列表:setuptools-33.1.1.zipPython-2.7.13.tgzpip-9.0.1.tar.gznginx-1.10.3.tar.gz软件统一上传到/usr/l ...
- virtualbox 设置windows 于ubuntu虚拟机共享文件夹
会弹出错误, .. ..还是会有错误, modprobe -a vboxsf 之后就可以挂载成功了!!
- 终端内容输出的同时保存到文件 tee
突然有这个需求,一查用tee就能实现 用法:tee [选项]... [文件]... 将标准输入复制到每个指定文件,并显示到标准输出. -a, --append 内容追加到给定的文件而非覆盖 -i, - ...
- Android项目总结
功能: 1.图片载入 ImageLoader 參数配置要合理 cacheMemory 一次性的图片最好不要缓存在内存中 合理控制在内存中的内存大小 ,适当的释放 volley是googl ...
- Selenium webdriver Java 查找元素
1.简单查找 By ID: WebElement element=driver.findElement(By.id("userId")); By Name:WebElement e ...
- wireshark过滤语法总结 (转载)
做应用识别这一块经常要对应用产生的数据流量进行分析. 抓包采用wireshark,提取特征时,要对session进行过滤,找到关键的stream,这里总结了wireshark过滤的基本语法,供自己以后 ...
- android adt 最新下载地址23.03
打开这个网址就可以看到adt的详细信息: http://developer.android.com/sdk/installing/installing-adt.html 或者直接在你的eclipse ...