function initReward_clubTournament() {
    changetypeTo_clubTournament()
    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])
    })
    let rankMap = ['clubRanks', 'userRanks']
    $('input[name="clubTournamentConfig[preTimes]"]').val(activity_extra_data['preTimes']/3600)
    if(activity_extra_data.list && activity_extra_data.list.length>0){
        $.each(activity_extra_data.list, function(i, o){
            addClubTournamenStarsWrap()
            $('input[name="clubTournamentConfig[list]['+i+'][start]"]').val(o.start)
            $('input[name="clubTournamentConfig[list]['+i+'][end]"]').val(o.end)
            $('input[name="clubTournamentConfig[list]['+i+'][clubNum]"]').val(o.clubNum)
            $('input[name="clubTournamentConfig[list]['+i+'][clubMinNum]"]').val(o.clubMinNum)
            $('input[name="clubTournamentConfig[list]['+i+'][userMinNum]"]').val(o.userMinNum)

            console.log(i, o)
            for(let rankTitle of rankMap){
                if(o[rankTitle] && o[rankTitle].length>0){
                    $.each(o[rankTitle], function(i1, o1){
                        if ('clubRanks' == rankTitle)
                            addClubTournamentTr(i)
                        else
                            addClubTournamentUserTr(i)
                        $(`input[name="clubTournamentConfig[list][${i}][${rankTitle}][${i1}][prizes]"]`).val(escape(JSON.stringify(o1.prizes)))
                        var prizeHtml = ''
                        $.each(o1.prizes, function(ip,op){
                            prizeHtml += chestPropsHtml(op)
                        })
                        $(`.${rankTitle}StagePrize_${i}_${i1}`).html(prizeHtml)
                    })
                }
            }
        })
    }

}

function changetypeTo_clubTournament() {
    $("#reward_info").empty();
    initClubTournamentWrap()
}

function initClubTournamentWrap(){
    var html = '';

    clubTournamentSTarStage = -1;
    clubTournamentClubRankMap = {}
    clubTournamentUserRankMap = {}
    //分值配置初始化
    // 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(clubTournamentBasicConfig());

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

    // 用户排名奖励初始化
    // $("#reward_info").append(addClubTournamenUserWrap());

}
function clubTournamentBasicConfig() {
    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="clubTournamentConfig[preTimes]" value="" class="form-control"></div>';
    // html +=  '<label class="col-xs-2 control-label">俱乐部上榜门槛积分:</label><div class="col-sm-1"><input type="text"  name="clubTournamentConfig[clubMinNum]" value="" class="form-control"></div>';
    // html +=  '<label class="col-xs-2 control-label">用户上榜门槛积分:</label><div class="col-sm-1"><input type="text"  name="clubTournamentConfig[userMinNum]" value="" class="form-control"></div>';
    html += '</div>';
    html +='</div>';
    return html;
}



