StatusPresenter.php
1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace App\Presenters;
class StatusPresenter
{
public function render($name, $text, $status = null, $data = [0 => '禁用', 1 => '启用'], $option = [])
{
$isRequired = array_get($option, 'required', false);
$isDisable = array_get($option, 'disable') === true ? 'disabled' : '';
$width = array_get($option, 'width', 'auto');
$noName = array_get($option, 'noName');
$name = $noName ? '' : $name;
$labelWidth = array_get($option, 'label_width');
$requiredHtml = $isRequired ? '<span class="require">*</span>' : "";
$html = <<<EOF
<label class="layui-form-label" style="width: $labelWidth">
$requiredHtml
$text
</label>
<div class="layui-input-inline" style="width: $width">
<select name="$name" id="$name" lay-filter="$name" $isDisable lay-search="">
{$this->optionsRender($data, $status)}
</select>
</div>
EOF;
return $html;
}
public function optionsRender($data, $status)
{
$optionsHtml = ' <option value="">请选择</option>';
$checked = '';
foreach ($data as $key => $value) {
if ($status !== '' && $status !== null) {
if ($status === '0' || $status === 0) {
$checked = ($key === $status) ? "selected='selected'" : '';
}else{
$checked = ($key == $status) ? "selected='selected'" : '';
}
}
$optionsHtml = $optionsHtml . "<option value='$key' $checked>$value</option>";
}
return $optionsHtml;
}
}