将请求接口获取的json数据在前端进行拼接渲染

 //我审批的
    $(function(){
       // $('#mypower').click(function(){
           // alert('kk')
            $("#mysend").removeClass("approve_BA_1red");//清空liCSS属性  
            $(this).addClass('approve_BA_1red');//选中li添加属性  
            $(".approve_BA_Y2_1").show();  
            $(".approve_BA_Y2_2").hide();
            var s_id = getCookie('s_id');
            var time = getTime();
            var sign = getSign([s_id,time]);
            $.ajax({
            type: "POST",
            url: api_url+"/power/mypower",
            data: {
                s_id:s_id,
                time:time,
                sign:sign,
            },
            dataType: "json",
            success: function(data){
                    if(data.code == 1){
                    //console.log(data.message);
                    //console.log(data.data);
                    //              填充内容
                var html = '';
                var con = data['data'];
                for(var i=0;i<con.length;i++){
                    html += '<div class="approve_BA_Y2_left">';
                    html += '<div class="approve_BA_left_1"  >';
                    html += '<div class="approve_L1"><img src="';
                    html += con[i]['sp_image'];
                    html += '"/></div>';
                    html+=' <div class="approve_L2" >';
                    html+=' <p>';
                    if(con[i]['sp_sptid']==1){
                        html+="入库出错";
                    }
                    if(con[i]['sp_sptid']==2){
                       html+="商品内耗";
                    }
                    if(con[i]['sp_sptid']==3){
                        html+="买手拒单";
                    }
                    if(con[i]['sp_sptid']==4){
                        html+="其他";
                    }
                    //html+=con[i]['sp_sptid'];
                    html+='</p>';
                    html+='<p>订单编号:<span>';
                    html+=con[i]['o_second_order_id'];
                    html+='</span></p>';
                    html+='<p>';
                    if(con[i]['sp_status']==0){
                        html+="未审批";
                    }
                    if(con[i]['sp_status']==1){
                        html+="已同意";
                    }
                    if(con[i]['sp_status']==2){
                        html+="未同意";
                    }


                    html+='</p>';
                    html+='</div>';
                    html+='<div class="approve_L3" >';


                    html+='<p>';
                    var date = new Date(con[i]['sp_create']*1000);
                    Y = date.getFullYear() + '-';
                    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
                    D = date.getDate() + ' ';
                    h = date.getHours() + ':';
                    m = date.getMinutes() + ':';
                    s = date.getSeconds(); 
                    html+="提交时间";
                    html+=Y+M+D;
                    html+='</p>';


                    html+='<p>';
                    var date = new Date(con[i]['sp_modified']*1000);
                    Y = date.getFullYear() + '-';
                    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
                    D = date.getDate() + ' ';
                    h = date.getHours() + ':';
                    m = date.getMinutes() + ':';
                    s = date.getSeconds(); 
                    html+="审批时间";
                    html+=Y+M+D;
                    html+='</p>';
                    html+='</div>';


                    if(con[i]['sp_status']==0){
                        html+='<div style="width:1.3rem;height:0.4rem;margin-left:1.5rem;margin-top:0.15rem;">';
                        html+='<button id="argree" style="margin-right:0.2rem;" onclick="argree(';
                        html+= con[i]['sp_id'];
                        html+= ')">同意</button>';


                        html+='<button id="argree" onclick="forbid(';
                        html+= con[i]['sp_id'];
                        html+= ')">拒绝</button>';
                        html+='</div>';


                    }
                    
                   html += '</div></div>';
                }
                $("#approve_BA_Y2_1").html(html);


                }else{
                    alert(data.message);
                   
                }
            }
        });  
        //})
    })

猜你喜欢

转载自blog.csdn.net/tianjingang1/article/details/80382656