function changeTypeTo_rank(type) {
    changeTypeTo_buildRank(type)
}
function initReward_rank(type) {
    return initReward_buildRank(type)
}
function changeTypeTo_buildRank(type) {
    $("#reward_info").empty();
    initbuildRankWrap()
}
function initbuildRankWrap(){
    var html = '';
    //分值配置初始化
    // 收集积分配置
    var data = {"confType":1,"groupId":1,"attack_break":0,"attack_success":0,"steal_break":0,"steal_success":0,"one_hit":0,"two_hit":0,"three_hit":0,"one_attack":0,"two_attack":0,"one_steal":0,"two_steal":0};

    if(['build_rank', 'build_rank2'].includes(act_type))$("#reward_info").append(buildRankScoreSetting());
    else $("#reward_info").append(addStagePro('rank', data));

    // 分阶段奖励配置
    $("#reward_info").append(buildRankStagesRewards());

    //分区配置
    if (['rank', 'rank2'].includes(act_type)) {
        $("#reward_info").append(buildRankRoomAllotConf());
    } else {
        $("#reward_info").append(buildRankVipSet());
    }

    //排行榜机器人配置
    $("#reward_info").append(buildRankRobot() );

    //排行榜人数限制配置
    $("#reward_info").append(buildRankLimit() );

}
function initReward_buildRank(type) {
    initbuildRankWrap()

    reward_conf && $(`input[name="buildScoreSetting[minScore]"]`).val(reward_conf.minScore)
    if(['build_rank', 'build_rank2'].includes(act_type)) {
        reward_conf && reward_conf.actionConfig && $.each(reward_conf.actionConfig, function(i, o){
            addBuildRankScoreSetting()
            $(`input[name="buildScoreSetting[actionConfig][${i}][minLv]"]`).val(o.minLv)
            $(`input[name="buildScoreSetting[actionConfig][${i}][maxLv]"]`).val(o.maxLv)
            $(`input[name="buildScoreSetting[actionConfig][${i}][singleGet][0]"]`).val(o.singleGet[0])
            $(`input[name="buildScoreSetting[actionConfig][${i}][singleGet][1]"]`).val(o.singleGet[1])
        })
    }else{
        let scoreTypes = ['attack_success','attack_break','steal_success','steal_break','three_hit']
        for(let scoreType of scoreTypes) {
            $(`input[name="${scoreType}"]`).val(reward_conf[scoreType])
        }

    }

    if (extraData) {
        var roomAllotConf = JSON.parse(extraData)['roomAllotConf']
        roomAllotConf && $.each(roomAllotConf, (lvIdx, item) => {
            $('#addBuildRankRoomAllotLvWrapBtn').click()
            $(`input[name="roomAllotConf[${lvIdx}][lvStart]"]`).val(item.lvStart)
            $(`input[name="roomAllotConf[${lvIdx}][lvEnd]"]`).val(item.lvEnd)

            $.each(item.stages, (stageKey, rewardItem) => {
                $('.addBuildRankRoomAllotSpinsTrBtn:last').click()

                $(`input[name="roomAllotConf[${lvIdx}][stages][${stageKey}][spinsStart]"]`).val(rewardItem.spinsStart)
                $(`input[name="roomAllotConf[${lvIdx}][stages][${stageKey}][spinsEnd]"]`).val(rewardItem.spinsEnd)
                $(`input[name="roomAllotConf[${lvIdx}][stages][${stageKey}][robotStop]"]`).val(rewardItem.robotStop)
            })
        })
    }

    console.log('reward_pro',reward_pro);
    reward_pro && $.each(reward_pro, function(i1, o1){
        $('.addBuildRankLvWrap:last').click()
        $(`input[name="buildRankConfig[${i1}][start]"]`).val(o1.start)
        $(`input[name="buildRankConfig[${i1}][end]"]`).val(o1.end)
        $.each(o1.stages, function(i2, o2){
            $('.addBuildRankSpinsWrap:last').click()
            $(`input[name="buildRankConfig[${i1}][stages][${i2}][start]"]`).val(o2.start)
            $(`input[name="buildRankConfig[${i1}][stages][${i2}][end]"]`).val(o2.end)

            $.each(o2.stages, function(i3, o3){
                $('.addBuildRankShushuWrap:last').click()
                $(`select[name="buildRankConfig[${i1}][stages][${i2}][stages][${i3}][shushu][]"]`).val(o3.shushu)

                o3.stages && o3.stages.stages && $.each(o3.stages.stages, function(i4, o4){
                    $('.addBuildRankStageRewardTr:last').click()
                    if(typeof o4.prize == 'string' )o4.prize=JSON.parse(unescape(o4.prize))
                    $(`input[name="buildRankConfig[${i1}][stages][${i2}][stages][${i3}][stages][stages][${i4}][stage]"]`).val(o4.stage)
                    $(`input[name="buildRankConfig[${i1}][stages][${i2}][stages][${i3}][stages][stages][${i4}][progressBarId]"]`).val(o4.progressBarId)
                    $(`input[name="buildRankConfig[${i1}][stages][${i2}][stages][${i3}][stages][stages][${i4}][stepnum]"]`).val(o4.stepnum)
                    $(`input[name="buildRankConfig[${i1}][stages][${i2}][stages][${i3}][stages][stages][${i4}][prize]"]`).val(escape(JSON.stringify(o4.prize)))
                    let prizeHtml = ''
                    o4.prize && $.each(o4.prize, function(ip,op){
                        prizeHtml += chestPropsHtml(op)
                    })
                    $('.showStagePrize:last').html(prizeHtml)
                })
                o3.stages && o3.stages.ranks && $.each(o3.stages.ranks, function(i4, o4){
                    if(typeof o4.prize == 'string' )o4.prize=JSON.parse(unescape(o4.prize))
                    $('.addBuildRankStageRankRewardTr:last').click()
                    $(`input[name="buildRankConfig[${i1}][stages][${i2}][stages][${i3}][stages][ranks][${i4}][rankPos]"]`).val(o4.rankPos)
                    $(`input[name="buildRankConfig[${i1}][stages][${i2}][stages][${i3}][stages][ranks][${i4}][prize]"]`).val(escape(JSON.stringify(o4.prize)))
                    let prizeHtml = ''
                    o4.prize && $.each(o4.prize, function(ip,op){
                        prizeHtml += chestPropsHtml(op)
                    })
                    $('.showStagePrize:last').html(prizeHtml)
                })
            })
        })
    })
    $('.select2').select2()
}

//==================阶段奖励==================
var spinShuShu_reward_limit=[];//体力数数分组单配置奖励行[spinIdx][shushuIdx]配置行数

//阶段奖励配置(第一维)
function commonStageTable() {
    var html ='';
    html+='<hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    html +='<div class="" id="commonStageTable" style="top:10px">';
    var str ='体力数数阶段奖励';
    html +='<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">'+str+'</h5></div>';

    html+='</div>';
    html+='<div class="form-group"><div class="col-sm-4 col-sm-offset-2">';
    html+='<button class="btn btn-primary" id="addSpinsAndShuShuSatgeBtn" type="button">添加</button>';
    html+='<button class="btn btn-white"   id="delSpinsAndShuShuSatgeBtn" type="button">删除</button>';
    html+='</div></div><hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    return html;
}
//阶段奖励配置体力数数表(第二维)html
function commonStageRewardConfTable(spinIdx,data) {
    var cols = 5;
    var html ='<div class="row commonStageRewardConf" id="reward_table_'+spinIdx+'">';

    html +='<table class="table table-bordered spinStageRewardTable">';
    html +='<thead><tr><td colspan="'+cols+'">';
    html +='<div class="form-group"><label class="col-sm-2 control-label m-b">体力区间 </label><div class="col-sm-3 input-group">';
    html +='<input type="text" style="text-align: center" class="form-control" name="spinStage['+spinIdx+'][start]" value="'+data['start']+'">';
    html +='<span class="input-group-addon">-</span>';
    html +='<input type="text" style="text-align: center" class="form-control" name="spinStage['+spinIdx+'][end]" value="'+data['end']+'">';
    html +='<tr><td colspan="'+cols+'"><botton class="btn btn-primary addShushuStage" spinIdx="'+spinIdx+'">添加数数分组层</botton>';
    html +='<botton class="btn btn-danger del-tr delShushuStage" spinIdx="'+spinIdx+'">删除数数分组层</botton></tr>';
    html +='</div></div>';
    html +='</td></tr>';
    html +='</table>';

    html +='</div>';
    return html;
}
//阶段奖励详情表(第三维)html
function commonStageRewardInfoTable(spinIdx,shushuIdx) {
    var cols =5;var cols2=4;
    var html ='<div class="form-group commonStageRewardInfoTable" id="reward_info_table_'+spinIdx+"_"+shushuIdx+'" style="margin:10px;padding:10px;border:solid 1px black;">';
    html +='<table class="table table-bordered ">';
    html +='<tr><th colspan="2">数数分组：</th>';
    html +='<th colspan="3"><select class="select2 col-sm-10 commonShuShuSelect" name="spinStage['+spinIdx+'][shushu]['+shushuIdx+'][]" multiple style="min-width:100px;">';
    $.each(shushuGroups, function(i,o){
        html += '<option value="'+i+'">'+o+'</option>'
    });
    html +="</select>";
    html += '<div class="ibox-title" style="border-top: 0;">';
    html +='</div>';
    html +='<td><tr>';
    html +='<tr><th>阶段</th>';
    html += '<th>进度条</th>';
    html +='<th>阶段值</th>';
    html +='<th>奖品</th><th>奖励设置</th></tr></thead>' ;
    html +='<tbody id="table_info_body_'+spinIdx+"_"+shushuIdx+'">';

    html +='</tbody><tr><td colspan="'+cols+'"><div class="text-center"><botton class="btn btn-primary" onclick="addbuildRankStageRewardNum('+spinIdx+','+shushuIdx+')">添加</botton><botton class="btn btn-danger del-tr" onclick="delbuildRankStageRewardNum('+spinIdx+','+shushuIdx+')">删除</botton>';
    html +='</div></td></tr>';
    html +='</table>';
    html +='</div>';
    return html;
}
//阶段奖励行html
function buildRankStageRewardTR(spinIdx,shushuIdx,data) {
    var stage = data['stage'];
    var prize = data['prize']!=undefined?JSON.stringify(data['prize']):'[]';
    var prize_show_arr = JSON.parse(prize);
    prize = escape(prize);
    var html ='';
    html+='<tr id="rewardInfo_'+data['stage']+'" class="commonStageRewardTr">';
    html +='<td><input type="text" class="form-control" name="rewardnew['+spinIdx+']['+shushuIdx+']['+data['stage']+'][stage]" value="'+data['stage']+'"></td>';
    html +='<td><input type="text" class="form-control" name="rewardnew['+spinIdx+']['+shushuIdx+']['+data['stage']+'][progressBarId]" value="'+data['progressBarId']+'"></td>';
    html +='<td><input type="text" class="form-control" name="rewardnew['+spinIdx+']['+shushuIdx+']['+data['stage']+'][stepnum]" value="'+data['stepnum']+'"></td>';
    html +='<td class=" prizeShow showStagePrize_'+spinIdx+'_'+shushuIdx+'_'+data['stage']+'">';
    if(prize_show_arr.length>0){
        for(var j=0;j<prize_show_arr.length;j++){
            html+= chestPropsHtml(prize_show_arr[j]);
        }

    }
    html+='</td>';
    html +='<input class="prizeInput" type="hidden" name="rewardnew['+spinIdx+']['+shushuIdx+']['+data['stage']+'][prize]" value="'+prize+'">';
    html +='<td><button type="button" class="btn btn-outline btn-success" onclick="setPrize(this,\'setCommonPrize\','+spinIdx+','+shushuIdx+')">奖励配置</button></td>';// data-toggle="modal"
    html +='</tr>';

    return html;
}
//新增阶段奖励行
function addbuildRankStageRewardNum(spinIdx,shushuIdx) {
    // console.log(spinIdx,shushuIdx);
    parentIdx = spinIdx+"_"+shushuIdx;
    if(!spinShuShu_reward_limit[parentIdx]){
        spinShuShu_reward_limit[parentIdx] =1;
    }else{
        spinShuShu_reward_limit[parentIdx]++;
    }
    var data ={"stage":spinShuShu_reward_limit[parentIdx],"stepnum":0,"progressBarId":0,"lv":1};
    var html = buildRankStageRewardTR(spinIdx,shushuIdx,data);
    // console.log(html);

    $("#table_info_body_"+parentIdx).append(html);
}
//删除阶段奖励行
function delbuildRankStageRewardNum(spinIdx,shushuIdx) {
    parentIdx = spinIdx+"_"+shushuIdx;
    if(spinShuShu_reward_limit[parentIdx]>0){
        // console.log(reward_limit);
        $("#table_info_body_"+parentIdx).children("tr:last-child").remove();
        spinShuShu_reward_limit[parentIdx]--;
    }
}


//==================机器人====================

function buildRankVipSet() {
    if($info['extraData'] != undefined && ($info['extraData']['setType'])){
        var setType =$info['extraData']['setType'];
    }else{
        var setType = 1;
    }

    var vipSetHiden = "";
    var html = '<div class="col-sm-12"><div class="form-group"><label class="col-sm-1 control-label">分区类型：</label><div class="col-sm-11"><div class="col-sm-4">' +
        '<select id="setType" class="form-control m-b" name="setType" >';
    let types = {1:'等级'};
    if(['rank2', 'rank'].includes(act_type)){
        // types = {1:'VIP积分', 2:'体力', 3:'过去4天体力消耗'};
        types = {  2:'体力'};
    }
    for(let i in types){
        let selected = ''
        if(i == setType)selected = 'selected';
        html += `<option  value="${i}">${types[i]}</option>`
    }
    html += '</select></div></div></div></div>';

    if($info && $info['extraData'] && ($info['extraData']['userLvSet'])){
        var arr = $info['extraData']['userLvSet'];
    }else{
        var arr = [0,1000,5000,10000,50000,100000];
    }

    html+='<div class="col-sm-12" id="vipSet" style="'+vipSetHiden+'"><div class="form-group"><label class="col-sm-1 control-label">分块:</label><div class="col-sm-11">';
    for(i=0;i<arr.length;i++){
        html+='<div class="col-sm-1" style="text-align: center"><input type="text" style="text-align: center" class="form-control" name="userLvSet['+i+']" value="'+arr[i]+'"></div>';
    }
    html+='</div></div>';
    if($info && $info['extraData'] && ($info['extraData']['userLvSetRobotStop'])){
        var vipSetSpins  = $info['extraData']['userLvSetRobotStop'];
    }else{
        var vipSetSpins  = [500,800,800,800,800,800];
    }

    html+='<div class="form-group"><label class="col-sm-1 control-label">机器人停止标准:</label><div class="col-sm-11">';
    for(i=0;i<vipSetSpins.length;i++){
        html+='<div class="col-sm-1" style="text-align: center">' +
            '<input type="text" style="text-align: center" class="form-control" name="userLvSetRobotStop['+i+']" value="'+vipSetSpins[i]+'">' +
            '</div>';
    }
    html+='</div></div>';
    html+='</div>';


    return html;
}

