fastadmin后台列表页,用自带筛选功能筛选数据后,进行加总,在列表页显示出来
后端部分:publicfunctionindex(){$total_sc=0;$total_fee=0;$filter2=json_decode($this->request->get("filter",''),true);$this->request->get(['filter'=>json_encode($filter2
后端部分:
public function index(){ $total_sc = 0; $total_fee = 0; $filter2 = json_decode($this->request->get("filter", ''), true); $this->request->get(['filter' => json_encode($filter2, true)]); list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->where($where) ->order($sort, $order) ->paginate($limit); if($filter2){ if(array_key_exists('user_id',$filter2)){ // 获取当月第一天和最后一天 $monthStart = date('Y-m-01 00:00:00'); $monthEnd = date('Y-m-t 23:59:59'); $total_fee_month = Db::name('jsq') ->where('user_id', $filter2['user_id']) ->whereTime('addtime','between', [$monthStart, $monthEnd]) ->sum('total_fee'); $total_sc_month = Db::name('jsq') ->where('user_id', $filter2['user_id']) ->whereTime('addtime','between', [$monthStart, $monthEnd]) ->sum('sc'); $total_sc_month = $total_sc_month/3600; $total_sc_month = number_format($total_sc_month, 2, '.', ''); }else{ $total_fee_month = 0; $total_sc_month = 0; } }else{ $total_fee_month = 0; $total_sc_month = 0; } foreach ($list as $k1 => $v1) { $total_sc = $total_sc + $v1['sc']; $total_fee = $total_fee + $v1['total_fee']; } $total_sc = $total_sc/3600; $total_sc = number_format($total_sc, 2, '.', ''); //$this->assign('total_sc',$total_sc); //$this->assign('total_fee',$total_fee); $result = array("total" => $list->total(),'total_sc'=>$total_sc,'total_fee'=>$total_fee,'total_sc_month'=>$total_sc_month,'total_fee_month'=>$total_fee_month, "rows" => $list->items()); if ($this->request->isAjax()) { return json($result); } return $this->view->fetch(); }
js部分:(监听表格返回的数据)
$(document).ready(function() { // 监听表格数据加载完成事件 $(document).on('load-success.bs.table', function(e, data) { // data参数包含服务器返回的完整数据 console.log('表格数据加载完成', data); // 示例1:更新元素为总记录数 $('#tongji').text("月时长:"+data.total_sc_month+"小时,月收入:"+data.total_fee_month+"元,总时长:"+data.total_sc+"小时,总收入:"+data.total_fee+"元"); // 示例2:更新元素为第一行数据的某个字段 /*if (data.rows && data.rows.length > 0) { $('#first-item-name').text(data.rows[0].name || '无数据'); } // 示例3:根据筛选条件更新元素 const queryParams = $('#table').bootstrapTable('getOptions').queryParams({}); const filterText = queryParams.filter ? JSON.stringify(queryParams.filter) : '无筛选'; $('#current-filter').text(filterText); */ }); });
html部分:
<div id="tongji" style="text-align:center;display:inline-block;margin-left:30px;"></div>