任务:从商家中心导出数据,各个商品所属情况.
商品导出到Excel文件功能
/导出exel 功能make-in-lemon public function createExcelOp(){ $model = Model('goods'); $bill_list = $model->getGoodsOnlineList($condition); //导出Excel import('libraries.excel'); $excel_obj = new Excel(); $excel_data = array(); //设置样式 $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1'))); //header $excel_data[0][0] = array('styleid'=>'s_title','data'=>'SKU-ID'); $excel_data[0][1] = array('styleid'=>'s_title','data'=>'商品名称'); $excel_data[0][2] = array('styleid'=>'s_title','data'=>'供应商名'); $excel_data[0][3] = array('styleid'=>'s_title','data'=>'规格'); $excel_data[0][4] = array('styleid'=>'s_title','data'=>'市场价'); $excel_data[0][5] = array('styleid'=>'s_title','data'=>'商品价格'); $excel_data[0][6] = array('styleid'=>'s_title','data'=>'库存'); $excel_data[0][7] = array('styleid'=>'s_title','data'=>'商家货号'); $excel_data[0][8] = array('styleid'=>'s_title','data'=>'是否隐藏'); //data foreach ($bill_list as $k=>$v){ $excel_data[$k+1][0] = array('data'=>$v['goods_id']); $excel_data[$k+1][1] = array('data'=>$v['goods_name']); $excel_data[$k+1][2] = array('data'=>$v['supplier_name']); $excel_data[$k+1][3] = array('data'=>$v['goods_spec']); $excel_data[$k+1][4] = array('data'=>$v['goods_marketprice']); $excel_data[$k+1][5] = array('data'=>$v['goods_price']); $excel_data[$k+1][6] = array('data'=>$v['goods_storage']); $excel_data[$k+1][7] = array('data'=>$v['goods_serial']); $excel_data[$k+1][8] = array('data'=>$v['is_hidden']); } $excel_data = $excel_obj->charset($excel_data,CHARSET); $excel_obj->addArray($excel_data); $excel_obj->addWorksheet($excel_obj->charset('商品统计',CHARSET)); $excel_obj->generateXML($excel_obj->charset('商品统计',CHARSET).date('Y-m-d-H',time())); exit(); }
遇到的问题,当筛选商品事,如何只导出当前数据呢
思考:如何get到的如何传递到另一个方法使用呢
ajax 获取当前值并传递
view
<a href="javascript:void(0);" class="ncsc-btn ncsc-btn-green" style="right:250px" nctype="exel" data-param="{url:'<?php echo urlSeller('store_goods_online', 'createExcel');?>', sign:'batch_exel'}"onclick="return confirm('您确定要导出exel吗?');"><i></i>导出exel</a> <script> $(function(){ //导出exel $('a[nctype="exel"]').click(function(){ var data_str = ''; var data_str2 = $("select[name='supplier_id']").val(); var data_str3 = $("select[name='search_hidden_type']").val(); var data_str4 = $("select[name='gc_id']").val(); eval('data_str = ' + $(this).attr('data-param')); if(data_str.sign == 'batch_exel'){ window.open(data_str.url+ '&commonid='+'&supplier_id='+data_str2+'&search_hidden_type='+data_str3+'&gc_id='+data_str4); } }); }); </script>
最终 效果: