function initReward_club_garden() {
    changeTypeTo_club_garden()
    console.log('activity_extra_data:',activity_extra_data)
    var collectTypes = [
        'attack_success',
        'attack_break',
        'steal_success',
        'steal_break',
        // 'one_hit',
        // 'two_hit',
        // 'three_hit',
    ];
    $.each(collectTypes, function (i,o){
        $('input[name="'+o+'"]').val(reward_conf[o])
    })
    var basicConfigColumns = [
        // 'preTimes',
        'clubMinNum',
        'userMinNum',
    ];
    $.each(basicConfigColumns, function (i,o){
        $('input[name="clubGardenConfig['+o+']"]').val(activity_extra_data[o])
    })
    $('input[name="clubGardenConfig[preTimes]"]').val(activity_extra_data['preTimes']/3600)
    if(activity_extra_data.clubStagesList.length>0){
        $.each(activity_extra_data.clubStagesList, function(i, o){
            addClubGardenStarsTable()
            $(`input[name="clubGardenConfig[clubStagesList][${i}][start]"]`).val(o.start)
            $(`input[name="clubGardenConfig[clubStagesList][${i}][end]"]`).val(o.end)
            $(`input[name="clubGardenConfig[clubStagesList][${i}][userMinNum]"]`).val(o.userMinNum)

            if(o.stages.length>0){
                $.each(o.stages, function(i1, o1){
                    addClubGardenStarsStagesWrap(i)
                    $(`input[name="clubGardenConfig[clubStagesList][${i}][stages][${i1}][target_scores]"]`).val(o1.target_scores)
                    $(`input[name="clubGardenConfig[clubStagesList][${i}][stages][${i1}][prizes]"]`).val(escape(JSON.stringify(o1.prizes)))
                    var prizeHtml = ''
                    $.each(o1.prizes, function(ip,op){
                        prizeHtml += chestPropsHtml(op)
                    })
                    $(`#addClubGardenStarsStagesWrap_${i}_${i1}`).find('thead').find('.prizeShow').html(prizeHtml)

                    $.each(o1.user_rank, (i2,o2) =>{
                        addClubGardenRewardTr(i, i1)
                        $(`input[name="clubGardenConfig[clubStagesList][${i}][stages][${i1}][user_rank][${i2}][prizes]"]`).val(escape(JSON.stringify(o2.prizes)))

                        var prizeHtml = ''
                        $.each(o2.prizes, function(ip,op){
                            prizeHtml += chestPropsHtml(op)
                        })
                        $(`.showStagePrize_${i}_${i1}_${i2}`).html(prizeHtml)
                    })

                })
            }
        })
    }

}

function changeTypeTo_club_garden() {
    $("#reward_info").empty();
    initClubGardenWrap()
}


function initClubGardenWrap(){
    var html = '';

    clubGardenStartIdx = -1;
    clubGardenStartStagesIdxMap = {};
    clubGardenRewardsIdxMap = {}
    //分值配置初始化
    // 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};
    var data = {"confType":1,"attack_success":0,"attack_break":0,"steal_success":0,"steal_break":0};
    // 收集配置
    $("#reward_info").append(renderCollectType(data));

    // 基础配置
    $("#reward_info").append(clubGardenBasicConfig());

    // 俱乐部排名奖励初始化
    $("#reward_info").append(clubGardenWrap());

}
function clubGardenBasicConfig() {
    var html = '';
    html +='<div aria-hidden="true" id="stage_pro">';
    html += '<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">基础配置*:</h5></div>';
    html += '<div  class="form-group">';
    html +=  '<label class="col-xs-2 control-label">提前预告时长(小时):</label><div class="col-sm-1"><input type="text"  name="clubGardenConfig[preTimes]" value="" class="form-control"></div>';
    // html +=  '<label class="col-xs-2 control-label">俱乐部上榜门槛积分:</label><div class="col-sm-1"><input type="text"  name="clubGardenConfig[clubMinNum]" value="" class="form-control"></div>';
    // html +=  '<label class="col-xs-2 control-label">用户上榜门槛积分:</label><div class="col-sm-1"><input type="text"  name="clubGardenConfig[userMinNum]" value="" class="form-control"></div>';
    html += '</div>';
    html +='</div>';
    return html;
}



//==================结算奖励==================
//排行榜排名奖励table html
function clubGardenWrap() {
    var html ='';
    html +='<hr style=" height:2px;border:none;border-top:2px dotted #0b0;"><div class="form-group" id="clubGardenOutWrap">';
    html +='<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">奖励配置</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="addSpinClubGardenBtn" type="button" onclick="addClubGardenStarsTable()">添加星星区间</button>';
    html += '<button class="btn btn-white"   id="delSpinClubGardenBtn" type="button" onclick="delClubGardenStarsTable()">删除星星区间</button>';
    html +='</div></div><hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    return html;
}
function addClubGardenStarsTable() {
    clubGardenStartIdx++
    clubGardenStartStagesIdxMap[clubGardenStartIdx] = -1
    var html =`
            <div class="form-group clubGardenStarsWrap" id="clubGardenStarsWrap_${clubGardenStartIdx}" style="margin: 0;border: 1px solid ">
                <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="clubGardenConfig[clubStagesList][${clubGardenStartIdx}][start]" value="0">
                                        <span class="input-group-addon">-</span>
                                        <input type="text" style="text-align: center" class="form-control" name="clubGardenConfig[clubStagesList][${clubGardenStartIdx}][end]" value="0">
                                    </div>
                                    
                                   <label class="col-sm-1 control-label m-b">用户上榜门槛值</label> 
                                   <div class="col-sm-1" style="padding: 0"> 
                                       <input type="text" style="text-align: center" class="form-control" name="clubGardenConfig[clubStagesList][${clubGardenStartIdx}][userMinNum]" value="0">
                                   </div>
                                </div>
                            </td>
                        </tr>
                    </thead>
                </table>
                <div class="form-group btnGroup">
                    <div class="col-sm-4 col-sm-offset-2">
                        <button class="btn btn-primary addClubGardenStarsStagesWrapBtn" type="button" onclick="addClubGardenStarsStagesWrap(${clubGardenStartIdx})">添加阶段</button>
                        <button class="btn btn-white delClubGardenStarsStagesWrapBtn" type="button" onclick="delClubGardenStarsStagesWrap(${clubGardenStartIdx})">删除阶段</button>
                    </div>
                </div>
            </div>`
    $('#clubGardenOutWrap').append(html)
    // return html;
}
function delClubGardenStarsTable() {
    if(clubGardenStartIdx > 0){
        clubGardenStartIdx--
        $('.clubGardenStarsWrap:last').remove()
    }
    clubGardenStarsWrap
}

