选择+弹窗+分页+搜索 封装公用方法

一、调用页

商品选择 :

<div id='option_val'></div>
<input type="hidden" name="option_id" id="option_id" value="" />

<a href="javascript:void(0)" οnclick="nameEvent('option_id','option_val')">选择</a>


<script type="text/javascript">
function nameEvent(field, thumb){
$('#dialog').remove();

    $("#content").prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe id="ifr" name="ifr" src="index.php?route=common/choose_commodity&token=<?php echo $token; ?>"style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
$('#dialog').dialog({
title: '<?php echo '商品管理'; ?>',
close: function (event, ui) {
var option_id = '';
var option_name = '';
$(window.frames["ifr"].document).find("input[name*=\'selected\']:checked").each(function(){
option_id += $(this).val()+' ';

option_name += $(window.frames["ifr"].document).find("#"+$(this).val()).text()+' ';

});
$("#thumb").text(option_name);
$("#field").val(option_id);
// $.ajax({
// url: 'index.php?route=common/choose_commodity/move&token=<?php echo $token; ?>', //+ ($('#' + field).attr('value')),
// //type:'GET',
// //data:{option_name: 11,option_id:222},
// dataType: 'text',
// success: function(json) {

// },

// error:function(data){
// //alert(data);
// }
// });
},
bgiframe: false,
width: 800,
height: 400,
resizable: false,
modal: false
});

}

</script>

二、  controller页

<?php
class ControllerCommonChooseCommodity extends Controller{
public function index() {
if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
$this->data['base'] = HTTPS_SERVER;
} else {
$this->data['base'] = HTTP_SERVER;
}
$this->data['token'] = $this->session->data['token'];
$this->template = 'common/choose_commodity.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
public function loadMore(){

$rewardjson = array('status' => true, 'message' => '', 'data' => array(), 'lastPage' => false);

if (isset($this->request->post['filter_name'])) {
$filter_name = $this->request->post['filter_name'];
} else {
$filter_name = '';
}

if( isset($this->request->post['page']) && $this->request->post['page'] )
{
$page=$this->request->post['page'];
}
else{
$page=1;
}


$limit=10;//$this->config->get('config_catalog_limit');
$data = array(
'filter_name'  => $filter_name,
'start' => ($page - 1) * $limit,
'limit' => $limit
);

$this->load->model('catalog/product');
$results = $this->model_catalog_product->getProducts($data);
if(isset($results) && $results){
foreach ($results as $result) {
$rewardjson['data'][] = array(
'product_id' => $result['product_id'],
'name'      => $result['name'],
'status'     => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')),
'selected'   => isset($this->request->post['selected']) && in_array($result['product_id'], $this->request->post['selected'])
);
}
}else{
$rewardjson['message'] = '没有更多可显示的数据';
}

$reward_total = $this->model_catalog_product->getTotalProducts($data);

if(!empty($reward_total))
{
$page_total=ceil($reward_total/$limit);
if( $page >= $page_total){
$rewardjson['lastPage'] = true;
$rewardjson['message'] = '没有更多可显示的数据';
}
}




$this->response->setOutput(json_encode($rewardjson));
}


}


三、view页

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title><?php echo '';//$title; ?></title>
<base href="<?php echo $base; ?>" />
<link rel="stylesheet" type="text/css" href="view/stylesheet/stylesheet.css" />
<script type="text/javascript" src="view/javascript/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="view/javascript/jquery/ui/jquery-ui-1.8.16.custom.min.js"></script>
<link type="text/css" href="view/javascript/jquery/ui/themes/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<script type="text/javascript" src="view/javascript/jquery/tabs.js"></script>
<script type="text/javascript" src="view/javascript/jquery/superfish/js/superfish.js"></script>
<script type="text/javascript" src="view/javascript/common.js"></script>
<style type="text/css">
/* dialog {
  background: #f0f0f0;
  border: 1px solid gray;
  border-radius: 5px;
  box-shadow: 0 1px 10px gray;
  top: 30%;
}
dialog::backdrop {
  background: rgba(173, 216, 230, .7);
} */
dialog{
border:1px solid #003A88;;
width:500px;

}


