header_top.js
9.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
$(function(){
//渲染hello头
jQuery.ajax({
type : "GET",
url : "https://passport.nong12.com/uc/ws/helloService",
dataType : "jsonp",
cache:false,
success : function(data) {
if (data) {
if(data.info.indexOf("logout") > 0) {
$(".top .left").remove();
$(".top .right").before(data.info);
if(window.pageConfig){
if (window.pageConfig.navId && window.pageConfig.navId == "home"){
$(".pack-mo-tr1").find(".btn-big-y").each(function(){
$(this).remove();
});
$(".pack-mo-tr1").prepend(
'<a class="btn-big-w" href="http://user.nong12.com/purchase/order_pay.html"><img width="14" height="14" src="http://static.nong12.com/static/common/images/i/obligation.png"> 待付款</a>'
+ '<a class="btn-big-w" href="http://user.nong12.com/purchase/order_delivery.html"><img width="16" height="15" src="http://static.nong12.com/static/common/images/i/picking.png"> 待提货</a>').addClass("p-l1");
}
}
$(".top .left").append('<a class="h-user-msg" href="#" id="notify"></a>');
IM.notification($("#notify"));
}else {
$(".top .left a").first().attr("href",DiliPath.loginPath + "?ReturnUrl=" + window.location.href);
$(".top .left a").last().attr("href",DiliPath.registPath);
}
}
},
error : function() {
return false;
}
});
//渲染footer
jQuery.ajax({
type : "GET",
url : DiliPath.homePath + "common/footerJson.html",
dataType : "jsonp",
jsonp : "callFn",
jsonpCallback:'success_jsonpCallback1'+(new Date()).getTime(),
success : function(data) {
var html = [];
for ( var i = 0; i < data.length; i++) {
html.push("<li><i class='m-icon icon-a" + (i+1) + "'></i> <span>" + data[i].title + "</span><br>");
var vc = eval(data[i].extendsOne);
for ( var j = 0; j < vc.length; j++) {
if(j == vc.length - 1){
html.push("<a href='" + vc[j].link + "'>" + vc[j].text + "</a></li>");
}else{
html.push("<a href='" + vc[j].link + "'>" + vc[j].text + "</a><br>");
}
}
}
$(".m-left ul").empty().append(html.join(""));
}
});
//迷你购物车加载
if(window.location.href.indexOf("cartList") < 0 && window.location.href.indexOf("purchase_list") < 0) {
cartTools.showCart();
}
$(".mo-fn3 a").hover(function() {
cartTools.showCart();
}, function() {});
if($("head").find("script[src*='jquery.lazyload']").size()>0){
$("body").find("img").each(function(){
$(this).lazyload({
effect : "fadeIn",
skip_invisible : false
});
});
}
});
//公用系统域名
window.DiliPath = {
homePath : "http://www.nong12.com/",
userPath : "http://user.nong12.com/",
staticPath : "http://static.nong12.com/",
shopPath : "http://shop.nong12.com/",
loginPath : "https://passport.nong12.com/uc/login.aspx",
registPath : "https://passport.nong12.com/regedit/regedit.aspx",
packageProductPath : function(productId) {
return DiliPath.homePath + "product/" + productId + ".html";
}
};
window.Money = {
centToYuan : function(cent) {
cent = parseInt(cent);
if (cent <= 0) {
return "0.00";
}
yuan = (cent / 100).toFixed(2);
var result = yuan.toString();
if(result.indexOf(".") <= 0) {
result = result + ".00";
}
return result;
}
};
var cartTools = {
/**
* 加入购物车addrId:交割地 amount:数量 price:单价 sku:skuId
* @param addrId
* @param amount
* @param price
* @param sku
*/
addCart : function(addrId, amount, price, sku,fn) {
jQuery.ajax({
url : DiliPath.homePath + "cart/addCart.html",
type : "POST",
data : {addrId:addrId,amount:amount,price:price,sku:sku,userId:0},
dataType : "jsonp",
jsonp:'callFn',
jsonpCallback:'success_jsonpCallback'+(new Date()).getTime(),
cache : false,
success : function(result) {
if(fn && typeof(fn) == 'function'){
fn(result);
}
cartTools.showCart();
}
});
},
/**
* 渲染迷你购物车
*/
showCart : function () {
jQuery.ajax({
url: DiliPath.homePath + "cart/getMiniCart.html",
type: "POST",
dataType : "jsonp",//数据类型为jsonp
jsonp:'callFn',
jsonpCallback:'success_jsonpCallback'+(new Date()).getTime(),
cache: true,
success: function (miniCart) {
if (miniCart) {
$(".receipt-icon").html(miniCart.length);
if($(".hover-bill").length > 0){
$(".a-tit").siblings("b").html("(" + miniCart.length + ")").attr(
"count", miniCart.length);
var miniCartHtml = [];
var totalPrice = 0;
if (miniCart.length == 0) {
$(".hover-bill .u-con-no").remove();
$(".hover-bill").append('<div class="u-con-no">购物车中还没有商品,赶紧选购吧!</div>');
$(".hover-bill ul, .tab-xd, #near").hide();
} else {
$(".hover-bill ul, .tab-xd, #near").show();
for (var i = 0; i < miniCart.length; i++) {
var productImg = miniCart[i].productImage?miniCart[i].productImage.replace(/i[0-5]/g,'i'+4):'';
miniCartHtml[i] = "<li price='"
+ miniCart[i].price
+ "' amount='"
+ miniCart[i].amount
+ "'><a href='" + DiliPath.homePath + "product/" + miniCart[i].pid + ".html' class='a-img'><img data-original='"
+ productImg
+ "' src='" + DiliPath.staticPath + "static/common/images/gg/loading.gif' width='40' height='40' /></a><dl><dt><a href='" + DiliPath.homePath + "product/" + miniCart[i].pid + ".html'>"
+ miniCart[i].productName
+ " </a></dt><dd>¥"
+ Money.centToYuan(miniCart[i].price)
+ " * "
+ miniCart[i].amount
+ "</dd></dl><a href='#' class='a-del' id='"
+ miniCart[i].sku + "' addrId='" + miniCart[i].addrId + "'></a></li>";
totalPrice += miniCart[i].price
* miniCart[i].amount;
}
$(".hover-bill .u-con-no").remove();
$(".hover-bill ul").empty();
$(".hover-bill ul").append(miniCartHtml.join(""));
$(".hover-bill ul .a-del").each(function () {
$(this).click(function () {
cartTools.delMiniCart($(this).attr("id"), $(this).attr("addrId"));
return false;
});
});
$(".hover-bill ul").find("img").each(function () {
$(this).lazyload();
});
$(".tab-xd b").empty();
$(".tab-xd b").html("¥" + Money.centToYuan(totalPrice));
overflow_y($('.hover-bill ul'), miniCart.length * 71, 355);
}
}
}
}
});
},
/**
* 删除迷你购物车中的sku
* @param skuId
* @param addrId
*/
delMiniCart : function(skuId,addrId) {
jQuery.ajax({
url : window.DiliPath.homePath+"cart/delSkuFromCart.html",
type : "POST",
dataType : "jsonp",//数据类型为jsonp
jsonp: "callFn",//服务端用于接收callback调用的function名的参数
jsonpCallback:'success_jsonpCallback'+(new Date()).getTime(),
data : {sku:skuId,addrId:addrId},
async : false,
success : function(result) {
if (result) {
if (result.flag) {
$("#" + skuId).parents("li").slideUp("fast",function(){
$("#" + skuId).parents("li").remove();
$(".tab-xd b").html("¥" + cartTools.compute());
});
var cartCount = parseInt($(".a-tit").siblings("b").attr("count")) - 1;
$(".a-tit").siblings("b").html("(" + cartCount + ")").attr(
"count", cartCount);
$(".receipt-icon").html(cartCount);
if(cartCount == 0){
$(".hover-bill .u-con-no").remove();
$(".hover-bill").append('<div class="u-con-no">购物车中还没有商品,赶紧选购吧!</div>');
$(".hover-bill ul, .tab-xd, #near").hide();
}
overflow_y($('.hover-bill ul'), cartCount*71, 355);
}
}
}
});
},
/**
* 计算购物车价格
*/
compute : function(){
var totalPrice = 0;
$(".hover-bill ul li").each(function() {
totalPrice += parseFloat($(this).attr("price")) * parseInt($(this).attr("amount"));
});
return Money.centToYuan(totalPrice);
}
};
var otherTools = {
/**
* im
* @param sellerType
* @param sellerName
*/
imConnection : function(sellerType,sellerName){
var type = 2;//2默认客服
var name = '地利客服';
//第3方
if(sellerType == 30){
type = 0;
name = sellerName;
}
var timestamp = (new Date()).valueOf();
var ht = (screen.height-500)/2;
var wt = (screen.width-800)/2;
var url = 'http://chat.nong12.com/launch/launch.action?uid='+ name +'&type='+type+'&_t='+timestamp;
var param = 'height=600,width=800,resizable=yes,top=' + ht + ',left=' + wt;
window.open(url, name, param);
}
};