// 房间分区配置
function buildRankRoomAllotConf() {

    buildRankRoomAllotLvCnt = 0;
    buildRankRoomAllotStage = {};
    return `
        <div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">房间分区配置</h5></div>
        <div class="text-center" style="margin:5px;padding:5px;border:solid 1px lightgray;">
            <button style="margin-top: 20px" id="addBuildRankRoomAllotLvWrapBtn" class="btn btn-primary" onclick="addBuildRankRoomAllotLvWrap(this)" type="button">添加等级区间</button>
            <button style="margin-top: 20px" class="btn btn-danger" onclick="delBuildRankRoomAllotLvWrap()" type="button">删除等级区间</button>
        </div>`
}

function addBuildRankRoomAllotLvWrap(obj) {
    var lvIdx = buildRankRoomAllotLvCnt++

    buildRankRoomAllotStage[lvIdx] = 0
    var html = `
        <div class="buildRankRoomAllotLvWrap" id="buildRankRoomAllotlvWrap_${lvIdx}" data-idx="${lvIdx}" style="margin:10px;padding:5px;border:solid 1px goldenrod;">
            <table class="table table-bordered" >
                <thead>
                    <tr>
                        <td colspan="3">
                             <div class="form-group">
                                <label class="col-sm-1 control-label m-b">等级区间: </label>
                                <div class="col-sm-3 input-group">
                                    <input type="text" style="text-align: center" class="form-control" name="roomAllotConf[${lvIdx}][lvStart]" value="0">
                                    <span class="input-group-addon">-</span>
                                    <input type="text" style="text-align: center" class="form-control" name="roomAllotConf[${lvIdx}][lvEnd]" value="0">
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>体力下限</th>
                        <th>体力上限</th>
                        <th>机器人停止标准</th>
                    </tr>
                </thead>
                <tbody id="buildRankRoomAllotRewardBody_${lvIdx}"></tbody>
                <tr>
                    <td colspan="3">
                        <div class="text-center" style="margin-top: 20px">
                            <botton class="btn btn-primary addBuildRankRoomAllotSpinsTrBtn" onclick="addBuildRankRoomAllotRewardTr(this)">添加</botton>
                            <botton class="btn btn-danger del-tr" onclick="delBuildRankRoomAllotRewardTr(this)">删除</botton>
                        </div>
                    </td>
                </tr>
           </table>
        </div>`
    $(obj).before(html)
}

function delBuildRankRoomAllotLvWrap(obj) {
    if (buildRankRoomAllotLvCnt < 0) {
        return;
    }

    $('#buildRankRoomAllotlvWrap_' + (buildRankRoomAllotLvCnt - 1)).remove();
    buildRankRoomAllotLvCnt--;
}

function addBuildRankRoomAllotRewardTr(obj) {
    var lvIdx = $(obj).parents('.buildRankRoomAllotLvWrap').data('idx')
    var rewardStage = buildRankRoomAllotStage[lvIdx]++
    var rewardKey = lvIdx + '_' + rewardStage

    var html = `
        <tr class="buildRankRoomAllotRewardInfoTr" id="buildRankRoomAllotRewardInfo_${rewardKey}" data-idx="${rewardStage}">
            <td><input name="roomAllotConf[${lvIdx}][stages][${rewardStage}][spinsStart]" type="number" class="form-control" value="0"></td>
            <td><input name="roomAllotConf[${lvIdx}][stages][${rewardStage}][spinsEnd]" type="number" class="form-control" value="0"></td>
            <td><input name="roomAllotConf[${lvIdx}][stages][${rewardStage}][robotStop]" type="number" class="form-control" value="0"></td>
        </tr>`;

    $('#buildRankRoomAllotRewardBody_' + lvIdx).append(html)
}

