商品单个管理、批量管理

商品单个管理、批量管理
主要的的功能点为复选框选中个数的判断,js对批量选中后的处理及PHP后台的操作

<include file='public/header'/>
<style type="text/css">
	.panel-mod {
		float: right;
		display: block;
		font-size: 12px;
		padding: 11px 12px 12px;
	 }
</style>
<body class="sidebar-wide">
<!-- Navbar -->
<include file='public/headermenu'/>
<!-- /navbar --> 
<!-- Page container --> 
<include file='public/menu'/>
<!-- /sidebar --> 
<!-- Page content -->
<div class="page-content">
<!-- Page header -->
<div class="page-header">
  <div class="page-title">
   <h3> {$Think.lang.totaltitle}<small>{$Think.lang.Superadministrator}</small></h3>
  </div>
</div>
<!-- /page header --> 
<!-- Breadcrumbs line -->
<div class="breadcrumb-line">
  <ul class="breadcrumb">
    <li>{$Think.lang.Homepage}</li>
    <li>商品管理</li>
    <li class="active">商品回收站</li>
  </ul>
</div>
<!-- /breadcrumbs line -->
<!-- Search line -->
<form action="__URL__/recycleList" method="get" class="search-line block">  
  <div class="form-group">
    <label class="col-sm-3 control-label text-right">
        <input type="text" class="form-control" name="product_name" placeholder="请输入商品名称" value="{$product_name}"></label>       
        <label class="col-sm-2 control-label">
             <button class="btn btn-success btn-block " style="height:33px;" type="submit">搜索</button>
        </label>
	</div>
   <div class="clearfix"></div>
</form>
<!-- /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">{$vo.product_sn}</td>
                <td width="200px">{$vo.product_name}</td>
                <td width="100px">{$vo.product_price}</td>
                <td width="200px">{$vo.product_desc} </td>
                <td width="100px">{$vo.product_stock}</td>
                <td width="100px">{$vo.typeModel.t_name}</td>
                <td width="160px">{$vo.is_integral}</td>
                <td width="100px">{$vo.product_integral}</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>
<include file='public/foot'/>
<!-- /page container -->


		<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");
			}	
		</script>
<script>
  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>
</body>
</html>				

下面是PHP代码

<?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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值