實(shí)現(xiàn)單選和多選刪除


項(xiàng)目:http://m.123.local.qushiyun.com/manager/index.php?app=company

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

        //導(dǎo)出數(shù)據(jù)
        $('#export_all').click(function(){
            window.open('index.php?app=company&act=export', '_blank');
        });

//點(diǎn)擊方法例子
//點(diǎn)擊選擇全部
        // $(".check-all").click(function () {
        //     $(".ids").prop("checked", this.checked);
        // });
        // //選擇多個(gè)
        // $(".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('請先選擇要操作的數(shù)據(jù)!', '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('確定要執(zhí)行此操作嗎?', '提示', 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("確定要?jiǎng)h除會員嗎?", "提示", 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%">網(wǎng)站ID</td>
                <td width="18%">公司名稱</td>
                <td width="8%">聯(lián)系人名稱</td>
                <td width="8%">聯(lián)系方式</td>
                <td width="25%">地址</td>
                <td width="8%">公司狀態(tài)</td>
                <td width="15%">添加時(shí)間</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:;">導(dǎo)出</a>
                </td>
            </tr>
            <!--{else}-->
            <tr align="right" bgcolor="#f8f8f8">
                <td height="36" colspan="17" align="center"><span>您的數(shù)據(jù)為空</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' => '請選擇要?jiǎng)h除的數(shù)據(jù)',
            );
            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);   //重要 將數(shù)組變?yōu)樽址?            $condition=" store_id='$storeId' and id in($ids)";

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

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

    }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,569評論 19 139
  • 如果我午夜夢回時(shí)感受到陽光撲面 那一定是夢見了你
    Azalea_3bfc閱讀 184評論 0 0
  • 最近整理家里的書柜,發(fā)現(xiàn)有許多書收原封不動(dòng)沒有看過,有些書看過卻一點(diǎn)印象都沒有。跟朋友聊起這件事,她說她的情況也是...
    知恩媽媽V閱讀 366評論 0 0
  • 早知如此絆人心,當(dāng)初何如莫相識。 昨天晚上,你慎重認(rèn)真的拒絕了我。 前幾天我們還相處的很不錯(cuò),你對我也...
    深知你是夢ZL閱讀 418評論 0 2

友情鏈接更多精彩內(nèi)容