function delBuildRankRoomAllotRewardTr(obj) {
    var lvIdx = $(obj).parents('.buildRankRoomAllotLvWrap').data('idx')
    var rewardKey = lvIdx + '_' + (buildRankRoomAllotStage[lvIdx] - 1)

    if (buildRankRoomAllotStage[lvIdx] < 0) return;
    $('#buildRankRoomAllotRewardInfo_' + rewardKey).remove()
    buildRankRoomAllotStage[lvIdx]--
}

//机器人配置
function buildRankRobot() {
    var html ='';
    html +='<div class="col-sm-6"><div class="form-group">';
    html +='<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">排行榜机器人配置</h5></div>';
    html +='<table class="table table-bordered">';
    html +='<thead><tr><th>ID</th><th>排名比例</th><th>排名值</th><th>系数A</th><th>系数B</th></tr></thead>' ;
    html +='<tbody id="table_body3">';
    var readPro = "";
    var readNum = "";
    var readCo = "";
    if($info['extraData'] != undefined && ($info['extraData']['robot'])){
        var json = $info['extraData']['robot'];
        $.each(json,function (i,data) {
            if(i > 4){
                readPro = "readonly"
            }
            if(i <= 4){
                readNum = "readonly"
            }
            if(i > 2){
                readCo = "readonly"
            }
            html +='<tr>'
                +'<td><input type="text" class="form-control" name="robot['+i+'][id]"  value="'+i+'"></td>'
                +'<td><input type="text" class="form-control" name="robot['+i+'][pro]" '+readPro+' value="'+data.pro+'"></td>'
                +'<td><input type="text" class="form-control" name="robot['+i+'][num]" '+readNum+' value="'+data.num+'"></td>'
                +'<td><input type="text" class="form-control" name="robot['+i+'][co1]" '+readCo+' value="'+data.co1+'"></td>'
                +'<td><input type="text" class="form-control" name="robot['+i+'][co2]" '+readCo+' value="'+data.co2+'"></td>'
                +'</tr>';
            readPro = '';
            readNum = '';
            readCo = '';
        });
    }else{
        for (var i=1;i<=10;i++){
            if(i > 4){
                readPro = "readonly"
            }
            if(i <= 4){
                readNum = "readonly"
            }
            if(i > 2){
                readCo = "readonly"
            }
            html +='<tr>'
                +'<td><input type="text" class="form-control" name="robot['+i+'][id]"  value="'+i+'"></td>'
                +'<td><input type="text" class="form-control" name="robot['+i+'][pro]" '+readPro+' value="0"></td>'
                +'<td><input type="text" class="form-control" name="robot['+i+'][num]" '+readNum+' value="0"></td>'
                +'<td><input type="text" class="form-control" name="robot['+i+'][co1]" '+readCo+' value="0"></td>'
                +'<td><input type="text" class="form-control" name="robot['+i+'][co2]" '+readCo+' value="0"></td>'
                +'</tr>';
            readPro = '';
            readNum = '';
            readCo = '';
        }

        html +='<tr>'
            +'<td><input type="text" class="form-control" name="robot[49][id]"  value="49"></td>'
            +'<td><input type="text" class="form-control" name="robot[49][pro]" readonly value="0"></td>'
            +'<td><input type="text" class="form-control" name="robot[49][num]"  value="0"></td>'
            +'<td><input type="text" class="form-control" name="robot[49][co1]" readonly value="0"></td>'
            +'<td><input type="text" class="form-control" name="robot[49][co2]" readonly value="0"></td>'
            +'</tr>';
    }
    html +='</tbody>';
    html +='</table></div></div>';
    return html;
}

