art-template 弹出上传多图

主内容

<script id="img-show-tpl" type="text/html">
<div>
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <!--<div class="panel-heading">-->
                        <!--上传图片凭证-->
                    <!--</div>-->
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="table-responsive col-lg-10">
                            <form class="form-horizontal addForm" method="post" action="save_cert" name="form1" id="save_cert_form" enctype="multipart/form-data">
                                <input name="order_num" value="{{ data.order_num }}" hidden="hidden">
                                <input name="identify" value="{{ data.identify }}" hidden="hidden">
                                <div class="form-group col-lg-12">
                                    <label class="control-label col-lg-4"></label>
                                    <label class="col-lg-5 text-left">凭证图</label>
                                    <label class="control-label col-lg-1">
                                        <button type="button" class="btn btn-xs btn-danger add-img">添加凭证图</button>
                                    </label>
                                </div>

                                <div class="form-group col-lg-10 main_list" id="cert-content">
                                </div>

                                <div class="form-group col-lg-12">
                                    <div class="col-lg-2 col-lg-offset-3">
                                        <button type="button" class="btn btn-primary col-lg-8" id="add_btn">保存</button>
                                    </div>

                                    <div class="col-lg-2">
                                        <button type="button" class="btn btn-danger col-lg-8" id="cancel_btn">取消</button>
                                    </div>
                                    <div class="clear"></div>
                                </div>

                            </form>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
        </div>
    </div>
</div>
</script>

单元内容

<script id="img-module-tpl" type="text/template">
    {{ if data.is_new }}
    <div class="list">
        <input type="hidden" name="cert_id[]"/>
        <label class="control-label col-lg-3"></label>
        <span class="control-label col-lg-8 text-left">
                <span class="input-group file-caption-main col-lg-8" style="float: left;">
                    <div class="form-control file-caption kv-fileinput-caption" style="text-align:left;overflow: hidden;line-height: 23px;">
                    凭证图不限尺寸
                    </div>

                    <input style="display: none;width:0px;border:1px solid #ff99ff;" class="file-real for-add" name="cert_img[]" type="file" multiple="" />

                    <div class="input-group-btn file-btn">
                        <div class="btn btn-primary btn-file for-cert-img">
                            <i class="glyphicon glyphicon-folder-open"></i>&nbsp;
                            <span class="hidden-xs">凭证图</span>
                        </div>
                    </div>
                </span>
                <span class="col-lg-3 erbi-form-right">
                    (请上传图片)
                </span>
            </span>

        <label class="control-label col-lg-1 del-btn">
            <button type="button" class="btn btn-xs btn-danger del-img">删除</button>
        </label>
    </div>
    {{ else }}
    {{ each data.list }}
    <div class="list">
        <input type="hidden" name="cert_id[]" value="{{ $value.id }}"/>
        <label class="control-label col-lg-3"></label>
        <span class="control-label col-lg-8 text-left">
                    <span class="input-group file-caption-main col-lg-8" style="float: left;">
                        <div class="form-control file-caption kv-fileinput-caption" style="text-align:left;overflow: hidden;line-height: 23px;">
                        凭证图不限尺寸
                        </div>

                        <input style="display: none;width:0px;border:1px solid #ff99ff;" class="file-real for-edit" name="cert_img_{{ $value.id }}" type="file" multiple=""  />

                        <div class="input-group-btn file-btn">
                            <div class="btn btn-primary btn-file for-cert-img">
                                <i class="glyphicon glyphicon-folder-open"></i>&nbsp;
                                <span class="hidden-xs">凭证图</span>
                            </div>
                        </div>
                    </span>

                    <span class="col-lg-3 erbi-form-right">
                        <a href="{{ $value.img_url }}" target="_blank">点击查看</a>
                    </span>
                </span>

        <label class="control-label col-lg-1 del-btn">
            <button type="button" class="btn btn-xs btn-danger del-img">删除</button>
        </label>
    </div>
    {{ /each }}
    {{ /if }}

</script>

展示内容

