function changeTypeTo_TimeLimitedCards(){
    console.log('changeToTimeLimitedCards');
    $("#reward_info").empty();
    initTimeLimitedCardsWrap();
}
function initReward_TimeLimitedCards(){
    console.log('initReward_TimeLimitedCards-',activity_extra_data);
    changeTypeTo_TimeLimitedCards();
    activity_extra_data  && activity_extra_data.themeId && $('select[name="timeLimitedCards[themeId]"]').val(activity_extra_data.themeId)
    activity_extra_data && activity_extra_data.progress && $.each(activity_extra_data.progress, function(i,o){
        addTimeLimitedCardRewardTr()
        $(`input[name="timeLimitedCards[progress][${i}][stage]"]`).val(o.stage)
        $(`input[name="timeLimitedCards[progress][${i}][target]"]`).val(o.target)
        $(`input[name="timeLimitedCards[progress][${i}][rewards]"]`).val(escape(JSON.stringify(o.rewards)))
        let propHtml = ''
        $.each(o.rewards, function(ri,reward){
            propHtml+=chestPropsHtml(reward)
        })
        console.log(propHtml);
        $('.prizeShow:last').html(propHtml)
    })
}


function initTimeLimitedCardsWrap(){
    TimeLimitedCardStageCnt = 0;
    if(typeof timeLimitedCardsThemes == "undefined" ){
        $.ajax({
            type: "GET", // 数据提交类型
            url: "activity/getTimeLimitedCardsThemes", // 发送地址
            data: {}, //发送数据
            async: false, // 是否异步
            success: function(data) { // 成功回调
                data = JSON.parse(data);
                timeLimitedCardsThemes = data.data.themes
            }
        });
    }
    var html = ''
    html +='<div class="form-group">';
    html +=     '<label class="col-sm-2 control-label">开放主题:</label>'
    html +=     '<div class="col-sm-5">'
    html +=         '<select   name="timeLimitedCards[themeId]"  class="form-control select2">'
    $.each(timeLimitedCardsThemes, function(i,o){
        html += '<option value="'+o.id+'">'+o.theme_res+'</option>'
    })
    html +=         '</select>'
    html +=     '</div>';
    html +='</div>';

    $("#reward_info").append(html);

    initTimelimitCardStageWrap();
}

function initTimelimitCardStageWrap(){

    var html = `
        <div class="timelimitCardStageWrap" id="timelimitCardStageWrap"  style="margin:10px;padding:5px;border:solid 1px goldenrod;">

            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="120">进度条id</th>
                    <th width="140">收集物目标数量</th>
                    <th>奖励</th>
                    <th width="140">奖励设置</th>
                </tr>
                </thead>
                <tbody id="timelimitCardTBody">
                               
                </tbody>
                <tr>
                    <td colspan="8">
                        <div class="text-center">
                            <botton class="btn btn-primary addSerialProgressCollectRewardTrBtn" onclick="addTimeLimitedCardRewardTr(this)">添加</botton>
                            <botton class="btn btn-danger del-tr" onclick="delTimeLimitedCardRewardTr(this)">删除</botton>
                        </div>
                    </td>
                </tr>
            </table>
        </div>  
    `;

    $("#reward_info").append(html);
}

function addTimeLimitedCardRewardTr() {
    TimeLimitedCardStageCnt++
    var prize = escape('[]');
    var html = `
        <tr class="commonStageRewardTr timeLimitedCardsTr" id="timeLimitedCards" data-idx="${TimeLimitedCardStageCnt}">
            <td>
                <input  name="timeLimitedCards[progress][${TimeLimitedCardStageCnt}][stage]" type="text"   class="form-control"  value="${TimeLimitedCardStageCnt}" readonly >
            </td>
            <td>
                <input  name="timeLimitedCards[progress][${TimeLimitedCardStageCnt}][target]" type="text"   class="form-control"  value="0"  >
            </td>
        
            <td class="prizeShow"></td>
            <td>
                <input type="hidden" class="prizeInput" name="timeLimitedCards[progress][${TimeLimitedCardStageCnt}][rewards]" value="${prize}"> 
                <button type="button" class="btn btn-outline btn-success" onclick="setPrize(this,'setCommonPrize',1)">奖励配置</button>
            </td>
        </tr>
    `;

    $('#timelimitCardTBody').append(html)
}

function delTimeLimitedCardRewardTr() {
    if(TimeLimitedCardStageCnt > 0){
        TimeLimitedCardStageCnt--
        $('.timeLimitedCardsTr:last').remove()
    }
}