//机器人配置
function buildRankLimit() {
    var html ='';
    html +='<div class="col-sm-6"><div class="form-group">';
    html +='<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">排行榜人数限制配置</h5></div>';
    html +='<table class="table table-bordered">';
    html +='<thead><tr><th>剩余小时数</th><th>房间人数</th></tr></thead>' ;
    html +='<tbody id="table_body3">';
    if($info['extraData'] != undefined && ($info['extraData']['rankLimit'])){
        var json = $info['extraData']['rankLimit'];
        $.each(json,function (i,data) {
            html +='<tr>' +
                '<td><input type="text" class="form-control" name="rankLimit['+i+'][time]" value="'+data.time+'"></td>' +
                '<td><input type="text" class="form-control" name="rankLimit['+i+'][limit]" value="'+data.limit+'"></td>' +
                '</tr>'
        });
    }else{
        html +='<tr><td><input type="text" class="form-control" name="rankLimit[0][time]" value="12"></td><td><input type="text" class="form-control" name="rankLimit[0][limit]" value="30"></td></tr>'
        html +='<tr><td><input type="text" class="form-control" name="rankLimit[1][time]"  value="6"></td><td><input type="text" class="form-control" name="rankLimit[1][limit]" value="40"></td></tr>'
        html +='<tr><td><input type="text" class="form-control" name="rankLimit[2][time]"  value="3"></td><td><input type="text" class="form-control" name="rankLimit[2][limit]" value="45"></td></tr>'
        html +='<tr><td><input type="text" class="form-control" name="rankLimit[3][time]"  value="1"></td><td><input type="text" class="form-control" name="rankLimit[3][limit]" value="50"></td></tr>'
    }
    html +='</tbody>';
    html +='</table></div></div>';
    return html;
}




//===================================================================================
// 积分配置
function buildRankScoreSetting(){
    return `<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">积分配置</h5></div>
    <table class="table table-bordered ">
        <thead>
            <th>上榜门槛积分</th>
            <th><input name="buildScoreSetting[minScore]"></th>
        </thead>
        
    </table>
        
    <table class="table table-bordered ">
        <thead>
            <th>等级区间</th>
            <th>建造积分</th>
            <th>修复积分</th>
        </thead>
        <tbody id="buildRankScoreSettingTBody">
        </tbody>
        <tr>
            <td colspan="3">
                <button type="button" class="btn btn-outline btn-success addBuildRankScoreSetting" onclick="addBuildRankScoreSetting()">添加</button>
                <button type="button" class="btn btn-outline btn-danger  delBuildRankScoreSetting" onclick="delBuildRankScoreSetting()">删除</button>
            </td>
        </tr>
    </table>`;
}
function addBuildRankScoreSetting(){
    let curCnt = $('#buildRankScoreSettingTBody').find('tr').length
    let html = `
            <tr>
                 <td>
                    <input name="buildScoreSetting[actionConfig][${curCnt}][minLv]">-
                    <input name="buildScoreSetting[actionConfig][${curCnt}][maxLv]">
                 </td>           
                 <td><input name="buildScoreSetting[actionConfig][${curCnt}][singleGet][0]"></td>           
                 <td><input name="buildScoreSetting[actionConfig][${curCnt}][singleGet][1]"></td>           
            </tr>`
    $('#buildRankScoreSettingTBody').append(html)
}
function delBuildRankScoreSetting(){
    let curCnt = $('#buildRankScoreSettingTBody').find('tr').length
    if(curCnt > 0){
        $('#buildRankScoreSettingTBody').find('tr:last').remove()
    }
}

// 分阶段奖励配置
function buildRankStagesRewards(){
    buildRankLvCnt = 0;
    buildRankSpinsMap = {};
    buildRankShushuMap = {};
    buildRankStagesMap = {};
    buildRankStagesRankMap = {};
    return `<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">分阶段奖励配置</h5></div>
    <div class="rewardsWrap buildRankStagesRewardsWrap" id="buildRankStagesRewardsWrap">
        <div class="opBtns">
            <button type="button" class="btn btn-primary addBuildRankLvWrap" onclick="addBuildRankLvWrap(this)">添加等级区间</button>
            <button type="button" class="btn btn-danger  delBuildRankLvWrap" onclick="delBuildRankLvWrap(this)">删除等级区间</button>
        </div>
    </div>`;
}

// 登记区间配置
function addBuildRankLvWrap(obj){
    buildRankLvCnt++;
    buildRankSpinsMap[buildRankLvCnt] = 0;
    let html = `<div class="rewardsWrap buildRankLvWrap_${buildRankLvCnt}" id="buildRankLvWrap_${buildRankLvCnt}">
                <div class="form-group">
                    <label class="col-sm-2 control-label m-b">等级区间 </label>
                    <div class="col-sm-3 input-group">
                        <input type="text" style="text-align: center" class="form-control" name="buildRankConfig[${buildRankLvCnt}][start]" value="0">
                        <span class="input-group-addon">-</span>
                        <input type="text" style="text-align: center" class="form-control" name="buildRankConfig[${buildRankLvCnt}][end]" value="0">
                    </div>
                </div>
                <div class="opBtns ">
                    <botton  type="button" class="btn btn-primary addBuildRankSpinsWrap"  onclick="addBuildRankSpinsWrap(this, ${buildRankLvCnt})" >添加体力区间</botton>
                    <botton  type="button" class="btn btn-danger  delBuildRankSpinsWrap"  onclick="delBuildRankSpinsWrap(this, ${buildRankLvCnt})" >删除体力区间</botton>
                </div>
            </div>`;
    $(obj).parents('.opBtns').before(html)
}
function delBuildRankLvWrap(obj){
    if(buildRankLvCnt > 0 && $(`#buildRankLvWrap_${buildRankLvCnt}`).length > 0){
        $(`#buildRankLvWrap_${buildRankLvCnt}`).remove();
        buildRankLvCnt--
    }
}

