tp3.2 商品批量操作

最近这段时间整理了下一些小功能,希望能有一些帮助

<body class="sidebar-wide">

<div class="page-content">
<!-- Page header -->
<div class="page-header">
  <div class="page-title">
   <h3>  商品管理</h3>
  </div>
</div>
<!-- /page header --> 
<!-- Breadcrumbs line -->
<div class="breadcrumb-line">
</div>
<!-- /search line --> 
<!-- Bordered table -->
    <div class="panel panel-default">
      <div class="panel-heading">
        <h6 class="panel-title"> <i class="icon-users"></i>商品回收站列表</h6>
				<div class="panel-mod"  >
					<a onclick="if(Check()==true){reduc_all()}else{ return false; }">
					  <button  type="button" class="btn btn-icon btn-success" title="批量还原"><i class="icon-file6">批量还原</i> </button>
					</a>
					<button onclick="if(Check()==true){dele_all()}else{ return false; }" type="button" class="btn btn-icon btn-danger" title="批量删除">
					  <i class="icon-remove3">批量删除</i>
					</button>
				</div>
      </div>
      <!-- Form modal -->
      <div id="form_modal" class="modal fade" tabindex="-1" role="dialog">
        <div class="modal-dialog">
          11
        </div>
      </div>
      <!-- /form modal -->
      <div class="table-responsive">
        <table class="table table-bordered" id='fruit'>
          <thead>
            <tr align="center"> 
							<td align="center"><input name="All" type='checkbox' id="All"   value='checkbox'></td>
              <td><strong>商品编号</strong></td>
              <td><strong>商品名称</strong></td>
              <td><strong>商品价格</strong></td>
              <td><strong>商品描述</strong></td>
              <td><strong>商品库存</strong></td>
              <td><strong>所属分类</strong></td>
              <td><strong>是否支持全积分</strong></td>
              <td><strong>积分额度</strong></td>
              <td><strong>操作方式</strong></td>
            </tr>
          </thead>
          <tbody>
             <volist id="vo" name="modelList">
                <tr align="center">
								<td  width="65px" align="center"><input  type="checkbox" name="product_id"  value="{$vo.product_id}"></td>
                <td width="200px">PRO1572678717</td>
                <td width="200px">帆布鞋</td>
                <td width="100px">200.00 元</td>
                <td width="200px">好看的鞋子 </td>
                <td width="100px">20</td>
                <td width="100px">鞋靴</td>
                <td width="160px">积分加金额</td>
                <td width="100px">1000</td>
                <td width="200px">
                  
                <a onclick="reduction('{$vo.product_id}');">
                  <button  type="button" class="btn btn-icon btn-success" title="商品还原"><i class="icon-file6"></i> </button>
                </a>
                <button onclick="removeProduct('{$vo.product_id}')" type="button" class="btn btn-icon btn-danger" title="{$Think.lang.goods_delete}">
                  <i class="icon-remove3"></i>
                </button>
                </td>
              </tr>
             </volist>
          </tbody>
        </table>
		{$show}
      </div>
    </div>
    <!-- /bordered table --> 
    <!-- Footer -->
    <!-- /footer --> 
  </div>
  <!-- /page content --> 
</div>

下边是对应的js

<SCRIPT language=JavaScript>
		//是否有选中项
		function Check()
		{
		var chks=document.getElementsByTagName('input');
		
		var bl=true;

		for(var i=0;i<chks.length;i++)
		{
				if(chks[i].checked) 
				{
						bl=false;
						break;
				}
		} 

		if(bl){
		alert('最少选择一件商品!');
		 return false;
		}else{
		 return true;
		 }
		}
		</SCRIPT>
<script>
	//全选/全不选
	 $("#All").click(function(){
		 if (this.checked == true) { 
				$('input[name="product_id"]').each(function() { 
					this.checked = true; 
				}); 
		} else { 
			$('input[name="product_id"]').each(function() { 
				this.checked = false; 
			}); 
		} 
   
   });
	 //批量还原
			function reduc_all()
			{
					var arr = new Array();
				$('input[name="product_id"]:checked').each(function(i){
				
					    arr.push($(this).val());
				
				});
			  var url ='__MODULE__/Product/red_all/';
			  var bodyParam = {
			    "product_id":arr.toString(),
			  };
			  $.post(url,bodyParam,function(ret,err){
			    if(ret!=null)
			    {
			       
			       if(ret.status == 1)
			       {
			         alert('已批量还原');
			         window.location.href='__MODULE__/Product/productList';
			       }else{
			         alert('批量还原失败');
			       }
			       
			    }
			  },"JSON");
			}	
			//批量删除
			function dele_all()
			{
					var arr = new Array();
				$('input[name="product_id"]:checked').each(function(i){
				
					    arr.push($(this).val());
				
				});
			  var url ='__MODULE__/Product/del_all/';
			  var bodyParam = {
			    "product_id":arr.toString(),
			  };
			  $.post(url,bodyParam,function(ret,err){
			    if(ret!=null)
			    {
			      if(ret.status == 1)
			      {
			        alert('批量删除成功');
			        window.location.href='__MODULE__/Product/recycleList';
			      }
			      else
			      {
			        alert('批量删除失败');
			      }
			    }
			  },"JSON");
			}	
			
//单个操作
  function reduction(id=0)
  {
		
    var url ='__MODULE__/Product/reduction/';
    var bodyParam = {
      "product_id":id
    };
    $.post(url,bodyParam,function(ret,err){
      if(ret!=null)
      {
         
         if(ret.status == 1)
         {
           alert('已还原');
           window.location.href='__MODULE__/Product/productList';
         }else{
           alert('还原失败');
         }
         
      }
    },"JSON");
  }	
	
  function removeProduct(id)
  {
    if(confirm('{$Think.lang.confirm}')){
      var url = '__MODULE__/Product/deleteProduct'
      var bodyParam = {'product_id':id};
      $.post(url,bodyParam,function(ret,err){
        if(ret!=null)
        {
          alert('删除成功');
          window.location.href='__MODULE__/Product/recycleList';//跳转地址
        }
        else
        {
          alert('删除失败');
        }
      },"JSON");
    }
  }
		</script>
<script>

//控制器


```php

	//批量操作
	public function red_all()
	{
		$product_id = I('request.product_id');
		$product_id = substr($product_id,0,strlen($product_id));
	    $where['product_id'] = array('in',$product_id);
		$data['is_delete'] = 0;
		
		if($this->productService->editallProduct($data,$where) ==1 ){
			$res['status'] = '1';
			$this->ajaxReturn($res);
			}
		
	}
	//批量删除 
	public function del_all()
	{
		$product_id = I('request.product_id');
		$product_id = substr($product_id,0,strlen($product_id));
	    $where['product_id'] = array('in',$product_id);
		
		if($this->productService->delall($where) ==1 ){
			$res['status'] = '1';
			$this->ajaxReturn($res);
			}
		
	}


	public function editallProduct($data,$where)
	{
		$productModel = new ProductModel();
		
			$res = $productModel->where($where)->save($data);
			if($res){
				return 1;exit;
			}
			return 0;
	}
	 // 真实删除
	public function delall($where)
	{
		$productModel = new ProductModel();
		$res = $productModel->where($where)->delete();
		return 1;
	}



//model
```php
namespace Admin\Model;
class PowerModel extends \Think\Model\RelationModel {
	protected $tableName = 'user_power'; 
	protected $_link = array(
			'Modules' => array(
					'mapping_type'  => self::BELONGS_TO,
					'class_name' => 'Module',
					'foreign_key'   => 'mid',
					'mapping_name'  => 'module'
			)
	);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值