<?php
namespace app\admin\controller;
use think\App;
use think\facade\Session;
use think\facade\View;
use think\facade\Request;
 
class form extends Base{

	//Form首页
    public function index(){
		$tdata=Request::param();
		$info['pid']=$tdata['pid'];
		$info['typename']=tq_value($tdata['pid'],'title','form_type');
		$view=tq_value($tdata['pid'],'view','form_type');
		$table=tq_value($tdata['pid'],'table','form_type');
		$field=explode(',',tq_value($tdata['pid'],'field','form_type'));
		
		if(isset($tdata['limit'])){
			$limit=$tdata['limit'];
		}else{
			$limit=Session::get('limit');
		}

		$auto_page=tq_value(1,'auto_page','system');
		$auto_page_num=tq_value(1,'page_num','system');
		$syltem_page_list=tq_value(1,'page_list','system');
		if($auto_page==2 and isset($tdata['limit'])==''){
			$limit=$auto_page_num;
		}else{
			$limit=$limit;
		}
		
		
		$strtime=isset($tdata['strtime'])?$tdata['strtime']:'';
		$endtime=isset($tdata['endtime'])?$tdata['endtime']:'';
		$keyword=isset($tdata['keyword'])?$tdata['keyword']:'';
		
		$list=\app\admin\model\Form::list_data($limit);
		
		$limits=Session::get('limit');
		$count=$list['total'];
		View::assign([
			'strtime'=>$strtime,
			'endtime'=>$endtime,
			'keyword'=>$keyword,
			'info'=>$info,
			'table'=>$table,
			'field'=>$field,
			'limit'=>$limit,
			'limits'=>$limits,
			'count'=>$count,
			'view'=>$view,
			'syltem_page_list'=>$syltem_page_list,
			'curr'=>$list['current_page'],
			'list'=>$list['data']]
		);
		return View::fetch($view);
    }

    public function edit(){
		$tdata=Request::param();
		$view=$tdata['view']."_edit";
		
		$table=tq_value($tdata['pid'],'table','form_type');
		$field =\app\admin\model\Form::form_view($table);
		
		$info=\app\admin\model\Form::info($tdata['id'],$table,$tdata['pid']);
		
		//dump($tdata);
		//,'table'=>$tdata['view']
		View::assign(['info'=>$info,'list'=>$list,'field'=>$field,'table'=>$table]);
		return View::fetch($view);
	}
	
    public function update(){
		$tdata=Request::param();
		$info=\app\admin\model\Form::update_content($tdata);
		$data =['type' =>1,'ss'=>$info,'msg' =>'修改成功'];
		return json($data);
    }
	
}