// 体力区间配置
function addBuildRankSpinsWrap(obj, idx1){
    let idx2 = ++buildRankSpinsMap[idx1]
    let key3 = `${idx1}_${idx2}`
    buildRankShushuMap[key3] = 0
    let html = `<div class=" rewardsWrap buildRankSpinsWrap_${key3}" id="buildRankSpinsWrap_${key3}">
                <div class="form-group">
                    <label class="col-sm-2 control-label m-b">体力区间 </label>
                    <div class="col-sm-3 input-group">
                        <input type="text" style="text-align: center" class="form-control" name="buildRankConfig[${idx1}][stages][${idx2}][start]" value="0">
                        <span class="input-group-addon">-</span>
                        <input type="text" style="text-align: center" class="form-control" name="buildRankConfig[${idx1}][stages][${idx2}][end]" value="0">
                    </div>
                </div>
                <div class="opBtns ">
                    <botton type="button" class="btn btn-primary addBuildRankShushuWrap"  onclick="addBuildRankShushuWrap(this, ${idx1}, ${idx2})" >添加数数区间</botton>
                    <botton type="button" class="btn btn-danger  delBuildRankShushuWrap"  onclick="delBuildRankShushuWrap(this, ${idx1}, ${idx2})" >删除数数区间</botton>
                </div>
            </div>`;
    $(obj).parents('.opBtns').before(html)
}

function delBuildRankSpinsWrap(obj, idx1){
    let idx2 = buildRankSpinsMap[idx1]
    let key3 = `${idx1}_${idx2}`
    if(idx2 > 0 && $(`#buildRankSpinsWrap_${key3}`).length > 0){
        $(`#buildRankSpinsWrap_${key3}`).remove();
        buildRankSpinsMap[idx1]--
    }
}

// 数数区间配置
function addBuildRankShushuWrap(obj, idx1, idx2){
    let key3 = `${idx1}_${idx2}`;
    let idx3 = ++buildRankShushuMap[key3];
    let key4 = `${idx1}_${idx2}_${idx3}`;
    buildRankStagesMap[key4] = 0;
    buildRankStagesRankMap[key4] = 0;

    let arr = JSON.parse($hideSSGroup);
    let optionsHtml = ''
    $.each(arr, function (i, o) {
        optionsHtml += `<option value="${i}">${o}</option>`
    });
    let html = `<div class=" rewardsWrap buildRankShushuWrap_${key4}" id="buildRankShushuWrap_${key4}">
                    <div class="form-group">
                        <label class="col-sm-2 control-label m-b">数数分组</label>
                        <div class="col-sm-3 input-group">
                            <select class="select2  " style="width: 100%" name="buildRankConfig[${idx1}][stages][${idx2}][stages][${idx3}][shushu][]" multiple>
                                ${optionsHtml}
                            </select>
                        </div>
                    </div>`
    if(['build_rank', 'rank'].includes(act_type)){   // 有进度锦标赛阶段配置
        html += `
                    <label class="col-sm-2 control-label m-b " style="text-align: left">阶段奖励配置</label>
                    <table class="table table-bordered ">
                        <thead>
                            <th>阶段</th>
                            <th>进度条</th>
                            <th>阶段值</th>
                            <th>奖品</th>
                            <th>奖励设置</th>
                        </thead>
                        <tbody class="buildRankStageWrap_${key4}" id="buildRankStageWrap_${key4}">
                        
                        </tbody>
                    </table>
                    <div class="opBtns ">
                        <botton type="button" class="btn btn-primary addBuildRankStageRewardTr"  onclick="addBuildRankStageRewardTr(this, ${idx1}, ${idx2}, ${idx3})" >添加</botton>
                        <botton type="button" class="btn btn-danger  delBuildRankStageRewardTr"  onclick="delBuildRankStageRewardTr(this, ${idx1}, ${idx2}, ${idx3})" >删除</botton>
                    </div>`;
    }

    html += `
            <label class="col-sm-2 control-label m-b " style="text-align: left">排行奖励配置</label>
            <table class="table table-bordered ">
                <thead>
                    <th>ID</th>
                    <th>排名</th>
                    <th>奖品</th>
                    <th>奖励设置</th>
                </thead>
                <tbody class="buildRankStageRankWrap_${key4}" id="buildRankStageRankWrap_${key4}">
                
                </tbody>
            </table>
            <div class="opBtns ">
                <botton type="button" class="btn btn-primary addBuildRankStageRankRewardTr"  onclick="addBuildRankStageRankRewardTr(this, ${idx1}, ${idx2}, ${idx3})" >添加</botton>
                <botton type="button" class="btn btn-danger  delBuildRankStageRankRewardTr"  onclick="delBuildRankStageRankRewardTr(this, ${idx1}, ${idx2}, ${idx3})" >删除</botton>
            </div>`
    html += ` </div>`
    $(obj).parents('.opBtns').before(html)
    $('.select2').select2()
}

