作者 王晓刚
1 个管道 的构建 通过 耗费 11 秒

修改了好多

... ... @@ -12,6 +12,7 @@ namespace app\index\controller;
use app\common\controller\Frontend;
use app\common\controller\HomeBase;
use app\index\model\Store;
use think\Db;
class Car extends Frontend
{
... ... @@ -149,4 +150,11 @@ class Car extends Frontend
$total = $carModel->countData(['user_id'=>$user_id]);
$this->success('SUCCESS','',['total'=>$total]);
}
public function selected(){
$data = $this->request->param('data/a');
foreach($data as $key => $vo){
Db::name('car')->where(['id'=>$vo['car_id']])->update(['is_selected'=>$vo['is_selected']]);
}
}
}
\ No newline at end of file
... ...
... ... @@ -329,7 +329,7 @@
<ul>
{foreach name="$vo.car" item="c"}
<li>
<div class="radioBox"><input class="commodityCheck" type="checkbox" data-car_id="{$c.id}" data-goods_id="{$c.goods_id}" data-number="{$c.number}" value="{$c.id}"></div>
<div class="radioBox"><input class="commodityCheck" type="checkbox" data-car_id="{$c.id}" data-goods_id="{$c.goods_id}" data-number="{$c.number}" {if condition="$c.is_selected eq 1"}checked{/if} value="{$c.id}"></div>
<div class="borderBox">
<div class="imgBox">
<img src="{$c.goods.thumbnail}" alt="img">
... ... @@ -560,6 +560,31 @@
$('#checkAll_top').prop('checked', false)
}
checkedAll(this)
var data = [];
for(var i=0;i<$("input[class='commodityCheck']").length;i++){
var obj = {};
var car_id = $("input[class='commodityCheck']").eq(i).attr('data-car_id');
var is_selected = '2';
if($("input[class='commodityCheck']").eq(i).get(0).checked){
is_selected = "1";
};
obj.car_id = car_id;
obj.is_selected = is_selected;
data.push(obj);
}
$.ajax({
url:"{:url('index/car/selected')}",
type:"POST",
data:{'data':data},
success:function(res){
if(res.code == 1){
}
},
error:function(res){
toast('与服务器断开连接');
}
});
});
//全选、反选
... ... @@ -570,6 +595,31 @@
$('.shopBox').find('.commodityCheck').prop('checked', false);
}
contTotalPrice();
var data = [];
for(var i=0;i<$("input[class='commodityCheck']").length;i++){
var obj = {};
var car_id = $("input[class='commodityCheck']").eq(i).attr('data-car_id');
var is_selected = '2';
if($("input[class='commodityCheck']").eq(i).get(0).checked){
is_selected = "1";
};
obj.car_id = car_id;
obj.is_selected = is_selected;
data.push(obj);
}
$.ajax({
url:"{:url('index/car/selected')}",
type:"POST",
data:{'data':data},
success:function(res){
if(res.code == 1){
}
},
error:function(res){
toast('与服务器断开连接');
}
});
}
//单个商品选择按钮
... ... @@ -582,7 +632,43 @@
$('#checkAll_bottom').prop('checked', false);
}
contTotalPrice();
var data = [];
for(var i=0;i<$("input[class='commodityCheck']").length;i++){
var obj = {};
var car_id = $("input[class='commodityCheck']").eq(i).attr('data-car_id');
var is_selected = '2';
if($("input[class='commodityCheck']").eq(i).get(0).checked){
is_selected = "1";
};
obj.car_id = car_id;
obj.is_selected = is_selected;
data.push(obj);
}
$.ajax({
url:"{:url('index/car/selected')}",
type:"POST",
data:{'data':data},
success:function(res){
if(res.code == 1){
}
},
error:function(res){
toast('与服务器断开连接');
}
});
});
init();
function init(){
if($('.shopBox ul li').length == $("input[class='commodityCheck']:checked").length){
$('#checkAll_top').prop('checked', true);
$('#checkAll_bottom').prop('checked', true);
}else{
$('#checkAll_top').prop('checked', false);
$('#checkAll_bottom').prop('checked', false);
}
contTotalPrice();
}
//数量减
$('.car-decrease').on('click', function() {
... ...