Files
OMS/app/ome/lib/view/input.php
2025-12-28 23:13:25 +08:00

407 lines
15 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Copyright © ShopeX http://www.shopex.cn. All rights reserved.
* See LICENSE file for license details.
*/
/**
* @desc
* @author: jintao
* @since: 2016/8/22
*/
class ome_view_input{
public $app;
/**
* __construct
* @param mixed $app app
* @return mixed 返回值
*/
public function __construct(&$app){
$this->app = $app;
}
/**
* input_ome_object
* @param mixed $params 参数
* @return mixed 返回值
*/
public function input_ome_object($params)
{
$return_url = $params['return_url']?$params['return_url']:'index.php?app=ome&ctl=admin_crm_gift&act=object_rows';
$callback = $params['callback']?$params['callback'] : ($params['data']['callback'] ? $params['data']['callback'] : '');
$params['breakpoint'] = isset($params['breakpoint'])?$params['breakpoint']:20;
$object = $params['object'];
if(strpos($params['object'],'@')!==false){
list($object,$app_id) = explode('@',$params['object']);
$params['object'] = $object;
}elseif($params['app']){
$app_id = $params['app'];
}else{
$app_id = $this->app->app_id;
}
$app = app::get($app_id);
$o = $app->model($object);
$render = new base_render(app::get('desktop'));
$ui = new base_component_ui($app);
$dbschema = $o->get_schema();
$params['app_id'] = $app_id;
if(isset($params['filter'])){
if(!is_array($params['filter'])){
parse_str($params['filter'],$params['filter']);
}
}
$params['domid'] = substr(md5(uniqid()),0,6);
$key = $params['key']?$params['key']:$dbschema['idColumn'];
$textcol = $params['textcol']?$params['textcol']:$dbschema['textColumn'];
//显示列 可以多列显示 不完全修改 。。。。。。。
$textcol = explode(',',$textcol);
$_textcol = $textcol;
$textcol = $textcol[0];
$tmp_filter = $params['filter']?$params['filter']:null;
$count = $o->count($tmp_filter);
if($count<=$params['breakpoint']&&!$params['multiple']&&$params['select']!='checkbox'){
if(strpos($textcol,'@')===false){
$list = $o->getList($key.','.$textcol,$tmp_filter);
if(!$list[0]) $type=array();
foreach($list as $row){
$label = $row[$textcol];
if(!$label&&method_exists($o,'title_modifier')){
$label = $o->title_modifier($row[$key]);
}
$type[$row[$key]] = $label;
}
}else{
list($name,$table,$app_id) = explode('@',$textcol);
$app = $app_id?app::get($app_id):$app;
$mdl = $app->model($table);
$list = $o->getList($key,$tmp_filter);
foreach($list as $row){
$tmp_row = $mdl->getList($name,array($mdl->idColumn=>$row[$key]),0,1);
$label = $tmp_row[0][$name];
if(!$label&&method_exists($o,'title_modifier')){
$label = $o->title_modifier($row[$key]);
}
$type[$row[$key]] = $label;
}
}
$tmp_params['name'] = $params['name'];
$tmp_params['value'] = $params['value'];
$tmp_params['type'] = $type;
if($callback)
$tmp_params['onchange'] = $callback.'(this)';
$str_filter = $ui->input($tmp_params);
unset($tmp_params);
return $str_filter;
}
$params['idcol'] = $keycol['keycol'] = $key;
$params['textcol'] = implode(',',$_textcol);
$params['_textcol'] = $_textcol;
if($params['value']){
if(strpos($params['view'],':')!==false){
list($view_app,$view) = explode(':',$params['view']);
$params['view_app'] = $view_app;
$params['view'] = $view;
}
if(is_string($params['value'])){
$params['value'] = explode(',',$params['value']);
}
$params['items'] = &$o->getList('*',array($key=>$params['value']),0,-1);
//过滤不存在的值
//某些数据被添加后 可能原表数据已删除但此处value中还存在。
$_params_items_row_key = array();
foreach( $params['items'] as $_params_items_row ) {
$_params_items_row_key[] = $_params_items_row[$key];
}
$params['value'] = implode(',',$_params_items_row_key);
}
if(isset($params['multiple']) && $params['multiple']){
/*
if(isset($params['items']) && count($params['items'])){
$params['display_datarow'] = 'true';
}*/
$render->pagedata['_input'] = $params;
return $render->fetch('admin/gift/input.html','ome');
}else{
if($params['value']){
$string = $params['items'][0][$textcol];
}else{
$string = $params['emptytext']?$params['emptytext']:app::get('desktop')->_('请选择...');
}
unset($params['app']);
if($params['data']){
$_params = (array)$params['data'];
unset($params['data']);
$params = array_merge($params,$_params);
}
if($params['select']=='checkbox'){
if($params['default_id'] ) $params['domid'] = $params['default_id'];
$params['type'] = 'checkbox';
}else{
$id = "handle_".$params['domid'];
$params['type'] = 'radio';
$getdata = '&singleselect=radio';
}
if(is_array($params['items'])){
foreach($params['items'] as $key=>$item){
$items[$key] = $item[$params['idcol']];
}
}
$params['return_url'] = urlencode($params['return_url']);
$vars = $params;
$vars['items'] = $items;
$vars['items'] = array();
$vars['value'] = array();
unset($vars['replacehtml']);
$object = utils::http_build_query($vars);
$url = 'index.php?app=desktop&act=alertpages&goto='.urlencode('index.php?app=ome&ctl=admin_crm_gift&act=finder_common&app_id='.$app_id.'&'.$object.$getdata);
$render->pagedata['string'] = $string;
$render->pagedata['url'] = $url;
$render->pagedata['return_url'] = $return_url;
$render->pagedata['id'] = $id;
$render->pagedata['params'] = $params;
$render->pagedata['object'] = $object;
$render->pagedata['callback'] = $callback;
return $render->fetch('admin/gift/input_radio.html','ome');
}
}
/**
* input_branch_object
* @param mixed $params 参数
* @return mixed 返回值
*/
public function input_branch_object($params)
{
$return_url = $params['return_url']?$params['return_url']:'index.php?app=desktop&ctl=editor&act=object_rows';
$callback = $params['callback']?$params['callback'] : ($params['data']['callback'] ? $params['data']['callback'] : '');
$params['breakpoint'] = isset($params['breakpoint'])?$params['breakpoint']:20;
$object = $params['object'];
if(strpos($params['object'],'@')!==false){
list($object,$app_id) = explode('@',$params['object']);
$params['object'] = $object;
}elseif($params['app']){
$app_id = $params['app'];
}else{
$app_id = $this->app->app_id;
}
$app = app::get($app_id);
$o = $app->model($object);
$render = new base_render(app::get('desktop'));
$ui = new base_component_ui($app);
$dbschema = $o->get_schema();
$params['app_id'] = $app_id;
if(isset($params['filter'])){
if(!is_array($params['filter'])){
parse_str($params['filter'],$params['filter']);
}
}
$params['domid'] = substr(md5(uniqid()),0,6);
$key = $params['key']?$params['key']:$dbschema['idColumn'];
$textcol = $params['textcol']?$params['textcol']:$dbschema['textColumn'];
//显示列 可以多列显示 不完全修改 。。。。。。。
$textcol = explode(',',$textcol);
$_textcol = $textcol;
$textcol = $textcol[0];
$tmp_filter = $params['filter']?$params['filter']:null;
$count = $o->count($tmp_filter);
if($count<=$params['breakpoint']&&!$params['multiple']&&$params['select']!='checkbox'){
if(strpos($textcol,'@')===false){
$list = $o->getList($key.','.$textcol,$tmp_filter);
if(!$list[0]) $type=array();
foreach($list as $row){
$label = $row[$textcol];
if(!$label&&method_exists($o,'title_modifier')){
$label = $o->title_modifier($row[$key]);
}
$type[$row[$key]] = $label;
}
}else{
list($name,$table,$app_id) = explode('@',$textcol);
$app = $app_id?app::get($app_id):$app;
$mdl = $app->model($table);
$list = $o->getList($key,$tmp_filter);
foreach($list as $row){
$tmp_row = $mdl->getList($name,array($mdl->idColumn=>$row[$key]),0,1);
$label = $tmp_row[0][$name];
if(!$label&&method_exists($o,'title_modifier')){
$label = $o->title_modifier($row[$key]);
}
$type[$row[$key]] = $label;
}
}
$tmp_params['name'] = $params['name'];
$tmp_params['value'] = $params['value'];
$tmp_params['type'] = $type;
if($callback)
$tmp_params['onchange'] = $callback.'(this)';
$str_filter = $ui->input($tmp_params);
unset($tmp_params);
return $str_filter;
}
$params['idcol'] = $keycol['keycol'] = $key;
$params['textcol'] = implode(',',$_textcol);
$params['_textcol'] = $_textcol;
if($params['value']){
if(strpos($params['view'],':')!==false){
list($view_app,$view) = explode(':',$params['view']);
$params['view_app'] = $view_app;
$params['view'] = $view;
}
if(is_string($params['value'])){
$params['value'] = explode(',',$params['value']);
}
$params['items'] = &$o->getList('*',array($key=>$params['value']),0,-1);
//过滤不存在的值
//某些数据被添加后 可能原表数据已删除但此处value中还存在。
$_params_items_row_key = array();
foreach( $params['items'] as $_params_items_row ) {
$_params_items_row_key[] = $_params_items_row[$key];
}
$params['value'] = implode(',',$_params_items_row_key);
}
if(isset($params['multiple']) && $params['multiple']){
/*
if(isset($params['items']) && count($params['items'])){
$params['display_datarow'] = 'true';
}*/
$render->pagedata['_input'] = $params;
return $render->fetch('finder/input.html','desktop');
}else{
if($params['value']){
$string = $params['items'][0][$textcol];
}else{
$string = $params['emptytext']?$params['emptytext']:app::get('desktop')->_('请选择...');
}
unset($params['app']);
if($params['data']){
$_params = (array)$params['data'];
unset($params['data']);
$params = array_merge($params,$_params);
}
if($params['select']=='checkbox'){
if($params['default_id'] ) $params['domid'] = $params['default_id'];
$params['type'] = 'checkbox';
}else{
$id = "handle_".$params['domid'];
$params['type'] = 'radio';
$getdata = '&singleselect=radio';
}
if(is_array($params['items'])){
foreach($params['items'] as $key=>$item){
$items[$key] = $item[$params['idcol']];
}
}
$params['return_url'] = urlencode($params['return_url']);
$vars = $params;
$vars['items'] = $items;
$vars['items'] = array();
$vars['value'] = array();
unset($vars['replacehtml']);
$object = utils::http_build_query($vars);
$url = 'index.php?app=desktop&act=alertpages&goto='.urlencode('index.php?app=ome&ctl=admin_branch&act=finder_common&app_id='.$app_id.'&'.$object.$getdata);
$render->pagedata['string'] = $string;
$render->pagedata['url'] = $url;
$render->pagedata['return_url'] = $return_url;
$render->pagedata['id'] = $id;
$render->pagedata['params'] = $params;
$render->pagedata['object'] = $object;
$render->pagedata['callback'] = $callback;
return $render->fetch('finder/input_radio.html','desktop');
}
}
/**
* input_address
* @param mixed $params 参数
* @return mixed 返回值
*/
public function input_address($params)
{
$regionsObj = app::get('eccommon')->model('regions');
$regionList = $regionsObj->getlist('region_id as id,local_name as label,region_grade,case when p_region_id is null then 0 else p_region_id end as p_region_id',array('source'=>'systems'));
$treeList = ome_func::listToTree($regionList,'id','p_region_id');
$render = new base_render(app::get('desktop'));
$render->pagedata['params'] = $params;
$render->pagedata['treeList'] = json_encode($treeList);
return $render->fetch('finder/input_address.html','desktop');
}
/**
* input_china
* @param mixed $params 参数
* @return mixed 返回值
*/
public function input_china($params)
{
$regionsObj = app::get('eccommon')->model('regions');
$regionList = $regionsObj->getlist('region_id as id,local_name as label,region_grade,case when p_region_id is null then 0 else p_region_id end as p_region_id',array('source'=>'systems'));
$treeList = ome_func::listToTree($regionList,'id','p_region_id');
$chinaRoot = array(
'id' => 'CN',
'label' => '中国',
'children' => $treeList,
);
$render = new base_render(app::get('desktop'));
$render->pagedata['params'] = $params;
$render->pagedata['treeList'] = json_encode(array($chinaRoot));
return $render->fetch('finder/input_china.html','desktop');
}
}