function delBuildRankShushuWrap(obj, idx1, idx2){
    let key3 = `${idx1}_${idx2}`;
    let idx3 = buildRankShushuMap[key3];
    let key4 = `${idx1}_${idx2}_${idx3}`;
    if(idx3 > 0 && $(`#buildRankShushuWrap_${key4}`).length > 0){
        $(`#buildRankShushuWrap_${key4}`).remove();
        buildRankShushuMap[idx1]--
    }
}

// 阶段奖励配置
function addBuildRankStageRewardTr(obj, idx1, idx2, idx3){
    let key4 = `${idx1}_${idx2}_${idx3}`;
    let idx4 = ++buildRankStagesMap[key4];

    let html = `
<tr class="commonStageRewardTr">
    <td><input type="text" name="buildRankConfig[${idx1}][stages][${idx2}][stages][${idx3}][stages][stages][${idx4}][stage]" value="${idx4}" readonly></td>
    <td><input type="text" name="buildRankConfig[${idx1}][stages][${idx2}][stages][${idx3}][stages][stages][${idx4}][progressBarId]" value="${idx4}" ></td>
    <td><input type="text" name="buildRankConfig[${idx1}][stages][${idx2}][stages][${idx3}][stages][stages][${idx4}][stepnum]" value="0" ></td>
    <td class=" prizeShow showStagePrize"></td>
    <td class=" ">
        <input class="prizeInput" type="hidden" name="buildRankConfig[${idx1}][stages][${idx2}][stages][${idx3}][stages][stages][${idx4}][prize]" value="%5B%5D">
        <button type="button" class="btn btn-outline btn-success" onclick="setPrize(this, 'setCommonPrize', 1)">奖励配置</button>
    </td>
</tr>
`;
    $(`#buildRankStageWrap_${key4}`).append(html)
}

function delBuildRankStageRewardTr(obj, idx1, idx2, idx3){
    let key4 = `${idx1}_${idx2}_${idx3}`;
    let idx4 = buildRankStagesMap[key4];

    if(idx4>0 && $(`#buildRankStageWrap_${key4}`).find('tr').length > 0  ){
        $(`#buildRankStageWrap_${key4}`).find('tr:last').remove();
        buildRankStagesMap[key4]--
    }
}

// 排行奖励配置
function addBuildRankStageRankRewardTr(obj, idx1, idx2, idx3){
    let key4 = `${idx1}_${idx2}_${idx3}`;
    let idx4 = ++buildRankStagesRankMap[key4];

    let html = `
<tr class="commonStageRewardTr">
    <td><input type="text" name="buildRankConfig[${idx1}][stages][${idx2}][stages][${idx3}][stages][ranks][${idx4}][id]" value="${idx4}" disabled></td>
    <td><input type="text" name="buildRankConfig[${idx1}][stages][${idx2}][stages][${idx3}][stages][ranks][${idx4}][rankPos]" value="${idx4}" ></td>
    <td class=" prizeShow showStagePrize"></td>
    <td class=" ">
        <input class="prizeInput" type="hidden" name="buildRankConfig[${idx1}][stages][${idx2}][stages][${idx3}][stages][ranks][${idx4}][prize]" value="%5B%5D">
        <button type="button" class="btn btn-outline btn-success" onclick="setPrize(this, 'setCommonPrize', 1)">奖励配置</button>
    </td>
</tr>
`;
    $(`#buildRankStageRankWrap_${key4}`).append(html)
}

function delBuildRankStageRankRewardTr(obj, idx1, idx2, idx3){
    let key4 = `${idx1}_${idx2}_${idx3}`;
    let idx4 = buildRankStagesRankMap[key4];

    if(idx4>0 && $(`#buildRankStageRankWrap_${key4}`).find('tr').length > 0  ){
        $(`#buildRankStageRankWrap_${key4}`).find('tr:last').remove();
        buildRankStagesRankMap[key4]--
    }
}