[ 'title' => '用户', 'table' => 'user', 'field' => 'name', 'url' => 'user/user/dialog', ], 'role' => [ 'title' => '角色', 'table' => 'role', 'field' => 'name', 'url' => 'user/role/dialog', ], 'department' => [ 'title' => '部门', 'table' => 'department', 'field' => 'name', 'url' => 'user/department/dialog', ], 'supplier' => [ 'title' => '供应商', 'table' => 'supplier', 'join' => 'user', 'field' => 'user.name', 'url' => 'supplier/supplier/dialog', ], 'customer' => [ 'title' => '客户', 'table' => 'customer', 'join' => 'user', 'field' => 'user.name', 'url' => 'customer/customer/dialog', ], 'customer_contact' => [ 'title' => '客户联系人', 'table' => 'customer_contact', 'join' => 'user', 'field' => 'user.name', 'url' => 'customer/contact/dialog', ], 'supplier_product' => [ 'title' => '商品', 'table' => 'product', 'field' => 'name', 'url' => 'supplier/product/dialog', ], 'product' => [ 'title' => '产品', 'table' => 'product', 'field' => 'name', 'url' => 'product/product/dialog', ], 'promotion' => [ 'title' => '促销', 'table' => 'promotion', 'field' => 'id', 'url' => 'promotion/promotion/dialog', ], 'region' => [ 'title' => '销售团队', 'table' => 'customer_region', 'field' => 'name', 'url' => 'customer/region/dialog', ], 'hr' => [ 'title' => '人事档案', 'table' => 'hr', 'field' => 'name', 'url' => 'hr/hr/dialog', ], 'logistics' => [ 'title' => '物流', 'table' => 'logistics', 'field' => 'name', 'url' => 'order/logistics/dialog', ], ]; public static function text($item, $value) { $dialog = self::$items[$item]; $rows = ''; if ($value) { $ids = explode(',', $value); $table = $dialog['table']; $join = $dialog['join']; if ($join) { $rows = DB::table($table) ->LeftJoin('user', 'user.id', '=', $table.'.user_id') ->whereIn($table.'.id', $ids) ->pluck($dialog['field'])->implode(','); } else { $rows = DB::table($table) ->whereIn('id', $ids) ->pluck($dialog['field'])->implode(','); } } return $rows; } public static function show($key, $data, $multi = 0, $readonly = 0) { $id = $key.'_id'; $name = $key.'_name'; if ($readonly == 0) { $html[] = '
'; } else { $html[] = '
'; } if ($readonly == 0) { $arrow = $multi == 1 ? 'icon-group' : 'icon-user'; $option = "dialogShow('$id','$name','$multi');"; $html[] = '
'.$data[$name].'
'; $html[] = '
'; $html[] = ''; $html[] = '
'; } else { $html[] = '
'.$data[$name].'
'; } $html[] = ''; $html[] = '
'; return join("\n", $html); } public static function user($item, $name, $value = '', $multi = 0, $readonly = 0, $width = 'auto') { $rows = ''; $dialog = self::$items[$item]; if ($value) { $ids = explode(',', $value); $table = $dialog['table']; $join = $dialog['join']; if ($join) { $rows = DB::table($table) ->LeftJoin('user', 'user.id', '=', $table.'.user_id') ->whereIn($table.'.id', $ids) ->pluck($dialog['field'])->implode(','); } else { $rows = DB::table($table) ->whereIn('id', $ids) ->pluck($dialog['field'])->implode(','); } } $id = str_replace(['[',']'], ['_',''], $name); if ($readonly == 0) { $width = is_numeric($width) ? 'width:'.$width.'px;' : ''; $html[] = '
'; } else { $html[] = '
'; } if ($readonly == 0) { $html[] = ''; $html[] = '
'; $html[] = ''; $html[] = '
'; } else { $html[] = '
'.$rows.'
'; } $html[] = ''; $html[] = '
'; return join("\n", $html); } public static function search($data, $query) { $params = []; parse_str($query, $params); $defaultParams = [ 'prefix' => 1, 'multi' => 0, 'readonly' => 0, 'width' => '100%', 'title' => '', 'url' => 'index/api/dialog', ]; $params = array_merge($defaultParams, $params); extract($params); $_id = str_replace(['[',']'], ['_',''], $id); $_name = str_replace(['[',']'], ['_',''], $name); $jq = ''; foreach ($params as $key => $value) { $jq .= ' data-'.$key.'="'. $value.'"'; } $params['id'] = str_replace(['[',']'], ['_',''], $id); $params['name'] = str_replace(['[',']'], ['_',''], $name); $e[] = '
'; $e[] = ''; $e[] = '
'; $e[] = ''; $e[] = '
'; $e[] = ''; $e[] = '
'; return join("\n", $e); } }