Filter.php
3.48 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace backend\widgets;
use Yii;
use backend\widgets\Filter\Base;
use yii\web\View;
class Filter extends Base
{
/**
* 实例化自身
* @return \YHGEditor\Brand\Client
*/
public static function self()
{
return new self();
}
public function __construct() {
self::_attributes_config('submit', array('class'=>'btn btn-primary btn-sm mr5'));
self::_attributes_config('reset', array('class'=>'btn btn-primary btn-sm mr5'));
}
/**
* 输出
* @return type
*/
protected function render(){
$view = Yii::$app->getView();
$view->registerCssFile('/css/select2.css',array('postion'=>View::POS_END));
$view->registerJsFile('/js/select2.min.js',array('postion'=>View::POS_END));
$script = <<<EOT
<script type="text/javascript">
$(function(){
jQuery(".select-search").select2();
jQuery('.select-search-hide').select2({
minimumResultsForSearch: -1
});
});
</script>
EOT;
$this->html($script);
return parent::render();
}
public function reset($name = null, $value = '重置', array $attributes = NULL){
$filterForm = self::$filterFormId;
$script = <<<EOT
<script type="text/javascript">
$(function(){
filterResetTimeout = null;
filterReset = function(obj){
clearTimeout(filterResetTimeout);
filterResetTimeout = setTimeout(function(){
$(obj).parents('form:eq(0)').find('select').each(function(){
var text = $(this).find('option:selected').text();
$(this).prev('div').find('span[id^=select2-chosen-]').text(text);
});
}, 50)
};
});
</script>
EOT;
$this->html($script);
return parent::reset($name, $value, array('onclick'=>'filterReset(this)'));
}
/*
* 关键字查询
*/
public function keyword($name = null, $value = NULL){
if (!$name)
$name = 'keyword';
//构造当前元素
$this
->html('<div class="form-group"><label class="control-label">关键字:</label>')
->input_equal($name, $value,array('class'=>'form-control','placeholder'=>"输入关键字"))
->html('</div>');
return $this;
}
/*
* 直播间状态select
*/
public function liveStatus($name = null, $selected = NULL){
if (!$name)
$name = 'status';
//选项
$options = Yii::$app->params['config']['room_status'];
$options = array(''=>'ALL') + $options;
//构造当前元素
$this
->html('<div class="form-group"><label class="control-label"> 状态:</label>')
->select($name, $options, $selected, array('class'=>'select-search-hide','style'=>'width:150px'))
->html('</div>');
return $this;
}
/*
* 关键字查询
*/
public function masterName($name = null, $value = NULL){
if (!$name)
$name = 'name';
//构造当前元素
$this
->html('<div class="form-group"><label class="control-label">名称:</label>')
->input_equal($name, $value,array('class'=>'form-control','placeholder'=>"搜索主播名称"))
->html('</div>');
return $this;
}
}