shop_cart.html
11.3 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>学考无忧-购物车</title>
<link rel="stylesheet" href="__TMPL__/public/assets/css/reset.css" />
<link rel="stylesheet" href="__TMPL__/public/assets/css/base.css" />
</head>
<body>
<!-- 顶部 -->
<div class="ad_top top_navBg">
<a href="javascript:history.back(-1)">
<img class="ad_topImg" src="__TMPL__/public/assets/images/left2.png" alt="" />
</a>
<h1>购物车</h1>
<p>管理</p>
</div>
<div class="shopping_cartBox">
<!-- 几件 -->
<h2 class="sh_cartNum">共有{$num}件商品</h2>
<ul class="order_newsUl sp_cartUl" style="margin-bottom:2.1rem">
<volist name="goods_data" id="vo">
<li>
<div class="sh_cartround" data-id="{$vo.carid}">
<img src="__TMPL__/public/assets/images/39_0.png" alt="" />
</div>
<div class="order_newsImg">
<img src="{:cmf_get_image_url($vo.thumbnail)}" alt="" />
</div>
<div class="order_newsCon">
<div class="order_newsTxt1 txt-cut">
{$vo.book_name}
</div>
<div class="order_newsTxt2">×<span>{$vo.book_num}</span></div>
<div class="order_newsTxt3">
<p class="de_topTxt1_1">¥<span>{$vo.price0}.{$vo.price1}</span></p>
<div class="order_newsNum">
<div class="order_newsJian" onclick="jian({$vo.carid})">-</div>
<input class="order_newsnum" type="text" readonly="readonly" value="{$vo.book_num}" />
<div class="order_newsJia" onclick="jia({$vo.carid})">+</div>
</div>
</div>
</div>
</li>
</volist>
</ul>
</div>
<!-- 支付 -->
<div class="shop_carts">
<div class="shop_cartsBox">
<!-- 全选 -->
<div class="shop_carts1">
<img src="__TMPL__/public/assets/images/39_1.png" alt="" />
<p>全选</p>
</div>
<!-- 合计 -->
<div class="shop_carts2">
<span class="shop_cartsIco">合计:</span>
<p class="de_topTxt1_1 zoji">¥<span id="myprice">0.00</span></p>
</div>
<!-- 去支付 -->
<div class="shop_carts3" onclick="myjump()">
去支付
</div>
</div>
</div>
<!-- 删除 -->
<div class="shop_remove">
<div class="shop_removeBox">
<!-- 全选 -->
<div class="shop_carts1">
<img src="__TMPL__/public/assets/images/39_1.png" alt="" />
<p>全选</p>
</div>
<div class="shop_remove2" onclick="datadel()">
删除
</div>
</div>
</div>
<!-- 底部一级导航 -->
<div class="in_bottom">
<ul>
<a href="{:url('Index/index')}">
<li>
<img src="__TMPL__/public/assets/images/22.png" alt="" />
<p>首页</p>
</li>
</a>
<a href="{:url('Classify/classify')}">
<li>
<img src="__TMPL__/public/assets/images/16.png" alt="" />
<p>分类</p>
</li>
</a>
<li>
<img src="__TMPL__/public/assets/images/20.png" alt="" />
<p style="color:#FF7700;">购物车</p>
</li>
<a href="{:url('Personalcenter/Personal_center')}">
<li>
<img src="__TMPL__/public/assets/images/18.png" alt="" />
<p>我的</p>
</li>
</a>
</ul>
</div>
<script src="__TMPL__/public/assets/js/base.js"></script>
<script src="__TMPL__/public/assets/js/jquery.js"></script>
<script>
/**
*删除
*/
function datadel(){
ids = $('.add');
goods_id = [];
for(i=0;i<ids.length;i++){
goods_id[i] = ids[i].dataset.id;
}
goods_id = goods_id.join(',');
$.post("{:url('Shopcart/shop_cart_del')}",{goods_id:goods_id},function(data){
if(data){
}else{
alert('删除失败');
}
});
}
/**
*点击跳转到订单页
*/
function myjump(){
ids = $('.add');
goods_id = [];
for(i=0;i<ids.length;i++){
goods_id[i] = ids[i].dataset.id;
}
console.log(goods_id);
if(goods_id.length == 0){
alert('请选择商品');
}else{
$.post("{:url('Shopcart/is_to_pay')}",{},function(data){
if(data == 1){
goods_id = goods_id.join(',');
myprice = $('#myprice').text();
$.post("{:url('Shopcart/shop_cart_pay')}",{id:goods_id,myprice:myprice},function(data){
obj = JSON.parse(data);
if(obj.type == 3){
alert('团购商品和热销商品请分别付款');
}else if(obj.type == 1){
window.location.href = "{:url('Orderpage/order_page')}?indet_id="+obj.indet_id;
}else if(obj.type == 2){
window.location.href = "{:url('Orderpage/order_salesman_ty')}?indet_id="+obj.indet_id;
}
});
}else if(data == 0){
alert('业务员不能购买书籍');
}else{
alert('业务员审核中,不能购买书籍')
}
});
}
}
/**
*点击加一
*/
function jia(id){
$.post("{:url('Shopcart/shop_cart_numadd')}",{id:id},function(data){
});
}
/**
* 点击减一
*/
function jian(id){
$.post("{:url('Shopcart/shop_cart_numdec')}",{id:id},function(data){
});
}
// 计算总计
function calcTotal() {
var checkBoxes = $(".sh_cartround img");
var priceSpans = $(".order_newsTxt3 .de_topTxt1_1 span");
var countInputs = $(".order_newsNum .order_newsnum");
var totalCount = 0;
var totalPrice = 0;
for (var i = 0; i < priceSpans.length; i += 1) {
// 强调: jQuery对象使用下标运算或get方法会还原成原生的JavaScript对象
if ($(checkBoxes[i]).attr("src") == "__TMPL__/public/assets/images/39.png") {
var price = parseFloat($(priceSpans[i]).text());
var count = parseInt($(countInputs[i]).val());
totalCount += count;
totalPrice += price * count;
}
}
$(".zoji span").html(totalPrice.toFixed(2));
}
function calcTotal2() {
var checkBoxes = $(".sh_cartround img");
var priceSpans = $(".order_newsTxt3 .de_topTxt1_1 span");
var countInputs = $(".order_newsNum .order_newsnum");
var totalCount = 0;
var totalPrice = 0;
for (var i = 0; i < priceSpans.length; i += 1) {
// 强调: jQuery对象使用下标运算或get方法会还原成原生的JavaScript对象
var price = parseFloat($(priceSpans[i]).text());
var count = parseInt($(countInputs[i]).val());
totalCount += count;
totalPrice += price * count;
}
$(".zoji span").html(totalPrice.toFixed(2));
}
$(function() {
$(".order_newsNum div").on("click", function(evt) {
if ($(this).text() == "-") {
var count = parseInt($(this).next().val());
if (count > 1) {
count -= 1;
$(this).next().val(count);
} else {
alert("商品数量最少为1");
}
$(this).parents(".order_newsCon").find(".order_newsTxt2 span").text(count);
} else {
var count = parseInt($(this).prev().val());
if (count < 200) {
count += 1;
$(this).prev().val(count);
} else {
alert("商品数量最多为200");
}
$(this).parents(".order_newsCon").find(".order_newsTxt2 span").text(count);
}
var price = parseFloat($(this).parents(".order_newsTxt3").children(".de_topTxt1_1").text().split("¥")[1]);
calcTotal();
});
// 单选
$('.order_newsUl li').each(function() {
var length = $(".sh_cartround img").length;
$(this).find('.sh_cartround img').click(function() {
var flag = 1;
for (var i = 0; i < $(".sh_cartround img").length; i++) {
flag += Number($(".sh_cartround img").eq(i).attr('src') == "__TMPL__/public/assets/images/39.png");
}
if (length === flag) {
$(".shop_carts1 img").attr('src', "__TMPL__/public/assets/images/39.png");
} else {
$(".shop_carts1 img").attr('src', "__TMPL__/public/assets/images/39_1.png");
}
if ($(this).attr("src") == "__TMPL__/public/assets/images/39_0.png") {
$(this).attr("src", "__TMPL__/public/assets/images/39.png");
calcTotal();
$(this).parents('.sh_cartround').addClass('add');
} else {
$(this).attr("src", "__TMPL__/public/assets/images/39_0.png");
$(".shop_carts1 img").attr('src', "__TMPL__/public/assets/images/39_1.png");
calcTotal();
$(this).parents('.sh_cartround').removeClass('add');
}
});
});
// 全选
$(".shop_carts1 img").click(function() {
if ($(this).attr("src") == "__TMPL__/public/assets/images/39_1.png") {
$(this).attr("src", "__TMPL__/public/assets/images/39.png");
$(".sh_cartround img").attr("src", "__TMPL__/public/assets/images/39.png");
$('.sh_cartround').addClass('add');
calcTotal2();
} else {
$(this).attr("src", "__TMPL__/public/assets/images/39_1.png");
$(".sh_cartround img").attr("src", "__TMPL__/public/assets/images/39_0.png");
$('.sh_cartround').removeClass('add');
$(".zoji span").text("0");
}
});
// 点击管理
$(".top_navBg p").click(function() {
if ($(this).text() == "管理") {
$(this).text("完成");
$(".shop_carts").hide();
$(".shop_remove").show();
} else {
$(this).text("管理");
$(".shop_carts").show();
$(".shop_remove").hide();
}
});
// 点击删除
$(".shop_remove2").click(function() {
$($(".sh_cartround img")).each(function() {
if ($(this).attr("src") == "__TMPL__/public/assets/images/39.png") {
$(this)
.parents("li")
.remove();
}
});
});
});
</script>
</body>
</html>