';
            } else {
                if ($setting['css'] == 'input-inline') {
                    $width = '225px';
                }
                if ($setting['width']) {
                    // $width = $setting['width'].'px';
                }
                $attribute = $field['attribute'];
                $css = $css2 = '';
                if($attribute['required']) {
                    $css = ' input-required';
                    $css2 = ' input-search-required';
                }
                $query = [];
                if ($setting['query']) {
                    list($k, $v) = explode('=', $setting['query']);
                    if (strpos($v, '$') === 0) {
                        $v = substr($v, 1);
                        $query[$k] = $row[$v];
                    } else {
                        $query[$k] = $v;
                    }
                }
                $query['url'] = $dialog['url'];
                $query['title'] = $dialog['name'];
                $query['id'] = $related['field'];
                $query['form_id'] = $related['table'];
                $query['multi'] = $multi;
                $jq = '';
                foreach ($query as $k => $v) {
                    $jq .= ' data-'.$k.'="'. $v.'"';
                }
                $html[] = '
';
            return join("\n", $html);
        }
    }
    public static function content_urd($field, $content = '', $row = [])
    {
        $field = static::content_field($field);
        $setting = $field['setting'];
        $attribute = $field['attribute'];
        $attr_id = $attribute['id'];
        $attr_name = $attribute['name'];
        $name = str_replace('_id', '_name', $attr_name);
        $key_name = str_replace('_id', '_name', $attr_id);
        $v_id = $field['field'];
        $v_name = str_replace('_id', '_name', $v_id);
        $multi = (int)!$setting['single'];
        $params = [
            'multi' => $multi, 
            'prefix' => 1, 
            'name' => $key_name, 
            'title' => '组织架构',
            'url' => 'index/api/dialog',
            'id' => $attr_id,
            'toggle' => 'dialog-view'
        ];
        $jq = '';
        foreach ($params as $key => $value) {
            $jq .= ' data-'.$key.'="'. $value.'"';
        }
        if ($field['is_show']) {
            return $row[$v_name];
        } else {
            if ($field['is_hide'] == 1) {
                return '
';
            } else {
                $width = '100%';
                if ($field['is_read']) {
                    if ($setting['css'] == 'input-inline') {
                        $width = '153px';
                    }
                    if ($setting['width']) {
                        $width = $setting['width'].'px';
                    }
                    $html[] = '
';
                } else {
                    if ($setting['css'] == 'input-inline') {
                        $width = '225px';
                    }
                    if ($setting['width']) {
                        $width = $setting['width'].'px';
                    }
                    $html[] = '
';
                return join("\n", $html);
            }
        }
    }
    public static function content_option($field, $content = '', $row = [])
    {
        $field = static::content_field($field);
        $setting = $field['setting'];
        // 子表
        if ($field['is_show']) {
            return option($setting['type'], $content);
        }
        // 新增时设置默认值
        if (empty($row['id'])) {
            $content = $setting['default'];
        }
        if ($setting['single'] == 0) {
            $field['attribute']['multiple'] = 'multiple';
        }
        if ($field['is_read']) {
            $field['attribute']['readonly'] = 'readonly';
            $field['attribute']['onfocus'] = 'this.defaultIndex=this.selectedIndex;';
            $field['attribute']['onchange'] = 'this.selectedIndex=this.defaultIndex;';
        }
        $width = '100%';
        if ($setting['css'] == 'input-inline') {
            $width = '153px';
        }
        if ($setting['width']) {
            $width = $setting['width'].'px';
        }
        $str = '
';
    }
    public static function content_date($field, $content = '')
    {
        $field = static::content_field($field);
        $setting = $field['setting'];
        $type = isset($setting['type']) ? $setting['type'] : 'Y-m-d H:i:s';
        $save = isset($setting['save']) ? $setting['save'] : 'date';
        $time_sign = array(
            'Y'  => 'yyyy',
            'y'  => 'yy',
            'm'  => 'mm',
            'm'  => 'MM',
            'M'  => 'M',
            'n'  => 'm',
            'd'  => 'dd',
            'j'  => 'd',
            'l'  => 'DD',
            'jS' => 'D',
            'W'  => 'W',
            'H'  => 'HH',
            'h'  => 'hh',
            'G'  => 'H',
            'g'  => 'h',
            'i'  => 'mm',
            's'  => 'ss',
            'z'  => 'z',
            'c'  => 'c',
            'r'  => 'r',
            'a'  => 'a',
            't'  => 't',
            'A'  => 'A'
        );
        $time_format = strtr($type, $time_sign);
        $content = empty($content) ? ($setting['default'] == 1 ? date($type): '') : ($save == 'date' ? $content : date($type, $content));
        if ($content == '0000-00-00' || $content == '0000-00-00 00:00:00') {
            $content = '';
        }
        if ($content == '1900-01-01') {
            $content = '';
        }
        if ($field['is_show']) {
            return $content;
        }
        $attribute = $field['attribute'];
        if ($field['is_read']) {
            $attribute['readonly'] = 'readonly';
        } else {
            // 宏锁定
            if ($field['is_auto']) {
                $attribute['readonly'] = 'readonly';
            } else {
                $attribute['data-toggle'] = 'date';
                $attribute['data-format'] = $time_format;
                $attribute['data-min_date'] = $setting['min_date'];
                $attribute['data-max_date'] = $setting['max_date'];
            }
        }
        return '
';
    }
    public static function content_radio($field, $content = '', $row, $permission)
    {
        $field = static::content_field($field);
        $setting = $field['setting'];
        $select = explode("\n", $setting['content']);
        $str = [];
        $w = $permission[$field['field']]['w'] == 1 ? '' : 'disabled="disabled"';
        $disabled = $permission[$field['field']]['w'] == 1 ? '' : 'i-checks-disabled';
        if ($field['is_print']) {
            foreach ($select as $t) {
                $n = $v = '';
                list($n, $v) = explode('|', $t);
                $v = is_null($v) ? trim($n) : trim($v);
                if ($v == $content) {
                    $str[] = $n;
                }
            }
            return join(',', $str);
        }
        $attribute = $field['attribute'];
        unset($attribute['class']);
        $id = $attribute['id'];
        $name = $attribute['name'];
        
        foreach ($select as $i => $t) {
            $n = $v = '';
            list($n, $v) = explode('|', $t);
            $v = is_null($v) ? trim($n) : trim($v);
            $checked = $content == $v ? 'checked="checked"' : '';
            $attribute['id'] = $id.'_'.$i;
            if ($field['is_show']) {
                $str[] = '
';
            } else {
                $str[] = '
';
            }
        }
        return join('', $str);
    }
    public static function content_checkbox($field, $content = '', $row = [], $permission = [])
    {
        $field = static::content_field($field);
        // 配置
        $setting = $field['setting'];
        $default = $setting['default'];
        $content = is_null($content) ? $default : $content;
        $checkeds = [];
        $items = [];
        $values = explode(",", $content);
        if ($setting['type']) {
            $items = DB::table($setting['type'])->where('status', 1)->orderBy('sort', 'asc')->get();
        } else {
            if (not_empty($setting['content'])) {
                $selects = explode("\n", $setting['content']);
                foreach ($selects as $select) {
                    $n = $v = '';
                    list($n, $v) = explode('|', $select);
                    $v = is_null($v) ? trim($n) : trim($v);
                    $items[] = ['id' => $v, 'name' => $n];
                }
            } else {
                $items[] = ['id' => 1, 'name' => $field['name']];
            }
        }
        // 打印模式直接返回选中的值名称
        if ($field['is_print']) {
            foreach ($items as $item) {
                if ($field['type']) {
                    if (in_array($item['id'], $values)) {
                        $checkeds[] = $item['name'];
                    }
                } else {
                    if ($row[$item['id']] == 1) {
                        $checkeds[] = $item['name'];
                    }
                }
            }
            return join(',', $checkeds);
        }
        $str = [];
        foreach ($items as $item) {
            // 存在字段
            if ($field['type']) {
                $value = $v;
                $checked = in_array($v, $values) ? 'checked="checked"' : '';
                $name = $field['table'].'['.$field['field'].']['.$v.']';
                $key = $field['field'];
            } else {
                $value = 1;
                $checked = $row[$item['id']] == $value ? 'checked="checked"' : '';
                $name = $field['table'].'['.$item['id'].']';
                $key = $item['id'];
            }
            if ($field['is_show']) {
                $str[] = '
';
            } else {
                $w = $permission[$key]['w'] == 1 ? '' : 'disabled="disabled"';
                $disabled = $permission[$key]['w'] == 1 ? '' : 'i-checks-disabled';
                $str[] = '
';
            }
        }
        return join(' ', $str);
    }
    public static function content_location($field, $content = '', $row)
    {
        $field = static::content_field($field);
        $setting = $field['setting'];
        $attribute = $field['attribute'];
        $id = $attribute['id'];
        $name = $attribute['name'];
        $attribute['readonly'] = 'readonly';
        if ($field['is_show']) {
            return '
            
';
        } else {
            $str = '
            
            
                
                
                
            
';
        }
        return $str;
    }
    public static function content_image($field, $content = '')
    {
        $field = static::content_field($field);
        $setting = $field['setting'];
        $attribute = $field['attribute'];
        $attribute['readonly'] = 'readonly';
        $id = $attribute['id'];
        $name = $attribute['name'];
        if ($field['is_show']) {
            if (empty($content)) {
                $src = 'assets/images/nopic.jpg';
            } else {
                $src = 'uploads/'.$content;
            }
            return '
            
';
        } else {
            if (empty($content)) {
                $src = 'assets/images/nopic.jpg';
                $close = '';
            } else {
                $src = 'uploads/'.$content;
                $close = '
×';
            }
            $dialog = "mediaDialog('system/media/dialog', '".$name."', '".$id."', 0)";
            $str = '
            
            ';
        }
        return $str;
    }
    public static function content_images($field, $content = '')
    {
        $field = static::content_field($field);
        $setting = $field['setting'];
        $attribute = $field['attribute'];
        $id = $attribute['id'];
        $name = $attribute['name'];
        $attribute['readonly'] = 'readonly';
        if ($field['is_show']) {
            $html = '
';
            return $html;
        } else {
            $items = '';
            if (empty($content)) {
                $src = 'assets/images/nopic.jpg';
                $items .= '
';
            } else {
                $srcs = explode("\n", $content);
                foreach($srcs as $src) {
                    $items .= '
';
                }
            }
            $dialog = "mediaDialog('system/media/dialog', '".$name."', '".$id."', 1)";
            $html = '
            
';
            $html .= '
';
            $html .= $items;
            $html .= '
';
        }
        return $html;
    }
    public static function content_file($name, $content = '', $field = '')
    {
        // 配置
        $setting = isset($field['setting']) ? json_decode($field['setting'], true) : $field;
        // 必填字段
        $required = isset($field['not_null']) && $field['not_null'] ? ' required' : '';
        $type = base64_encode($setting['type']);
        $size = (int)$setting['size'];
        return '
	    
	    ';
    }
    public static function content_files($field, $content = '')
    {
        $field = static::content_field($field);
        $setting = $field['setting'];
        $attribute = $field['attribute'];
        $name = $attribute['name'];
        $input_id = $attribute['id'];
        $config = Setting::where('type', 'system')->pluck('value', 'key');
        $attachment = AttachmentService::edit($content, $field['table'], $field['field']);
        $str = '
';
        return $str;
    }
}