$(".info_upload_cert").on('click',function () {
    let identify = $(this).data('identify');
    let order_num = $(this).parent().data('num');
    let desc = $(this).data('desc');
    $.ajax({
        type: 'POST',
        url: 'ajaxGetCert',
        data: {identify: identify, order_num: order_num ,  more:1},
        dataType: 'json',
        success: function (data) {
            if (data.errno == 0) {
                // 设置主内容
                let show_html = template('img-show-tpl',{data:{identify:identify,order_num:order_num}});
                layer.open({
                    title: desc,
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['1200px', '600px'], //宽高
                    content: show_html
                });
                // 设置单元内容
                let module_html = template('img-module-tpl', {data:{is_new:false,list:data.data}});
                $('#cert-content').html(module_html);
            } else {
                alert(data.errdesc);
                return false;
            }
        }
    });
});

添加,删除,提交

$(document).on('click','.add-img',function(){
    var length = $('.main_list .list').length;
    if(length <= 5){
        let html = template('img-module-tpl', {data:{is_new:true}});
        $('#cert-content').append(html);
    }else{
        layer.msg('最多只可以添加6个!');
        return false;
    }
});

$(document).on('click','.del-img',function(){
    if(confirm('确定要删除吗')){
        $(this).parent().parent().remove();
    }
});

$(document).on('click','#cancel_btn',function(){
    layer.closeAll();
});

$(document).on('click','#add_btn',function(){
    $("#save_cert_form").ajaxForm({
        dataType: "json",
        success : function(obj){
            if(obj.errno == 0){
                layer.msg('已保存');
                setTimeout(function() {
                    layer.closeAll();
                    window.location.reload();
                },1000);
            }else{
                layer.msg(obj.errdesc);
            }
            return false;
        }
    });

    $("#save_cert_form").submit();
    return false;
});

接口

/**
 * 获取凭证
 */
public function ajaxGetCert() {
    $identify = $_POST['identify'];
    $order_num =  $_POST['order_num'];
    if (!$identify) {
        $this->json->E('缺少参数',10001);
    }
    if (!$order_num) {
        $this->json->E('缺少参数',10002);
    }
    $more = $_POST['more'] ? true : false ;
    $cert_list = OrderService::getCert($order_num,$identify,$more);
    $this->json->S($cert_list);
}

/**
 * 上传凭证
 */
public function save_cert() {
    if (!$identifyStr = $_POST['identify']) {
        $this->json->E('缺少参数identify');
    }

    if (!$order_num = $_POST['order_num']) {
        $this->json->E('缺少参数order_num');
    }
    $identify = OrderService::getIdentifyByStr($identifyStr)['identify'];
    $type = OrderService::getIdentifyByStr($identifyStr)['type'];
    $temp_cert_id = $_POST['cert_id'];
    if (count($temp_cert_id) === 0) {
        $this->json->E('请上传凭证');
    }

    M()->startTrans();
    // 先删除凭证
    $order_cert = M('order_cert');
    $order_cert->where(['order_num'=>$order_num,'identify'=>$identify])->save(['status'=>0]);

    $temp_all_file = $_FILES;
    $temp_new_file = $_FILES['cert_img'];
    unset($_FILES);
    $cursor_new = 0;
    foreach ($temp_cert_id as $k=>$v) {
        // 重置$data数据
        $data = [];
        if ($v) { // 修改
            // 可能传图,也可能未传图
            if ($temp_all_file['cert_img_'.$v]) { // 传图了
                $_FILES['cert_img'] = $temp_all_file['cert_img_'.$v];
                $file = $this->upload(1,0,0,'cert_img','cert_img');
                $data['img_url'] = $file['save_name'];
                if(!$data['img_url']) {
                    M()->rollback();
                    $this->json->E('图片上传失败',10001);
                }
            }
            $data['status'] = 1;
            $edit_flag = $order_cert->where(['id'=>$v])->save($data);
            if (!$edit_flag && $edit_flag !==0 ) {
                M()->rollback();
                $this->json->E('凭证更新失败',10002);
            }

        } else { // 新增,变更游标
            $file_up = array();
            $file_up['name'] = $temp_new_file['name'][$cursor_new];
            $file_up['type'] = $temp_new_file['type'][$cursor_new];
            $file_up['tmp_name'] = $temp_new_file['tmp_name'][$cursor_new];
            $file_up['error'] = $temp_new_file['error'][$cursor_new];
            $file_up['size'] = $temp_new_file['size'][$cursor_new];
            $_FILES['cert_img'] = $file_up;

            $file = $this->upload(1,0,0,'cert_img','cert_img');
            $data['img_url'] = $file['save_name'];

            if(!$data['img_url']) {
                M()->rollback();
                $this->json->E('图片上传失败',10001);
            }

            $data['order_num'] = $order_num;
            $data['identify'] =  $identify;
            $data['type'] =  $type;
            $data['status'] = 1;
            $data['create_time'] = time();
            $add_flag = $order_cert->add($data);
            if (!$add_flag) {
                M()->rollback();
                $this->json->E('凭证添加失败',10002);
            }
            unset($_FILES, $file_up);
            $cursor_new ++;
        }
    }

    // 设置凭证为已上传
    $order = M('order');
    $save_order_flag = $order->where(['order_num'=>$order_num])->save([$identifyStr=>'1']);
    if ($save_order_flag !== false) {
        M()->commit();
        $this->json->S('操作成功');
    } else {
        M()->rollback();
        $this->json->E('修改订单数据失败',10003);
    }
}