</style>
</head>
<body>
<input type="hidden" id="currentPage" value="1" />
<div class="box" style="text-align:center">
<div class="heading">
<h1> <?php echo "商品选择"//$heading_title ?></h1>
<div class="buttons">
<a href="javascript:void(0)" id="confirm" οnclick="clickEvent();" class="button"><?php echo "确定";?></a>
</div>
</div>
<div class="content"style="min-height:0">
<div style="margin-bottom: 5px;text-align:left">商品名称:
<input type="text" value="" name="filter_name">
<a href="javascript:void(0)" class="button" οnclick="seekEvent()">搜索</a>
</div>
<table class="list">
<thead>
<tr>
<td width="1" style="text-align: center">
<input id="select_all" type="checkbox" οnclick="checkedEvent()"/>
</td>
<td class="center">id</td>
<td class="center">商品名称</td>
</tr>
</thead>
<tbody id="rewardList"></tbody>
</table>
<div class="pagination">
<a href="javascript:void(0)"id="uppage"οnclick="PageEvent(-1);">上一页</a>
<a href="javascript:void(0)"id="bottompage"οnclick="PageEvent(1);">下一页</a>
</div>
</div>
</div>
<script type="text/javascript">


function checkedEvent(){

if($("#select_all").is(':checked')){
$("input[name*=\'selected\']").each(function(){
$(this).attr('checked','checked');
});
}else{
$("input[name*=\'selected\']").each(function(){
$(this).removeAttr('checked');
});

}
}


function clickEvent(){
 
var option_id = '';
var option_name = '';
$("input[name*=\'selected\']:checked").each(function(){

option_name += $("#"+$(this).val()).text()+' ';
option_id += $(this).val()+' ';
}); 
if(option_id){
parent.$('#dialog').dialog('close');

}else{
alert("您还没有选择产品!");
}
//self.close();
}


PageEvent('');
function seekEvent(){
$("#currentPage").val('1');
PageEvent(0);
}
function PageEvent(paged){
var page = parseInt($("#currentPage").val());
var filter_name = $('input[name=\'filter_name\']').attr("value");
//if(!filter_name){filter_name = '';}

page = paged+page;

if(page<=0 || page == 1){
page = 1;
$("#uppage").hide();
}else{
$("#uppage").show();
}


$.ajax({
url:'index.php?route=common/choose_commodity/loadMore&token=<?php echo $token;?>',
data:{
page : page,
filter_name : filter_name
},
type:'POST',
dataType:'json',
success:function(json){
var html='';
var data=json.data;;
if(json.status){
if(data.length > 0){
for( var i=0;i<data.length;i++){
html += '<tr class="reward">';
html += '<td style="text-align: center;">';
if (data[i]['selected']) { 
html += '<input type="checkbox" name="selected[]" value='+data[i]['product_id']+'checked="checked" />';
}else{
html += '<input type="checkbox" name="selected[]" value='+data[i]['product_id']+' />';
}
        html += '</td>';
        html += '<td class="right">'+data[i]['product_id']+'</td>';
        html += '<td class="left"id='+data[i]['product_id']+'>'+data[i]['name']+'</td></tr>';

}
$("#bottompage").show();
}else{
html += '<tr class="reward">';
html += '<td colspan="3"style="text-align: center;">没有数据了!</td>';
html += '</tr>';
$("#bottompage").hide();
}
$(".reward").parent().empty();
$("#select_all").removeAttr("checked");
$("#rewardList").append(html);

if(json.lastPage){
$("#bottompage").hide();
//html ="<tr class='reward'><td colspan='3'style='text-align: center;'>"+json.message+"</td></tr>";
}
}  
//holdnode.style.display = "none";
$("#currentPage").val(page);

  },
error:function(){
alert('加载异常');
//holdnode.style.display = "none";
}
});
}
</script>
</body>
</html>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

M_小强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值