This commit is contained in:
hant 2025-03-14 20:33:29 +08:00
parent 2369446995
commit f6e39867df
3 changed files with 83 additions and 12 deletions

View File

@ -79,14 +79,28 @@ class Worker extends Backend
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$area_code = request()->get('area_code');
$area_code = request()->get('area_id');
$item_id = request()->get('item_id');
$keyword = request()->get('keyword');
$build = $this->model
->with(['area'])
->where($where)
->field('worker.id,name,tel,area_id,create_time,deposit_amount,update_time,status,star')
->order($sort, $order);
if ($keyword){
$build->where(function ($q) use ($keyword) {
$q->where('name','like','%'.$keyword.'%')->whereOr('tel','like','%'.$keyword.'%');
});
}
if ($item_id){
$build->join('worker_item','worker_item.worker_id = worker.id','left');
$build->where('worker_item.item_id',$item_id);
}
if ($area_code){
$build->where('area_id','like',$this->getSelectAreaCode($area_code).'%');
}
$list = $build
->paginate($limit);
@ -94,6 +108,27 @@ class Worker extends Backend
return json($result);
}
$items = Db::name('item')
->where('status',1)
->field(['id','title','key_word','pid'])
->order('pid','asc')
->order('sort','desc')
->select();
$filtered = array_filter($items, function($item) {
return $item['pid'] == 0;
});
$pid_map = array_column($filtered,null,'id');
$res_items = [];
foreach ($items as $item){
if ($item['pid'] != 0 && isset($pid_map[$item['pid']])){
$res_items [] = [
...$item,'ptitle' => $pid_map[$item['pid']]['title']
];
}
}
$this->view->assign('items', $res_items);
return $this->view->fetch();
}

View File

@ -32,16 +32,36 @@
<a class="btn btn-success btn-recyclebin btn-dialog {:$auth->check('workers/worker/recyclebin')?'':'hide'}" href="workers/worker/recyclebin" title="{:__('Recycle bin')}"><i class="fa fa-recycle"></i> {:__('Recycle bin')}</a>
<form id="select-form" class="form-inline" role="form" style="margin-top: 5px">
<div class='form-group'>
<label style="padding-left: 0px;text-align: left">{:__('Area_id')}:</label>
<div style="display: inline-block;width: 300px;margin-left: 5px">
<input id="c-city" style="width: 100%;height: 32px" data-toggle="city-picker" name="row[address]" type="text" value="" />
<form id="select-form" style="padding-left: 15px;margin-top: 10px" role="form" class="form-horizontal" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="col-xs-12 col-sm-2" style="padding-left: 0px;text-align: left">区域:</label>
<div style="display: inline-block;width: 300px;position: absolute">
<input id="c-city-search" data-rule="required" class="form-control" data-toggle="city-picker" type="text" />
<input id="area_id" style="display: none" class="form-control" name="area_id" hidden type="text" />
</div>
<p id="reset" style="display: inline-block;margin-bottom: 2px;" class="btn btn-default">重置</p>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-2" style="text-align: left;padding-left: 0px;">工种:</label>
<div style="width: 300px;display: inline-block;">
<select id="citem" data-live-search="true" title="请选择" name="item_id" class="form-control selectpicker show-tick">
<option value="0">不过滤</option>
{foreach $items as $item}
<option value="{$item['id']}">{$item['title']}</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-2" style="padding-left: 0px;text-align: left">关键字:</label>
<div style="display: inline-block;width: 300px;position: absolute">
<input id="keyword" class="form-control" style="width: 100%;height: 32px" placeholder="名称或电话号码搜索" name="keyword" type="text" value="" />
</div>
</div>
<p id="search_btn" class="btn btn-primary">搜索</p>
<p id="reset_btn" class="btn btn-primary">清空</p>
</form>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('workers/worker/edit')}"

View File

@ -57,15 +57,31 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','jstree'], function ($
]
]
});
$("#c-city").on("cp:updated", function() {
$("#c-city-search").on("cp:updated", function() {
var citypicker = $(this).data("citypicker");
var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province");
table.bootstrapTable('refresh',{query: {area_code: code}});
// table.bootstrapTable('refresh',{query: {area_code: code}});
$('#area_id').val(code);
});
$("#reset").on("click", function() {
$("#c-city").citypicker('reset');
table.bootstrapTable('refresh');
$("#search_btn").on("click", function() {
table.bootstrapTable('refresh',{
url:$.fn.bootstrapTable.defaults.extend.index_url +'&' + getQueryData(),
});
});
function getQueryData(){
return $('#select-form').serialize();
}
$("#reset_btn").on("click", function() {
$("#c-city-search").citypicker('reset');
$("#area_id").val('');
$("#citem").val('').selectpicker('refresh');
$("#keyword").val('');
table.bootstrapTable('refresh',{
url:$.fn.bootstrapTable.defaults.extend.index_url +'?' + getQueryData(),
});
});
Form.events.citypicker($("#select-form"));
// 为表格绑定事件
Table.api.bindevent(table);