ajax删除(根据一个标签属性判断是否删除,带删除提示,带删除后tr标签移除)

6 篇文章 0 订阅
4 篇文章 0 订阅

html代码

<div class="am-scrollable-horizontal am-u-sm-12">
    <table width="100%" class="am-table am-table-compact am-table-striped
     tpl-table-black am-text-nowrap">
        <thead>
        <tr>
            <th>活动编号</th>
            <th>活动名称</th>
            <th>封面图</th>
            <th>活动类型</th>
            <th>活动/报名时间</th>
            <th>活动地点</th>
            <th>发布方式</th>
            <th>是否发布</th>
            <th>状态</th>
            <th>目标金额</th>
            <th>已捐金额</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <?php if (!empty($list)): foreach ($list as $key=>$item): ?>
            <tr>
                <td class="am-text-middle">HD-<?= $item['activity_id'] ?></td>
                <td class="am-text-middle"><?= $item['activity_name'] ?></td>
                <td class="am-text-middle">
                    <a href="<?= $item['image']['file_path'] ?>" title="点击查看大图" target="_blank">
                        <img src="<?= $item['image']['file_path'] ?>" height="72" alt="">
                    </a>
                </td>
                <td class="am-text-middle">
                    <?php if($item['activity_type'] == 1 ): ?>
                        线上活动
                    <?php endif; ?>
                    <?php if($item['activity_type'] == 2 ): ?>
                        线下活动
                    <?php endif; ?>
                </td>
                <td class="am-text-middle">开始:<?= $item['activity_start_date'] ?> <br/> 结束:<?= $item['activity_end_date'] ?></td>
                <td class="am-text-middle"><?= $item['activity_address'] ?></td>
                <td class="am-text-middle">
                    <?php if($item['activity_publish'] == 1 ): ?>
                        手动
                    <?php endif; ?>
                    <?php if($item['activity_publish'] == 2): ?>
                        <?= $item['publish_time'] ?> <br/>定时发布
                    <?php endif; ?>

                </td>
                <td class="am-text-middle">
                        <input type="checkbox" name="sex" id="male.<?= $key ?>" class="chooseBtn "
                            <?php if($item['is_publish'] == 1 ): ?>
                                checked="checked"
                            <?php endif; ?>
                               onclick="choose_fun(<?=  $item['activity_id'] ?>,<?= $key?>)" />
                        <label for="male.<?= $key ?>" class="choose-label"></label>
                </td>
                <td class="am-text-middle"><?= $item['activity_status'] ?></td>
                <td class="am-text-middle">
                    <?php if($item['activity_type'] == 1): print_r($item['target_money']); endif; ?>
                    <?php if($item['activity_type'] == 2): print_r('无'); endif; ?>
                </td>
                <td class="am-text-middle"><?= $item['sum_price'] ?></td>
                <td class="am-text-middle">

                    <div class="tpl-table-black-operation">
                        <?php if (checkPrivilege('content.activity/edit')): ?>
                            <a href="#"  onclick="editbtn_fun(<?=  $item['activity_id'] ?>,<?= $key ?>);">
                                <i class="am-icon-pencil"></i> 编辑
                            </a>
                        <?php endif; ?>
                        <?php if (checkPrivilege('content.activity/delete')): ?>
                            <a href="#" class="item-delete tpl-table-black-operation-del" onclick="deletebtn_fun(<?=  $item['activity_id'] ?>,<?= $key ?>,this);">
                                <i class="am-icon-trash"></i> 删除
                            </a>
                        <?php endif; ?>
                        <div id="btn6" style="data-clipboard-text="1"></div>
                        <button style="margin-top:4%" class="button" data-clipboard-text="<?php if($item['activity_type'] == 1 ): ?>/pages/activityDetails/activityDetails?activity_id=<?=  $item['activity_id'] ?>&activity_type=1<?php endif; ?><?php if($item['activity_type'] == 2 ): ?>/pages/activityDetails/activityDetails?activity_id=<?=  $item['activity_id'] ?>&activity_type=2<?php endif; ?>">
                            <i class="am-icon-copy"></i> 复制小程序地址
                        </button>
                    </div>

                </td>
            </tr>
        <?php endforeach; else: ?>
            <tr>
                <td colspan="12" class="am-text-center">暂无记录</td>
            </tr>
        <?php endif; ?>
        </tbody>
    </table>
</div>

jq代码

<script>
    //修改(如果发布状态不可修改)
    function editbtn_fun(activity_id,key) {
        var test= $(".chooseBtn").eq(key).is(":checked");
        if(test){
            layer.msg('发布状态不可修改');
            return false;
        }else{
            var data = {};
            data['activity_id'] = activity_id;
            window.location = "<?= url('content.activity/edit') ?>" + '&' + $.urlEncode(data);
            return false;
        }
    }
    //删除(如果是发布状态不可删除)
    function deletebtn_fun(activity_id,key,obj){
        var test= $(".chooseBtn").eq(key).is(":checked");
        if(test){
            layer.msg('发布状态不可删除');
            return false;
        }else{
            if(window.confirm('你确定要删除这项活动吗?')){
                $.ajax({
                    url: "<?= url('content.activity/delete') ?>",
                    type:"POST",
                    dataType: 'text',
                    data:{
                        activity_id:activity_id
                    },
                    dataType:"json",
                    success: function(data){
                        if(data === 1){
                            layer.msg("删除成功!");
                            var tr = obj.parentNode.parentNode.parentNode;
                            var tbody = tr.parentNode;
                            tbody.removeChild(tr);
                        }else{
                            layer.msg("删除失败!");
                        }
                    }
                })
            }
        }
    }
</script>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值