// 添加阶段
function addClubGardenStarsStagesWrap(startIdx){
    //
    let stageIdx = ++clubGardenStartStagesIdxMap[startIdx]
    let stageNum = stageIdx+1
    let starStageIdx = `${startIdx}_${stageIdx}`
    clubGardenRewardsIdxMap[starStageIdx] = -1
    var html =`
    <table class="table table-bordered addClubGardenStarsStagesWrap" id="addClubGardenStarsStagesWrap_${starStageIdx}" data-idx="${starStageIdx}">
        <thead>
            <tr>
                <td colspan="3">
                   <div class="form-group"> 
                       <label class="col-sm-1 control-label m-b">阶段</label> 
                       <div class="col-sm-1">
                           <input type="text" readonly style="text-align: center" class="form-control" name="clubGardenConfig[clubStagesList][${startIdx}][stages][${stageIdx}][stage]" value="${stageNum}">
                       </div>
                       <label class="col-sm-1 control-label m-b">阶段积分值</label> 
                       <div class="col-sm-1"> 
                           <input type="text" style="text-align: center" class="form-control" name="clubGardenConfig[clubStagesList][${startIdx}][stages][${stageIdx}][target_scores]" value="0">
                       </div>
                   </div>
                </td>
            </tr>
            <tr  class="commonStageRewardTr">
                <th>
                    阶段奖励
                    <input type="hidden" name="clubGardenConfig[clubStagesList][${startIdx}][stages][${stageIdx}][prizes]" value="[]" class="prizeInput">
                </th>
                <th class="prizeShow"></th>
                <th><button type="button" class="btn btn-outline btn-success" onclick="setPrize(this,'setCommonPrize',1 )">奖励配置</button></th>
            </tr>
            <tr>
                <th colspan="3" style="text-align: center">排行奖励</th>
            </tr>
            <tr>
                <th>排名</th>
                <th>奖励</th>
                <th>奖励配置</th>
            </tr>
        </thead>
        <tbody id="addClubGardenReward_${starStageIdx}">
        </tbody>
        <tr>
            <td colspan="4">
                <div class="text-center">
                    <botton class="btn btn-primary" id="addClubGarden" onclick="addClubGardenRewardTr(${startIdx}, ${stageIdx})">添加</botton>
                    <botton class="btn btn-danger del-tr" onclick="delClubGardenRewardTr(${startIdx}, ${stageIdx})">删除</botton>
                </div>
            </td>
        </tr>
    </table>`
    $("#clubGardenStarsWrap_"+startIdx).find('.btnGroup').before(html);
}
// 删除阶段
function delClubGardenStarsStagesWrap(startIdx){
    if(clubGardenStartStagesIdxMap[startIdx] > 0){
        clubGardenStartStagesIdxMap[startIdx]--
        $("#clubGardenStarsWrap_"+startIdx).find('.addClubGardenStarsStagesWrap:last').remove()
    }
}

//添加俱乐部排名奖励行
function addClubGardenRewardTr(startIdx, stageIdx){
    let starStageIdx = `${startIdx}_${stageIdx}`
    clubGardenRewardsIdxMap[starStageIdx]++
    var data ={"idx":clubGardenRewardsIdxMap[starStageIdx],"stage":clubGardenRewardsIdxMap[starStageIdx]+1 ,"clubGardenNum":0};

    var stage = data['stage'];
    var 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="clubGardenConfig[clubStagesList]['+startIdx+'][stages]['+stageIdx+'][user_rank]['+data['idx']+'][rank]" value="'+data['stage']+'" readonly></td>';
    html +='<td class="showStagePrize_'+starStageIdx+'_'+data['idx']+' prizeShow">';
    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 type="hidden" name="clubGardenConfig[clubStagesList]['+startIdx+'][stages]['+stageIdx+'][user_rank]['+data['idx']+'][prizes]" value="'+prize+'" class="prizeInput">';
    html +='<td><button type="button" class="btn btn-outline btn-success" onclick="setPrize(this,\'setCommonPrize\',1 )">奖励配置</button></td>';// data-toggle="modal"
    html +='</tr>';
    $("#addClubGardenReward_"+starStageIdx).append(html);
}
//删除俱乐部排名奖励行
function delClubGardenRewardTr(startIdx, stageIdx){
    let starStageIdx = `${startIdx}_${stageIdx}`
    console.log(starStageIdx)
    console.log(clubGardenRewardsIdxMap[starStageIdx])
    if(clubGardenRewardsIdxMap[starStageIdx] > 0){
        $("#addClubGardenReward_"+starStageIdx).children("tr:last-child").remove();
        clubGardenRewardsIdxMap[starStageIdx]--;
    }
}
