layui上传文件(通过class='layui-btn layui-btn-sm uploadBtn file2_"+i+"')

================================================================================================

回显数据:

for(var k = 0;k < bonusList.length; k++) {
    var bonus  = bonusList[k];
    i += 1;
    var tablestr = "";
    tablestr += "<tr id=\"tr_bonus_"+i+"\">";
    tablestr += "<input type=\"hidden\" value="+i+" name=\"bonus\"/>";
    tablestr += "<td style='width: 15.2%!important;'><input type=\"text\" id=\"bonusYears"+i+"\" name=\"bonusYears\" class=\"form-control\"" +
        "placeholder=\"分红年限\"></td>";
    tablestr += "<td style=\"text-align: center; vertical-align: middle; width: 100px; \">";
    tablestr += "  <span class=\"editable-container editable-inline\" style=\"\"> ";
    tablestr += "     <div> ";
    tablestr += "        <form class=\"form-inline editableform form-nowidth\" style=\"\"> ";
    tablestr += "           <div class=\"control-group\">";
    tablestr += "              <div>";
    tablestr += "                 <div class=\"editable-input\">";
    tablestr += "<select   lay-ignore id=\"bonusUnitType"+i+"\"  οnchange=\"lianCha(this.id)\" class=\"form-control input-sm\">";
    tablestr += "<option value=''>请选择</option>";
    for(var j= 0;j<unitTypeList.length;j++) {
        var  UnitType = unitTypeList[j];
        tablestr += "<option value=\""+UnitType.unit_type_id+"\">"+UnitType.unit_type_name+"</option>";
    }
    tablestr += "                    </select>";
    tablestr += "                 </div>";
    tablestr += "              </div>";
    tablestr += "           </div>";
    tablestr += "        </form>";
    tablestr += "     </div>";
    tablestr += "  </span>";
    tablestr += "</td>";

    tablestr += "<td style=\"text-align: center; vertical-align: middle; width: 100px; \">";
    tablestr += "  <span class=\"editable-container editable-inline\" style=\"\"> ";
    tablestr += "     <div> ";
    tablestr += "        <form class=\"form-inline editableform form-nowidth\" style=\"\"> ";
    tablestr += "           <div class=\"control-group\">";
    tablestr += "              <div>";
    tablestr += "                 <div class=\"editable-input\">";
    tablestr += "                    <select   lay-ignore class=\"form-control input-sm\" id=\"investUnit"+i+"\">";
    tablestr += "<option value=''>请选择</option>";
    tablestr += "                    </select>";
    tablestr += "                 </div>";
    tablestr += "              </div>";
    tablestr += "           </div>";
    tablestr += "        </form>";
    tablestr += "     </div>";
    tablestr += "  </span>";
    tablestr += "</td>";
    tablestr += "<td><input   type=\"text\" id=\"investment"+i+"\" name=\"investment\" class=\"form-control\"" +
        "placeholder=\"投资金额\"></td>";
    tablestr += "<td><input  type=\"text\" id=\"bonusPrec"+i+"\" name=\"bonusPrec\" class=\"form-control\"" +
        "placeholder=\"分红比例\"></td>";
    if(bonus.agreementName == undefined){
        tablestr += "<td id=\"fileDiv"+i+"\">";
        tablestr += "<button type='button'  οnclick=\"fileupload('"+i+"')\" class='layui-btn layui-btn-sm uploadBtn file_"+i+"' >";
        tablestr += "<i class='layui-icon'>&#xe67c;</i>分红协议附件";
        tablestr += "</button>"
        tablestr += "</td>";
    }else{
        tablestr += "<td style='width: 15.2%!important;'><input   type=\"hidden\" id=\"bonusAgreement"+i+"\" value="+bonus.bonusAgreement+" class=\"form-control\" ><a target=\"_blank\" href="+bonus.agreementUrl+">"+bonus.agreementName+"</a></td>";
    }
    if(bonus.annexName == undefined){
        tablestr += "<td id=\"fileDiv2"+i+"\">";
        tablestr += "<button type='button' οnclick=\"fileupload('"+i+"')\" class='layui-btn layui-btn-sm uploadBtn file2_"+i+"' >";
        tablestr += "<i class='layui-icon'>&#xe67c;</i>分红票据附件";
        tablestr += "</button>";
        tablestr += "</td>";
    }else{
        tablestr += "<td style='width: 15.2%!important;'><input   type=\"hidden\" id=\"bonusBill"+i+"\" value="+bonus.bonusBill+" class=\"form-control\" ><a target=\"_blank\" href="+bonus.annexUrl+">"+bonus.annexName+"</a></td>";
    }
    tablestr += "<td>";
    tablestr += "<a class=\"layui-btn layui-btn-mini layui-btn-primary\" οnclick=\"gofenHBody('"+i+"')\">";
    tablestr += "删除</a></td>";
    tablestr += "</tr>";
    $("#fenHBody1").append(tablestr);
    $("#bonusYears"+i).val(bonus.bonus_years);
    $("#bonusPrec"+i).val(bonus.bonus_prec);
    $("#bonusUnitType"+i).val(bonus.bonus_unit_type);
    $("#investUnit"+i).val(bonus.bonus_unit_id);
    $("#investment"+i).val(bonus.investment);
    var bonusUnitTypeid = "bonusUnitType"+i  ;
    var bonus_unit_id = bonus.bonus_unit_id  ;
    var investUnitDiv = "#investUnit"+i  ;
    var selectId = bonusUnitTypeid.substring(13, bonusUnitTypeid.length);
    var unit_class = $("#" + bonusUnitTypeid).val();
    $.ajax({//查询投资单位参数表
        url: "../project/investUnit",
        type: "POST",
        data: {"unit_class": unit_class},
        dataType: "json",
        async: false,
        success: function (data) {
            $("#investUnit" + selectId).empty();
            var tablestr = "<option>请选择</option>";
            for (var j = 0; j < data.investUnitList.length; j++) {
                var investUnit = data.investUnitList[j];
                tablestr += "<option value=\"" + investUnit.in_unit_id + "\">" + investUnit.in_unit_name + "</option>";
            }
            $("#investUnit" + selectId).append(tablestr)
            $(investUnitDiv).val(bonus_unit_id);
            form.render();
        }
    });
    upload.render({
        elem: '.file_'+i
        ,url: '../file/fileUpload'
        ,method: 'post'
        ,done: function(res){ //上传后的回调
            if(res.msg=='1'){
                layer.msg("上传成功");
                console.log(res.file_name)
                addUpoloadTr(res.file_name,res.file_url,1);
            }else{
                layer.msg("上传失败");
            }
        }
        ,accept: 'file' //允许上传的文件类型
    })

    upload.render({
        elem: '.file2_'+i
        ,url: '../file/fileUpload'
        ,method: 'post'
        ,done: function(res){ //上传后的回调
            if(res.msg=='1'){
                layer.msg("上传成功");
                console.log(res.file_name)
                addUpoloadTr(res.file_name,res.file_url,2);
            }else{
                layer.msg("上传失败");
            }
        }
        ,accept: 'file' //允许上传的文件类型
    })

}

 

