/**
 * Created by MyPC on 2019/12/17.
 */

//构建养护关联CLD客户列表
function buildClientBySearch(data){
    var html='';
    $.each(data, function(k, v) {
        html+='<span data="'+ v.cidKey+'" ><div   class="card pointer-hover p-3 mb-3" data-toggle="tooltip" data-placement="bottom" title="点击关联该客户" data-original-title="点击关联该客户"> <div class="row">' +
            '<div class="col-1 pr-0">'+ v.clientname+'</div>' +
            '<div class="col-2 pr-0">'+ v.position+'</div>' +
            '<div class="col-2 pr-0">'+ v.telephone+'</div>' +
            '<div class="col-4 pr-0">'+ v.companyname+'</div></div> </div></span>';
    });
    return html;
}

//构建养护用户列表
function fnStructureCuringUser(data){
    var html='';
    $.each(data, function(k, v) {
        html+='<tr curingInfoEdi dataCid="'+setUndefined(v.client_id)+'" data='+setUndefined(v.ssoId)+' dataId="'+setUndefined(v._id)+'" data-toggle="modal" data-target="#detail">';
        html+='<td>'+setUndefined(v.mobile)+'</td>';
        html+='<td>'+setUndefined(v.company)+'</td>';
        html+='<td>'+setUndefined(v.clientInfo.clientname)+'</td>';
        html+='<td>'+setUndefined(v.clientInfo.companyname)+'</td>';
        
        html+='<td>'+setUndefined(v.latest_login)+'</td>';
        html+='<td>'+setUndefined(v.latest_usedName)+'</td>';
        html+='<td>'+setUndefined(v.online_newest)+'</td>';
        html+='<td>'+setUndefined(v.addtime)+'</td>';
        html+='<td>'+setUndefined(v.upgradeListName)+'</td>';
        
       
        html+='</tr>';
    });
    $('tbody[curingUser]').html(html);
    $('div[curingListBox]').show();
    $('p[upClientBox]').hide();
}



//构建养护用户信息
function buildCuringInfo(data){

    var html=' ' +
        ' <div class="form-header">' +
        ' <div class="d-flex justify-content-between"><span class="text-muted">通行账号</span></div> ' ;

    if(data.mobile==''){
        html+='<legend>'+setUndefined(data.email)+'</legend> ';
    }else{
        html+='<legend>'+setUndefined(data.mobile)+'</legend> ';
    }

    html+='</div><div class="cldform clearfix"> <div class="cldform-line"></div> <div class="cldform-item  cldform-item-half pr-3"> ' +
        '<div class="cldform-label">手机</div> <div class="cldform-control"> <div class="cldform-contarl-box cldform-contarl-textareabox cldform-contarl-blank">' +
        '<span>'+setUndefined(data.mobile)+'</span></div> </div> </div> <div class="cldform-item cldform-item-half pl-3"> ' +
        '<div class="cldform-label">邮箱</div> ' +
        '<div class="cldform-control"> <div class="cldform-contarl-box cldform-contarl-textareabox cldform-contarl-blank">' +
        '<span>'+setUndefined(data.email)+'</span></div></div>';

    html+='</div> <div class="cldform-line"></div> <div class="cldform-item"> ' +
        '<div class="cldform-label">称呼</div> <div class="cldform-control"> <div class="cldform-contarl-box cldform-contarl-textareabox cldform-contarl-blank"> ' +
        '<span>'+setUndefined(data.username)+'</span></div> </div> </div>';

    html+='<div class="cldform-line"></div> <div class="cldform-item cldform-item-half pr-3"> ' +
        '<div class="cldform-label">注册云版</div> <div class="cldform-control"> <div class="cldform-contarl-box cldform-contarl-textareabox cldform-contarl-blank">' +
        '<span>'+setUndefined(data.create_time)+'</span></div> </div> </div>';

    html+='<div class="cldform-line"></div> <div class="cldform-item cldform-item-half pr-3"> ' +
        '<div class="cldform-label">企业名称</div> <div class="cldform-control"> <div class="cldform-contarl-box cldform-contarl-textareabox cldform-contarl-blank">' +
        '<span>'+setUndefined(data.company)+'</span></div> </div> </div>';


    html+='<div class="cldform-item cldform-item-half pl-3"> ' +
        '<div class="cldform-label">企业地区</div> <div class="cldform-control"> <div class="cldform-contarl-box cldform-contarl-textareabox cldform-contarl-blank">' +
        '<span>'+setUndefined(data.province)+'</span></div> </div> </div> </div>';

    return html;
}

//构建养护升级产品信息
function buildCuringCompilation(data){
    var upMajorBoxHtml='';
    $.each(data.detail.compilationList, function(k, v) {
        upMajorBoxHtml+='<tr>';
        upMajorBoxHtml+='<td></td>';
        upMajorBoxHtml+='<td>'+ v.name+'</td>';
        upMajorBoxHtml+='<td>';
        if(v.isUpgrade !== undefined && v.isUpgrade === true){
            upMajorBoxHtml+='已升级';
        }else{
            upMajorBoxHtml+='<a onclick=upCuring("'+ v.name+'","'+ v._id+'","'+data.detail.userInfo.username+'")  ' +
                'href="#update-confirm"  class="btn btn-xs btn-outline-primary waves-effect waves-themed" data-toggle="modal" data-target="#update-confirm">升级</a>';
        }
        upMajorBoxHtml+='</td>';
        upMajorBoxHtml+='</tr>';
    });
    $('#curingSsoid').val(data.detail.userInfo.ssoIdKey);
    $('#curingMobile').val(data.detail.userInfo.mobile);
    $('#client_id').val(data.detail.clientInfo.cidKey);

    return upMajorBoxHtml;
}

//关联CLD客户
function relevanceClient(data){
    var html='';
    if(isExistence(data)){
        html=buildClient(data);
    }else{
        html='<div class="form-header mt-3"> <div class="d-flex justify-content-between"><span class="text-muted">CLD客户</span><span class="text-muted"></span></div> <div class="text-center">' +
            '<a href="#linkcld" class="btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#linkcld"><i class="far fa-link"></i> 关联CLD客户</a></div> </div>';
    }
    return html;
}

function buildCuringOperateLog(data){

    var html='';
    if(isExistence(data)){
        $.each(data, function(k, v) {
            html+='<p>' +
                '<a href="#">@'+ v.username+'</a>' +
                ' '+ v.operation+'<br>' +
                '<span class="text-muted">'+ v.createDate+'</span></p></p> ';
        });
    }else{
        html='';
    }
    html+='';
    return html;
}

function autoHeight(){
    html='<script type="text/javascript">autoFlashHeight();console.log("sdfsdf")</script> <script type="text/javascript">$(".slimScroll1").slimScroll({position: \'right\', height:\'auto\' , railVisible: true}); </script> <script type="text/javascript">        $(".slimScrol2").slimScroll({            position: \'right\',            height:\'auto\' ,            railVisible: true        });</script>    <script type="text/javascript">        $(".slimScrol3").slimScroll({            position: \'right\',            height:\'auto\' ,            railVisible: true});</script> <script type="text/javascript"> $(".slimScrol4").slimScroll({position: \'right\', height:\'auto\' , railVisible: true});</script>'
    $('div[autoHeight]').html(html);

}