原文地址:https://www.cnblogs.com/jiqing9006/p/11155839.html

时间: 2024-10-18 04:32:37

art-template 弹出上传多图的相关文章

js实现点击按钮弹出上传文件的窗口

转自:https://www.jb51.net/article/100916.htm 1.详细描述 在页面上设置一个"选择文件"按钮,点击该按钮,会弹出本地磁盘信息用于选择文件. 2.代码 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>

后台模拟弹出上传匡

FileInfo fi = new FileInfo(fileName);//excelFile为文件在服务器上的地址                    HttpResponse contextResponse = HttpContext.Current.Response;                    contextResponse.Clear();                    contextResponse.Buffer = true;                 

HTML+js+css实现点击图片弹出上传文件窗口的两种思路

第一种:CSS实现 <style><!-- .fileInputContainer{        height:256px;        background:url(upfile.png);        position:relative;        width: 256px;    }    .fileInput{        height:256px;        overflow: hidden;        font-size: 300px;        po

帝国CMS7.2新增多图同时上传插件,上传多图效率更高

原来上传多图文件,需要挨个选择文件,然后再点批量上传,比较麻烦.所以帝国CMS7.2新增了多图上传插件:为采用FLASH方式实现同时选择多个图片一起上传,提高多图上传效率. 帝国CMS多图上传插件特性如下: 1.采用FLASH方式实现同时选择多个图片一起上传. 2.多图插件安装后,在以下3个地方可以使用: (1).信息上传图片时; (2).图集字段morepic上传图片时; (3).编辑器多图片上传时. 3.上传图片后显示格式采用单独模板文件,用户可自行修改返回格式模板文件,很个性化. 4.本插

【Android源码解析】--选择多张图片上传多图预览

最近做了选择多图并且上传服务器,在网上找了一些demo,适当的做了一下调整,用过了不能忘记,记下来以后还能多看看,本人觉得自己的博客有些渣渣,还希望大家不要介意啊,哪里有错误希望大家及时指正. 好了下面具体的分析一下:(想要做出功能,需求分析是必不可少的,需求.逻辑弄懂了再上手写代码,思路会很清晰的) 1.多图上传首先得选择图片(这里项目需求是既可以拍照上传也可以从相册中选择) 2.拍照上传很简单了网上也有很多例子,调用照相机,返回uri,获取图片 3.从相册中选择图片 3.1 获取手机中的所有

微信JSSDK上传多图预览,点击查看大图

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no"> <meta name="ap

微信JSSDK上传图片,代码为上传单张图

HTML端 //这里需要注意的是,千万不要把onclick放到input file上 <div class="load_box"> <img src="ajax返回显示的图片,初始化可以设置个默认的URL" alt="" id="img1" class="star" style="height:142px;" onclick="chooseImage('fil

asp.net页面后退,重复弹出上一页对话框处理办法

我们在实例中,虽然页面内有导航,但是用户使用的时候难免会使用浏览器的后退按钮. 时常会发现,当后退的时候,上一页的对话框会自动弹出,下面是解决办法. 问题:使用此js代码,后退按钮时,重复显示对话框内容 ClientScript.RegisterClientScriptBlock(GetTypr(),"alert('不能重复提交');",true); 解决办法: ClientScript.RegisterClientScriptBlock(GetTypr(),"alert('

HDFS文件系统上传时序图 PB级文件存储时序图

自己设计的时序图. 来自为知笔记(Wiz)