作者 jinglong
1 个管道 的构建 通过 耗费 23 秒

增加后台独立年检列表

... ... @@ -58,6 +58,9 @@ class AdminCheckController extends AdminBaseController
$common = new AdminCommonController();
$status = $common->getCheckStatus();
foreach($data as &$value) {
$value['title'] = $value['project_name'] . '月检' . date('Y-m-d', $value['ins_m_time']);
}
//渲染
$this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
$this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
... ...
... ... @@ -91,6 +91,15 @@ class AdminCommonController extends AdminBaseController
return $p_ids;
}
//查询项目
public function getProjectName1($project_id){
$res = Db::name('project')
->where('id',$project_id)
->field('id,name project_name,is_inspect')
->find();
return $res;
}
//获取项目id
public function getProjectId($id){
$res = Db::name('user')
... ... @@ -442,7 +451,7 @@ class AdminCommonController extends AdminBaseController
$arr['b_company']['company_name'] = !empty($b_company['company_name'])?$b_company['company_name']:'';
$arr['b_company']['logo'] = !empty($b_company['logo'])?$host.$b_company['logo']:'';
//报表标题
$arr['title'] = $project['name'].$report_name.'报表';
$arr['title'] = $report_name.'报表';
}
return $arr;
}
... ... @@ -735,9 +744,9 @@ class AdminCommonController extends AdminBaseController
$arr = [];
//甲乙方logo,名称,报表名称
if($table == 'check'){
$company = $this->getCompanyName($res['project_id'],'月检');
$company = $this->getCompanyName($res['project_id'],$res['title'].'月检');
}else{
$company = $this->getCompanyName($res['project_id'],'年检');
$company = $this->getCompanyName($res['project_id'],$res['title'].'年检');
}
if($company){
$arr['a_company'] = $company['a_company'];
... ... @@ -747,6 +756,9 @@ class AdminCommonController extends AdminBaseController
//月检时间
if($table == 'check'){
$arr['title'] = $res['project_name'] . '月检' . date('Y-m-d', $res['ins_m_time']).'报表';
//月检时间
$arr['ins_m_time'] = date('Y/m/d',$res['ins_m_time']);
//月检点
... ... @@ -939,9 +951,9 @@ class AdminCommonController extends AdminBaseController
$arr = [];
//甲乙方logo,名称,报表名称
if($table == 'train'){
$company = $this->getCompanyName($res['project_id'],'培训');
$company = $this->getCompanyName($res['project_id'],$res['title'].'培训');
}else{
$company = $this->getCompanyName($res['project_id'],'演习');
$company = $this->getCompanyName($res['project_id'],$res['title'].'演习');
}
if($company){
$arr['a_company'] = $company['a_company'];
... ... @@ -1061,15 +1073,15 @@ class AdminCommonController extends AdminBaseController
//甲乙方logo,名称,报表名称
if($table == 'repair'){
if($party == 0){
$company = $this->getCompanyName($res['project_id'],'(甲方)报修');
$company = $this->getCompanyName($res['project_id'],$res['title'].'(甲方)报修');
}else{
$company = $this->getCompanyName($res['project_id'],'(乙方)报修');
$company = $this->getCompanyName($res['project_id'],$res['title'].'(乙方)报修');
}
}else{
if($party == 0){
$company = $this->getCompanyName($res['project_id'],'(甲方)改造');
$company = $this->getCompanyName($res['project_id'],$res['title'].'(甲方)改造');
}else{
$company = $this->getCompanyName($res['project_id'],'(乙方)改造');
$company = $this->getCompanyName($res['project_id'],$res['title'].'(乙方)改造');
}
}
if($company){
... ... @@ -1414,4 +1426,151 @@ class AdminCommonController extends AdminBaseController
}
return $result;
}
//独立年检获取乙方公司id
public function getCompanyB(){
$admin_id = cmf_get_current_admin_id();
if($admin_id == 1){
$company_id_b = '';
}else{
//获取乙方公司id
$company_id_b = $this->getProjectId($admin_id);
}
return $company_id_b;
}
//根据乙方公司查询乙方员工
public function getStaffB($company_id){
$company = Db::name('company')
->where('id',$company_id)
->where('pid',0)
->field('id,u_s_id')
->find();
$u_s_id_s = [];
if($company){
$u_s_id_s = explode(',',trim($company['u_s_id'],','));
}
return $u_s_id_s;
}
//独立年检巡检点
public function getTestPoint($where){
//查询项目的月检点
$res_test = Db::name('spot')
->where($where)
->field('id,spot_name')
->select()
->toArray();
if($res_test){
$testIns = $this->getInsTest($where,'status,spot_id,images,uid');
foreach ($res_test as &$value){
$value['status'] = 2;
foreach ($testIns as $ins_value){
if($value['id'] == $ins_value['spot_id']){
$value['status'] = $ins_value['status'];
$user = $this->getUserById(['id'=>$ins_value['uid']]);
if($user){
$value['user_login'] = $user['user_login'];
}else{
$value['user_login'] = '';
}
$images = $this->absolutionUrl($ins_value['images']);
$images = $this->getDayImages($images);
if($images){
$value['images'] = $images;
}else{
$value['images'] = [];
}
}
}
if(!isset($value['user_login'])){
$value['user_login'] = '';
}
if(!isset($value['images'])){
$value['images'] = [];
}
}
$result = $res_test;
}else{
$result = [];
}
return $result;
}
//获取独立年检的巡检信息
public function getInsTest($where,$field){
$res = Db::name('years')
->where($where)
->field($field)
->select()
->toArray();
return $res;
}
//查看独立年检数据是否有
public function exportTestList($param,$field){
$res = Db::name('test')
->alias('t')
->join('user u','t.uid = u.id','LEFT')
->where(function (Query $query) use ($param){
$common = new AdminCommonController();
//获取乙方公司id
$company_id_b = $common->getCompanyB();
if(!empty($company_id_b)){
$u_s_id_s = $common->getStaffB($company_id_b);
$query->whereIn('uid',$u_s_id_s);
}
//查询登录乙方账号的所有项目
$startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
$endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
if (!empty($startTime)) {
$query->where('t.test_time', '>=', $startTime);
}
if (!empty($endTime)) {
$query->where('t.test_time', '<=', $endTime);
}
})
->field($field)
->select()->toArray();
return $res;
}
//独立年检详情
public function testExportData($res){
$arr = [];
//查找乙方发起人所在乙方公司
$uid = ','.$res['uid'].',';
$host = new InspectModel();
$host = $host::host.'/';
$b_company = $this->getCompany(['u_s_id'=>['like','%'.$uid.'%']],'id,company_name,logo');
$arr['b_company']['company_name'] = !empty($b_company['company_name'])?$b_company['company_name']:'';
$arr['b_company']['logo'] = !empty($b_company['logo'])?$host.$b_company['logo']:'';
//报表标题
$arr['title'] = $res['title'].'独立年检报表';
//独立年检时间
$arr['test_time'] = date('Y/m/d',$res['test_time']);
$arr['time'] = date('Y-m-d',$res['test_time']).'('.$res['id'].')';
//独立年检点
$arr['test_point'] = $this->getTestPoint(['test_id'=>$res['id']]);
//地点
$arr['address'] = $res['address'];
//单号
$arr['number'] = $res['number'];
//备注
$arr['remark'] = $res['remark'];
//独立年检(乙方发起人)
$user = $this->getUserById(['id'=>$res['uid']]);
if($user){
$arr['user_login'] = $user['user_login'];
}else{
$arr['user_login'] = '';
}
return $arr;
}
}
... ...
... ... @@ -956,6 +956,187 @@ class AdminExcelDataController extends AdminBaseController
return $url;
}
//独立年检渲染数据到表格上
public function testExcelData($arr){
//设置脚本的最大执行时间,设置为0则无时间限制
set_time_limit(0);
ini_set("memory_limit","-1");
$spreadsheet = new Spreadsheet();
$adminCommon = new AdminCommonController();
$sheet = $spreadsheet->getActiveSheet();
$xlsName = $arr['time'];
//设置sheet名称
$name = '报表';
$name = $adminCommon->iconv_to_utf8($name);
$sheet->setTitle($xlsName.$name);
//合并单元格
//报表名称
$sheet->mergeCells('B1:J1');
//乙方logo,乙方公司名称
$sheet->mergeCells('B3:B4');
$sheet->mergeCells('C3:D3');
$sheet->mergeCells('C4:D4');
//乙方发起人姓名
$sheet->mergeCells('B6:C6');
$sheet->mergeCells('B7:C7');
$spreadsheet->getDefaultStyle()->getFont()->setName('微软雅黑');//字体
//设置默认宽
$sheet->getDefaultColumnDimension()->setWidth(8);
//设置高度
$sheet->getRowDimension(1)->setRowHeight(45);
// $sheet->getRowDimension(2)->setRowHeight(55);
//***********************背景填充颜色*****************************
$sheet->getStyle( 'A1:M8')->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID);
$sheet->getStyle( 'A1:M8')->getFill()->getStartColor()->setRGB('222B35');//背景颜色
//***********************画出单元格边框结束*****************************
//标题
$sheet->setCellValue('B1', $arr['title']);
$sheet->getStyle('B1')->getFont()->setSize(18);//字体大小
$sheet->getStyle('B1')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
$sheet->getStyle('B1')->getFont()->setBold(true);//字体加粗
//甲方logo适用网络图片
$imageB = $arr['b_company']['logo'];
if($imageB){
$img = $this->getFileSuffix($imageB);
$objMemory = new MemoryDrawing();
$objMemory->setImageResource($img);
$objMemory->setRenderingFunction(MemoryDrawing::RENDERING_DEFAULT);//渲染方法
$objMemory->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
//设置宽度高度
$objMemory->setResizeProportional(false);
$objMemory->setHeight(40);//照片高度
$objMemory->setWidth(40); //照片宽度
// /*设置图片要插入的单元格*/
$objMemory->setCoordinates('B3');
$objMemory->setWorksheet($sheet);
}
$sheet->getStyle('B3:J7')->getFont()->setSize(8);//字体大小
$sheet->getStyle('C3:G3')->getFont()->getColor()->setRGB('949494');//设置颜色为灰色
$sheet->getStyle('B6:I6')->getFont()->getColor()->setRGB('949494');//设置颜色为灰色
$sheet->getStyle('C4:G4')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
$sheet->getStyle('B7:I7')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
//乙方公司
$sheet->setCellValue('C3', '乙方公司');
//乙方公司名称
$sheet->setCellValue('C4', $arr['b_company']['company_name']);
//乙方发起人姓名
$sheet->setCellValue('B6', '乙方发起人');
$sheet->setCellValue('B7', $arr['user_login']);
//独立年检时间
$sheet->setCellValue('D6', '年检时间');
$sheet->setCellValue('D7', $arr['test_time']);
$array1 = [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT,
'textRotation' => 0,
'wrapText' => TRUE
];
$sheet->getStyle('F10')->getAlignment()->applyFromArray($array1);//垂直水平居左
$sheet->getStyle('I10')->getAlignment()->applyFromArray($array1);//垂直水平居左
//月检点信息图片循环开始
$cols = 11;
$cells = ['C','E','G','I','K'];
$common = new AdminCommonController();
$state = $common::inspectStatus;
foreach($arr['test_point'] as $value){
$cols += 0;
//巡检点名称
$array = [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
'textRotation' => 0,
'wrapText' => TRUE
];
$sheet->mergeCells('A'.$cols.':B'.$cols);
$sheet->setCellValue('A'.$cols, $value['spot_name'].'('.$value['user_login'].')'."\n".$state[$value['status']]);
$sheet->getStyle('A'.$cols)->getAlignment()->applyFromArray($array);//垂直水平居中
//循环第二层
foreach($value['images'] as $image_image){
//渲染图片日期
$col_day = $cols - 1;
$sheet->mergeCells('C'.$col_day.':D'.$col_day);
$sheet->setCellValue('C'.$col_day, $image_image['day']);
//获取图片个数
$length = count($image_image['image']);
$col = ceil($length/5);
for($i=0;$i<$col;$i++) {
$col_i = $cols + $i;
$sheet->getRowDimension($col_i)->setRowHeight(105);
$sheet->mergeCells('C' . $col_i . ':D' . $col_i);
$sheet->mergeCells('E' . $col_i . ':F' . $col_i);
$sheet->mergeCells('G' . $col_i . ':H' . $col_i);
$sheet->mergeCells('I' . $col_i . ':J' . $col_i);
$sheet->mergeCells('K' . $col_i . ':L' . $col_i);
$key = 0;
foreach($image_image['image'] as $k=>$image_value){
$pre = $i+4*$i;
$next = $i+1+4*($i+1);
if($k>=$pre && $k<$next){
//巡检图片
$image = $image_value['image_url'];
if($image){
$img = $this->getFileSuffix($image);
$objMemory = new MemoryDrawing();
$objMemory->setImageResource($img);
$objMemory->setRenderingFunction(MemoryDrawing::RENDERING_DEFAULT);//渲染方法
$objMemory->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
//设置宽度高度
$objMemory->setResizeProportional(false);
$objMemory->setHeight(120);//照片高度
$objMemory->setWidth(105); //照片宽度
// /*设置图片要插入的单元格*/
$objMemory->setCoordinates($cells[$key].$col_i);
$objMemory->setWorksheet($sheet);
}
$key++;
}
}
}
$cols += $col+1;
}
}
// $sheet->getStyle( 'A12:M'.$cols)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
$sheet->getStyle( 'A9:M'.$cols)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID);
$sheet->getStyle( 'A9:M'.$cols)->getFill()->getStartColor()->setRGB('F3F3F4');//背景颜色浅灰色
$objWrite = IOFactory::createWriter($spreadsheet, 'Xls');
$file_name = $xlsName.'.xls';
$files_url = ROOT_PATH . '/public/upload/export';
if(!is_dir($files_url)){
mkdir($files_url);
}
$file_url = ROOT_PATH . '/public/upload/export/'.$file_name;
$objWrite->save($file_url);
$sys = $adminCommon->getOperateSys();
if($sys == 'Linux'){
chmod($file_url, 0777);//适用于linux
}
//相对路径
$url = 'upload/export/'.$file_name;
return $url;
}
//培训演习渲染数据到表格上
public function trainExcelData($arr,$table){
//设置脚本的最大执行时间,设置为0则无时间限制
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\AdminBaseController;
use think\Db;
use think\db\Query;
//乙方独立年检列表
class AdminTestController extends AdminBaseController
{
public function index(){
$param = $this->request->param();
//获取登录人所在的项目
$res = Db::name('test')
->alias('t')
->join('user u','t.uid = u.id','LEFT')
->where(function (Query $query) {
$common = new AdminCommonController();
$param = $this->request->param();
//获取乙方公司id
$company_id_b = $common->getCompanyB();
if(!empty($company_id_b)){
$u_s_id_s = $common->getStaffB($company_id_b);
$query->whereIn('uid',$u_s_id_s);
}
//查询登录乙方账号的所有项目
$startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
$endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
if (!empty($startTime)) {
$query->where('t.test_time', '>=', $startTime);
}
if (!empty($endTime)) {
$query->where('t.test_time', '<=', $endTime);
}
})
->field('u.user_login,t.id,t.title,t.test_time,t.address')
->order('t.id desc')
->paginate(10,false,['query'=>request()->param()]);
$data = $res->toArray();
$data = $data['data'];
$page = $res->render();
//渲染
$this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
$this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
$this->assign('list',$data);
$this->assign('page',$page);
return $this->fetch();
}
//编辑页面
public function edit(){
$id = $this->request->param('id');
$res = Db::name('test')
->where(['id'=>$id])
->find();
$common = new AdminCommonController();
//独立年检乙方发起人
$user = $common->getUserById(['id'=>$res['uid']]);
if($user){
$res['user_login'] = $user['user_login'];
}else{
$res['user_login'] = '';
}
//查找年检点,年检图片,年检人员
$res['check_point'] = $common->getTestPoint(['test_id'=>$res['id']]);
$this->assign('post',$res);
$this->assign('state',$common::inspectStatus);
return $this->fetch();
}
//导出数据
public function exportData(){
$param = $this->request->param();
$adminCommon = new AdminCommonController();
$adminExcel = new AdminExcelDataController();
$res_ins = $adminCommon->exportTestList($param,'t.*,u.user_login');
$arr_url = [];
$arr_time = [];
foreach($res_ins as $key=>$value){
$arr = $adminCommon->testExportData($value);
//获取文件路径
$url = $adminExcel->testExcelData($arr);
//按日导出
$arr_url[$key] = $url;
$arr_time[$key] = $arr['time'].'报表.xls';
}
$xlsName = '独立年检报表';
//解决zip中文文件名
$xlsName = $adminCommon->iconv_to_utf8($xlsName);
$filename = ROOT_PATH . 'public/upload/export/' . $xlsName . '.zip';
$adminCommon->zip($arr_url,$filename,$arr_time);
}
//检查是否有数据
public function checkData(){
$param = $this->request->param();
$adminCommon = new AdminCommonController();
$res_ins = $adminCommon->exportTestList($param,'t.id');
if($res_ins){
$adminCommon->apiResponse(1);
}else{
$adminCommon->apiResponse(0,'暂无数据');
}
}
}
... ...
... ... @@ -187,6 +187,8 @@ return array (
'PORTAL_ADMINTAG_DELETE' => '删除文章标签',
'PORTAL_ADMINTAG_INDEX' => '文章标签',
'PORTAL_ADMINTAG_UPSTATUS' => '更新标签状态',
'PORTAL_ADMINTEST_INDEX' => '独立年检列表',
'PORTAL_ADMINTESTDEFAULT_DEFAULT' => '独立年检管理',
'PORTAL_ADMINTRAIN_INDEX' => '培训列表',
'PORTAL_ADMINTRAINDEFAULT_DEFAULT' => '培训管理',
'PORTAL_ADMINTRAINSTATISTICAL_INDEX' => '培训统计',
... ...
<include file="public@header"/>
<style type="text/css">
.pic-list li {
margin-bottom: 5px;
}
</style>
<script type="text/html" id="photos-item-tpl">
<li id="saved-image{id}">
<input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
<input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
style="width: 200px;" title="图片名称">
<img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
onclick="imagePreviewDialog(this.src);">
<a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
<a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
</li>
</script>
<script type="text/html" id="files-item-tpl">
<li id="saved-file{id}">
<input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
<input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
style="width: 200px;" title="文件名称">
<a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
<a href="javascript:uploadOne('文件上传','#file-{id}','file');">替换</a>
<a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
</li>
</script>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li><a href="{:url('AdminTest/index')}">独立年检列表</a></li>
<li class="active"><a href="{:url('AdminTest/edit')}">独立年检详情</a></li>
</ul>
<form action="{:url('AdminTest/editPost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
<div class="row">
<div class="col-md-9">
<table class="table table-bordered">
<tr>
<th width="150">独立年检标题</th>
<td>
<input class="form-control" type="text" value="{$post.title}"/>
</td>
</tr>
<tr>
<th>独立年检发起人</th>
<td>
<input class="form-control" type="text" value="{$post.user_login}"/>
</td>
</tr>
<tr>
<th>独立年检时间</th>
<td>
<input class="form-control" type="text" value="{$post.test_time|date='Y-m-d',###}"/>
</td>
</tr>
<tr>
<th>独立年检地点</th>
<td>
<input class="form-control" type="text" value="{$post.address}"/>
</td>
</tr>
<tr>
<th>独立年检备注</th>
<td>
<input class="form-control" type="text" value="{$post.remark}"/>
</td>
</tr>
<!--独立年检点检测情况start-->
<tr>
<th style="border:2px solid lightgrey;"></th>
<td style="border:2px solid lightgrey;"></td>
</tr>
<volist name="post.check_point" id="vo">
<!--循环-->
<tr>
<th>独立年检点名称</th>
<td>
<input class="form-control" type="text" value="{$vo.spot_name}"/>
</td>
</tr>
<tr>
<th>独立年检点状态</th>
<td>
<input class="form-control" type="text" value="{$state[$vo.status]}"/>
</td>
</tr>
<tr>
<th>独立年检人员</th>
<td>
<input class="form-control" type="text" value="{$vo.user_login}"/>
</td>
</tr>
<volist name="vo.images" id="voo">
<tr>
<th>独立年检日期</th>
<td>
{$voo.day}
</td>
</tr>
<tr>
<th>独立年检图片</th>
<td>
<volist name="voo.image" id="vooo">
<img src="{$vooo.image_url}" width="250"/>
</volist>
</td>
</tr>
</volist>
<tr>
<th style="border:2px solid lightgrey;"></th>
<td style="border:2px solid lightgrey;"></td>
</tr>
</volist>
</table>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<a class="btn btn-default" href="{:url('AdminTest/index')}">{:lang('BACK')}</a>
</div>
</div>
</div>
</div>
</form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
//编辑器路径定义
var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
$(function () {
editorcontent = new baidu.editor.ui.Editor();
editorcontent.render('content');
try {
editorcontent.sync();
} catch (err) {
}
});
</script>
</body>
</html>
... ...
<include file="public@header"/>
</head>
<body>
<div class="wrap">
<ul class="nav nav-tabs">
<li class="active"><a>独立年检列表</a></li>
</ul>
<form class="well form-inline margin-top-20" method="post" action="{:url('AdminTest/index')}">
独立年检时间:
<input type="text" class="form-control js-bootstrap-date" style="width:160px;" name="start_time" value="{$start_time|default=''}" autocomplete="off" id="start_time" placeholder="请输入开始时间">-
<input type="text" class="form-control js-bootstrap-date" style="width:160px;" name="end_time" value="{$end_time|default=''}" autocomplete="off" id="end_time" placeholder="请输入结束时间"> &nbsp;
<input type="submit" class="btn btn-primary" value="搜索"/>
<a class="btn btn-danger" href="{:url('AdminTest/index')}">清空</a>
</form>
<button class="btn btn-success" id="export_data">导出独立年检数据</button>
<form method="post" class="js-ajax-form">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th width="16">
<label>
<input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
</label>
</th>
<th>ID</th>
<th>表头信息</th>
<th>独立年检发起人</th>
<th>独立年检时间</th>
<th>独立年检地点</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<foreach name="list" item="vo">
<tr>
<td>
<input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
value="{$vo.id}">
</td>
<td>{$vo.id}</td>
<td>{$vo.title}</td>
<td>{$vo.user_login}</td>
<td>{$vo.test_time|date="Y-m-d",###}</td>
<td>{$vo.address}</td>
<td width="150">
<a class="btn btn-xs btn-primary" href="{:url('AdminTest/edit',array('id'=>$vo['id']))}">详情</a>
</td>
</tr>
</foreach>
</tbody>
</table>
<div class="pagination">{$page}</div>
</form>
</div>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>
<script>
$(function(){
//导出数据
$('#export_data').click(function(){
var project_name = $('#project_name').val();
var start_time = $('#start_time').val();
var end_time = $('#end_time').val();
var code = checkData(start_time,end_time,project_name);
if(code == 1){
window.location.href = 'exportData?start_time='+start_time+'&end_time='+end_time+'&name='+project_name;
}
});
});
//检查是否有可导出的数据
function checkData(start_time,end_time,project_name){
if(start_time == ''){
alert('请输入独立年检开始时间');
return false;
}
if(end_time == ''){
alert('请输入独立年检结束时间');
return false;
}
var code = 1;
$.ajax({
type:'GET',
url:'checkData' ,
data:{
'start_time':start_time,
'end_time':end_time,
'name':project_name
},
dataType:'json',
async:false,//同步
success:function(data){
if (data.code == 0) {
alert(data.msg);
code = 0;
}
}
});
return code;
}
</script>
\ No newline at end of file
... ...