<?php
/**
 * 元数据
 */
$elename = substr(basename(__FILE__),0,-4);
return [
    'pwcode'=>'B700',
    //元数据名称
    'elename'=>$elename,
    //元数据标题
	'cn_name' => "父子零件", 
	'en_name' => "Fatherson", 
	//
	'table' => "pro_fatherson", 
	'key' => "pf_id", //主键字段
	'order' => "pf_father_pid,pf_son_pid", //默认排序
	'caption' => 'pf_son_pid', //主要显示字段
    'url'=>[
        'css'=> false, //\mvc::$cfg['path']['site'].'/static/css/element/'.$elename.'.css',
        'js'=> \mvc::$cfg['path']['site'].'/static/js/element/'.$elename.'.js',
        'list'=> \mvc::$cfg['path']['site'].'/element/list?elename='.$elename,
        'editCell'=> \mvc::$cfg['path']['site'].'/element/editCell?elename='.$elename,
        'detail'=> \mvc::$cfg['path']['site'].'/element/detail?elename='.$elename,
        //'addview'=> \mvc::$cfg['path']['site'].'/element/detail?elename='.$elename,
        'edit'=> \mvc::$cfg['path']['site'].'/element/edit?elename='.$elename,
        'delete'=> \mvc::$cfg['path']['site'].'/element/delete?elename='.$elename,
        'deleteRows'=> \mvc::$cfg['path']['site'].'/pro/deleteElementRows?elename='.$elename,
        'checkUnique'=> \mvc::$cfg['path']['site'].'/element/checkUnique?elename='.$elename,
        'import'=> '',
        'export'=> true,
    ],
    'viewIsEditCell'=>false, //详情页是否允许字段单个编辑
    'add'=>[
        'function'=> 'openAdd', //按钮调用的 js 函数, openAdd, openAddFull, openAddPage
    ],
    'openDivArea'=> ['600px', '800px'],
    'listcfg' => [
        'editor'=> true,
        'multiselect'=> true,
    ],
    'listButtons' => [],
	'fields'=>[
		'pf_id'=>[
			'field'=>'pf_id',
			'cn_name'=>'ID', //字段描述
			'en_name'=>lg('ID'),
			'type'=>'int',
			'key'=>true, //是否为主键
			'unique'=>true, //是否唯一
			'scale'=>0, //小数位数
			'islist'=>true, //是否在列表中显示
            'list'=>[
                'width'=> 40,
                'hidden'=>true, //是否在列表中默认隐藏
    			'search'=>false, //是否参入查询
                //'searchField'=>'snt_number', //使用某个字段来查询
    			'editable'=>false, //是否编辑
    			'order'=>true, //是否参入排序
    			'edittype'=>'text',  //编辑类型,text,checkbox
            ],
			'isview'=>true, //是否在详情视图中显示
            'view'=>[
    			'edittype'=>'hidden', //编辑类型 none,hidden,text,select,textarea,checkbox,checkboxgroup
            ],
			'editor'=> [
				'required'=> false, //是否为必须项
				'fieldtype'=> 'string',//string,number(含有小数),digits(整数)
    			'maxlength'=>10, //最大长度(含有小数长度)
				'minlength'=>0, //最小长度
                'scale'=>0, //小数位数
                'preg'=>'', //正则表达式判断 如邮箱 /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
			]
		],
       
		'pf_father_cate'=>[
			'field'=>'pf_father_cate',
			'cn_name'=>'父零件品名', //字段描述
			'en_name'=>'Cate',
            'linkOne'=>[ //关联表
                'table'=>'pro',
                'field'=>'p_id',
                'myfield'=>'pf_father_pid',
                'caption'=>function($row,$db){
                    $cate = $row['p_cate'];
                    if($cate){
                        $cRow = $db->get('pro_cate',['parent_id','cn_name','en_name'],['id'=>$cate]);
                        $cpRow = $db->get('pro_cate',['parent_id','cn_name','en_name'],['id'=>$cRow['parent_id']]);
                        return $cpRow[cateName()].' · '.$cRow[cateName()];
                    }
                    return '';
                }, 
                'search'=>[
                    'function'=>function(&$field,&$op,&$data,&$join,&$joinWhere,&$group,&$objList,$db){
                        if(!isset($objList['cate'])){
                            $objList['cate'] = makeOne(\model\pro\cate::class);
                        }
                        $op = null;
                        $field = 'pf_father_pid';
                        if($rows = $objList['cate']->likeAndChilds($data,true)){
                            $data = $rows;
                        }else{
                            $data = 0;
                        }
                        $join['[>]pro(p)'] = ['e.pf_father_pid'=>'p_id'];
                        $joinWhere['p.p_cate'] = $data;
                    }
                ],
                'order'=>[
                    'function'=>function(&$join,&$joinWhere,&$group,&$objList,$db){
                        if(!isset($this->join['[>]pro(p)'])){
                            $join['[>]pro(p)'] = ['e.pf_father_pid'=>'p_id'];
                        }
                        return 'p.p_cate';
                    }
                ]
            ],
			'type'=>'varchar',
			'key'=>false, //是否为主键
			'unique'=>false, //是否唯一
			'scale'=>0, //小数位数
			'islist'=>true, //是否在列表中显示
            'list'=>[
                'width'=> 260,
                'hidden'=>false, //是否在列表中默认隐藏
                'hidedlg'=>true, //在查询条件中隐藏
    			'search'=>true, //是否参入查询
                //'searchField'=>'snt_number', //使用某个字段来查询
    			'editable'=>false, //是否编辑
    			'order'=>true, //是否参入排序
    			'edittype'=>'text',  //编辑类型,text,checkbox
            ],
			'isview'=>true, //是否在详情视图中显示
            'view'=>[
    			'edittype'=>'hidden', //编辑类型 none,hidden,text,select,textarea,checkbox,checkboxgroup
            ],
			'editor'=> [
				'required'=> false, //是否为必须项
				'fieldtype'=> 'string',//string,number(含有小数),digits(整数)
    			'maxlength'=>10, //最大长度(含有小数长度)
				'minlength'=>0, //最小长度
                'scale'=>0, //小数位数
                'preg'=>'', //正则表达式判断 如邮箱 /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
			]
		],
        'pf_father_brand'=>[
            'field'=>'pf_father_brand',
			'cn_name'=>'父零件品牌', //字段描述
			'en_name'=>lg('Brand'),
            'linkOne'=>[ //关联表
                'table'=>'pro',
                'field'=>'p_id',
                'myfield'=>'pf_father_pid',
                'caption'=>function($row,$db){
                    $brand = $row['p_pb_id'];
                   
                    if($brand){
                        $cRow = $db->get('pro_brand',['pb_id','pb_'.LG_NAME],['pb_id'=>$brand]);
                        return $cRow['pb_'.cateName()];
                    }
                    return '';
                }, 
                'search'=>[
                    'function'=>function(&$field,&$op,&$data,&$join,&$joinWhere,&$group,&$objList,$db){
                        if(!isset($objList['pro'])){
                            $objList['pro'] = makeOne(\model\pro\pro::class);
                        }
                        $op = null;
                        $field = 'pf_father_pid';
                        if($rows = $objList['pro']->getProBrandId($data,true)){
                            $data = $rows;
                        }else{
                            $data = 0;
                        }
                        $join['[>]pro(p)'] = ['e.pf_father_pid'=>'p_id'];
                        $joinWhere['p.p_pb_id'] = $data;
                    }
                ],
                'order'=>[
                    'function'=>function(&$join,&$joinWhere,&$group,&$objList,$db){
                        if(!isset($this->join['[>]pro(p)'])){
                            $join['[>]pro(p)'] = ['e.pf_father_pid'=>'p_id'];
                        }
                        return 'p.p_pb_id';
                    }
                ]
            ],
            'type'=>'varchar',
			'key'=>false, //是否为主键
			'unique'=>false, //是否唯一
			'scale'=>0, //小数位数
			'islist'=>true, //是否在列表中显示
            'list'=>[
                'width'=> 260,
                'hidden'=>false, //是否在列表中默认隐藏
                'hidedlg'=>true, //在查询条件中隐藏
    			'search'=>true, //是否参入查询
    			'editable'=>false, //是否编辑
    			'order'=>true, //是否参入排序
    			'edittype'=>'text',  //编辑类型,text,checkbox
            ],
			'isview'=>true, //是否在详情视图中显示
            'view'=>[
    			'edittype'=>'hidden', //编辑类型 none,hidden,text,select,textarea,checkbox,checkboxgroup
            ],
			'editor'=> [
				'required'=> false, //是否为必须项
				'fieldtype'=> 'string',//string,number(含有小数),digits(整数)
    			'maxlength'=>10, //最大长度(含有小数长度)
				'minlength'=>0, //最小长度
                'scale'=>0, //小数位数
                'preg'=>'', //正则表达式判断 如邮箱 /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
			]
        ],
		'pf_father_pid'=>[
			'field'=>'pf_father_pid',
			'cn_name'=>'父零件', //字段描述
			'en_name'=>'Father', 
			'type'=>'varchar',
			'key'=>false, //是否为主键
			'unique'=>false, //是否唯一
			'islist'=>true, //是否在列表中显示
            'linkOne'=>[ //关联表
                'table'=>'pro',
                'field'=>'p_id',
                'myfield'=>'pf_father_pid',
                'captionField'=>'p_innum',
                'caption'=>function($row,$db){
                    return '<a href="javascript:qg.page.open(\''.$row['p_innum'].'\',\''.HOST.'/pro/detail?tab=base&p_id='.$row['p_id'].'\')">'.$row['p_innum'].'</a>';
                }, 
            ],
			'formartSearchBegin'=> function(&$field,&$op,&$data){
				$data = explode(',',$data);
			},
            'list'=>[
                'width'=> 155,
                'hidden'=>false, //是否在列表中默认隐藏
    			'search'=>true, //是否参入查询
    			'editable'=>false, //是否编辑
    			'order'=>true, //是否参入排序
    			'edittype'=>'text', //编辑类型
    			'searchoptions'=> "getSearchoptions_numbers('pf_father_pid')",
            ],
			'isview'=>false, //是否在详情视图中显示
            'view'=>[
    			'editable'=>false, //是否编辑
    			'edittype'=>'text', //编辑类型 none,hidden,text,select,textarea
            ],
			'editor'=> [
				'required'=> false, //是否为必须项
				'fieldtype'=> 'digits',//string,number(含有小数),digits(整数)
    			'maxlength'=>50, //长度
				'minlength'=>0,
                'scale'=>0, //小数位数
                'preg'=>'', //正则表达式判断
			]
		],
		'pf_son_pid'=>[
			'field'=>'pf_son_pid',
			'cn_name'=>'子零件', //字段描述
			'en_name'=>'Son', 
			'type'=>'varchar',
			'key'=>false, //是否为主键
			'unique'=>false, //是否唯一
			'islist'=>true, //是否在列表中显示
            'linkOne'=>[ //关联表
                'table'=>'pro',
                'field'=>'p_id',
                'myfield'=>'pf_son_pid',
                'captionField'=>'p_innum',
                'caption'=>function($row,$db){
                    return '<a href="javascript:qg.page.open(\''.$row['p_innum'].'\',\''.HOST.'/pro/detail?tab=base&p_id='.$row['p_id'].'\')">'.$row['p_innum'].'</a>';
                }, 
            ],
			'formartSearchBegin'=> function(&$field,&$op,&$data){
				$data = explode(',',$data);
			},
            'list'=>[
                'width'=> 155,
                'hidden'=>false, //是否在列表中默认隐藏
    			'search'=>true, //是否参入查询
    			'editable'=>false, //是否编辑
    			'order'=>true, //是否参入排序
    			'edittype'=>'text', //编辑类型
    			'searchoptions'=> "getSearchoptions_numbers('pf_son_pid')",
            ],
			'isview'=>false, //是否在详情视图中显示
            'view'=>[
    			'editable'=>false, //是否编辑
    			'edittype'=>'text', //编辑类型 none,hidden,text,select,textarea
            ],
			'editor'=> [
				'required'=> false, //是否为必须项
				'fieldtype'=> 'digits',//string,number(含有小数),digits(整数)
    			'maxlength'=>50, //长度
				'minlength'=>0,
                'scale'=>0, //小数位数
                'preg'=>'', //正则表达式判断
			]
		],
         
		'pf_son_cate'=>[
			'field'=>'pf_son_cate',
			'cn_name'=>'子零件品名', //字段描述
			'en_name'=>'Cate',
            'linkOne'=>[ //关联表
                'table'=>'pro',
                'field'=>'p_id',
                'myfield'=>'pf_son_pid',
                'caption'=>function($row,$db){
                    $cate = $row['p_cate'];
                    if($cate){
                        $cRow = $db->get('pro_cate',['parent_id','cn_name','en_name'],['id'=>$cate]);
                        $cpRow = $db->get('pro_cate',['parent_id','cn_name','en_name'],['id'=>$cRow['parent_id']]);
                        return $cpRow[cateName()].' · '.$cRow[cateName()];
                    }
                    return '';
                }, 
                'search'=>[
                    'function'=>function(&$field,&$op,&$data,&$join,&$joinWhere,&$group,&$objList,$db){
                        if(!isset($objList['cate'])){
                            $objList['cate'] = makeOne(\model\pro\cate::class);
                        }
                        $op = null;
                        $field = 'pf_son_pid';
                        if($rows = $objList['cate']->likeAndChilds($data,true)){
                            $data = $rows;
                        }else{
                            $data = 0;
                        }
                        $join['[>]pro(p)'] = ['e.pf_son_pid'=>'p_id'];
                        $joinWhere['p.p_cate'] = $data;
                    }
                ],
                'order'=>[
                    'function'=>function(&$join,&$joinWhere,&$group,&$objList,$db){
                        if(!isset($this->join['[>]pro(p)'])){
                            $join['[>]pro(p)'] = ['e.pf_son_pid'=>'p_id'];
                        }
                        return 'p.p_cate';
                    }
                ]
            ],
			'type'=>'varchar',
			'key'=>false, //是否为主键
			'unique'=>false, //是否唯一
			'scale'=>0, //小数位数
			'islist'=>true, //是否在列表中显示
            'list'=>[
                'width'=> 260,
                'hidden'=>false, //是否在列表中默认隐藏
                'hidedlg'=>true, //在查询条件中隐藏
    			'search'=>true, //是否参入查询
                //'searchField'=>'snt_number', //使用某个字段来查询
    			'editable'=>false, //是否编辑
    			'order'=>true, //是否参入排序
    			'edittype'=>'text',  //编辑类型,text,checkbox
            ],
			'isview'=>true, //是否在详情视图中显示
            'view'=>[
    			'edittype'=>'hidden', //编辑类型 none,hidden,text,select,textarea,checkbox,checkboxgroup
            ],
			'editor'=> [
				'required'=> false, //是否为必须项
				'fieldtype'=> 'string',//string,number(含有小数),digits(整数)
    			'maxlength'=>10, //最大长度(含有小数长度)
				'minlength'=>0, //最小长度
                'scale'=>0, //小数位数
                'preg'=>'', //正则表达式判断 如邮箱 /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
			]
		],
        'pf_son_brand'=>[
            'field'=>'pf_son_brand',
			'cn_name'=>'子零件品牌', //字段描述
			'en_name'=>lg('Brand'),
            'linkOne'=>[ //关联表
                'table'=>'pro',
                'field'=>'p_id',
                'myfield'=>'pf_son_pid',
                'caption'=>function($row,$db){
                    $brand = $row['p_pb_id'];
                   
                    if($brand){
                        $cRow = $db->get('pro_brand',['pb_id','pb_'.LG_NAME],['pb_id'=>$brand]);
                        return $cRow['pb_'.cateName()];
                    }
                    return '';
                }, 
                'search'=>[
                    'function'=>function(&$field,&$op,&$data,&$join,&$joinWhere,&$group,&$objList,$db){
                        if(!isset($objList['pro'])){
                            $objList['pro'] = makeOne(\model\pro\pro::class);
                        }
                        $op = null;
                        $field = 'pf_son_pid';
                        if($rows = $objList['pro']->getProBrandId($data,true)){
                            $data = $rows;
                        }else{
                            $data = 0;
                        }
                        $join['[>]pro(p)'] = ['e.pf_son_pid'=>'p_id'];
                        $joinWhere['p.p_pb_id'] = $data;
                    }
                ],
                'order'=>[
                    'function'=>function(&$join,&$joinWhere,&$group,&$objList,$db){
                        if(!isset($this->join['[>]pro(p)'])){
                            $join['[>]pro(p)'] = ['e.pf_son_pid'=>'p_id'];
                        }
                        return 'p.p_pb_id';
                    }
                ]
            ],
            'type'=>'varchar',
			'key'=>false, //是否为主键
			'unique'=>false, //是否唯一
			'scale'=>0, //小数位数
			'islist'=>true, //是否在列表中显示
            'list'=>[
                'width'=> 260,
                'hidden'=>false, //是否在列表中默认隐藏
                'hidedlg'=>true, //在查询条件中隐藏
    			'search'=>true, //是否参入查询
    			'editable'=>false, //是否编辑
    			'order'=>true, //是否参入排序
    			'edittype'=>'text',  //编辑类型,text,checkbox
            ],
			'isview'=>true, //是否在详情视图中显示
            'view'=>[
    			'edittype'=>'hidden', //编辑类型 none,hidden,text,select,textarea,checkbox,checkboxgroup
            ],
			'editor'=> [
				'required'=> false, //是否为必须项
				'fieldtype'=> 'string',//string,number(含有小数),digits(整数)
    			'maxlength'=>10, //最大长度(含有小数长度)
				'minlength'=>0, //最小长度
                'scale'=>0, //小数位数
                'preg'=>'', //正则表达式判断 如邮箱 /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
			]
        ]
	],
];