美文网首页
实现单选和多选删除

实现单选和多选删除

作者: 雨中笑之 | 来源:发表于2018-08-21 17:58 被阅读0次

项目:http://m.123.local.qushiyun.com/manager/index.php?app=company

<script type="text/javascript">
    $(function(){

        //导出数据
        $('#export_all').click(function(){
            window.open('index.php?app=company&act=export', '_blank');
        });

//点击方法例子
//点击选择全部
        // $(".check-all").click(function () {
        //     $(".ids").prop("checked", this.checked);
        // });
        // //选择多个
        // $(".ids").click(function () {
        //     var option = $(".ids");
        //     option.each(function (i) {
        //         if (!this.checked) {
        //             $(".check-all").prop("checked", false);
        //             return false;
        //         } else {
        //             $(".check-all").prop("checked", true);
        //         }
        //     });
        // });

        //批量删除
        $("#deleteAll").live('click',function(){
            var _ = $('form .chooseNow:checked').length;
            if (_ < 1) {
                $.jBox.tip('请先选择要操作的数据!', 'info');
                return false;
            }
            var submit = function(v, h, f) {
                if (v == 'ok') {
                    _ = $('[name=form2]').serialize();
                    var action = $('[name=form2]').attr('load');
                    var _load  = $('[name=form2]').attr('action');
                    $.post(action, _, function(data) {
                        if (data.status == '1') {
                            $.jBox.tip(
                                data.info,
                                'success',
                                {closed: function () {
                                        window.location=_load;
                                    }
                                }
                            );
                        } else
                            $.jBox.tip(data.info, 'error');
                    }, 'json');
                }
                return true;
            }
            $.jBox.confirm('确定要执行此操作吗?', '提示', submit);
            return false;
        })
    })

    function member_delete (id){
        var submit = function (v, h, f) {
            if (v == 'ok') {
                $.ajax({
                    type: 'POST',
                    url: 'index.php?app=company&act=drop_company&id='+id,
                    dataType:'json',
                    success: function(data){
                        if(data.status == '1'){
                            $.jBox.tip(
                                data.info,
                                'success',
                                {closed:
                                    function () {
                                        location.reload();}});
                        }else{
                            $.jBox.tip(data.info, 'error');
                        }
                    } ,
                });
            }
            return true;
        };
        top.jBox.confirm("确定要删除会员吗?", "提示", submit);
    }
</script>

<form name="form2" class="submitForm" action="index.php?app=company&act=index" load="index.php?app=company&act=drop_company">
        <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#D6D6D6" style="margin-top:8px">
            <tr>
                <td height="28" colspan="17" background="{res file=images/tbg.gif}">
                    <table width='96%' cellpadding='0' cellspacing='0'>
                        <tr>
                            <td height="28" background="/manager/templates/images/tbg.gif" style="padding-left:10px;" colspan="2"> ◆客户公司管理</td>
                            <td align='right'>
                                <a href="index.php?app=company&act=addCompany" class='np coolbg'>增加公司</a>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr align="center" bgcolor="#f8f8f8" height="25">
                <td width="5%">选择</td>
                <td width="5%">网站ID</td>
                <td width="18%">公司名称</td>
                <td width="8%">联系人名称</td>
                <td width="8%">联系方式</td>
                <td width="25%">地址</td>
                <td width="8%">公司状态</td>
                <td width="15%">添加时间</td>

            </tr>
            <!--{if !empty($companyList)}-->
             <!--{foreach from=$companyList item=item name=list}-->
            <tr align="center" bgcolor="#FFFFFF" height="26" align="center" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
                <td class="list-text">
                    <input name='id[]'  type='checkbox'  class="chooseNow"  value='{$item.id}' />
                </td>
                <td>
                {$item.store_id}
            </td>
                <td>
                    {$item.company_name}
                </td>
                <td>
                    {$item.linkman_name|default:-}
                </td>
                <td>
                    {$item.phone_mob|default:-}
                </td>
                <td>
                    {$item.address|default:-}
                </td>
                <td>
                    {if $item.status==20}正常
                    {elseif $item.status==10}<span style="color:red">禁用</span>
                    {/if}
                </td>
                <td>
                    {$item.add_time|date:Y-m-d H:i:g|default:-}
                </td>
                <td width="" class="list-text">
                    <div class="lista">
                        <a href="index.php?app=company&act=addCompany&id={$item.id}"><img src='{res file=images/gtk-edit.png}' title="编辑" alt="编辑" style='cursor:pointer' border='0' width='16' height='16' /></a>
                        <a onclick="member_delete({$item.id})" href="javascript:;"><img src='{res file=images/gtk-del.png}' title="删除" alt="删除" style='cursor:pointer' border='0' width='16' height='16' /></a>
                    </div>
                </td>
            </tr>
            <!--{/foreach}-->
            <tr bgcolor="#ffffff">
                <td height="36" colspan="17">&nbsp;
                    <a class="coolbg" id="checkAll" href="javascript:;">全选</a>
                    <a class="coolbg" id="unCheck" href="javascript:;">取消</a>
                    <a class="coolbg" id="deleteAll" href="javascript:;">&nbsp;删除&nbsp;</a>  &nbsp;
                    <a id="export_all" class="coolbg" href="javascript:;">导出</a>
                </td>
            </tr>
            <!--{else}-->
            <tr align="right" bgcolor="#f8f8f8">
                <td height="36" colspan="17" align="center"><span>您的数据为空</span></td>
            </tr>
            <!--{/if}-->
            <tr bgcolor="#f8f8f8">
                <td height="36" colspan="17" align="center">
                    {include file="./layout/page_bottom.html"}
                </td>
            </tr>
        </table>
    </form>

控制器

 /*
     * 删除公司
     */
    public function drop_company()
    {

        if($_GET['id']){
            $id = $_GET['id'];
        }
        if($_POST['id']){
            $id = $_POST['id'];
        }

        if ($id <= 0) {
            $data = array(
                'status' => 'n',
                'info' => '请选择要删除的数据',
            );
            echo json_encode($data);
        } else {
            $store_companyModel=m("oa_company");
            $store_com=$store_companyModel->delCompany($this->store_id, $id);
            $info="删除成功";
            if(!$store_com){
                $info="删除失败";
            }
            $data = array(
                'status' => '1',
                'info' => $info,
            );
            echo json_encode($data);
        }

    }

model

public function delCompany($storeId, $id)
    {
        if(is_array($id))
        {
            $ids=implode(',',$id);   //重要 将数组变为字符串
            $condition=" store_id='$storeId' and id in($ids)";

        }else{
            $condition['store_id'] = $storeId;
            $condition['id'] = $id;

        }
        return $this->where($condition)->delete();

    }

相关文章

网友评论

      本文标题:实现单选和多选删除

      本文链接:https://www.haomeiwen.com/subject/gnodiftx.html