功能描述:冷庫公司需要對預約訂單指派送冰員,
效果如下:



支持批量處理
Ice控制器
public function actionSetShrIdAndName($oId,$shrId){
$shr=User::model()->find('userId='.$shrId);//根據送貨人ID找到該用戶資訊
$order=Ice::model()->findAll("id in (".$oId.")");//找訂單
if($order){
foreach ($order as $v){
$v->deliver_id=$shrId;//填入送貨人資訊
$v->deliver_name=$shr->TCNAME;
$v->deliver_tel=$shr->PHONE;
$v->order_state='已派送';//修改狀態
$v->save();
}
}
echo CJSON::encode('succeed');
}
public function getUserKeyWords($keywords){
return get_like('1','TCNAME',$keywords);
}
public function actionOpenDialogShr($keywords=''){
$model = User::model();
$criteria = new CDbCriteria;
$criteria -> condition = $this->getUserKeyWords($keywords);
$data = array();
parent::_list($model, $criteria, 'select', $data);//渲染select
}
views檔案

index_appoint代碼如下
<div class="box">
<div class="box-content">
<div class="box-header">
<a class="btn" href="javascript:;" onclick="we.reload();"><i class="fa fa-refresh"></i>重繪</a>
<a style="display:none;" id="j-delete" class="btn" href="javascript:;"
onclick="chooseShr(we.checkval('.check-item input:checked'));">
批量指定送冰員</a>
</div><!--box-header end-->
<div class="box-search">
<form action="<?php echo Yii::app()->request->url; ?>" method="get">
<input type="hidden" name="r" value="<?php echo Yii::app()->request->getParam('r'); ?>">
<label style="margin-right:10px;">
<span>關鍵字:</span>
<input style="width:200px;" class="input-text" type="text" name="keywords"
value="<?php echo Yii::app()->request->getParam('keywords'); ?>">
</label>
<button class="btn btn-blue" type="submit">查詢</button>
</form>
</div><!--box-search end-->
<div class="box-table">
<table class="list">
<thead>
<tr>
<th class="check"><input id="j-checkall" class="input-check" type="checkbox"></th>
<th width="6%"><?php echo $model->getAttributeLabel('order_name'); ?></th>
<th width="8%"><?php echo $model->getAttributeLabel('order_tel'); ?></th>
<th width="5%"><?php echo $model->getAttributeLabel('ice_amount'); ?></th>
<th width="25%"><?php echo $model->getAttributeLabel('order_destination'); ?></th>
<th width="11%"><?php echo $model->getAttributeLabel('order_time'); ?></th>
<th width="30%"><?php echo $model->getAttributeLabel('order_remark'); ?></th>
<th width="5%"><?php echo $model->getAttributeLabel('order_state'); ?></th>
<th width="7%">操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($arclist as $v) { ?>
<tr>
<td class="check check-item">
<?php if ($v->order_state=='已預約'){?>
<input class="input-check" type="checkbox"
value="<?php echo CHtml::encode($v->id); ?>">
<?php }?>
</td>
<td style='text-align: center;'><?php echo $v->order_name; ?></td>
<td style='text-align: center;'><?php echo $v->order_tel; ?></td>
<td style='text-align: center;'><?php echo $v->ice_amount; ?></td>
<td style='text-align: center;'><?php echo $v->order_destination; ?></td>
<td style='text-align: center;'><?php echo $v->order_time; ?></td>
<td style='text-align: center;'><?php echo $v->order_remark; ?></td>
<td style='text-align: center;'><?php echo $v->order_state; ?></td>
<td>
<?php if ($v->order_state=='已預約'){?>
<button class="btn" type="button" onclick="chooseShr(<?php echo $v->id;?>);">選擇送冰員</button>
<?php }?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div><!--box-table end-->
<div class="box-page c"><?php $this->page($pages); ?></div>
</div><!--box-content end-->
</div><!--box end-->
<script>
function chooseShr(id){
url = '<?php echo $this->createUrl("OpenDialogShr");?>'
$.dialog.data('id',0)
$.dialog.open(url,{
id: 'chooseShr',
lock:true,opacity:0.3,
width:'1000px',
height:'80%',
title:'選擇送冰員',
close: function () {
if($.dialog.data('id')>0){
s1='<?php echo $this->createUrl('SetShrIdAndName')?>'
s1=s1+'&shrId='+$.dialog.data('id')+'&oId='+id
$.ajax({
type: 'get',
url: s1,
dataType: 'json',
success: function(data){
we.reload()
},
});
}
}
});
};
</script>
select代碼如下:
<div class="box">
<div class="box-content">
<div class="box-header">
<!-- <a class="btn" href="--><?php //echo $this->createUrl('create'); ?><!--"><i class="fa fa-plus"></i>添加用戶</a>-->
<a class="btn" href="javascript:;" onclick="we.reload();"><i class="fa fa-refresh"></i>重繪</a>
<!-- <a style="display:none;" id="j-delete" class="btn" href="javascript:;"-->
<!-- onclick="we.dele(we.checkval('.check-item input:checked'), deleteUrl);"><i-->
<!-- class="fa fa-trash-o"></i>洗掉</a>-->
</div><!--box-header end-->
<div class="box-search">
<form action="<?php echo Yii::app()->request->url; ?>" method="get">
<input type="hidden" name="r" value="<?php echo Yii::app()->request->getParam('r'); ?>">
<label style="margin-right:10px;">
<span>關鍵字:</span>
<input style="width:200px;" class="input-text" type="text" name="keywords"
value="<?php echo Yii::app()->request->getParam('keywords'); ?>">
</label>
<button class="btn btn-blue" type="submit">查詢</button>
</form>
</div><!--box-search end-->
<div class="box-table">
<table class="list">
<thead>
<tr>
<!-- <th class="check"><input id="j-checkall" class="input-check" type="checkbox"></th>-->
<th><?php echo $model->getAttributeLabel('userId'); ?></th>
<th><?php echo $model->getAttributeLabel('TCNAME'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($arclist as $v) { ?>
<tr data-id="<?php echo $v->userId;?>" >
<!-- <td class="check check-item"><input class="input-check" type="checkbox" value="--><?php //echo CHtml::encode($v->userId); ?><!--"></td>-->
<td style='text-align: center;'><?php echo $v->userId; ?></td>
<td style='text-align: center;'><?php echo $v->TCNAME; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div><!--box-table end-->
<div class="box-page c"><?php $this->page($pages); ?></div>
</div><!--box-content end-->
</div><!--box end-->
<script>
var deleteUrl = '<?php echo $this->createUrl('delete', array('id' => 'ID')); ?>';
$(function(){
let api = $.dialog.open.api; // art.dialog.open擴展方法
api.button(
{
name: '取消'
}
);
$('.box-table tbody tr').on('click', function(){
console.log($(this).attr('data-id'))
if($(this).attr('data-id')){
$.dialog.data('id',$(this).attr('data-id'));
$.dialog.close();
}
});
});
</script>
說明:
1.
<?php echo $this->createUrl('SetShrIdAndName')?>
上述代碼表示輸出一個路徑,該路徑對應當前控制器的SetShrIdAndName方法
<?php echo $this->createUrl('ControllerName/ActionName')?>
上述代碼表示輸出一個路徑,該路徑對應ControllerName控制器的ActionName方法
$.ajax({
type: 'get',
url: s1,
dataType: 'json',
success: function(data){
we.reload()
},
});
$.ajax 在jquery用于請求,即瀏覽器(前端)請求服務器端(后端),
需要寫url,就能請求對應控制器的介面,可以使用第1點的createUrl方法生成,如果還要傳遞引數,可以使用字串拼接的方法構造url,或者書寫形如 data:{ 引數名1:引數值1,引數名2:引數值2}
success后呼叫回呼函式,和微信小程式中的wx.request類似,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/289311.html
標籤:其他
上一篇:JavaScript(三)(面向物件編程、異步操作)
下一篇:JavaScript網頁特效