//==================结算奖励==================
//排行榜排名奖励table html
function clubTournamentTable() {
    var html ='';
    html +='<hr style=" height:2px;border:none;border-top:2px dotted #0b0;"><div class="form-group" id="clubTournament_table">';
    html +='<div class="ibox-title" style="border-top: 0;"></div>';

    html +='</div>';
    html +='<div class="form-group"><div class="col-sm-4 col-sm-offset-2">';
    html += '<button class="btn btn-primary" id="addSpinClubTournamentBtn" type="button" onclick="addClubTournamenStarsWrap()">添加星星区间</button>';
    html += '<button class="btn btn-white"   id="delSpinClubTournamentBtn" type="button" onclick="delClubTournamenStarsWrap()">删除星星区间</button>';
    html +='</div></div><hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    return html;
}
// 添加星星区间
function addClubTournamenStarsWrap(){
    console.log(clubTournamentSTarStage)
    clubTournamentSTarStage++
    clubTournamentClubRankMap[clubTournamentSTarStage] = -1
    clubTournamentUserRankMap[clubTournamentSTarStage] = -1
    var html =`
    <table class="table table-bordered addClubTournamenStarsWrap">
        <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="clubTournamentConfig[list][${clubTournamentSTarStage}][start]" value="0">
                            <span class="input-group-addon">-</span>
                            <input type="text" style="text-align: center" class="form-control" name="clubTournamentConfig[list][${clubTournamentSTarStage}][end]" value="0">
                        </div>
                    </div>
                </td>
            </tr>
            <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" style="text-align: center" class="form-control" name="clubTournamentConfig[list][${clubTournamentSTarStage}][clubNum]" value="0">
                        </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="clubTournamentConfig[list][${clubTournamentSTarStage}][clubMinNum]" value="0">
                        </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="clubTournamentConfig[list][${clubTournamentSTarStage}][userMinNum]" value="0">
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <th colspan="3">俱乐部排行奖励</th>
            </tr>
            <tr>
                <th>排名</th>
                <th>奖励</th>
                <th>奖励配置</th>
            </tr>
        </thead>
        <tbody id="clubRanks_${clubTournamentSTarStage}">
        </tbody>
        <tr>
            <td colspan="4">
                <div class="text-center">
                    <botton class="btn btn-primary" id="addClubTournament" onclick="addClubTournamentTr(${clubTournamentSTarStage})">添加</botton>
                    <botton class="btn btn-danger del-tr" onclick="delClubTournamentTr(${clubTournamentSTarStage})">删除</botton>
                </div>
            </td>
        </tr>
        <thead>
            <tr>
                <th colspan="3">用户排行奖励</th>
            </tr>
            <tr>
                <th>排名</th>
                <th>奖励</th>
                <th>奖励配置</th>
            </tr>
        </thead>
        <tbody id="userRanks_${clubTournamentSTarStage}">
        </tbody>
        <tr>
            <td colspan="4">
                <div class="text-center">
                    <botton class="btn btn-primary" id="addClubTournament" onclick="addClubTournamentUserTr(${clubTournamentSTarStage})">添加</botton>
                    <botton class="btn btn-danger del-tr" onclick="delClubTournamentUserTr(${clubTournamentSTarStage})">删除</botton>
                </div>
            </td>
        </tr>
    </table>`;

    $("#clubTournament_table").append(html);
    return html;
}
// 删除星星区间
function delClubTournamenStarsWrap(){
    if(clubTournamentSTarStage >= 0){
        clubTournamentSTarStage--
        $('.addClubTournamenStarsWrap:last').remove()
    }
}

//添加俱乐部排名奖励行
function addClubTournamentTr(index){
    clubTournamentClubRankMap[index]++
    var data ={"idx":clubTournamentClubRankMap[index],"stage":clubTournamentClubRankMap[index] + 1,"clubTournamentNum":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="clubTournamentConfig[list]['+index+'][clubRanks]['+data['idx']+'][rank]" value="'+data['stage']+'" readonly></td>';
    html +='<td class="clubRanksStagePrize_'+index+'_'+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="clubTournamentConfig[list]['+index+'][clubRanks]['+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>';
    $("#clubRanks_"+index).append(html);
}
//删除俱乐部排名奖励行
function delClubTournamentTr(index){
    if(clubTournamentClubRankMap[index] >= 0){
        $("#clubRanks_"+index).children("tr:last-child").remove();
        clubTournamentClubRankMap[index]--;
    }
}



//添加用户排名奖励行
function addClubTournamentUserTr(starIdx){
    clubTournamentUserRankMap[starIdx]++
    var data ={"idx":clubTournamentUserRankMap[starIdx],"stage":clubTournamentUserRankMap[starIdx] + 1,"clubTournamentNum":0};

    var stage = data['stage'];
    var prize = '[]';
    var prize_show_arr = JSON.parse(prize);
    prize = escape(prize);
    var html =`
        <tr id="rewardInfo_'+data['stage']+'" class="commonStageRewardTr">
            <td><input type="text" class="form-control" name="clubTournamentConfig[list][${starIdx}][userRanks][${data['idx']}][rank]" value="${data['stage']}" readonly></td>
            <td class="userRanksStagePrize_${starIdx}_${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="clubTournamentConfig[list]['+starIdx+'][userRanks]['+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>';
    $("#userRanks_"+starIdx).append(html);
}
//删除用户排名奖励行
function delClubTournamentUserTr(starIdx){
    if(clubTournamentUserRankMap[starIdx] >= 0){
        $("#userRanks_"+starIdx).children("tr:last-child").remove();
        clubTournamentUserRankMap[starIdx]--;
    }
}