==================================================================================== 

添加一行操作: 

function fenHong(){
    i += 1;
    var tablestr = "";
    tablestr += "<tr id=\"tr_bonus_"+i+"\">";
    tablestr += "<input type=\"hidden\" value="+i+" name=\"bonus\"/>";
    tablestr += "<td style='width: 15.2%!important;'><input type=\"text\" id=\"bonusYears"+i+"\" name=\"bonusYears\" class=\"form-control\"" +
        "placeholder=\"分红年限\"></td>";
    tablestr += "<td style=\"text-align: center; vertical-align: middle; \">";
    tablestr += "  <span class=\"editable-container editable-inline\" style=\"\"> ";
    tablestr += "     <div> ";
    tablestr += "        <form class=\"form-inline editableform form-nowidth\" style=\"\"> ";
    tablestr += "           <div class=\"control-group\">";
    tablestr += "              <div>";
    tablestr += "                 <div class=\"editable-input\">";
    tablestr += "                    <select lay-ignore id=\"bonusUnitType"+i+"\" οnchange=\"lianCha(this.id)\"   class=\"form-control input-sm\">";
    tablestr += "                               <option value=''>请选择</option>";
    for(var j= 0;j<unitTypeList.length;j++) {
        var  UnitType = unitTypeList[j];
        tablestr += "<option value=\""+UnitType.unit_type_id+"\">"+UnitType.unit_type_name+"</option>";
    }
    tablestr += "                    </select>";
    tablestr += "                 </div>";
    tablestr += "              </div>";
    tablestr += "           </div>";
    tablestr += "        </form>";
    tablestr += "     </div>";
    tablestr += "  </span>";
    tablestr += "</td>";
    tablestr += "<td style=\"text-align: center; vertical-align: middle; width: 100px; \">";
    tablestr += "  <span class=\"editable-container editable-inline\" style=\"\"> ";
    tablestr += "     <div> ";
    tablestr += "        <form class=\"form-inline editableform form-nowidth\" style=\"\"> ";
    tablestr += "           <div class=\"control-group\">";
    tablestr += "              <div>";
    tablestr += "                 <div class=\"editable-input\">";
    tablestr += "                    <select lay-ignore class=\"form-control input-sm\" id=\"investUnit"+i+"\">";
    tablestr += "                               <option value=''>请选择</option>";
    tablestr += "                    </select>";
    tablestr += "                 </div>";
    tablestr += "              </div>";
    tablestr += "           </div>";
    tablestr += "        </form>";
    tablestr += "     </div>";
    tablestr += "  </span>";
    tablestr += "</td>";
    tablestr += "<td style='width: 15.2%!important;'><input type=\"text\" id=\"investment"+i+"\" name=\"investment\" class=\"form-control\"" +
        "placeholder=\"投资金额\"></td>";
    tablestr += "<td style='width: 15.4%!important;'><input type=\"text\" id=\"bonusPrec"+i+"\" name=\"bonusPrec\" class=\"form-control\"" +
        "placeholder=\"分红比例\"></td>";
    tablestr += "<td id=\"fileDiv"+i+"\">";
    tablestr += "<button type='button'  οnclick=\"fileupload('"+i+"')\" class='layui-btn layui-btn-sm uploadBtn file_"+i+"' >";
    tablestr += "<i class='layui-icon'>&#xe67c;</i>分红协议附件";
    tablestr += "</button>"
    tablestr += "</td>";
    tablestr += "<td id=\"fileDiv2"+i+"\">";
    tablestr += "<button type='button' οnclick=\"fileupload('"+i+"')\" class='layui-btn layui-btn-sm uploadBtn file2_"+i+"' >";
    tablestr += "<i class='layui-icon'>&#xe67c;</i>分红票据附件";
    tablestr += "</button>";
    tablestr += "</td>";
    tablestr += "<td>";
    tablestr += "<a class=\"layui-btn layui-btn-mini layui-btn-primary\" οnclick=\"goDelBonus('"+i+"')\">";
    tablestr += "删除</a></td>";
    tablestr += "</tr>";
    $("#fenHBody1").append(tablestr);
    upload.render({
        elem: '.file_'+i
        ,url: '../file/fileUpload'
        ,method: 'post'
        ,done: function(res){ //上传后的回调
            if(res.msg=='1'){
                layer.msg("上传成功");
                console.log(res.file_name)
                addUpoloadTr(res.file_name,res.file_url,1);
            }else{
                layer.msg("上传失败");
            }
        }
        ,accept: 'file' //允许上传的文件类型
    })

    upload.render({
        elem: '.file2_'+i
        ,url: '../file/fileUpload'
        ,method: 'post'
        ,done: function(res){ //上传后的回调
            if(res.msg=='1'){
                layer.msg("上传成功");
                console.log(res.file_name)
                addUpoloadTr(res.file_name,res.file_url,2);
            }else{
                layer.msg("上传失败");
            }
        }
        ,accept: 'file' //允许上传的文件类型
    })
}

 

var uploadList = [];
function addUpoloadTr(file_name,file_url,type) {
    var uploadObject = new Object();
    uploadObject['parentId'] = parentId;
    uploadObject['annexName'] = file_name;
    uploadObject['fileUrl'] = file_url;
    //1是分红协议附件 2是分红票据附件
    uploadObject['type'] = type;
    if(type ==1 ){
        $("#fileDiv"+parentId).empty();
        var tablestr = "";
        tablestr += "<input type=\"text\" disabled value='"+file_name+"' class=\"form-control\">";
        $("#fileDiv"+parentId).append(tablestr);
    }
    if(type ==2 ){
        $("#fileDiv2"+parentId).empty();
        var tablestr = "";
        tablestr += "<input type=\"text\" disabled value='"+file_name+"' class=\"form-control\">";
        $("#fileDiv2"+parentId).append(tablestr);
    }
    uploadList.push(uploadObject);
}
var parentId ;
function fileupload(v){
    parentId = v
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值