console.log('actTypes', actTypes)
if (!act_type || !act_type.length) act_type = $('#select_type').val()
console.log('act_type', act_type);
// 已加载的js类型
let loadedJsFiles = [];
loadJs(act_type)

imgNameInvalid = 0;
couponSkinImgNameInvalid = 0;
isInit = true;
commonhushuGroupArr = [];//数数分组集合 [体力组spinIdx1:数数组数,,...]
$('#myModal5').css("cssText", "z-index:100!important")
showLoading()

function ucTypeChanged(ucType) {
    ucType = parseInt(ucType)
    if (ucType == 0) {
        couponSkinImgNameInvalid = 0
        $('#act_coupon_skin_selector').hide()
        $('#ishide').hide()
        $('#act_coupon_skin').val('')
        $('input[name=act_coupon_skin]').val('')
    } else {
        $('#act_coupon_skin_selector').show()
        $('#ishide').show()
    }
}

$(document).ready(function () {

    laydate.render({
        elem: '#test',
        type: 'datetime',
        range: true
    });
    laydate.render({
        elem: '#test1',
        type: 'datetime',
    });

    imgNames_str = $imgNames;//资源类型
    imgNames = JSON.parse(imgNames_str);

    var reward_type_str = $reward_type;
    reward_type = JSON.parse(reward_type_str);//奖励类型
    $.each(reward_type, function (k, v) {
        reward_type_arr[k] = v;
    });
    // console.log("初始化数据：奖品分类数组==",reward_type_arr);

    goodSku_str = $goodSku;
    goodSku = JSON.parse(goodSku_str);//礼包类商品sku

    var actProps_str = $actProps;//活动道具
    if (actProps_str.length > 0) {
        actProps = JSON.parse(actProps_str);
    }
    var reward_conf_str = $reward_conf;
    if (reward_conf_str.length > 0) {
        reward_conf = JSON.parse(reward_conf_str);
    }
    var reward_pro_str = $reward_pro;
    if (reward_pro_str.length > 0) {
        reward_pro = JSON.parse(reward_pro_str);
    }

    var reward_info_str = $reward_info;
    if (reward_info_str.length > 0 && reward_info_str != 'null') {
        reward_info = JSON.parse(reward_info_str);
    }
    var extra_reward_str = extra_reward;
    if (extra_reward_str.length > 0 && extra_reward_str != 'null') {
        extra_reward = JSON.parse(extra_reward_str);
    }
    var reward_info_new_str = reward_info_new;
    if (reward_info_new_str.length > 0 && reward_info_new_str != 'null') {
        reward_info_new = JSON.parse(reward_info_new_str);
    }

    var activity_extra_data_str = extraData;
    if (activity_extra_data_str.length > 0 && activity_extra_data_str != 'null') {
        activity_extra_data = JSON.parse(activity_extra_data_str);
    }
    // console.log($("input[name='id']").val());
    //初始化显示
    act_type = $("#select_type").val();
    // showCidSelect();
    console.log($info)

    // 活动券皮肤选择 -- begin
    if (imgNames.couponSkin) {
        $.each(imgNames.couponSkin, function (skinIdx, skinItem) {
            if (skinItem['name'] && skinItem['type']) {
                $('#act_coupon_skin').append(`<option value="${skinItem['type']}">${skinItem['name']}</option>`)
            }
        })
    }
    $('#act_coupon_skin').change(function () {
        $('input[name=act_coupon_skin]').val($(this).val())
        couponSkinImgNameInvalid = 0
        $('.couponSkinImgNameTips').text('').hide()
        if ($(this).val()) {
            checkCouponSkinImgName($(this).val())
        }
    })
    if ($info['act_coupon_skin']) {
        $('#act_coupon_skin').val($info['act_coupon_skin'])
        $('input[name=act_coupon_skin]').val($info['act_coupon_skin'])
        checkCouponSkinImgName($info['act_coupon_skin'])
    }

    ucTypeChanged($('select[name=uc_type]').val())
    $('select[name=uc_type]').change(function () {
        ucTypeChanged($(this).val())
    })
    // 活动券皮肤选择 -- end

    // 客户端类型选择器状态调整
    clientSelectorStatus()
    if (($info['cid'])) {
        $('#select_cid').val($info['cid'])
    }
    if (($info['imgName'])) {
        $('#imgName').val($info['imgName'])
        checkImgName($info['imgName'])
    }
    // console.log("活动道具==",actProps);
    console.log("初始化数据:活动本身表配置 =activity_extra_data=", activity_extra_data);
    console.log("初始化数据：阶段奖励=reward_info=", reward_info);
    console.log("初始化数据：扩展奖励=extra_reward=", extra_reward);
    console.log("初始化数据：reward_conf=reward_conf=", reward_conf);
    // 已拆分的活动
    var recodeActs = ['rank', 'rank2', "black_golden_card_trade", "golden_card_trade", "super_serial_pack", "super_serial_pack2", "super_serial_pack3", "super_serial_pack4", "shop_promotion", "one_plus_gift"];
    if (Object.keys(reward_info).length > 0
        || (actTypes[act_type].rcid >= 53)
        || (recodeActs.includes(act_type))
        || (["chain_gift", "super_collect", "premium", "super_balloon", "easter_egg", "spins_master"].includes(act_type) && Object.keys(extra_reward).length > 0)
        || ["premium", "traffic_permit_bet", "traffic_permit"].includes(act_type)
        || (reward_conf != null && Object.keys(reward_conf).length > 0 && ["traffic_permit", "collect_bet", "easter_egg", "change_collect"].includes(act_type))
        || (Object.keys(extra_reward).length > 0 && ["rank2"].includes(act_type))
    ) {
        initReward(act_type);
    } else {
        console.log('没有数据:初始化配置');
        showHtmlByType(act_type);
    }

    function chooseAbType(type) {
        str = '';
        //$('select[name="taTest"]').find('option[value="0"]').attr('selected', true);
        if (type == 2) {
            str += '<option value="0">全部</option>';
            str += '<option value="1">A组(双)</option>';
            str += '<option value="2">B组(单)</option>';
        } else {
            str += '<option value="0">关闭</option>';
            str += '<option value="1">基准组</option>';
            str += '<option value="2">变量1</option>';
            str += '<option value="3">变量2</option>';
            str += '<option value="4">非变量1</option>';
            str += '<option value="5">非变量1非变量2</option>';
            str += '<option value="6">非基准非变量1</option>';
        }
        return str;
    }

    //监听选类
    $("select[name='abType']").change(function () {
        var html = '';
        if ($(this).val() == 2) {
            html = chooseAbType(2);
            $('#taLabel').show();
            $('#taSel').show();
        } else {
            html = chooseAbType(1);
            $('#taLabel').hide();
            $('#taSel').hide();
        }
        $("select[name='abTest']").html(html);
    });

    //监听选类
    $("#select_type").change(function () {
        reward_info = [];
        extra_reward = [];
        reward_limit = 0;
        reward_limit2 = 0;
        reward_limit3 = 0;
        rank_limit = [];
        bet_limit = 0;
        this_index = 0;
        spin_reward_limit = [];
        spinStage = 0;
        rankSpinStage = 0;
        act_type = $(this).val();
        showCidSelect();
        if (act_type === 'chain_gift') {
            getChainGiftConf();
        }

        showHtmlByType(act_type);
    })
    //监听选收集物
    $("#select_cid").change(function () {
        var cid = $(this).val();
        if (cid < 1) {
            setImgName('');
        } else {
            if (imgNames[act_type]) {
                setImgName(imgNames[act_type][cid]['type']);
            }
        }
        // console.log(act_type);
    });
    //初始化进度奖励行
    $('.select2').select2({})
    hideLoading()
});

function clientSelectorStatus() {
    var selector = $('select[name=client]')
    if (clientFilteredActTypes.includes(act_type)) {
        selector.removeAttr('disabled')
    } else {
        selector.val(0)
        selector.attr("disabled", "disabled");
    }
}

//添加分体力阶段配置监听
$(document).on('click', '#addSpinStageBtn', function (e) {
    spinStage++;
    var d = {"star": 0, "end": 0};
    html2 = spinStageRewardTable(spinStage, d);
    $("#spinStageTable").append(html2);
});
//删除分体力阶段配置监听
$(document).on('click', '#delSpinStageBtn', function (e) {
    if (spinStage > 1) {
        $("#spinStageTable").children(".spinStageRewardTable:last-child").remove();
        spinStage--;
    }
});
//添加排行榜奖励table
$(document).on('click', '#addSpinRankBtn', function (e) {
    rankSpinStage++;
    var d = {"start": 0, "end": 0};
    html2 = spinRankTable(rankSpinStage, d);
    $("#rank_table").append(html2);
});
//删除排行榜奖励table
$(document).on('click', '#delSpinRankBtn', function (e) {
    if (rankSpinStage > 1) {
        $("#rank_table").children(".spinRankTable:last-child").remove();
        rankSpinStage--;
    }
});
//添加积分分区超级连环礼包
$(document).on('click', '#addCGTableBtn', function (e) {
    spinStage++;
    if (scoreCGType == 1) {
        var d = {"star": 0, "end": 0};
    } else {
        var d = {"gid": 0};
    }
    var html2 = scoreCGRewardTable(scoreCGType, spinStage, d);
    $("#scoreCGTable").append(html2);
    $('.select2').select2({})
});
//删除积分分区超级连环礼包
$(document).on('click', '#delCGTableBtn', function (e) {
    console.log('del-CGtable:', spinStage);
    if (spinStage > 1) {
        if (scoreCGType == 2) {
            $("input[name='scoreStage[" + spinStage + "][gid][]']").each(function () {
                var vaule = $(this).val()
                scoreCGGidArr = scoreCGGidArr.filter(v => {
                    return v != vaule;
                });
            })
        }
        $("#scoreCGTable").children(".scoreCGRewardTable:last-child").remove();
        spinStage--;
    }
});
//超级连环礼包监听选择购买类型
$(document).on('change', '.selMtype', function (e) {
    var mtype = e.currentTarget.value;
    var this_selSku = e.currentTarget.parentElement.nextElementSibling;
    $(this_selSku).empty();

    var index = $(this_selSku).attr('t_index');
    var stage = $(this_selSku).attr('t_stage');
    var data = {"stage": stage, "coin": "coins01", "mtype": mtype, "bet": 0, "price": "0", "sku": "com.gworld.cc.gift07"};
    var html = selSku(index, data);
    $(this_selSku).append(html);
    // console.log();
});
//超级连环礼包监听选择价格
$(document).on('change', '.selPrice', function (e) {
    var tds = e.currentTarget.parentElement;
    var price = e.currentTarget.value;
    $.each(goodSku, function (k, v) {
        if (price == v["price"]) {
            sku = v["sku"];
        }
    });
    tds.children[1].value = sku;
});
//连环礼包道具选择监听
$(document).on('change', '.selChainProp', function (e) {
    var prop = e.currentTarget.value;
    $res = propSelVersion(prop);
    if (!$res) {
        e.currentTarget.value = 1;
        return false;
    }
});
//监听任务选择限制
$(document).on('change', '.seltask', function (e) {
    var tids = [];
    var tid = e.currentTarget.value;
    $('.seltask').each(function (index, val) {
        tids.push(val.value);
    });
    if (tids.indexOf(tid) >= 0) {
        alert('不能存在相同的任务');
        return false;
    }
});
//监听收集子类型选择
$(document).on('change', '#selectChildGroup', function (e) {
    var groupId = e.currentTarget.value;
    $('#collectChildGroupBasic').empty();
    var data = {"groupId": groupId, "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};
    $('#collectChildGroupBasic').append(collectChildGroupBasicCfg(data));
    selGroupId = parseInt(groupId);
});
//监听分组类型选择
$(document).on('change', '#selectConfigGroup', function (e) {
    var groupId = e.currentTarget.value;
    selGroupId = parseInt(groupId);
    var groupName = '';
    if (selGroupId == 2) {
        groupName = 'RFM分组';
        var arr = JSON.parse($userGroup2);
    } else {
        groupName = '数数分组';
        var arr = JSON.parse($hideSSGroup);
    }
    console.log("用户分组:", selGroupId);

    $(".scoreCGGidDivGroupTow").html("");

    var html = '<option value="0">默认</option>';
    for (let i in arr) {
        html += '<option value="' + i + '">' + arr[i] + '</option>';
    }
    $(".scoreCGGidDivGroup").each(function () {
        $(this).find(".scoreCGGidDivGroupName").text(groupName);
        $(this).find(".scoreCGGidDivGroupSelect").html(html);
    })
    $('.select2').select2({})
});

/* 数组转json
 * @param array 数组
 * @param type 类型 json array
 */
function formatArray(array, type) {
    var dataArray = {};
    $.each(array, function () {
        if (dataArray[this.name]) {
            if (!dataArray[this.name].push) {
                dataArray[this.name] = [dataArray[this.name]];
            }
            dataArray[this.name].push(this.value || '');
        } else {
            dataArray[this.name] = this.value || '';
        }
    });
    return ((type === "json") ? JSON.stringify(dataArray) : dataArray);
}

//======================请求=====================
//提交表单
$('#submitBtn').click(function () {
    if (imgNameInvalid > 0) {
        alert('请选择已存在的资源文件');
        $('#select_cid').focus()
        return;
    }
    if (couponSkinImgNameInvalid > 0) {
        alert('请选择已存在的道具券皮肤');
        $('#act_coupon_skin').focus()
        return;
    }
    var datas = $('#activityFrom').serializeArray();
    var spinStageArr = [];
    var rankSpinStageArr = [];
    if (spinStage > 0) {
        for (var n = 1; n <= spinStage; n++) {
            for (var j = 1; j <= spin_reward_limit[n]; j++) {
                spinStageArr.push('rewardnew[' + n + '][' + j + '][prize]');
            }
        }
    }
    if (betStage > 0) {
        for (var n = 1; n <= betStage; n++) {
            for (var j = 1; j <= balloon_bet_limit[n]; j++) {
                spinStageArr.push('rewardnew[' + n + '][' + j + '][prize]');
            }
        }
    }
    if (rankSpinStage > 0) {
        for (var n = 1; n <= rankSpinStage; n++) {
            for (var j = 1; j <= rank_limit[n]; j++) {
                rankSpinStageArr.push('rank[' + n + '][' + j + '][prize]');
            }
        }
    }
    if (commonhushuGroupArr.length > 0) {//通用体力数数分组阶段奖励配置
        for (var m = 1; m <= commonhushuGroupArr.length; m++) {//体力层
            for (var n = 1; n <= commonhushuGroupArr[m]; n++) {//数数层
                parentIdx = m + "_" + n;
                for (var j = 1; j <= spinShuShu_reward_limit[parentIdx]; j++) {//奖励层
                    spinStageArr.push('rewardnew[' + m + '][' + n + '][' + j + '][prize]');
                }
            }
        }
    }

    const format_type_list = ['lucky_fox', 'super_collect', 'spins_master', 'super_gashapon', 'collect_jigsw', 'super_collect2',
        'great_memories', 'build_rank', 'build_rank2', 'rank', 'rank2', 'super_collect3', 'maya_wheel', 'club_farm', 'lucky_dice'];

    for (var i = 0; i < datas.length; i++) {
        for (var j = 1; j <= reward_limit; j++) {
            if (datas[i].name == 'reward[' + j + '][prize]') {
                datas[i].value = unescape(datas[i].value);
            }
        }
        // for(var j=1;j<=rank_limit;j++){
        //     if(datas[i].name=='rank['+j+'][prize]'){
        //         datas[i].value = unescape(datas[i].value);
        //     }
        // }
        for (var j = 1; j <= treasure_limit; j++) {
            if (datas[i].name == 'treasure[' + j + '][prize]') {
                datas[i].value = unescape(datas[i].value);
            }
            if (datas[i].name == 'treasure[' + j + '][bet]') {
                datas[i].value = unescape(datas[i].value);
            }
        }
        for (var j = -1; j <= trafficPermit_limit; j++) {
            if (datas[i].name == 'trafficPermit[' + j + '][prize]') {
                datas[i].value = unescape(datas[i].value);
            }
            if (datas[i].name == 'trafficPermit[' + j + '][specialPrize]') {
                datas[i].value = unescape(datas[i].value);
            }
        }


        for (var j = 0; j <= steel_safelimit_limit; j++) {
            if (datas[i].name == 'safeLimit[' + j + '][prize]') {
                datas[i].value = unescape(datas[i].value);
            }
        }
        for (var j = 0; j <= chooseOne; j++) {
            if (datas[i].name == 'chooseOne[' + j + '][prize]') {
                datas[i].value = unescape(datas[i].value);
            }
        }
        for (var j = 1; j <= 14; j++) {
            if (datas[i].name == 'fund[' + j + '][prize]') {
                datas[i].value = unescape(datas[i].value);
            }
        }
        if (spinStageArr.includes(datas[i].name)) {
            datas[i].value = unescape(datas[i].value);
        }
        if (rankSpinStageArr.includes(datas[i].name)) {
            datas[i].value = unescape(datas[i].value);
        }

        // 解析奖励
        if (format_type_list.includes(act_type)) {
            if (datas[i].name.indexOf('[prize]') !== -1) {
                datas[i].value = JSON.parse(unescape(datas[i].value));
            }
            if (datas[i].name.indexOf('[prizes]') !== -1) {
                datas[i].value = JSON.parse(unescape(datas[i].value));
            }
        }

        // 解析Bet
        if (act_type === "lucky_dice") {
            if (datas[i].name.indexOf('[bet]') !== -1) {
                datas[i].value = JSON.parse(unescape(datas[i].value));
            }
        }
    }

    if (format_type_list.includes(act_type)) {
        datas = formatArray(datas)
    }
    // console.log(spinStage,spin_reward_limit);
    // console.log(datas);
    // return ;
    if (!actVersion()) {
        return false;
    }
    // console.log(toNum('1.7.7.0')<toNum("1.9"));
    // showLoading()
    $.ajax({
        url: rootPath + 'activity/hsave',
        type: 'POST',
        data: datas,
        dataType: 'json',
        success: function (data) {
            hideLoading()
            console.log(data.data)
            alert(data.msg);
            var id = $("input[name='id']").val();
            if (!id && data.ret == 0) {
                // history.back(-1);
            }
        },
        error: function (data) {
            hideLoading()
            alert(data.msg);
        }
    });
});

//连环礼包
function getChainGiftConf() {
    $.ajax({
        url: rootPath + 'activity/chainGiftcCfg',
        type: 'POST',
        data: {},
        dataType: 'json',
        async: false,
        success: function (data) {
            chain_gift_conf = data.data;
            console.log(data);
        },
        error: function (data) {
            console.log(data);
        }
    });
}

//卡组
function getAllGoldenCardByGroup(type) {
    if (golden_card[type] != undefined && golden_card[type].length != 0) {
        return true;
    }
    $.ajax({
        url: rootPath + 'card/getGoldenCard/' + type,
        type: 'POST',
        data: {},
        dataType: 'json',
        async: false,
        success: function (data) {
            golden_card[type] = data.data;
        },
        error: function (data) {
            console.log(data);
        }
    });
}

//===========================================
//初始进度化奖励行
function initReward(type) {
    console.log('initReward', type)
    switch (type) {
        case 'jackpot':
            initRewardJackpot();
            break;
        case 'surprise_collect':
            initReward_surprise_collect();
            break;
        case 'coin_push_mania':
            renderRewardCoinPushMania();
            break;
        case 'surprise_card':
            initRewardSurpriseCard();
            break;
        case 'club_garden':
            return initReward_club_garden();
        case 'super_collect':
            return initReward_super_collect(type);
        case 'collect_jigsw':
            return initReward_collect_jigsw(type);
        case 'treasure'://宝藏
            return initReward_treasure();
        case 'spins_master'://体力大师
            return initReward_spins_master(type);
        case 'super_gashapon'://超级扭蛋
            return initReward_superGashapon(type);
        case 'maya_wheel'://玛雅转盘
            return initReward_mayaWheel();
        case 'choose_you_want'://随心配
            return initReward_chooseYouWant();
        case 'fox_hammer'://狐狸之锤礼包
            return initReward_foxHammer();
        case 'easter_egg'://四选一
            return initReward_easterEgg();
        // todo rank
        case 'rank':
        case 'rank2'://锦标赛,无进度锦标赛
            return initReward_rank(type);
        case 'build_rank':
        case 'build_rank2'://建筑锦标赛,无进度锦标赛
            return initReward_buildRank(type);
        case 'super_serial_pack'://连环礼包
        case 'super_serial_pack2'://连环礼包2
        case 'super_serial_pack3'://六格连环礼包
        case 'super_serial_pack4'://六格连环礼包
            return initReward_superSerialPack(type);
        case 'super_serial_pack5'://有进度六格连环礼包
        case 'super_serial_pack6'://有进度连环礼包1
        case 'super_serial_pack7'://有进度连环礼包2
            return initReward_superSerialProgressPack(type);
        case 'theme_pack'://主题礼包
        case 'theme_pack2'://主题礼包
            return initReward_themePack();
        case 'safe_surprise':
            return initReward_SafeSurprise()
        case 'shop_promotion'://优惠券
            return initReward_shopPromotion();
        case 'pick_one'://三选一
            return initReward_ChooseOne();
        case 'one_plus_gift'://1+1
            return initReward_OnePlus();
        case 'callback_score'://好友召回活动
            return initReward_CallbackScore();
        case 'time_limited_card'://限时卡组
            return initReward_TimeLimitedCards();
        case 'club_tournament'://公会锦标赛
            return initReward_clubTournament();
        case 'lucky_fox'://幸运狐狸
            return initReward_luckyFox(type);
        case 'super_bomb'://超级炸弹
            return initReward_superBomb(type);
        case 'crazy_build'://疯狂建造
            return initReward_crazyBuild(type);
        case 'special_notice'://特殊公告
            return initReward_specialNotice(type);
        case 'perfect_attack'://完美打
        case 'perfect_chestSpins'://皮肤宝箱最大体力
        case 'perfect_richKing'://richKing最大金币
            return initReward_hideAct(type);
        case 'super_collect2':
        case 'super_collect3'://漂流的宝藏,旅行日记
            return initReward_driftTreasure(type);
        case "great_memories"://回归签到
            return initReward_greatMemories(type);
        case "pinata"://皮纳塔
        case "tarot"://塔罗牌
            return initReward_pinata(type);
        case "club_farm":   // 公会农场
            return initReward_clubFarm(type);
        case "lucky_dice":  // 幸运转盘
            return initReward_luckyDice(type);
    }

    var html2, html3, html4, html_a = '';
    if (["collect", "steal", "attack", "rank", "collect_only", "super_collect"].includes(type)) {//偷，打，收集，排行 概率及收集底数设置 rank2 无进度
        if (Object.keys(reward_conf).length > 0) {
            data = reward_conf;
            selGroupId = data.groupId;
        }
        if ($.inArray(type, ["collect", "collect_only", "super_collect"]) != -1) {
            html_a += addTimeLimit();
            html_a += setProChange();
        }
        html_a += addStagePro(type, data);
        html_a += spinStageTable(type);//阶段table外框
        $("#reward_info").append(html_a);
        initLayDate();
    }
    if (["rank2"].includes(type)) {
        if (Object.keys(reward_conf).length > 0) {
            data = reward_conf;
            selGroupId = data.groupId;
        }
        html_a += addStagePro(type, data);
        $("#reward_info").append(html_a);
    }

    if (["architecture", "accumulated_pay"].includes(type)) {//建筑大师，邀请，累充 单套进度奖励（默认设置table头）
        var html = rewardTable(type);
        $("#reward_info").append(html);
    }

    if ((typeGrout.includes(type)) && Object.prototype.toString.call(reward_info) === '[object Object]' && Object.keys(reward_info).length > 0) {
        console.log("==进度==", reward_info);
        $.each(reward_info, function (k, v) {
            var html = rewardTableTR(v);
            $("#table_body").append(html);
            reward_limit++;
        });
    }
    if (spansTypeGrout.includes(type) || type === 'rank' || type === 'rank2') {
        //收集，偷，打（体力套）初始化数据
        // $('#spinStageRewardOpt').show();
        if (type === 'rank') {
            if (Object.prototype.toString.call(reward_info[1]['list']) === '[object Object]') {
                var stageReward = reward_info;
                console.log('--new_rank_stage_reward--');
            } else {//过度兼容
                var stageReward = {1: {"star": 0, "end": 1000000, "list": reward_info}};
                console.log('--old_rank_stage_reward--');
            }

        } else {
            var stageReward = extra_reward;
        }

        if (Object.prototype.toString.call(stageReward) === '[object Object]' && Object.keys(stageReward).length > 0) {
            console.log("==阶段体力套==", stageReward);
            $.each(stageReward, function (k, v) {
                spinStage++;
                var d = {"star": v['star'], "end": v['end']};
                html2 = spinStageRewardTable(spinStage, d);
                $("#spinStageTable").append(html2);
                $.each(v['list'], function (key, val) {
                    var html = spinStageRwardTR(spinStage, val);
                    $("#table_body_" + spinStage).append(html);
                    if (!spin_reward_limit[spinStage]) {
                        spin_reward_limit[spinStage] = 1;
                    } else {
                        spin_reward_limit[spinStage]++;
                    }
                });
            });
            console.log("体力套数：", spinStage);
        }
    }

    switch (type) {

        case 'rank2'://排行榜无进度
        case 'rank'://排行榜-额外
            html2 = rankTable();
            $("#reward_info").append(html2);
            if (Object.prototype.toString.call(extra_reward[1]['list']) === '[object Object]') {
                var rankReward = extra_reward;
                console.log('--new_rank_reward--');
            } else {//过度兼容
                var rankReward = {1: {"star": 0, "end": 1000000, "list": extra_reward}};
                console.log('--old_rank_reward--');
            }
            if (Object.prototype.toString.call(rankReward) === '[object Object]' && Object.keys(rankReward).length > 0) {
                console.log("==排名体力套==", rankReward);
                $.each(rankReward, function (k, v) {
                    rankSpinStage++;
                    var d = {"star": v['star'], "end": v['end']};
                    html2 = spinRankTable(rankSpinStage, d);
                    $("#rank_table").append(html2);
                    $.each(v['list'], function (key, val) {
                        var html = rankTableTR(rankSpinStage, val);
                        $("#table_body2_" + rankSpinStage).append(html);
                        if (!rank_limit[rankSpinStage]) {
                            rank_limit[rankSpinStage] = 1;
                        } else {
                            rank_limit[rankSpinStage]++;
                        }
                    });
                });
                console.log("排名体力套数：", rankSpinStage);
            }
            $("#reward_info").append(rankVipSet());
            $("#reward_info").append(rankRobot() + rankLimit());
            break;
        case 'collect':
            break;
        case 'speed_spins':
            //体力加速
            // html3= speedSpinsLine(reward_info);
            commonLineTitles = [{"tname": "加速倍率", "vname": "bet"}];
            html3 = commonInput(reward_conf);
            $("#reward_info").append(html3);

            break;
        case 'crazy_bet'://超级倍率
            if (Object.prototype.toString.call(reward_info) === '[object Object]' && Object.keys(reward_info).length > 0) {
                html2 = crazyBetInput(reward_info);
                $("#reward_info").append(html2);
                html3 = crazyBetSpinsRange();
                $("#reward_info").append(html3);

                console.log("==bet==", reward_info);
                if (reward_info['conf']) {
                    $.each(reward_info['conf'], function (k, v) {
                        var html3 = crazyBetLine(v);
                        $("#addCrazyBetLine").before(html3);
                        bet_limit++;
                    });
                }
                if (reward_info['init']['spinsRange']) {
                    $.each(reward_info['init']['spinsRange'], function (k, v) {
                        var html3 = crazyBetSpinsRangeLine(v);
                        $("#addCrazyBetSpinsRange").before(html3);
                        betSpinsRange_limit++;
                    });
                }
            }
            break;
        case 'chain_gift'://连环礼包
            getChainGiftConf();//拉取基础模板数据chain_gift_conf
            if (Object.prototype.toString.call(extra_reward) === '[object Object]' && Object.keys(extra_reward).length > 0) {
                $.each(extra_reward, function (key, val) {
                    this_index++;
                    var html3 = '';
                    var initData = {"score_star": val['score_star'], "score_end": val['score_end']};
                    html2 = chainGiftTable(this_index, initData);
                    $("#reward_info").append(html2);
                    $.each(val['giftList'], function (ke, va) {
                        html3 += chainGift(va, this_index);
                    });
                    $("#chainInfo_" + this_index).append(html3);
                });
                html4 = chainOptBtn();
                $("#reward_info").append(html4);
            }
            break;
        case 'crazy_card_group'://疯狂卡组
            html2 = crazyCardRewardTable();
            $("#reward_info").append(html2);
            if (Object.prototype.toString.call(reward_info) === '[object Object]' && Object.keys(reward_info).length > 0) {
                $.each(reward_info, function (key, val) {
                    var html3 = crazyCardTR(val);
                    $("#table_body").append(html3);
                    reward_limit++;
                });
            }
            break;
        case 'architecture'://建筑大师

            break;
        case 'time_limit_invite'://限时邀请
            $("#reward_info").prepend(initTimelimitInviteWrap());
            if (extra_reward == null || extra_reward == undefined) extra_reward = [];
            $.each(extra_reward, function (i, o) {
                console.log(i, o)
                addTimeLimitInviteGroup()
                $('input[name="timelimitInviteConf[' + i + '][ext_num]"]').val(o.ext_num)
                $('input[name="timelimitInviteConf[' + i + '][msgId]"]').val(o.msgId)
                $('input[name="timelimitInviteConf[' + i + '][url]"]').val(o.url)
                $('select[name="timelimitInviteConf[' + i + '][shushu][]"]').find('option').each(function (i1, o1) {
                    if (o.shushu.includes(parseInt($(o1).val()))) {
                        $(o1).attr('selected', true)
                    }
                })
                $('select[name="timelimitInviteConf[' + i + '][type]"]').find('option').each(function (i1, o1) {
                    if (parseInt(o.type) == parseInt($(o1).val())) {
                        console.log($(o1).text())
                        $(o1).attr('selected', true)
                    }
                })
                $.each(o.reward, function (i1, o1) {
                    addTimelimitInviteRewardNum(i)

                    console.log(i1, o1)
                    $('input[name="timelimitInvite[' + i + '][' + i1 + '][stage]"]').val(o1.stage)
                    $('input[name="timelimitInvite[' + i + '][' + i1 + '][stepnum]"]').val(o1.stepnum)
                    $('select[name="timelimitInvite[' + i + '][' + i1 + '][isShare]"]').val(o1.isShare)
                    $('input[name="timelimitInvite[' + i + '][' + i1 + '][prize]"]').val(unescape(JSON.stringify(o1.prize)))
                    var prizeHtml = ''
                    $.each(o1.prize, function (i2, o2) {
                        prizeHtml += chestPropsHtml(o2);
                    })
                    $('.showStagePrize_' + i + '_' + i1).html(prizeHtml)
                })
            })
            break;
        case 'golden_card_trade'://金卡交换
        case 'black_golden_card_trade'://黑金卡交换
            $("#reward_info").append(goldenCardTradeHtml(type));
            break;
        // case 'shop_promotion'://商城促销
        //     console.log("商城促销 - initReward");
        //     $("#reward_info").append(shop_promotion_html());
        //     for(var i = 0; i < reward_info.init.length; i++){
        //         addShopPromotionConf(reward_info.init[i]);
        //     }
        //     break;
        case 'accumulated_pay'://累充

            break;

        case 'traffic_permit'://通信证
            initTrafficPermitConfig()
            break;
        case 'discounts_architecture'://建筑打折
            html2 = disArchConf(reward_info);
            $("#reward_info").append(html2);
            if (reward_conf) {
                $('input[name="reward_conf[posterDiscount]"]').val(reward_conf.posterDiscount)
            }
            break;
        case 'spin_safe'://保险柜
            var data = reward_conf ? reward_conf : {"groupId": 10, "one_hit": 0, "two_hit": 0, "three_hit": 0};
            $("#reward_info").append(spinCollectChildGroupBasicCfg(data));

            // $("#reward_info").append(getSteelSafeNHtml(extra_reward.n));
            $("#reward_info").append(getSteelSafeHtml());
            $("#reward_info").append(getSteelSafeLimitHtml());
            $("#reward_info").append(getSteelSafeLimitRewardHtml());

            console.log(reward_info);
            if (Object.prototype.toString.call(extra_reward) === '[object Object]' && Object.keys(extra_reward).length > 0) {
                $.each(extra_reward.config, function (key, val) {
                    getSteelSafeTr(val)
                });
                $.each(extra_reward.limit, function (key, val) {
                    getSteelSafeLimitTr(val)
                });
            }
            if (Object.prototype.toString.call(reward_info) === '[object Array]' && Object.keys(reward_info).length > 0) {
                $.each(reward_info, function (key, val) {
                    $("#table_SteelSafeLimitReward").append(getSteelSafeLimitRewardTr(val));
                    steel_safelimit_limit++;
                });
            }
            break;
        case 'super_serial_pack':
        case 'super_serial_pack2'://新连环礼包
        case 'super_serial_pack3'://六格连环礼包
        case 'super_serial_pack4'://六格连环礼包2
            scoreCGType = reward_info['scoreCGType'];
            var html = scoreCGTable(scoreCGType);//体力分套table外框
            $("#reward_info").append(html);
            if (Object.prototype.toString.call(extra_reward) === '[object Object]' && Object.keys(extra_reward).length > 0) {
                console.log("==阶段积分套==", extra_reward);
                $.each(extra_reward, function (k, v) {
                    spinStage++;
                    if (scoreCGType == 1) {
                        var d = {"star": v['star'], "end": v['end']};
                    } else {
                        var d = {"gid": v['gid']};
                    }
                    html2 = scoreCGRewardTable(scoreCGType, spinStage, d);
                    $("#scoreCGTable").append(html2);
                    $.each(v['list'], function (key, val) {
                        var html = scoreCGRwardTR(spinStage, val);
                        $("#table_body_" + spinStage).append(html);
                        if (!spin_reward_limit[spinStage]) {
                            spin_reward_limit[spinStage] = 1;
                        } else {
                            spin_reward_limit[spinStage]++;
                        }
                    });
                });
            }
            break;
        case "coin_blast"://金币大爆炸
            $("#reward_info").append(getCoinCfgHtml(reward_info));
            break;
        case "premium"://
            $("#reward_info").append(getPremiumHtml(reward_conf.spins));
            if (Object.prototype.toString.call(reward_conf.groupArr) === '[object Array]' && Object.keys(reward_conf.groupArr).length > 0) {
                $.each(reward_conf.groupArr, function (key, val) {
                    $("#table_body_premium").append(premiumTR(val));
                    premium_limit++;
                });
            }
            break;
        case "super_balloon"://超级气球
            var html2 = '';
            html2 += setBalloonStyleHtml(activity_extra_data);
            html2 += balloonTable();
            $("#reward_info").append(html2);
            if (Object.prototype.toString.call(extra_reward) === '[object Object]' && Object.keys(extra_reward).length > 0) {
                console.log("==阶段Bet套==", extra_reward);
                $.each(extra_reward, function (k, v) {
                    betStage++;
                    var d = {"star": v['star'], "end": v['end']};
                    $("#balloon_table").append(balloonBetTable(betStage, d));
                    $.each(v['list'], function (key, val) {
                        var html = balloonTableTRHtml(betStage, val);
                        $("#table_body3_" + betStage).append(html);
                        if (!balloon_bet_limit[betStage]) {
                            balloon_bet_limit[betStage] = 1;
                        } else {
                            balloon_bet_limit[betStage]++;
                        }
                    });
                });
            }
            break;
        case "traffic_permit_bet":
            $("#reward_info").append(getTrafficPermitBetHtml(activity_extra_data.bet));
            break;
        case "safe_surprise":
        case "one_plus_gift":
        case "choose_one":
            ChooseOnePriceGroupHtml(reward_info);
            addGroupSelect(extra_reward.groupRid);
            //$("#reward_info").append(ChooseOne(1));
            //if(Object.prototype.toString.call(reward_info) === '[object Object]'&&Object.keys(reward_info).length>0) {
            //    $.each(reward_info,function(key,val) {
            //        chooseOne++
            //        $("#table_body_ChooseOne").append(ChooseOneTR(val))
            //    });
            //}
            break;
        case "fund":
            $("#reward_info").append(Fund());
            if (Object.prototype.toString.call(reward_info) === '[object Array]' && Object.keys(reward_info).length > 0) {
                FundPriceGroupHtml(reward_conf);
                FundHtml(reward_info);
            }
            break;
        case "collect_bet":
            commonLineTitles = [{"tname": "倍率", "vname": "bet"}];
            html3 = commonInput(reward_conf);
            $("#reward_info").append(html3);
            break;
        case "daily_chest":
            var html3 = dailyChest(reward_conf);
            $("#reward_info").append(html3);
            break;
        case "change_collect"://小玩法收集
            var html3 = collectChangeSel(reward_conf);
            $("#reward_info").append(html3);
            commonLineTitles = [{"tname": "收集物1奖励数", "vname": "one_hit"}, {"tname": "收集物2奖励数", "vname": "two_hit"}, {"tname": "收集物3奖励数", "vname": "three_hit"}];
            $("#reward_info").append(commonInput(reward_conf));
            break;
        default:
    }
    $('.select2').select2({})
}

// 按需加载js文件
function loadJs(type) {
    let scriptName = actJSMapping[type]
    if (!scriptName) switch (type) {
        case "super_collect2":
        case "super_collect3":
            scriptName = "drift_treasure"
            break;
        default:
            scriptName = type
    }

    if(loadedJsFiles.includes(scriptName)){
        console.warn(`活动 ${type} JS文件${scriptName}已存在，无需重复加载`);
        return;
    }
    $.ajax({
        async: false,
        url: `static/activity/js/${scriptName}.js`,
        dataType: "script",
        success: function () {
            console.log(`活动 ${type} JS文件${scriptName}加载成功`);
            loadedJsFiles.push(scriptName)
        },
        error: function (data) {
            console.error(`活动 ${type} JS文件${scriptName}加载失败`);
            console.error(data);
        }
    });
}

//无数据状态初始化样式及数据
function showHtmlByType(type) {
    console.log("showHtmlByType====类型：" + type + "====");
    loadJs(type)

    clientSelectorStatus()
    var cid = $("#select_cid").val(0);
    // if(!$("#imgName").val()&&imgNames[act_type] ){
    //     setImgName('');
    // }
    if (!isInit) {
        setImgName('');
    }
    isInit = false;
    switch (type) {
        case 'jackpot':
            return changeTypeToJackpot();
        case 'surprise_collect':
            return changeTypeTo_surprise_collect();
        case 'coin_push_mania':
            return changeTypeToCoinPushMania();
        case 'club_garden':
            return changeTypeTo_club_garden();
        case 'super_collect':
            return changeTypeTo_super_collect();
        case 'spins_master':
            return changeTypeTo_spins_master();
        case 'super_gashapon':
            return changeTypeTo_superGashapon();
        case 'collect_jigsw':
            return changeTypeTo_collect_jigsw();
        case 'treasure'://宝藏活动
            return changeTypeTo_treasure();
        case 'maya_wheel'://玛雅转盘
            return changeTypeTo_mayaWheel();
        case 'choose_you_want'://随心配
            return changeTypeTo_chooseYouWant();
        case 'fox_hammer'://狐狸之锤礼包
            return changeTypeTo_foxHammer();
        case 'easter_egg'://四选一
            return changeTypeTo_easterEgg();
        case "rank":
        case "rank2":
            return changeTypeTo_rank(type);
        case "build_rank":
        case "build_rank2":
            return changeTypeTo_buildRank(type);
        case 'super_serial_pack'://连环礼包
        case 'super_serial_pack2'://连环礼包2
        case 'super_serial_pack3'://六格连环礼包
        case 'super_serial_pack4'://六格连环礼包2
            return changeTypeTo_superSerialPack(type);
        case 'super_serial_pack5'://有进度六格连环礼包
        case 'super_serial_pack6'://有进度连环礼包1
        case 'super_serial_pack7'://有进度连环礼包2
            return changeTypeTo_superSerialProgressPack(type);
        case 'theme_pack'://主题礼包
        case 'theme_pack2'://主题礼包
            return changeTypeTo_themePack(type);
        case 'safe_surprise':
            return changeTypeTo_SafeSurprise()
        case 'shop_promotion'://优惠券
            return changeTypeTo_shopPromotion();
        case 'pick_one'://优惠券
            return changeTypeTo_ChooseOne();
        case 'one_plus_gift'://1+1
            return changeTypeTo_OnePlus();
        case 'callback_score'://好友召回活动
            return changeTypeTo_CallbackScore();
        case 'time_limited_card'://限时卡组
            return changeTypeTo_TimeLimitedCards();
        case 'club_tournament'://公会锦标赛
            return changetypeTo_clubTournament();
        case 'lucky_fox'://幸运狐狸
            return changetypeTo_luckyFox(type);
        case 'super_bomb'://超级炸弹
            return changetypeTo_superBomb(type);
        case 'crazy_build'://疯狂建造
            return changetypeTo_crazyBuild(type);
        case 'special_notice'://特殊公告
            return changetypeTo_specialNotice(type);
        case 'perfect_attack'://完美打
        case 'perfect_chestSpins'://皮肤宝箱最大体力
        case 'perfect_richKing'://richKing最大金币
            return changetypeTo_hideAct(type);
        case 'super_collect2':
        case 'super_collect3'://漂流的宝藏，旅行日记
            return changeTypeTo_driftTreasure(type);
        case "great_memories"://回归签到
            return changeTypeTo_greatMemories(type);
        case "pinata"://皮纳塔
        case "tarot"://塔罗牌
            return changeTypeTo_pinata(type);
        case "club_farm"://公会农场
            return changetypeTo_clubFarm(type);
        case "lucky_dice":  // 幸运转盘
            return changeTypeTo_luckyDice(type);
    }
    var html = '';

    $("#reward_info").empty();
    if (["rank", "super_collect", "rank2"].includes(type)) {//收集，排行 概率及收集底数（默认设置）
        data = {"attack_success": 0, "attack_break": 0, "three_hit": 0, "steal_success": 0, "steal_break": 0, "two_hit": 0, "one_hit": 0, "groupId": 1};

        html += addStagePro(type, data);
        if (type != 'rank2') {
            html += spinStageTable(type);//阶段table外框
        }
    }
    if (["architecture", "accumulated_pay"].includes(type)) {//建筑大师，邀请，累充,体力大师 单套进度奖励（默认设置）

        html += rewardTable(type);
    }
    $("#reward_info").append(html);
    initLayDate();

    if (spansTypeGrout.includes(type)) {//收集，偷，打（体力套）,排行榜,四选一（默认配置）
        spinStage = 1;
        var d = {"star": 0, "end": 0};
        if (type != 'rank2') { //有进度
            html = spinStageRewardTable(spinStage, d);//阶段奖励内部table
            $("#spinStageTable").append(html);
        }
    }
    switch (type) {
        case 'surprise_card':
            changeTypeToSurpriseCard();
            break;
        case 'collect':
            break;
        case 'rank2'://排行榜 - 无进度
        case 'rank'://排行榜-额外
            var html2 = '';
            // html2 = rankTable();
            // $("#reward_info").append(html2);
            html2 = rankTable();
            $("#reward_info").append(html2);
            rankSpinStage = 1;
            html2 = spinRankTable(rankSpinStage, d);
            $("#rank_table").append(html2);
            $("#reward_info").append(rankVipSet());
            $("#reward_info").append(rankRobot() + rankLimit());
            break;
        case 'speed_spins'://体力加速
            commonLineTitles = [{"tname": "加速倍率", "vname": "bet"}];
            html2 = commonInput({"bet": 2});
            // reward_info = [
            //     {"id":1,"tips":"开启最大bet","bet":2,"effecteTime":600,"max":1,"open":1},
            //     {"id":2,"tips":"开启自动转动","bet":2,"effecteTime":600,"max":1,"open":1},
            //     {"id":3,"tips":"看过3次广告","bet":2,"effecteTime":600,"max":1,"open":1},
            //     {"id":4,"tips":"当天购买过体力","bet":2,"effecteTime":600,"max":1,"open":1},
            //     {"id":5,"tips":"粉丝开启","bet":2,"effecteTime":600,"max":1,"open":1}
            // ];
            // html2= speedSpinsLine(reward_info);
            $("#reward_info").append(html2);
            break;
        case 'crazy_bet'://超级倍率
            reward_info = {"init": {"actSpinsLimit": 150}};
            html2 = crazyBetInput(reward_info);
            $("#reward_info").append(html2);
            html3 = crazyBetSpinsRange();
            $("#reward_info").append(html3);
            break;
        case 'chain_gift'://连环礼包
            this_index = 1;
            var html2 = html3 = html4 = '';
            var initData = {"score_star": 0, "score_end": 0,};
            html2 = chainGiftTable(this_index, initData);
            $("#reward_info").append(html2);
            for (var i = 0; i < chain_gift_conf.length; i++) {
                html3 += chainGift(chain_gift_conf[i], this_index);
            }
            $("#chainInfo_" + this_index).append(html3);
            html4 = chainOptBtn();
            $("#reward_info").append(html4);
            break;
        case 'crazy_card_group':
            html2 = crazyCardRewardTable();
            $("#reward_info").append(html2);
            break;
        case 'architecture'://建筑大师
            break;
        case 'golden_card_trade'://金卡交换
        case 'black_golden_card_trade'://黑金卡交换
            $("#reward_info").append(goldenCardTradeHtml(type));
            break;
        case 'time_limit_invite'://限时邀请
            data = {"type": 3, "ext_num": 2};
            // html = timelimitInvite(data);
            // console.log(html)
            $("#reward_info").prepend(initTimelimitInviteWrap());
            return;
            break;
        case 'shop_promotion'://商城促销
            console.log("商城促销 ---- reward_info", reward_info);
            $("#reward_info").append(shop_promotion_html());
            console.log(shop_promotion_html());
            // for(var i = 0; i < reward_info.init.length; i++){
            // 	addShopPromotionConf(reward_info.init[i]);
            // }
            break;
        case 'accumulated_pay'://累充
            break;
        case 'traffic_permit'://通信证
            initTrafficPermitWrap()
            break;
        case 'discounts_architecture'://建筑打折
            var conf = [{"level": 1, "disNum": 20}, {"level": 2, "disNum": 20}, {"level": 3, "disNum": 20}, {"level": 4, "disNum": 20}, {"level": 5, "disNum": 20}];
            html2 = disArchConf(conf);
            $("#reward_info").append(html2);
            break;
        case 'super_serial_pack':
        case 'super_serial_pack2'://新版连环礼包
        case 'super_serial_pack3'://六格连环礼包
        case 'super_serial_pack4'://六格连环礼包2
            html += scoreCGTable(scoreCGType);//体力分套table外框
            $("#reward_info").append(html);
            if (scoreCGType == 1) {
                var d = {"star": 0, "end": 0};
            } else {
                var d = {"gid": 0};
            }
            html = scoreCGRewardTable(scoreCGType, ++spinStage, d);//阶段奖励内部table
            $("#scoreCGTable").append(html);
            break;
        case "spin_safe":
            var data = {"groupId": 10, "one_hit": 0, "two_hit": 0, "three_hit": 0};
            $("#reward_info").append(spinCollectChildGroupBasicCfg(data));
            //$("#reward_info").append(getSteelSafeNHtml(2));
            $("#reward_info").append(getSteelSafeHtml());
            var conf = [{"progress": 1, "coins": "coins01", "bet": 1, "n": 1}, {"progress": 2, "coins": "coins01", "bet": 1, "n": 1}, {"progress": 3, "coins": "coins01", "bet": 1, "n": 1}];
            conf.forEach(function (data, index) {
                getSteelSafeTr(data);
            });
            $("#reward_info").append(getSteelSafeLimitHtml());
            $("#reward_info").append(getSteelSafeLimitRewardHtml());
            break;
        case "coin_blast"://金币大爆炸
            var d = [{"type": "steal", "bet": 0}, {"type": "attack", "bet": 0}, {"type": "slot", "bet": 0}];
            $("#reward_info").append(getCoinCfgHtml(d));
            break;
        case "premium"://premium
            $("#reward_info").append(getPremiumHtml(50));
            break;
        case "super_balloon":
            var html2 = '';
            var d = {"moveType": 1, "speed": 1, "outPut": {1: 600, 2: 30, 3: 10}, "showPv": 50};
            html2 += setBalloonStyleHtml(d);
            html2 += balloonTable();
            $("#reward_info").append(html2);
            betStage = 1;
            var d2 = {"star": 1, "end": 20};
            $("#balloon_table").append(balloonBetTable(betStage, d2));
            break;
        case "traffic_permit_bet":
            $("#reward_info").append(getTrafficPermitBetHtml(2));
            break;
        case "safe_surprise":
        case "one_plus_gift":
        case "choose_one":
            ChooseOnePriceGroupHtml({});
            addGroupSelect(0);
            //$("#reward_info").append(ChooseOne(1));
            //addChooseOneBtn(1)
            //addChooseOneBtn(2)
            break;
        case "fund":
            $("#reward_info").append(Fund());
            FundPriceGroupHtml(reward_conf);
            FundHtml([{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}, {"id": 6}, {"id": 7}, {"id": 8}, {"id": 9}, {"id": 10}, {"id": 11}, {"id": 12}, {"id": 13}, {"id": 14}]);
            break;
        case "collect_bet":
            commonLineTitles = [{"tname": "倍率", "vname": "bet"}];
            $("#reward_info").append(commonInput({"bet": 2}));
            break;
        case "daily_chest":
            var html3 = dailyChest(reward_conf);
            $("#reward_info").append(html3);
            break;
        case "change_collect":
            var html3 = collectChangeSel({"item": 1});
            $("#reward_info").append(html3);
            commonLineTitles = [{"tname": "收集物1奖励数", "vname": "one_hit"}, {"tname": "收集物2奖励数", "vname": "two_hit"}, {"tname": "收集物3奖励数", "vname": "three_hit"}];
            $("#reward_info").append(commonInput({"one_hit": 0, "two_hit": 0, "three_hit": 1}));
            break;
        default:
            console.log(type)
    }
}

function showCidSelect() {
    $("#select_cid").empty();
    $("#imgName").val('');
    var html = cidSelectOp();
    $("#select_cid").append(html);
}

//设置资源名，显示资源图（展不实现）
function setImgName(str) {
    imgNameInvalid = 0;
    $('.imgNameTips').text('').hide()
    $("#imgName").val(str);
    checkImgName(str)
}

$('#imgName').blur(function () {
    imgNameInvalid = 0;
    $('.imgNameTips').hide()
    var imgName = $(this).val()
    if (imgName) {
        checkImgName(imgName)
    }
})
$('select[name="extraData[isShowSpine]"]').change(function () {
    imgNameInvalid = 0;
    $('.imgNameTips').hide()
    var imgName = $('#imgName').val()
    if (imgName) {
        checkImgName(imgName)
    }
})

function checkImgName(imgName) {
    if (!imgName || imgName.length < 1) return;
    if (act_type == 'traffic_permit') return;
    var isSpine = 0;
    if ($('select[name="extraData[isShowSpine]"]').length > 0) {
        isSpine = $('select[name="extraData[isShowSpine]"]').val()
    }
    showLoading()
    $.post('/activity/checkImgName/' + imgName + '/' + isSpine, {imgName: imgName, isSpine: isSpine}, function (res) {
        hideLoading()
        if (typeof res == 'string') res = JSON.parse(res)
        console.log(res)

        if (res.ret < 0) {
            imgNameInvalid = 1
            $('.imgNameTips').text(res.msg).show()
        } else {
            imgNameInvalid = 0
            $('.imgNameTips').text(res.msg).hide()
        }
    })
}

function checkCouponSkinImgName(imgName) {
    showLoading()
    var isSpine = 0
    $.post('/activity/checkImgName/' + imgName + '/' + isSpine, {imgName: imgName, isSpine: isSpine}, function (res) {
        hideLoading()
        if (typeof res == 'string') res = JSON.parse(res)
        console.log(res)

        if (res.ret < 0) {
            couponSkinImgNameInvalid = 1
            $('.couponSkinImgNameTips').text(res.msg).show()
        } else {
            couponSkinImgNameInvalid = 0
            $('.couponSkinImgNameTips').text(res.msg).hide()
        }
    })
}

//==================公共方法===================
//============================================
//添加进度奖行
function addRewardNum() {
    reward_limit++;
    if (act_type == 'crazy_card_group') {//疯狂卡组奖励行
        var data = {"stage": reward_limit, "slv": 10, "elv": 20, "num": 50};
        var html = crazyCardTR(data);
    } else {
        var data = {"stage": reward_limit, "stepnum": 0, "progressBarId": 0, "lv": 1};
        var html = rewardTableTR(data);
    }
    $("#table_body").append(html);
}

//删除进度奖励行
function delRewardNum() {
    if (reward_limit > 0) {
        // console.log(reward_limit);
        $("#table_body").children("tr:last-child").remove();
        reward_limit--;
    }
}

//第二个阶段奖励
function addRewardNum2(index, t) {
    if (index == 2) {
        reward_limit2++;
        if (reward_limit2 > 10) {
            alert('不能超过10行');
            return;
        }
        var data = {"stage": reward_limit2, "stepnum": 0, "progressBarId": 0, "lv": 1};
    } else if (index == 3) {
        reward_limit3++;
        if (reward_limit3 > 1) {
            alert('不能超过1行');
            return;
        }
        var data = {"stage": reward_limit3, "stepnum": 0, "progressBarId": 0, "lv": 1};
    }
    var html = rewardTableTR2(data, t, index);
    $("#table_body" + index).append(html);
}

//删除进度奖励行
function delRewardNum2(index) {
    if (index == 2 && reward_limit2 > 0) {
        // console.log(reward_limit2);
        $("#table_body2").children("tr:last-child").remove();
        reward_limit2--;
    } else if (index == 3 && reward_limit3 > 0) {
        $("#table_body3").children("tr:last-child").remove();
        reward_limit3--;
    }
}

function addSpinRewardNum(index) {
    if (!spin_reward_limit[index]) {
        spin_reward_limit[index] = 1;
    } else {
        spin_reward_limit[index]++;
    }
    var data = {"stage": spin_reward_limit[index], "stepnum": 0, "progressBarId": 0, "lv": 1};
    var html = spinStageRwardTR(index, data);
    // console.log(html);

    $("#table_body_" + index).append(html);
}

function delSpinRewardNum(index) {
    if (spin_reward_limit[index] > 0) {
        // console.log(reward_limit);
        $("#table_body_" + index).children("tr:last-child").remove();
        spin_reward_limit[index]--;
    }
}

//道具版本支持判别
function propSelVersion(pid) {
    var isok = true;
    var pname = reward_type_arr[pid]['name'];
    if ($.inArray(parseInt(pid), [25, 26]) != -1) {//建筑,大师气球
        $('input[name="act_version[]"]:checked').each(function () {
            var selVersion = $(this).val();
            // if(toNum(selVersion)<toNum('1.7.5.0')){
            //     alert(pname+'仅支持1.7.5.0及之后版本');
            //     isok =false;
            //     return false;
            // }
        });
        if ($('input[name="act_version[]"]:checked').length == 0) {
            var ret = window.confirm('当前没有选择任何版本,默认所有版本,但活动道具只支持1.7.5.0及之后的版本,可能出现老版本无法展示道具(' + pname + '),确认如此操作么!!!');
            if (!ret) {
                return false;
            }
        }
    }
    if ($.inArray(parseInt(pid), [28, 31, 32, 33, 34]) != -1) {//金币爆炸,疯狂加倍,建筑打折,卡片活动,商场优惠
        $('input[name="act_version[]"]:checked').each(function () {
            var selVersion = $(this).val();
            // if(toNum(selVersion)<toNum('1.7.7.0')){
            //     alert('('+pname+')仅支持1.7.7.0及之后版本');
            //     isok =false;
            //     return false;
            // }
        });
        if ($('input[name="act_version[]"]:checked').length == 0) {
            var ret = window.confirm('当前没有选择任何版本,默认所有版本,但此活动道具只支持1.7.7.0及之后的版本,可能出现老版本无法展示此道具(' + pname + '),确认如此操作么!!!');
            if (!ret) {
                return false;
            }
        }
    }

    // if($.inArray(parseInt(pid),actPropArr)!= -1&&$.inArray(act_type,actTypeProp) == -1){
    //     if(parseInt(pid) != 41 || act_type != "rank" ||act_type=='rank2'){
    //         alert('(收集活动限时,特殊收集限时,通行证,连环礼包,超级连环礼包,二选一活动)以外的活动可能会有兼容问题，谨慎配置');
    //         // return false;
    //     }
    // }
    // console.log("=========>"+actProps[pid]+"<=========");
    if (actProps[pid] != null || actProps[pid] != undefined) {
        $('input[name="act_version[]"]:checked').each(function () {
            var selVersion = $(this).val();
            // if(toNum(selVersion)<toNum(actProps[pid])){
            //     alert('('+pname+')仅支持'+actProps[pid]+'及之后版本');
            //     isok =false;
            //     return false;
            // }
        });
        if ($('input[name="act_version[]"]:checked').length == 0) {
            var ret = window.confirm('当前没有选择任何版本,默认所有版本,但此活动道具只支持(' + actProps[pid] + ')及之后的版本,可能出现老版本无法展示此道具(' + pname + '),确认如此操作么!!!');
            if (!ret) {
                return false;
            }
        }
    }

    if (!isok) {
        return false;
    }
    return true;
}

//活动对版本支持判别
function actVersion() {
    var isok = true;
    var actTypeVersionMin = {};//最低版本支持
    var actTypeVersionMax = {};//最高版本支持
    // if(!actTypeVersionMin[act_type]&&!actTypeVersionMax[act_type]){
    //     return true;
    // }
    $('input[name="act_version[]"]:checked').each(function () {
        var selVersion = $(this).val();
        // if(actTypeVersionMin[act_type]&&toNum(selVersion)<toNum(actTypeVersionMin[act_type])){
        //     isok =false;
        //     alert(act_type+'仅支持'+actTypeVersionMin[act_type]+'及之后版本');
        //     return false;
        // }
        // if(actTypeVersionMax[act_type]&&toNum(selVersion)>toNum(actTypeVersionMax[act_type])){
        //     isok =false;
        //     alert(act_type+'仅支持'+actTypeVersionMax[act_type]+'及之前的版本');
        //     return false;
        // }
        console.log(toNum(selVersion) < toNum("1.10"), selGroupId, [8, 9].includes(selGroupId));
        // if(act_type=='super_collect'&&toNum(selVersion)<toNum("1.10")&&[8,9].includes(selGroupId)){
        //     isok =false;
        //     alert(act_type+'活动子类型<<'+child_groups[selGroupId]+'>>仅支持1.10及之后的版本');
        //     return false;
        // }
    });
    if (actTypeVersionMin[act_type] && $('input[name="act_version[]"]:checked').length == 0) {
        alert(act_type + '仅支持' + actTypeVersionMin[act_type] + '及之后版本,当前未选择版本');
        isok = false;
    }
    if (actTypeVersionMax[act_type] && $('input[name="act_version[]"]:checked').length == 0) {
        alert(act_type + '仅支持' + actTypeVersionMax[act_type] + '及之前版本,当前未选择版本');
        isok = false;
    }
    if (!isok) {
        return false;
    }
    return true;
}

//===============新连环礼包====================

function addCGScoreRewardNum(index) {
    if (!spin_reward_limit[index]) {
        spin_reward_limit[index] = 1;
    } else {
        spin_reward_limit[index]++;
    }
    console.log('分组：阶段-', index, spin_reward_limit[index]);

    var data = {"stage": spin_reward_limit[index], "name": "连环礼包" + spin_reward_limit[index], "mtype": 1, "sku": 0, "price": 0, "coin": "coin01", "bet": 0, 'gMax': 1};
    var html = scoreCGRwardTR(index, data);
    // console.log(html);

    $("#table_body_" + index).append(html);
}

function delCGScoreRewardNum(index) {
    if (spin_reward_limit[index] > 0) {
        // console.log(reward_limit);
        $("#table_body_" + index).children("tr:last-child").remove();
        spin_reward_limit[index]--;
    }
}

//===================================
//添加排行奖励行
//添加bet行
function addBetConf() {
    bet_limit++;
    var data = {"id": bet_limit, "bet": 1, "levelId": 1, "spins": 0, "spinsLimit": 0};
    var html = crazyBetLine(data);
    $("#addCrazyBetLine").before(html);
}

//添加bet spins range行
function addBetSpinsRangeConf() {
    betSpinsRange_limit++;
    var data = {"id": betSpinsRange_limit, "bet": 1, "spins": 1};
    var html = crazyBetSpinsRangeLine(data);
    $("#addCrazyBetSpinsRange").before(html);
}

//删除bet行
function delBetConf() {
    if (bet_limit) {
        $("#bet_line").children(".row")[bet_limit - 1].remove();
        bet_limit--;
    }
}

//删除bet行
function delBetSpinsRangeConf() {
    if (betSpinsRange_limit) {
        $("#betSpinsRange_line").children(".row")[betSpinsRange_limit - 1].remove();
        betSpinsRange_limit--;
    }
}

function addChainStage() {
    this_index++;
    console.log("新增连环礼包配置行：" + this_index);
    var html2 = html3 = '';
    var initData = {"score_star": 0, "score_end": 0,};
    html2 = chainGiftTable(this_index, initData);
    $("#chainOptBtn").before(html2);
    for (var i = 0; i < chain_gift_conf.length; i++) {
        html3 += chainGift(chain_gift_conf[i], this_index);
    }
    console.log(chain_gift_conf);
    $("#chainInfo_" + this_index).append(html3);
}

function delChainStage() {
    if (this_index > 1) {
        $("#reward_info").find("#chainTable_" + this_index).remove();
        this_index--;
    }
}

//添加连环礼包奖励行
function addprops(gid, index) {
    var prop = {"pronId": 14, "num": 1};
    var pid = $("#props_" + index + '_' + gid).children().length;
    var html = chainGiftProps(prop, pid, gid, index);
    $("#props_" + index + '_' + gid).append(html);
}

//删除连环礼包奖励行
function delprops(gid, index) {
    $("#props_" + index + '_' + gid).children(".props_line:last-child").remove();
}

//添加限时排期
function addTimeLimitTs(type = 0) {
    var count = $(".laydate-item").length;
    if (type && count) {
        var lastDay = ''
        var dayIdx = {};
        $(".laydate-item").each(function (i, o) {
            var day = $(o).val().split(' ');
            day = lastDay = day[0]
            if (dayIdx[day] == undefined) {
                dayIdx[day] = []
            }
            dayIdx[day].push(i)
        });
        $.each(dayIdx[lastDay], function (i, o) {
            var str = $($(".laydate-item")[o]).val();
            var arr = str.split('~');
            var str1 = arr[0].replace(/(^\s*)|(\s*$)/g, "");
            var str2 = arr[1].replace(/(^\s*)|(\s*$)/g, "");
            str1 = addOneDays(str1);
            str2 = addOneDays(str2);
            addTimeLimitTsItem(str1, str2);
        })

    } else {
        if ($(".laydate-item").length > 0) {
            var date1 = $(".laydate-item:last").val();
            var arr = date1.split('~');
            var str1 = arr[0].replace(/(^\s*)|(\s*$)/g, "");
            var str2 = arr[1].replace(/(^\s*)|(\s*$)/g, "");
        } else {
            var date = new Date();
            var dateObj = {year: date.getFullYear(), month: parseInt(date.getMonth() + 1), date: date.getDate()};
            var dateStr = dateObj.year + '-' + dateObj.month + '-' + dateObj.date;
            var str1 = new Date(dateStr);
            var str2 = str1.getTime() + 1 * 3600 * 1000;
        }
        // 限时奖励添加时间间隔配置
        var timeJG = parseInt($('.addTimeLimitDefaultHours').val())
        str1 = addOneDays(str1, timeJG);
        str2 = addOneDays(str2, timeJG);
        addTimeLimitTsItem(str1, str2);
    }
    initLayDate();
}

//添加限时排期子项
function addTimeLimitTsItem(date1, date2) {
    timeLimit++;
    var html = timeLimitTs(timeLimit, date1, date2);
    $("#timelimit_ts").append(html);
}

//删除限时排期
function delTimeLimitTs() {
    if (timeLimit > 0) {
        $("#timelimit_ts").children(".ttss")[timeLimit - 1].remove();
        timeLimit--;
    }
}

//添加限时bet奖励值排期
function addTimeLimitBetTs() {
    timeLimitBet++;
    var date1 = $curDate;
    var html = timeLimitBetTs(timeLimitBet, date1, date1);
    $("#timelimit_bet_ts").append(html);
}

//删除限时bet奖励值排期
function delTimeLimitBetTs() {
    if (timeLimitBet > 1) {
        $("#timelimit_bet_ts").children(".ttss")[timeLimitBet - 1].remove();
        timeLimitBet--;
    }
}

function addSpinsProTR() {
    spinsProLimit++;
    var data = {"stage": spinsProLimit, "spins": 0, "num": 1};
    var html = SpinsProTR(data);
    $("#table_body_changeSpinsPro").append(html);
}

function delSpinsProTR() {
    if (spinsProLimit > 1) {
        $("#table_body_changeSpinsPro").children(".ttss")[spinsProLimit - 1].remove();
        spinsProLimit--;
    }
}

//================================================
//资源目录选项html
function cidSelectOp() {
    var html = '';
    console.log(imgNames[act_type]);

    html += '<option value="0">选择活动皮肤</option>';
    if (imgNames[act_type] && imgNames[act_type] != undefined) {
        $.each(imgNames[act_type], function (k, v) {
            html += '<option value="' + k + '">' + v['name'] + '</option>';
        });
    }
    return html;
}

//====================收集类型=======================
function timeLimitTs(n, value1, value2) {
    var html = '<div class="col-sm-3 ttss">';
    html += '<input type="text" class="form-control laydate-item" id="time_' + n + '" placeholder=" 时间选择 " name="extraData[ts][' + n + ']" value="' + value1 + ' ~ ' + value2 + '">';
    html += '</div>';
    return html;
}

//限时bet(已放弃使用)===>>
function addTimeLimit() {
    var html = '';
    html += '<div class="form-group">';
    var sel = activity_extra_data['open'] == 1 ? 'checked' : '';
    // html +='<label class="col-sm-2 control-label">是否开启限时奖励(时间仅精确到分):</label><div class="col-sm-1"><input type="checkbox" class="form-check-input" name="extraData[open][]" value="1" '+sel+'></div>';
    html += '<label class="col-sm-2 control-label">是否开启限时奖励(时间仅精确到分):</label>' +
        '<div class="col-sm-1">' +
        '<input type="checkbox" class="form-check-input" name="extraData[open][]" value="1" ' + sel + '>' +
        '</div>' +
        '<label class="col-sm-2 control-label">添加按钮增加的时间间隔小时数:</label>' +
        '<div class="col-sm-1">' +
        '<input  class="form-check-input addTimeLimitDefaultHours" type="number"   name="addTimeLimitDefaultHours" value="3" >' +
        '</div>';
    html += '</div>';
    html += '<br><div id="timelimit_ts" class="form-group">';
    console.log(activity_extra_data['ts']);
    if (activity_extra_data['ts'] && Object.keys(activity_extra_data['ts']).length > 0) {
        $.each(activity_extra_data['ts'], function (k, v) {
            //     console.log(v);
            html += timeLimitTs(k, v['s'], v['e']);
            timeLimit++;
        });
    }
    html += '</div>';
    html += '<div class="text-center"><botton class="btn btn-primary" id="addReward2" onclick="addTimeLimitTs(0)">添加</botton>&nbsp;<botton class="btn btn-primary" id="addReward3" onclick="addTimeLimitTs(1)">超级添加</botton>&nbsp;<botton class="btn btn-danger del-tr" onclick="delTimeLimitTs()">删除</botton>';
    html += '<hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    return html;
}

function addTimeLimitBet() {
    console.log(activity_extra_data);
    var html = '';
    html += '<div class="form-group">';
    var sel = activity_extra_data['open_bet'] == 1 ? 'checked' : '';
    var bet = activity_extra_data['bet'] > 0 ? activity_extra_data['bet'] : 2;
    html += '<label class="col-sm-2 control-label">是否开启限时进度值加倍:</label><div class="col-sm-1"><input type="checkbox" class="form-check-input" name="extraData[open_bet][]" value="1" ' + sel + '></div>';
    html += '<label class="col-sm-2 control-label">加倍BET值:</label><div class="col-sm-1"><input type="text" class="form-control" name="extraData[bet]" value="' + bet + '" ></div>';
    html += '</div>';
    html += '<br><div id="timelimit_bet_ts" class="form-group">';
    console.log(activity_extra_data['bet_ts']);
    if (activity_extra_data['bet_ts'] && Object.keys(activity_extra_data['bet_ts']).length > 0) {
        $.each(activity_extra_data['bet_ts'], function (k, v) {
            //     console.log(v);
            html += timeLimitBetTs(k, v['s'], v['e']);
            timeLimitBet++;
        });
    }
    html += '</div>';
    html += '<div class="text-center"><botton class="btn btn-primary" id="addReward3" onclick="addTimeLimitBetTs()">添加</botton><botton class="btn btn-danger del-tr" onclick="delTimeLimitBetTs()">删除</botton>';
    html += '<hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    return html;
}

function timeLimitBetTs(n, value1, value2) {
    var html = '<div class="col-sm-3 ttss">';
    html += '<input type="text" class="form-control" id="bet_time_' + n + '" placeholder=" 时间选择 " name="extraData[bet_ts][' + n + ']" value="' + value1 + ' ~ ' + value2 + '">';
    html += '</div>';
    var id = '#bet_time_' + n;
    laydate.render({
        elem: id
        , type: 'datetime'
        , range: '~'
    });
    return html;
}

//<<====
//体力对概率系数修正
function setProChange() {
    var html = '';
    var cols = 3;
    html += '<div class="form-group" id="spinsPro_table">';
    var selected = activity_extra_data['openPro'] == 1 ? 'selected' : '';
    html += '<div class="form-group">';
    html += '<label class="col-sm-2 control-label">是否开启体力及阶段对概率的修正:</label>';
    html += '<div class="col-sm-1"><select name="extraData[openPro]" class="form-control"><option value="0" ' + selected + '>关闭</option><option value="1" ' + selected + '>开启</option></select></div>';
    html += '</div>';
    html += '<div class="form-group">';
    html += '<label class="col-sm-2 control-label">体力对概率的修正配置:</label>';
    html += '</div>';
    html += '<table class="table table-bordered">';
    html += '<thead><tr><th>stage</th><th>体力值</th><th>系数</th></thead>';
    html += '<tbody id="table_body_changeSpinsPro">';
    if (activity_extra_data['spinsPro'] && Object.keys(activity_extra_data['spinsPro']).length > 0) {
        $.each(activity_extra_data['spinsPro'], function (k, v) {
            html += SpinsProTR(v);
            spinsProLimit++;
        });
    }
    html += '</tbody><tr><td colspan="' + cols + '"><div class="text-center"><botton class="btn btn-primary" id="addReward" onclick="addSpinsProTR()">添加</botton><botton class="btn btn-danger del-tr" onclick="delSpinsProTR()">删除</botton>';
    html += '</div></td></tr></table></div>';
    html += '<hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    return html;
}

function SpinsProTR(data) {
    var html = '';
    html += '<tr id="spinsPro_' + data['stage'] + '" class="ttss">';
    html += '<td><input type="text" class="form-control" name="extraData[spinsPro][' + data['stage'] + '][stage]" value="' + data['stage'] + '" readonly></td>';
    html += '<td><input type="text" class="form-control" name="extraData[spinsPro][' + data['stage'] + '][spins]" value="' + data['spins'] + '" ></td>';
    html += '<td><input type="text" class="form-control" name="extraData[spinsPro][' + data['stage'] + '][num]" value="' + data['num'] + '"></td>';
    html += '</tr>';
    return html;
}

//添加奖励html
function addStagePro(type, data = []) {
    // var pro =["攻击","偷袭","体力","护盾","1个金币","2个金币","3个金币","1个钱袋","2个钱袋","3个钱袋","没有奖励","活动"];

    var groupId = 0;
    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>';
    if (act_type === 'super_collect') {
        groupId = data.groupId != undefined && data.groupId ? parseInt(data.groupId) : 0;
        html += '<div class="form-group">';
        html += '<label class="col-sm-1 control-label">收集类型*: </label><div class="col-sm-4"><select id="selectChildGroup" class="form-control m-b" name="groupId">';
        $.each(child_groups, function (k, v) {
            var sel = groupId == k ? 'selected' : '';
            html += '<option  value="' + k + '"' + sel + '>' + v + '</option>'
        });
        html += '</select></div>';
        html += '</div>';
    }

    html += '<div id="collectChildGroupBasic">';
    html += collectChildGroupBasicCfg(data);
    html += '</div>';

    html += '</div>';
    html += '<hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    return html;
}

function spinCollectChildGroupBasicCfg(data) {
    html = '<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">收集基础值配置*:</h5></div>';
    html += '<div id="collectChildGroupBasic">';
    html += collectChildGroupBasicCfg(data);
    html += '</div></div>';
    return html;
}

function collectChildGroupBasicCfg(data) {
    var html = '';
    var groupId = data.groupId != undefined && data.groupId ? parseInt(data.groupId) : 1;
    html += '<div class="form-group">';
    if ($.inArray(groupId, [1, 4, 6, 7, 9]) != -1 || act_type == 'rank' || act_type == 'rank2') {
        var txt1 = '';
        if (groupId == 9) {
            txt1 = '三个';
            html += '<label class="col-xs-1 control-label">一个打:</label><div class="col-sm-1"><input type="text"  name="one_attack" value="' + data.one_attack + '" class="form-control"></div>';
            html += '<label class="col-xs-1 control-label">两个打:</label><div class="col-sm-1"><input type="text"  name="two_attack" value="' + data.two_attack + '" class="form-control"></div>';
        }
        html += '<label class="col-xs-1 control-label">打:</label><div class="col-sm-1"><input type="text"  name="attack_success" value="' + data.attack_success + '" class="form-control"></div>';
        var gtype_1 = 'text';
        var gdata_1 = data.attack_break;
        var noshow_1 = '';
        if ($.inArray(groupId, [4, 9]) != -1) {
            gtype_1 = 'hidden';
            gdata_1 = data.steal_success;
            noshow_1 = 'noshow';
        }
        html += '<label class="col-xs-1 control-label ' + noshow_1 + '">打到盾:</label><div class="col-sm-1"><input type="' + gtype_1 + '"  name="attack_break" value="' + gdata_1 + '" class="form-control"></div>';
    }
    if ($.inArray(groupId, [1, 3, 5, 7, 8]) != -1 || act_type == 'rank' || act_type == 'rank2') {
        var txt2 = ''
        if (groupId == 8) {
            txt2 = "三个";
            html += '<label class="col-xs-1 control-label">一个偷:</label><div class="col-sm-1"><input type="text"  name="one_steal" value="' + data.one_steal + '" class="form-control"></div>';
            html += '<label class="col-xs-1 control-label">两个偷:</label><div class="col-sm-1"><input type="text"  name="two_steal" value="' + data.two_steal + '" class="form-control"></div>';
        }
        html += '<label class="col-xs-1 control-label">' + txt2 + '偷:</label><div class="col-sm-1"><input type="text"  name="steal_success" value="' + data.steal_success + '" class="form-control"></div>';
        var gtype_2 = 'text';
        var gdata_2 = data.steal_break;
        var noshow_2 = ''
        if ($.inArray(groupId, [3, 8]) != -1) {
            gtype_2 = 'hidden';
            gdata_2 = data.steal_success;
            noshow_2 = 'noshow';
        }
        html += '<label class="col-xs-1 control-label ' + noshow_2 + '">完美偷:</label><div class="col-sm-1"><input type="' + gtype_2 + '"  name="steal_break" value="' + gdata_2 + '" class="form-control"></div>';
    }
    if ($.inArray(groupId, [2, 3, 4, 7, 10]) != -1) {
        var two_hit = data.two_hit != undefined ? data.two_hit : data.tow_hit;//过度
        html += '<label class="col-xs-1 control-label">一连击:</label><div class="col-sm-1"><input type="text"  name="one_hit" value="' + data.one_hit + '" class="form-control"></div>';
        html += '<label class="col-xs-1 control-label">二连击:</label><div class="col-sm-1"><input type="text"  name="two_hit" value="' + two_hit + '" class="form-control"></div>';
        html += '<label class="col-xs-1 control-label">三连击:</label><div class="col-sm-1"><input type="text"  name="three_hit" value="' + data.three_hit + '" class="form-control"></div>';
    }
    if (groupId == 1 || act_type == 'rank' || act_type == 'rank2') {
        html += '<label class="col-xs-1 control-label">三个钻石:</label><div class="col-sm-1"><input type="text"  name="three_hit" value="' + data.three_hit + '" class="form-control"></div>';
    }
    // todo rank
    if (data.confType != undefined) {
        html += '<input type="hidden"  name="confType" value=' + data.confType + '>';
    } else {
        html += '<input type="hidden"  name="confType" value=0>';
    }

    html += '</div>';
    return html;
}

function renderCollectType(data) {
    var html = '';
    html += '<div class="form-group">';
    var textLableMap = {
        'one_attack': '一个打',
        'two_attack': '两个打',
        'attack_success': '打',
        'attack_break': '打到盾',
        'one_steal': '一个偷',
        'two_steal': '两个偷',
        'steal_success': '偷',
        'steal_break': '完美偷',
        'one_hit': '一连击',
        'two_hit': '二连击',
        'three_hit': '三连击'
    }
    for (i in data) {
        if (textLableMap[i] == undefined) continue;
        html += '<label class="col-xs-1 control-label">' + textLableMap[i] + ':</label><div class="col-sm-1"><input type="text"  name="' + i + '" value="' + data[i] + '" class="form-control"></div>';
    }

    if (data.confType != undefined) {
        html += '<input type="hidden"  name="confType" value=' + data.confType + '>';
    } else {
        html += '<input type="hidden"  name="confType" value=0>';
    }

    html += '</div>';
    return html
}

//=====
//创建表格式html
function rewardTable(type) {
    var cols = 4;
    var html = '';
    var str = '阶段奖励';
    html += '<div class="form-group" id="reward_table">';
    html += '<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">' + str + '</h5></div>';
    html += '<table class="table table-bordered">';
    html += '<thead><tr><th>阶段</th>';
    if (type == 'rank') {
        html += '<th>进度条</th>';
        cols = 5
    }
    if (type == 'architecture') {
        html += '<th>等级</th>';
    } else {
        html += '<th>阶段值</th>';
    }
    html += '<th>奖品</th><th>奖励设置</th></tr></thead>';
    html += '<tbody id="table_body">';

    html += '</tbody><tr><td colspan="' + cols + '"><div class="text-center"><botton class="btn btn-primary" id="addReward" onclick="addRewardNum()">添加</botton><botton class="btn btn-danger del-tr" onclick="delRewardNum()">删除</botton>';
    html += '</div></td></tr></table></div>';
    return html;
}


//阶段奖励2
function rewardTable2(title, index, t) {
    return rewardTableOrig(title, index, t);
}

function rewardTableOrig(title, index, t) {
    var cols = 4;
    var html = '';
    +
        '<div class="form-group" id="reward_table' + index + '">';
    html += '<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">' + title + '</h5></div>';
    html += '<table class="table table-bordered">';
    html += '<thead><tr>';
    if (index != 3) {
        html += '<th>阶段</th>';
        html += '<th>阶段值</th>';
    } else {
        html += '<th>ID</th>';
    }
    html += '<th>奖品</th><th>奖励设置</th></tr></thead>';
    html += '<tbody id="table_body' + index + '">';

    html += '</tbody><tr><td colspan="' + cols + '"><div class="text-center"><botton class="btn btn-primary" id="addReward' + index + '" onclick="addRewardNum2(' + index + ',' + t + ')">添加</botton><botton class="btn btn-danger del-tr" onclick="delRewardNum2(' + index + ')">删除</botton>';
    html += '</div></td></tr></table></div>';
    return html;
}

//奖励阶段行数据html
function rewardTableTR2(data, t, index) {
    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' + index + '_' + data['stage'] + '">';
    html += '<td><input type="text" class="form-control" name="reward' + index + '[' + data['stage'] + '][stage]" value="' + data['stage'] + '" readonly></td>';
    if (index != 3) {
        html += '<td><input type="text" class="form-control" name="reward' + index + '[' + data['stage'] + '][stepnum]" value="' + data['stepnum'] + '"></td>';
    }
    html += '<td class="showStagePrize_' + index + '_' + 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 type="hidden" name="reward' + index + '[' + data['stage'] + '][prize]" value="' + prize + '">';
    html += '<td><button type="button" class="btn btn-outline btn-success" onclick="setPrize(' + stage + ',' + t + ',' + index + ')">奖励配置</button></td>';// data-toggle="modal"
    html += '</tr>';
    return html;
}

//奖励阶段行数据html
function rewardTableTR(data) {
    // console.log(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'] + '">';
    html += '<td><input type="text" class="form-control" name="reward[' + data['stage'] + '][stage]" value="' + data['stage'] + '"></td>';
    if (act_type == 'rank') {
        html += '<td><input type="text" class="form-control" name="reward[' + data['stage'] + '][progressBarId]" value="' + data['progressBarId'] + '"></td>';
    }
    if (act_type == 'architecture') {
        html += '<td><input type="text" class="form-control" name="reward[' + data['stage'] + '][lv]" value="' + data['lv'] + '"></td>';
    } else {
        html += '<td><input type="text" class="form-control" name="reward[' + data['stage'] + '][stepnum]" value="' + data['stepnum'] + '"></td>';
    }

    html += '<td class="showStagePrize_' + 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 type="hidden" name="reward[' + data['stage'] + '][prize]" value="' + prize + '">';
    html += '<td><button type="button" class="btn btn-outline btn-success" onclick="setPrize(' + stage + ',1)">奖励配置</button></td>';// data-toggle="modal"
    html += '</tr>';

    return html;
}

//每日宝箱奖励配置
function dailyChest(data) {
    var stage = 1;
    var prize = (data !== null && data['prize'] != undefined) ? JSON.stringify(data['prize']) : '[]';
    var prize_show_arr = JSON.parse(prize);
    prize = escape(prize);
    var html = '';
    html += '<tr id="rewardInfo_1">';
    html += '<td class="showStagePrize_1">';
    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="reward[' + stage + '][prize]" value="' + prize + '">';
    html += '<td><button type="button" class="btn btn-outline btn-success" onclick="setPrize(1,1)">奖励配置</button></td>';// data-toggle="modal"
    html += '</tr>';

    return html;
}


//奖励阶段行数据html
function rankTableTR(index, data) {
    // console.log(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="rankInfo_' + data['stage'] + '">';
    html += '<td><input type="text" class="form-control" name="rank[' + index + '][' + data['stage'] + '][stage]" value="' + data['stage'] + '" readonly></td>';
    html += '<td><input type="text" class="form-control" name="rank[' + index + '][' + data['stage'] + '][rankNum]" value="' + data['rankNum'] + '"></td>';
    html += '<td class="showRankStagePrize_' + index + '_' + data['stage'] + '">';
    if (prize_show_arr.length > 0) {
        for (var j = 0; j < prize_show_arr.length; j++) {
            html += chestPropsHtml(prize_show_arr[j]);
            // if($.inArray(parseInt(prize_show_arr[j]['type']),actPropArr)!= -1){
            //     var dv = "分钟";
            //     var dc = "btn-danger";
            // }else{
            //     var dv = prize_show_arr[j]['rtype']==1?'个':'倍';
            //     var dc = prize_show_arr[j]['rtype']==1?'btn-primary':'btn-danger';
            // }
            // html +='<span class="btn btn-outline '+dc+'">'+reward_type_arr[prize_show_arr[j]['type']]['name']+':'+prize_show_arr[j]['num']+dv+'</span>';
        }
    }
    html += '</td>';
    html += '<input type="hidden" name="rank[' + index + '][' + data['stage'] + '][prize]" value="' + prize + '">';
    html += '<td><button type="button" class="btn btn-outline btn-success" onclick="setPrize(' + stage + ',2,' + index + ')">奖励配置</button></td>';// data-toggle="modal"
    html += '</tr>';
    return html;
}


//设置类型
function setTypeFunction() {
    var setType = $('#setType').val();
    if (setType == 1) {
        $("#vipSet").show();
        $("#spinsSet").hide();
    } else {
        $("#vipSet").hide();
        $("#spinsSet").show();
    }
}


//体力加速配置html
function speedSpinsLine(data) {
    console.log(data);
    var html = '';
    for (var i = 0; i < data.length; i++) {
        html += '<div class="row" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;"><div class="form-group" >';
        html += '<label class="col-sm-1 control-label">ID*: </label>';
        html += '<div class="col-sm-1"><input type="text" class="form-control" readonly name="reward[' + i + '][id]" value="' + data[i]['id'] + '"></div>';
        html += '<label class="col-sm-1 control-label">加速来源*: </label>';
        html += '<div class="col-sm-2"><input type="text" class="form-control" readonly name="reward[' + i + '][tips]" value="' + data[i]['tips'] + '"></div>';
        html += '<label class="col-sm-1 control-label">加速倍率*: </label>';
        html += '<div class="col-sm-1"><input type="text" class="form-control"  name="reward[' + i + '][bet]" value="' + data[i]['bet'] + '"></div>';
        html += '<label class="col-sm-1 control-label">加速时长(秒)*: </label>';
        html += '<div class="col-sm-1"><input type="text" class="form-control"  name="reward[' + i + '][effecteTime]" value="' + data[i]['effecteTime'] + '"></div>';
        html += '<label class="col-sm-1 control-label">加速次数(每天)*: </label>';
        html += '<div class="col-sm-1"><input type="text" class="form-control"  name="reward[' + i + '][max]" value="' + data[i]['max'] + '"></div>';
        html += '<label class="col-sm-1 control-label">是否开启*: </label>';
        var selected = data[i]['open'] == 1 ? 'selected' : "";
        html += '<div class="col-sm-1"><select name="reward[' + i + '][open]" class="form-control"><option value="0" ' + selected + '>关闭</option><option value="1" ' + selected + '>开启</option></select></div>';
        html += '</div></div>';
    }
    return html;
}

//超级bet输入html
function crazyBetInput(data) {//actSpinsLimit
    var html = '';
    html += '<div class="col-sm-6"><div class="form-group"><label class="col-sm-4 control-label">超级Bet触发体力点:</label>';
    html += '<div class="col-sm-8"><input type="text" placeholder="体力值" name="reward[init][actSpinsLimit]" value="' + data["init"]["actSpinsLimit"] + '" class="form-control"></div>';
    html += '</div>';
    html += '<div class="text-center" id="bet_line"><botton class="btn btn-primary" id="addCrazyBetLine" onclick="addBetConf()">添加</botton><botton class="btn btn-danger del-tr" onclick="delBetConf()">删除</botton>';
    html += '</div></div>';
    return html;
}

//超级bet配置行html
function crazyBetLine(data) {
    var html = '';
    var i = data["id"];
    html += '<div class="row" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;"><div class="form-group" >';
    html += '<input type="hidden" class="form-control" readonly name="reward[conf][' + i + '][id]" value="' + data["id"] + '">';
    html += '<label class="col-sm-1 control-label">倍率</label><div class="col-sm-2"><input type="text" class="form-control"  name="reward[conf][' + i + '][bet]" value="' + data["bet"] + '"></div>';
    html += '<label class="col-sm-1 control-label">等级</label><div class="col-sm-2"><input type="text" class="form-control"  name="reward[conf][' + i + '][levelId]" value="' + data["levelId"] + '"></div>';
    html += '<label class="col-sm-1 control-label">体力</label><div class="col-sm-2"><input type="text" class="form-control"  name="reward[conf][' + i + '][spins]" value="' + data["spins"] + '"></div>';
    html += '<label class="col-sm-1 control-label">倍率关闭体力上限</label><div class="col-sm-2"><input type="text" class="form-control"  name="reward[conf][' + i + '][spinsLimit]" value="' + data["spinsLimit"] + '"></div>';
    html += '</div></div>';
    return html;
}

// crazy_bet 体力弹框规则html
function crazyBetSpinsRange() {
    var html = '';
    html += '<div class="col-sm-6"><div class="form-group"><label class="col-sm-4 control-label">超级Bet体力不足弹框规则:</label>';
    html += '<div class="col-sm-4"></div>';
    html += '</div> ';
    html += '<div class="text-center" id="betSpinsRange_line"><botton class="btn btn-primary" id="addCrazyBetSpinsRange" onclick="addBetSpinsRangeConf()">添加</botton><botton class="btn btn-danger del-tr" onclick="delBetSpinsRangeConf()">删除</botton>';
    html += '</div></div>';
    return html;
}

// crazy_bet 体力弹框规则行
function crazyBetSpinsRangeLine(data) {
    var html = '';
    var i = data["id"];
    html += '<div class="row" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;"><div class="form-group" >';
    html += '<input type="hidden" class="form-control" readonly name="reward[init][spinsRange][' + i + '][id]" value="' + data["id"] + '">';
    html += '<label class="col-sm-1 control-label">体力</label><div class="col-sm-2"><input type="text" class="form-control"  name="reward[init][spinsRange][' + i + '][spins]" value="' + data["spins"] + '"></div>';
    html += '<label class="col-sm-1 control-label">倍率</label><div class="col-sm-2"><input type="text" class="form-control"  name="reward[init][spinsRange][' + i + '][bet]" value="' + data["bet"] + '"></div>';
    html += '</div></div>';
    return html;
}

//==========================连环礼包 star=======================================
//连环礼包积分table Html
function chainGiftTable(index, data) {
    var html = '';
    html += '<div  id="chainTable_' + index + '"><table class="table table-bordered chainTable">';
    html += '<thead><tr><td>';
    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="scoreStage[' + index + '][score_star]" value="' + data['score_star'] + '">';
    html += '<span class="input-group-addon">-</span>';
    html += '<input type="text" style="text-align: center" class="form-control" name="scoreStage[' + index + '][score_end]" value="' + data['score_end'] + '">';
    html += '</div></div>';
    html += '</td></tr></thead>';
    html += '<tr><td id="chainInfo_' + index + '">';

    html += '</td></tr></table><div>';
    return html;
}

function chainOptBtn() {
    var html = '';
    html += '<div class="text-center" id="chainOptBtn"><botton class="btn btn-primary" onclick="addChainStage()">添加</botton><botton class="btn btn-danger del-tr" onclick="delChainStage()">删除</botton></div>';
    return html;
}

//连环礼包配置html
function chainGift(data, index = 0) {
    var sel = '';
    var coins = ["coins01", "coins02", "coins03", "coins04", "coins05", "coins06"];
    var html = '';
    html += '<div class="row AllTypeControl" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">';//0-->
    //====>>
    html += '<div class="form-group" >';
    html += '<label class="col-sm-1 control-label">商品GID*: </label><div class="col-sm-1"><input type="text" class="form-control" readonly name="rewardnew[' + index + '][' + data['gid'] + '][gid]" value="' + data['gid'] + '"></div>';
    html += '<label class="col-sm-1 control-label">商品名称*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="rewardnew[' + index + '][' + data['gid'] + '][gname]" value="' + data['gname'] + '"></div>';
    html += '<label class="col-sm-1 control-label">商品SKU*: : </label><div class="col-sm-2"><input type="text" class="form-control"  name="rewardnew[' + index + '][' + data['gid'] + '][gsku]" value="' + data['gsku'] + '"></div>';
    html += '<label class="col-sm-1 control-label">商品简介*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="rewardnew[' + index + '][' + data['gid'] + '][gdesc]" value="' + data['gdesc'] + '"></div>';
    html += '</div>';
    //<<====
    //====>>
    html += '<div class="form-group">';
    html += ' <label class="col-sm-1 control-label">商品价格*: </label> <div class="col-sm-1"><input type="text" class="form-control"  name="rewardnew[' + index + '][' + data['gid'] + '][gprice]" value="' + data['gprice'] + '"></div>';
    html += '<label class="col-sm-1 control-label">商品金币价格*: </label>';
    html += '<div class="col-sm-2"><select class="form-control typeControl" name="rewardnew[' + index + '][' + data['gid'] + '][gsku1][coins]">';
    for (i = 0; i < coins.length; i++) {
        if (coins[i] == data['gsku1']['coins']) {
            sel = 'selected';
        } else {
            sel = '';
        }
        html += '<option value="' + coins[i] + '" ' + sel + '>' + coins[i] + '</option>';
    }
    html += '</select></div>';
    html += '<label class="col-sm-1 control-label">价格倍率*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="rewardnew[' + index + '][' + data['gid'] + '][gsku1][bet]" value="' + data['gsku1']['bet'] + '"></div>';
    html += '<label class="col-sm-1 control-label">商品限购*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="rewardnew[' + index + '][' + data['gid'] + '][gMax]" value="' + data['gMax'] + '"></div>';
    html += '</div>';
    //<<====
    //=========
    html += '<div class="form-group"><label class="col-sm-1 control-label">商品货物*: </label>';//1-->
    html += '<div class="col-sm-8"><div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;" >';//2-->,3-->


    html += '<div class="form-group">';//4-->
    //====>>
    html += '<label class="col-sm-2 control-label">金币*: </label>';
    html += '<div class="col-sm-3"><select class="form-control typeControl" name="rewardnew[' + index + '][' + data['gid'] + '][gbaseReward][coins][coins]">';
    for (i = 0; i < coins.length; i++) {
        var sel2 = '';
        if (coins[i] == data['gbaseReward']['coins']['coins']) {
            sel2 = 'selected';
        } else {
            sel2 = '';
        }
        html += '<option value="' + coins[i] + '" ' + sel2 + '>' + coins[i] + '</option>';
    }
    html += '</select></div>';
    html += '<label class="col-sm-2 control-label">倍率*: </label>';
    html += '<div class="col-sm-3"><input type="text" class="form-control"  name="rewardnew[' + index + '][' + data['gid'] + '][gbaseReward][coins][bet]" value="' + data['gbaseReward']['coins']['bet'] + '"></div>';
    html += '</div>';//<--4
    //<<====
    html += '<div class="form-group"><label class="col-sm-2 control-label">体力*: </label>';
    html += '<div class="col-sm-3"><input type="text" class="form-control"  name="rewardnew[' + index + '][' + data['gid'] + '][gbaseReward][spins]" value="' + data['gbaseReward']['spins'] + '"></div></div>';

    var prons = data['gbaseReward']['props'] ? data['gbaseReward']['props'] : [];
    html += '<div class="form-group" id="props_' + index + '_' + data['gid'] + '">';
    for (var j = 0; j < prons.length; j++) {
        html += chainGiftProps(prons[j], j, data['gid'], index);
    }
    html += '</div>';

    html += '<button type="button" class="btn btn-success addParent"  style="margin-left: 12px;margin-bottom: 10px;" onclick="addprops(' + data['gid'] + ',' + index + ')">增加</button>';
    html += '<button type="button" class="btn btn-danger deleteParent" style="margin-left: 12px;margin-bottom: 10px;" onclick="delprops(' + data['gid'] + ',' + index + ')">删除</button>';
    html += '</div></div></div>';
    html += '</div>';

    return html;
}

//连环礼包道具行html
function chainGiftProps(prons, pid, gid, index = 0) {
    var html = '';
    html += "<div class='props_line'>";
    html += '<div class="form-group"><label class="col-sm-2 control-label">道具*: </label><div class="col-sm-3"><select class="form-control selChainProp" name="rewardnew[' + index + '][' + gid + '][gbaseReward][props][' + pid + '][propsId]">';
    $.each(reward_type, function (k, v) {
        var sel3 = "";
        if (prons['propsId'] == v["id"]) {
            sel3 = "selected";
        } else {
            sel3 = '';
        }
        html += '<option value="' + v["id"] + '" ' + sel3 + '>' + v["name"] + '</option>';
    });
    html += '</select></div>';
    html += '<label class="col-sm-2 control-label">数量*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="rewardnew[' + index + '][' + gid + '][gbaseReward][props][' + pid + '][num]" value="' + prons['num'] + '"></div>';
    html += '</div>';
    html += "</div>";
    return html;
}

//=================================end========================================
//==========================新连环礼包 star=======================================
function scoreCGTable(scoreCGType) {
    var sel1 = scoreCGType == 1 ? "selected" : "";
    var sel2 = scoreCGType == 2 ? "selected" : "";
    var sel3 = scoreCGType == 3 ? "selected" : "";
    var html = '';
    html += '<div aria-hidden="true">';
    html += '<div class="form-group">';
    html += '<label class="col-sm-1 control-label">分阶段模式:</label><div class="col-sm-1"><select class="form-control typeControl" name="scoreCGType" onchange="ScoreCGType(this,this.value)">';
    html += '<option ' + sel1 + ' value="1">积分</option>';
    html += '<option ' + sel2 + ' value="2">分组</option>';
    html += '<option ' + sel3 + ' value="3">数数分组</option>';
    html += '</select></div>';
    html += '</div>';
    html += '</div>';
    html += '<hr style=" height:2px;border:none;border-top:2px dotted #0b0;"><div class="form-group" id="scoreCGTable">';
    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="addCGTableBtn" type="button">添加</button>';
    html += '<button class="btn btn-white"   id="delCGTableBtn" type="button">删除</button>';
    html += '</div></div><hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    return html;
}

function ScoreCGType(obj, value) {
    spinStage = 1;
    spin_reward_limit = [];
    scoreCGType = value
    if (value == 1) {
        var d = {"star": 0, "end": 0};
    } else if (value == 2) {
        var d = {"gid": 0};
    } else if (value == 3) {
        var d = {"gid": 0};
    }
    var html = scoreCGRewardTable(scoreCGType, 1, d);//阶段奖励内部table
    $("#scoreCGTable").html(html);
    $('.select2').select2({})
}

//分体力阶段奖励配置表html
function scoreCGRewardTable(scoreCGType, index, data) {
    var html = '';
    cols = 7;
    html += '<table class="table table-bordered scoreCGRewardTable" id="reward_table_' + index + '">';
    html += '<thead><tr><td colspan="' + cols + '"><div class="form-group">';
    if (scoreCGType == 1) {
        html += '<label class="col-sm-1 control-label m-b">积分区间</label><div class="col-sm-3 input-group">';
        html += '<input type="text" style="text-align: center" class="form-control" name="scoreStage[' + index + '][star]" value="' + data['star'] + '">';
        html += '<span class="input-group-addon">-</span>';
        html += '<input type="text" style="text-align: center" class="form-control" name="scoreStage[' + index + '][end]" value="' + data['end'] + '">';
        html += '</div>';
    } else {
        if (scoreCGType == 2) {
            var arr = JSON.parse($userGroup2);
        } else if (scoreCGType == 3) {
            var arr = JSON.parse($userGroup5);
        }

        html += '<label class="col-sm-1 control-label m-b">添加分组</label><div class="col-sm-1"><select class="form-control select2" onchange="AddScoreCGRGid(this,' + index + ')">';
        html += '<option value="0">默认</option>';
        for (let i in arr) {
            html += '<option value="' + i + '">' + arr[i] + '</option>';
        }
        html += '</select></div><div class="col-sm-10" id="scoreCGGidDiv' + index + '">';
        if (index == 1) {
            html += '<div class="col-sm-1"><input class="btn btn-primary" type="button" value="默认"><input class="btn btn-primary" type="hidden" name="scoreStage[' + index + '][gid][]" value="0"></div>';
        }
        if (data['gid'] != 0) {
            var gidArr = data['gid'].split(",");
            for (var i = 0; gidArr.length > i; i++) {
                var val = parseInt(gidArr[i])
                if (val != 0) {
                    html += '<div class="col-sm-1" style="width:fit-content;" onclick="DelScoreCGRGid(this,' + val + ')"><input class="btn btn-primary" type="button" value="' + arr[val] + '"><input class="btn btn-primary" type="hidden" name="scoreStage[' + index + '][gid][]" value="' + val + '"></div>';
                }
            }
        }
        html += '</div>';
    }
    html += '</div></td></tr><tr><th>阶段</th><th>名称</th><th>限量</th><th>购买货币</th><th>价格</th><th>奖励</th><th>奖励设置</th></tr>';
    html += '</thead>';
    html += '<tbody id="table_body_' + index + '">';
    html += '</tbody><tr><td colspan="' + cols + '"><div class="text-center"><botton class="btn btn-primary" onclick="addCGScoreRewardNum(' + index + ')">添加</botton><botton class="btn btn-danger del-tr" onclick="delCGScoreRewardNum(' + index + ')">删除</botton>';
    html += '</div></td></tr></table>';
    return html;
}

//召回好友活动选择RFM分组id
function ChooseRFMGroup(data, index, flag = 1, groupRid = 2) {
    var html = '', name = flag ? 'cond' : 'scoreStage';
    cols = 2;
    html += '<tr><td colspan="' + cols + '"><div class="form-group">';
    var groupName = '';
    if (groupRid == 2) {
        var arr = JSON.parse($userGroup2);
        groupName = 'RFM分组';
    } else {
        var arr = JSON.parse($hideSSGroup);
        groupName = '数数分组';
    }

    html += '<label class="col-sm-1 control-label m-b scoreCGGidDivGroupName ">' + groupName + '</label><div class="col-sm-1"><select class="form-control scoreCGGidDivGroupSelect select2" onchange="AddScoreCGRGid(this,' + index + ',' + 0 + ')">';
    html += '<option value="0">默认</option>';
    for (let i in arr) {
        html += '<option value="' + i + '">' + arr[i] + '</option>';
    }
    html += '</select></div><div class="col-sm-10 scoreCGGidDivGroupTow" id="scoreCGGidDiv' + index + '">';
    //html +='<div class="col-sm-1"><input class="btn btn-primary" type="button" value="默认"><input class="btn btn-primary" type="hidden" name="'+name+'['+index+'][gid][]" value="0"></div>';
    if (data.gid != undefined) {
        var gidArr = data.gid;
        for (var i = 0; gidArr.length > i; i++) {
            var val = parseInt(gidArr[i]);
            if (val != 0) {
                html += '<div class="col-sm-3" style="width:fit-content;" onclick="DelScoreCGRGid(this,' + val + ')"><input class="btn btn-primary" type="button" value="' + arr[val] + '"><input class="btn btn-primary" type="hidden" name="' + name + '[' + index + '][gid][]" value="' + val + '"></div>';
            } else {
                html += '<div class="col-sm-3" style="width:fit-content;" onclick="DelScoreCGRGid(this,' + val + ')"><input class="btn btn-primary" type="button" value="默认"><input class="btn btn-primary" type="hidden" name="' + name + '[' + index + '][gid][]" value="0"></div>';
            }
        }
    }
    html += '</div></td></tr>';
    return html;
}

function AddScoreCGRGid(obj, index, alertFlag = 1) {
    var name = $(obj).find("option:selected").text();
    var value = $(obj).val();
    for (var i = 0; scoreCGGidArr.length > i; i++) {
        if (scoreCGGidArr[i] == value) {
            if (alertFlag) {
                alert("分组冲突");
            } else {
                return;
            }
        }
    }
    scoreCGGidArr.push(value)
    //if(value != 0){
    var html = '<div class="col-sm-3" style="width:fit-content;" onclick="DelScoreCGRGid(this,' + value + ')"><input class="btn btn-primary" type="button" value="' + name + '"><input class="btn btn-primary" type="hidden" name="scoreStage[' + index + '][gid][]" value="' + value + '"></div>';
    $("#scoreCGGidDiv" + index).append(html)
    //}
}

function DelScoreCGRGid(obj, value) {
    $(obj).remove();
    scoreCGGidArr = scoreCGGidArr.filter(v => {
        return v != value;
    });
}

//分体力阶段奖励行html
function scoreCGRwardTR(index, 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'] + '">';
    html += '<td><input type="text" class="form-control" readonly name="rewardnew[' + index + '][' + data['stage'] + '][stage]" value="' + data['stage'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="rewardnew[' + index + '][' + data['stage'] + '][name]" value="' + data['name'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="rewardnew[' + index + '][' + data['stage'] + '][gMax]" value="' + data['gMax'] + '"></td>';
    html += '<td><select class="form-control selMtype" name="rewardnew[' + index + '][' + data['stage'] + '][mtype]">';
    var arr = {1: "金币", 2: "美元"};
    for (var i = 1; i < 3; i++) {
        data['mtype'] == i ? sel = 'selected' : sel = '';
        html += '<option value="' + i + '" ' + sel + '>' + arr[i] + '</option>';
    }
    html += '</select></td>';
    html += '<td class="selSku" t_index="' + index + '" t_stage="' + data['stage'] + '">';
    html += selSku(index, data);
    html += '</td>';
    html += '<td class="showStagePrize_' + index + '_' + 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 type="hidden" name="rewardnew[' + index + '][' + data['stage'] + '][prize]" value="' + prize + '">';
    html += '<td><button type="button" class="btn btn-outline btn-success" onclick="setPrize(' + stage + ',1,' + index + ')">奖励配置</button></td>';// data-toggle="modal"
    html += '</tr>';

    return html;
}

function selSku(index, data) {
    var html = '';
    if (data['mtype'] == 2) {
        html += '价格:<select class="form-control m-b selPrice" name="rewardnew[' + index + '][' + data['stage'] + '][price]">';
        $.each(goodSku, function (k, v) {
            if (data["price"] == v["price"]) {
                sel = "selected";
            } else {
                sel = "";
            }
            html += '<option value="' + v["price"] + '" ' + sel + '>' + v["price"] + '</option>';
        });
        html += '</select>';
        html += '商品sku:<input class="form-control t_sku" type="text" name="rewardnew[' + index + '][' + data['stage'] + '][sku]" value="' + data['sku'] + '">';
        html += '<input type="hidden" name="rewardnew[' + index + '][' + data['stage'] + '][coin]" value="0">';
        html += '<input type="hidden" name="rewardnew[' + index + '][' + data['stage'] + '][bet]" value="0">';
    } else {
        html += '价格:<select class="form-control m-b" name="rewardnew[' + index + '][' + data['stage'] + '][coin]">';
        for (var i = 0; i < coins_list.length; i++) {
            if (data["coin"] == coins_list[i]) {
                sel = "selected";
            } else {
                sel = "";
            }
            html += '<option value="' + coins_list[i] + '" ' + sel + '>' + coins_list[i] + '</option>';
        }
        html += '</select>倍数:<input class="form-control" type="text" name="rewardnew[' + index + '][' + data['stage'] + '][bet]" value="' + data['bet'] + '">';
        html += '<input type="hidden" name="rewardnew[' + index + '][' + data['stage'] + '][sku]" value="0">';
        html += '<input type="hidden" name="rewardnew[' + index + '][' + data['stage'] + '][price]" value="0">';
    }
    return html;
}

//=================================end========================================
//疯狂的卡组奖励加成html
function crazyCardRewardTable() {
    var cols = 4;
    var html = '';
    html += '<div class="form-group" id="reward_table">';
    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>';
    html += '<th>起始等级</th>';
    html += '<th>终止等级</th>';
    html += '<th>加成百分比</th></tr></thead>';
    html += '<tbody id="table_body">';

    html += '</tbody><tr><td colspan="' + cols + '"><div class="text-center"><botton class="btn btn-primary" id="addReward" onclick="addRewardNum()">添加</botton><botton class="btn btn-danger del-tr" onclick="delRewardNum()">删除</botton>';
    html += '</div></td></tr></table></div>';

    return html;
}

//疯狂的卡组奖励行html
function crazyCardTR(data) {
    var html = '';
    html += '<tr id="rewardInfo_' + data['stage'] + '">';
    html += '<td><input type="text" class="form-control" name="reward[' + data['stage'] + '][stage]" value="' + data['stage'] + '" readonly></td>';
    html += '<td><input type="text" class="form-control" name="reward[' + data['stage'] + '][slv]" value="' + data['slv'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="reward[' + data['stage'] + '][elv]" value="' + data['elv'] + '"></td>';
    html += '<td><div class="col-sm-3 input-group"><input type="text" class="form-control" name="reward[' + data['stage'] + '][num]" value="' + data['num'] + '"><span class="input-group-addon">%</span></dev></td>';
    html += '</tr>';
    return html;
}

//========================体力分套阶段收集======================================
function spinStageTable(type) {
    var html = '';
    html += '<hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    html += '<div class="" id="spinStageTable" 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="addSpinStageBtn" type="button">添加</button>';
    html += '<button class="btn btn-white"   id="delSpinStageBtn" type="button">删除</button>';
    html += '</div></div><hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    return html;
}

//收集分体力阶段奖励配置表html
function spinStageRewardTable(index, data) {
    var type = act_type;
    var cols = 4;
    if (["architecture", "rank", "super_collect"].includes(type)) {
        cols = 5
    }
    var html = '';
    html += '<table class="table table-bordered spinStageRewardTable" id="reward_table_' + index + '">';
    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[' + index + '][star]" value="' + data['star'] + '">';
    html += '<span class="input-group-addon">-</span>';
    html += '<input type="text" style="text-align: center" class="form-control" name="spinStage[' + index + '][end]" value="' + data['end'] + '">';
    html += '</div></div>';
    html += '</td></tr>';
    html += '<tr><th>阶段</th>';
    if (type == 'super_collect') {
        html += '<th>预设消耗体力</th>';
    }
    if (type == 'rank') {
        html += '<th>进度条</th>';
    }
    if (type == 'architecture') {
        html += '<th>等级</th>';
    } else {
        html += '<th>阶段值</th>';
    }
    html += '<th>奖品</th><th>奖励设置</th></tr></thead>';
    html += '<tbody id="table_body_' + index + '">';

    html += '</tbody><tr><td colspan="' + cols + '"><div class="text-center"><botton class="btn btn-primary" onclick="addSpinRewardNum(' + index + ')">添加</botton><botton class="btn btn-danger del-tr" onclick="delSpinRewardNum(' + index + ')">删除</botton>';
    html += '</div></td></tr></table>';

    return html;
}

//收集分体力阶段奖励行html
function spinStageRwardTR(index, 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'] + '">';
    html += '<td><input type="text" class="form-control" name="rewardnew[' + index + '][' + data['stage'] + '][stage]" value="' + data['stage'] + '"></td>';
    if (act_type == 'rank') {
        html += '<td><input type="text" class="form-control" name="rewardnew[' + index + '][' + data['stage'] + '][progressBarId]" value="' + data['progressBarId'] + '"></td>';
    }
    if (act_type == 'architecture') {
        html += '<td><input type="text" class="form-control" name="rewardnew[' + index + '][' + data['stage'] + '][lv]" value="' + data['lv'] + '"></td>';
    } else {
        html += '<td><input type="text" class="form-control" name="rewardnew[' + index + '][' + data['stage'] + '][stepnum]" value="' + data['stepnum'] + '"></td>';
    }

    html += '<td class="showStagePrize_' + index + '_' + 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 type="hidden" name="rewardnew[' + index + '][' + data['stage'] + '][prize]" value="' + prize + '">';
    html += '<td><button type="button" class="btn btn-outline btn-success" onclick="setPrize(' + stage + ',1,' + index + ')">奖励配置</button></td>';// data-toggle="modal"
    html += '</tr>';

    return html;
}

//=================================end========================================

//=======================限时邀请 star=========================================
function initTimelimitInviteWrap() {
    timelimitInviteGroupCnt = 0;
    timelimitInviteGroupArr = []
    var html = '';
    html += '<div class="form-group" id="timelimit_invite_table_wrap" style="margin:0px;position:relative;padding-bottom: 50px">' +
        '<button class="btn btn-primary" style="position: absolute;bottom:0;width:110px;" type="button" onclick="addTimeLimitInviteGroup()">添加分组区间</button>' +
        '<button class="btn btn-danger"  style="position: absolute;bottom:0;width:110px;left:110px;" type="button" onclick="delTimeLimitInviteGroup()">删除分组区间</button>' +
        '</div>';

    return html;
}

function addTimeLimitInviteGroup() {
    timelimitInviteGroupCnt++;
    timelimitInviteGroupArr[timelimitInviteGroupCnt] = 0

    var arr = JSON.parse($hideSSGroup);
    var html = '' +
        '<div class="form-group timelimitInviteGroup" data-idx="' + timelimitInviteGroupCnt + '" id="timelimitInviteGroup_' + timelimitInviteGroupCnt + '"  >' +
        '<div class="row">' +
        '<label class="col-sm-1 control-label">数数分组：</label>' +
        '<div class="col-sm-8"> ' +
        '<select class="form-control select2" name="timelimitInviteConf[' + timelimitInviteGroupCnt + '][shushu][]" multiple>';
    $.each(arr, function (i, o) {
        html += '<option value="' + i + '">' + o + '</option>'
    })
    html += '</select>' +
        '</div>' +
        '</div>' +
        '<div class="row">' +
        '<label class="col-sm-1 control-label">成功条件：</label>' +
        '<div class="col-sm-2"> ' +
        '<select class="form-control" name="timelimitInviteConf[' + timelimitInviteGroupCnt + '][type]">' +
        //'<option value="1" '+sel+'>完成注册绑定FB</option>'+
        '<option value="2" >绑定FB并完成新手引导</option>' +
        '<option value="3" >绑定FB并完成指定等级(2-5)</option>' +
        '</select>' +
        '</div>' +
        '<div class="col-sm-1">' +
        '<input type="text" class="form-control" name="timelimitInviteConf[' + timelimitInviteGroupCnt + '][ext_num]" value="">' +
        '</div>' +
        '<label class="col-sm-2 control-label">活动结束时邮件模版Id：</label>' +
        '<div class="col-sm-1">' +
        '<input type="text" class="form-control" name="timelimitInviteConf[' + timelimitInviteGroupCnt + '][msgId]" value="">' +
        '</div>' +
        '</div>' +
        '<div class="row">' +
        '<label class="col-sm-1 control-label">跳转链接<br>(留空则不跳转)：</label>' +
        '<div class="col-sm-2"> ' +
        '<input type="text" class="form-control" name="timelimitInviteConf[' + timelimitInviteGroupCnt + '][url]" value="">' +
        '</div>' +
        '</div>' +
        '</div>';
    $('#timelimit_invite_table_wrap').append(html)
    $('#timelimitInviteGroup_' + timelimitInviteGroupCnt).append(timelimitInviteRewardTable(timelimitInviteGroupCnt))
    $('.select2').select2({})
}

function delTimeLimitInviteGroup() {
    if (timelimitInviteGroupCnt > 0) {
        $('#timelimitInviteGroup_' + timelimitInviteGroupCnt).remove()
        timelimitInviteGroupArr[timelimitInviteGroupCnt] = 0
        timelimitInviteGroupCnt--;
    }

}

function timelimitInviteRewardTable(timelimitInviteGroupIdx) {
    var cols = 5;
    var html = '';
    html += '<div class="form-group reward_table" style="margin:0;">' +
        '<div class="ibox-title" style="border-top: 0;">' +
        '<h5 style="font-weight: bold">阶段奖励</h5>' +
        '</div>' +
        '<table class="table table-bordered">' +
        '<thead>' +
        '<tr>' +
        '<th>阶段</th>' +
        '<th>阶段值</th>' +
        '<th>是否显示邀请按钮</th>' +
        '<th>奖品</th>' +
        '<th>奖励设置</th>' +
        '</tr>' +
        '</thead>' +
        '<tbody id="table_body_' + timelimitInviteGroupIdx + '">' +
        '</tbody>' +
        '<tr>' +
        '<td colspan="' + cols + '">' +
        '<div class="text-center">' +
        '<botton class="btn btn-primary" id="addReward" onclick="addTimelimitInviteRewardNum(' + timelimitInviteGroupIdx + ')">添加</botton>' +
        '<botton class="btn btn-danger del-tr" onclick="delTimelimitInviteRewardNum(' + timelimitInviteGroupIdx + ')">删除</botton>' +
        '</div>' +
        '</td>' +
        '</tr>' +
        '</table>' +
        '</div>';
    return html;
}

function addTimelimitInviteRewardNum(stage) {
    timelimitInviteGroupArr[stage]++
    var data = {"stage": timelimitInviteGroupArr[stage], "stepnum": 0, "progressBarId": 0, "lv": 1};
    // console.log(data);
    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_' + stage + '_' + data['stage'] + '">';
    html += '<td><input type="text" class="form-control" name="timelimitInvite[' + stage + '][' + data['stage'] + '][stage]" value="' + data['stage'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="timelimitInvite[' + stage + '][' + data['stage'] + '][stepnum]" value="' + data['stepnum'] + '"></td>';
    html += '<td><select  class="form-control" name="timelimitInvite[' + stage + '][' + data['stage'] + '][isShare]" >' +
        '<option value="0">否</option>' +
        '<option value="1">是</option>' +
        '</select>' +
        '</td>';

    html += '<td class="showStagePrize_' + stage + '_' + 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 type="hidden" name="timelimitInvite[' + stage + '][' + data['stage'] + '][prize]" value="' + prize + '">';
    html += '<td><button type="button" class="btn btn-outline btn-success" onclick="setPrize(' + stage + ',\'timelimitInvite\',' + data['stage'] + ')">奖励配置</button></td>';// data-toggle="modal"
    html += '</tr>';
    $('#table_body_' + stage).append(html)
}

function delTimelimitInviteRewardNum(stage) {
    if (timelimitInviteGroupArr[stage] < 1) return;
    $('#rewardInfo_' + stage + '_' + timelimitInviteGroupArr[stage]).remove()
    timelimitInviteGroupArr[stage]--;
}

function timelimitInvite(data) {
    console.log(data);
    var html = '';
    html += '<div class="form-group"><label class="col-sm-2 control-label">成功条件：</label>';
    html += '<div class="col-sm-2"> <select class="form-control" name="reward_conf[type]">';
    var sel, sel2, sel3 = '';
    data['type'] == 1 ? sel = 'selected' : (data['type'] == 2 ? sel2 = 'selected' : sel3 = 'selected');
    // html+= '<option value="1" '+sel+'>完成注册绑定FB</option>';
    html += '<option value="2" ' + sel2 + '>绑定FB并完成新手引导</option>';
    html += '<option value="3" ' + sel3 + '>绑定FB并完成指定等级(2-5)</option>';
    html += '</select></div>';
    html += '<div class="col-sm-1"><input type="text" class="form-control" name="reward_conf[ext_num]" value="' + data["ext_num"] + '"></div>';
    html += '</div>';
    return html;
}

//=================================end========================================


function goldenCardTradeHtml(type) {
    if (golden_card[type] == undefined || golden_card[type].length == undefined || golden_card[type].length == 0) {
        getAllGoldenCardByGroup(type);
    }
    var arr = [];
    if (($info['extraData'])) {
        arr = $info['extraData'];
    }
    var html = '<div class="form-group">';
    for (c = 0; c <= 1; c++) {
        html += '<label class="col-sm-1 control-label">金卡：</label><div class="col-sm-4"><select class="form-control m-b select2" name="goldenCard[' + c + ']">';
        for (j = 0; j < golden_card[type].length; j++) {
            var tStr = "";
            if (arr[c] == golden_card[type][j].ciid * 1) {
                tStr = "selected";
            }
            html += '<option ' + tStr + ' value="' + golden_card[type][j].ciid + '">' + golden_card[type][j].ci_name_zh + '</option>';
        }
        html += '</select></div>';
    }
    html += '</select></div>';
    html += '</div>';
    return html;
}

//商城促销
function shop_promotion_html() {
    var html = '';
    html += '<div class="col-sm-12"><div class="form-group"><label class="col-sm-2 control-label">积分配置:</label>';
    html += '<div class="col-sm-10" id="shop_promotion_point"></div>';
    html += '</div>';
    html += '<div class="text-center"><botton class="btn btn-primary" id="addCrazyBetLine" onclick="addShopPromotionConf([])">添加</botton><botton class="btn btn-danger del-tr" onclick="delShopPromotionConf()">删除</botton>';
    html += '</div></div>';
    return html;
}

//商城促销
function addShopPromotionConf(data) {
    var html = addShopPromotionLine(data);
    $("#shop_promotion_point").append(html);
    shop_promotion_limit++;
}

//商城促销
function addShopPromotionLine(data = []) {
    var html = '';
    if (JSON.stringify(data) === '[]') {
        html += '<div class="row"><div class="form-group">';
        html += '<label class="col-sm-2 control-label">截止积分:</label>';
        html += '<div class="col-sm-2"><input type="text" placeholder="积分" name="reward[init][' + shop_promotion_limit + '][point]" value="" class="form-control"></div>';
        html += '<label class="col-sm-2 control-label">奖励倍数:</label>';
        html += '<div class="col-sm-2"><input type="text" placeholder="奖励倍数" name="reward[init][' + shop_promotion_limit + '][bet]" value="" class="form-control"></div>';
        html += '<label class="col-sm-2 control-label">限购次数:</label>';
        html += '<div class="col-sm-2"><input type="text" placeholder="限购次数" name="reward[init][' + shop_promotion_limit + '][buyNum]" value="" class="form-control"></div>';
        html += '</div></div>';
    } else {
        html += '<div class="row"><div class="form-group">';
        html += '<label class="col-sm-2 control-label">截止积分:</label>';
        html += '<div class="col-sm-2"><input type="text" placeholder="积分" name="reward[init][' + shop_promotion_limit + '][point]" value="' + data.point + '" class="form-control"></div>';
        html += '<label class="col-sm-2 control-label">奖励倍数:</label>';
        html += '<div class="col-sm-2"><input type="text" placeholder="奖励倍数" name="reward[init][' + shop_promotion_limit + '][bet]" value="' + data.bet + '" class="form-control"></div>';
        html += '<label class="col-sm-2 control-label">限购次数:</label>';
        html += '<div class="col-sm-2"><input type="text" placeholder="限购次数" name="reward[init][' + shop_promotion_limit + '][buyNum]" value="' + data.buyNum + '" class="form-control"></div>';
        html += '</div></div>';
    }
    return html;
}

//商城促销
function delShopPromotionConf() {
    if (shop_promotion_limit > 0) {
        $("#shop_promotion_point").children(":last-child").remove();
        shop_promotion_limit--;
    }
}


/**
 * 通信证 ----------------------------- star -------------------------------------------------
 */
/**
 * 通信证 ----------------------------- end -------------------------------------------------
 */
function disArchConf(data) {
    var html = '';
    html += '<table class="table table-bordered"><thead><tr><td>建筑</td><td>优化力度（%）</td><tr></thead>';
    html += '<tr><td>1<input type="hidden" name="reward[0][level]" value="1"></td><td><input type="text" placeholder="" name="reward[0][disNum]" value="' + data[0]['disNum'] + '" class="form-control"></td></tr>';
    html += '<tr><td>2<input type="hidden" name="reward[1][level]" value="2"></td><td><input type="text" placeholder="" name="reward[1][disNum]" value="' + data[1]['disNum'] + '" class="form-control"></td></tr>';
    html += '<tr><td>3<input type="hidden" name="reward[2][level]" value="3"></td><td><input type="text" placeholder="" name="reward[2][disNum]" value="' + data[2]['disNum'] + '" class="form-control"></td></tr>';
    html += '<tr><td>4<input type="hidden" name="reward[3][level]" value="4"></td><td><input type="text" placeholder="" name="reward[3][disNum]" value="' + data[3]['disNum'] + '" class="form-control"></td></tr>';
    html += '<tr><td>5<input type="hidden" name="reward[4][level]" value="5"></td><td><input type="text" placeholder="" name="reward[4][disNum]" value="' + data[4]['disNum'] + '" class="form-control"></td></tr>';
    html += '</table>';

    html += '<div class="form-group">' +
        '<label class="col-sm-2" style="text-align: center">海报显示折扣：</label>' +
        '<input class="col-sm-8" type="number" name="reward_conf[posterDiscount]" value="0">' +
        '</div>'
    return html;
}


/**
 *  体力存钱罐 ---------------------------------
 */
function getSteelSafeHtml() {
    var html = '';
    html += '<div class="col-sm-4"><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><th>sku</th><th>价格</th></thead>';
    html += '<tbody id="table_body5">';
    html += '</tbody>';
    html += '</table></div></div>';
    return html;
}

function getSteelSafeTr(data) {
    var progress = data['progress'];
    var html = '';

    html += '<tr><td style="width: 15%"><input type="text" class="form-control" readonly name="config[' + progress + '][progress]" value="' + progress + '"></td>';
    //var coinsArr = {1:"coins01",2:"coins02",3:"coins03",4:"coins04",5:"coins05",6:"coins06"};
    var spins = data['spins'] != undefined ? data['spins'] : 3;
    var sku = data['sku'] != undefined ? data['sku'] : '';
    var price = data['price'] != undefined ? data['price'] : '';
    html += '<td style="width: 30%"><input type="text" value="' + spins + '" class="form-control" name="config[' + progress + '][spins]">';
    if (progress == 1) {
        html += '<td style="width: 60%"><input type="text" value="' + sku + '" class="form-control" name="config[' + progress + '][sku]">';
        html += '<br>sku:<input type="text" value="' + price + '" class="form-control" name="config[' + progress + '][price]"></td>';
    } else {
        html += '<td style="width: 60%">价格:<select class="form-control m-b selPrice" name="config[' + progress + '][price]">';
        $.each(goodSku, function (k, v) {
            if (data["price"] == v["price"]) {
                sel = "selected";
            } else {
                sel = "";
            }
            html += '<option value="' + v["price"] + '" ' + sel + '>' + v["price"] + '</option>';
        });
        html += '</select>sku:<input class="form-control t_sku" type="text" name="config[' + progress + '][sku]" value="' + data['sku'] + '"></td></td>';
    }


    //for(var j=1;j<=6;j++){
    //    var tStr = "";
    //    var coins= coinsArr[j];
    //    if(coins == data['coins']){
    //        tStr = "selected";
    //    }
    //    html += '<option '+tStr+' value="'+coins+'">'+coins+'</option>';
    //}
    //html +='</select></td>';
    //html +='<td><input type="text" class="form-control" name="config['+progress+'][bet]" value="'+data['bet']+'"></td>';
    html += '</td>';
    //html +='<td><input type="text" class="form-control" name="config['+progress+'][n]" value="'+data['n']+'"></td>';
    html += '</tr>';
    $("#table_body5").append(html);
}

function getSteelSafeLimitHtml() {
    var html = '';
    html += '<div class="col-sm-8"><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><th>延时(秒)</th><th>持续时间(秒)</th><th>积分区间(下线)</th><th>积分区间(上线)</th></thead>';
    html += '<tbody id="table_SteelSafePoint">';
    html += '</tbody><tr><td colspan="6"><div class="text-center"><botton class="btn btn-primary" onclick="addSteelSafeLimitTr()">添加</botton><botton class="btn btn-danger del-tr" onclick="delSteelSafeLimitTr()">删除</botton></div></td></tr>';
    html += '</table></div></div>';
    return html;
}

function getSteelSafeLimitTr(data) {
    steel_safelimit_tr++;
    var id = data['id'];
    var html = '';
    html += '<tr><td style="display: none"><input type="text" class="form-control" name="limit[' + id + '][id]" value="' + id + '"></td>';
    html += '<td><input type="text" class="form-control" name="limit[' + id + '][progress]" value="' + data['progress'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="limit[' + id + '][percent]"  value="' + data['percent'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="limit[' + id + '][delay]"    value="' + data['delay'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="limit[' + id + '][duration]" value="' + data['duration'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="limit[' + id + '][pointMin]" value="' + data['pointMin'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="limit[' + id + '][pointMax]" value="' + data['pointMax'] + '"></td>';
    html += '</tr>';
    $("#table_SteelSafePoint").append(html);
}

function addSteelSafeLimitTr() {
    console.log(steel_safelimit_tr);
    var conf = {"id": steel_safelimit_tr, "progress": 1, "percent": 1, "delay": 1, "pointMin": 1, "pointMax": 1, "duration": 1};
    getSteelSafeLimitTr(conf);
}

function delSteelSafeLimitTr() {
    $("#table_SteelSafePoint").children("tr:last-child").remove();
    steel_safelimit_tr--;
}

function getSteelSafeLimitRewardHtml() {
    var html = '';
    html += '<div class="col-sm-12"><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>进度1概率</th><th>进度2概率</th><th>进度3概率</th><th>奖励</th><th>操作</th></thead>';
    html += '<tbody id="table_SteelSafeLimitReward">';
    html += '</tbody><tr><td colspan="6"><div class="text-center"><botton class="btn btn-primary" onclick="addSteelSafeLimitReward()">添加</botton><botton class="btn btn-danger del-tr" onclick="delSteelSafeLimitReward()">删除</botton>';
    html += '</div></td></tr></table></div>';
    return html;
}

function getSteelSafeLimitRewardTr(data) {
    var id = data['id'];
    var reward = data['prize'] != undefined ? JSON.stringify(data['prize']) : '[]';
    var reward_show_arr = JSON.parse(reward);
    reward = escape(reward);

    var html = '';
    html += '<tr id="safeLimitInfo_' + id + '">';
    html += '<td style="width: 5%;"><input type="text" class="form-control" name="safeLimit[' + id + '][id]" value="' + id + '" readonly></td>';
    html += '<td style="width: 10%;"><input type="text" class="form-control" name="safeLimit[' + id + '][pro0]" value="' + data['pro0'] + '"></td>';
    html += '<td style="width: 10%;"><input type="text" class="form-control" name="safeLimit[' + id + '][pro1]" value="' + data['pro1'] + '"></td>';
    html += '<td style="width: 10%;"><input type="text" class="form-control" name="safeLimit[' + id + '][pro2]" value="' + data['pro2'] + '"></td>';
    html += '<td class="showSafeLimitPrize_' + id + '">';
    if (reward_show_arr.length > 0) {
        for (var j = 0; j < reward_show_arr.length; j++) {
            html += chestPropsHtml(reward_show_arr[j]);
        }
    }
    html += '</td>';
    html += '<input type="hidden" name="safeLimit[' + id + '][prize]" value="' + reward + '">';
    html += '<td style="width: 15%;"><button type="button" class="btn btn-outline btn-success" onclick="setPrize(' + id + ',6)">奖励配置</button></td>';
    html += '</tr>';
    return html;
}

function addSteelSafeLimitReward() {
    steel_safelimit_limit++;
    var data = {"id": steel_safelimit_limit, "pro0": 1, "pro1": 1, "pro2": 1};
    var html = getSteelSafeLimitRewardTr(data);
    $("#table_SteelSafeLimitReward").append(html);
}

function delSteelSafeLimitReward() {
    $("#table_SteelSafeLimitReward").children("tr:last-child").remove();
    steel_safelimit_limit--;
}


/** -------------金币大爆炸---------------*/
function getCoinCfgHtml(data) {
    var html = '';
    var names = {"steal": "偷", "attack": "打", "slot": "旋转老虎机"};
    for (var i = 0; i < data.length; i++) {
        html += '<div class="row"><div class="form-group">';
        html += '<div class="col-sm-2"><input type="hidden" placeholder="" name="reward[' + i + '][type]" value="' + data[i]['type'] + '" class="form-control"></div>';
        html += '<label class="col-sm-2 control-label">' + names[data[i]['type']] + '-奖励倍数:</label>';
        html += '<div class="col-sm-2"><input type="text" placeholder="奖励倍数" name="reward[' + i + '][bet]" value="' + data[i]['bet'] + '" class="form-control"></div>';
        html += '</div></div>';
    }
    return html;
}

function getSteelSafeNHtml(n) {
    var html = '';
    html += '<div aria-hidden="true" id="SteelSafeN">';
    html += '<div class="form-group">';
    html += '<label class="col-sm-1 control-label">体力系数:</label><div class="col-sm-1"><input type="text"  name="steelSafeN" value="' + n + '" class="form-control"></div>';
    html += '</div>';
    html += '</div>';
    return html;
}

/** ------------- premium ---------------*/
function getPremiumHtml(spins) {
    var html = '';
    html += '<div aria-hidden="true">';
    html += '<div class="form-group">';
    html += '<label class="col-sm-1 control-label">消耗体力:</label><div class="col-sm-1"><input type="text"  name="premiumSpins" value="' + spins + '" class="form-control"></div>';
    html += '</div>';
    html += '</div>';
    html += '<div class="form-group" id="premium_table">';
    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_body_premium">';
    html += '</tbody><tr><td colspan="6"><div class="text-center"><botton class="btn btn-primary" onclick="addPremium()">添加</botton><botton class="btn btn-danger del-tr" onclick="delPremium()">删除</botton>';
    html += '</div></td></tr></table></div>';
    return html;
}

function addPremium() {
    premium_limit++;
    var data = {"id": premium_limit};
    var html = premiumTR(data);
    $("#table_body_premium").append(html);
}

function delPremium() {
    if (premium_limit > 0) {
        $("#table_body_premium").children("tr:last-child").remove();
        premium_limit--;
    }
}

function premiumTR(data) {
    var id = data['id'];
    var html = '';
    html += '<tr id="premium_' + id + '">';
    html += '<td style="width: 20%"><input type="text" class="form-control" name="premium[' + id + '][id]" value="' + id + '"></td>';
    var arr = $userGroup3;
    arr = JSON.parse(arr);
    html += '<td><select class="form-control" name="premium[' + id + '][gid]">';
    for (let i in arr) {
        var tStr = "";
        if (i == data['gid']) {
            tStr = "selected";
        }
        html += '<option ' + tStr + ' value="' + i + '">' + arr[i] + '</option>';
    }
    html += '</select></td>';
    html += '</tr>';
    return html;
}

function getTrafficPermitBetHtml(n) {
    var html = '';
    html += '<div aria-hidden="true">';
    html += '<div class="form-group">';
    html += '<label class="col-sm-1 control-label">经验倍率:</label><div class="col-sm-1"><input type="number" onchange="checkTrafficPermitBet(this,this.value)" name="trafficPermitBet" value="' + n + '" class="form-control"></div>';
    html += '</div>';
    html += '</div>';
    return html;
}

function checkTrafficPermitBet(obj, val) {
    if (val > 5 || val < 2) {
        alert("倍率范围：2-5");
        $(obj).val(2);
    }
}

//********************** 2 选 1 礼包 *******************/
function ChooseOnePriceGroupHtml(data) {
    html = '<div class="col-sm-12""><div class="form-group"><div class="col-sm-4 col-sm-offset-2">';
    html += '<botton class="btn btn-primary" onclick="addChooseOnePrice()">添加</botton>';
    html += '<botton class="btn btn-danger del-tr" onclick="delFundPrice()">删除</botton></div></div></div>';
    $("#reward_info").prepend(html);
    var html = '';
    html += '<div id="fundProducts">';
    if (act_type == "choose_one") {
        var products = {1810: "商品1", 1811: "商品2"};
    } else if (act_type == "safe_surprise") {
        var products = {1839: "商品1", 1840: "商品2"};
    } else {
        var products = {1837: "商品1", 1838: "商品2"};
    }

    if (data == undefined) {
        html += GroupPriceHtml({}, 0, products, 7);
    } else {
        for (var i in data) {
            for (var j in data[i].gid) {
                scoreCGGidArr.push(data[i].gid[j]);
            }
            html += GroupPriceHtml(data[i], parseInt(i), products, 7);
        }
    }
    html += '</div>';
    $("#reward_info").prepend(html);
    $('.select2').select2({})
}

function addChooseOnePrice() {
    if (act_type == "choose_one") {
        var products = {1810: "商品1", 1811: "商品2"};
    } else if (act_type == "safe_surprise") {
        var products = {1839: "商品1", 1840: "商品2"};
    } else {
        var products = {1837: "商品1", 1838: "商品2"};
    }
    $("#fundProducts").append(GroupPriceHtml({}, $(".fundGroup").length, products, 7));
    $('.select2').select2({})
}

//function ChooseOne() {
//    var html = '';
//    html +='<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>商品SKU</th><th>折扣（显示1-当前值）</th><th>奖励</th><th>操作</th></tr></thead>' ;
//    html +='<tbody id="table_body_ChooseOne">';
//    html +='</tbody></table></div>';
//    return html;
//}

//function addChooseOneBtn(n) {
//    chooseOne++
//    var gid      = n == 1 ? 1810 : 1811;
//    var sku      = n == 1 ? "com.gworld.cc.luckydraw01" : "com.gworld.cc.gift08";
//    var price    = n == 1 ? 0.99 : 2.99;
//    var discount = n == 1 ? 1 : 1;
//    var data ={"gid":gid,"gsku":sku,"gprice":price,"gdiscount":discount};
//    $("#table_body_ChooseOne").append(ChooseOneTR(data));
//}

//奖励阶段行数据html
function ChooseOneTR(data) {
    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_' + chooseOne + '">';
    html += '<td><input readonly type="text" class="form-control" name="chooseOne[' + chooseOne + '][gid]"    value="' + data['gid'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="chooseOne[' + chooseOne + '][gprice]" value="' + data['gprice'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="chooseOne[' + chooseOne + '][gsku]"   value="' + data['gsku'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="chooseOne[' + chooseOne + '][gdiscount]"   value="' + data['gdiscount'] + '"></td>';
    html += '<td class="chooseOnePrize_' + chooseOne + '">';
    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="chooseOne[' + chooseOne + '][prize]" value="' + prize + '">';
    html += '<td><button type="button" class="btn btn-outline btn-success" onclick="setPrize(' + chooseOne + ',7)">奖励配置</button></td>';
    html += '</tr>';
    return html;
}

//********************** 基金活动 *******************/
function Fund() {
    var html = '';
    html += '<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><th>操作</th></tr></thead>';
    html += '<tbody id="table_body_Fund">';
    html += '</tbody></table></div>';
    return html;
}

function FundPriceGroupHtml(data) {
    html = '<div class="col-sm-12""><div class="form-group"><div class="col-sm-4 col-sm-offset-2">';
    html += '<botton class="btn btn-primary" onclick="addFundPrice()">添加</botton>';
    html += '<botton class="btn btn-danger del-tr" onclick="delFundPrice()">删除</botton></div></div></div>';
    $("#reward_info").prepend(html);
    var html = '';
    html += '<div id="fundProducts">';
    var products = {1812: "首购", 1813: "续购", 1832: "补签"};
    if (data == undefined) {
        html += GroupPriceHtml({}, 0, products, 0);
    } else {
        for (var i in data) {
            for (var j in data[i].gid) {
                scoreCGGidArr.push(data[i].gid[j]);
            }
            html += GroupPriceHtml(data[i], parseInt(i), products, 0);
        }
    }
    html += '</div>';
    $("#reward_info").prepend(html);
}

function addFundPrice() {
    var products = {1812: "首购", 1813: "续购", 1832: "补签"};
    $("#fundProducts").append(GroupPriceHtml({}, $(".fundGroup").length, products), 0);
}

function delFundPrice() {
    $("#fundProducts").children(".fundGroup:last-child").remove();
}

//基金分组组首购,续购,补签价格
function GroupPriceHtml(data, index, products, rewardIndex = 0) {
    var html = '';
    var str = '商品分组' + (index + 1);
    var group = (data === undefined || data.gid === undefined) ? {} : data.gid;
    var d = (data === undefined || data.data === undefined) ? {} : data.data;

    html += '<div class="fundGroup">';
    html += '<div class="form-group">';
    html += '<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">' + str + '</h5></div>';
    html += '</div>';

    html += '<div class="ibox-content">';
    html += '<div class="form-group scoreCGGidDivGroup">';
    if (act_type == "choose_one" || act_type == "one_plus_gift" || act_type == "safe_surprise") {
        var groupId = $("#selectConfigGroup").val();
        if (!groupId) {
            groupId = extra_reward.groupRid;
        }
        html += ChooseRFMGroup({"gid": group}, index, 0, groupId); //rfm分组
    } else {
        html += ChooseRFMGroup({"gid": group}, index, 0); //rfm分组
    }

    html += '</div>';

    for (var i in products) {
        var price = (d[i] === undefined || d[i].gprice === undefined) ? '' : d[i].gprice;
        var sku = (d[i] === undefined || d[i].gsku === undefined) ? '' : d[i].gsku;
        var discount = (d[i] === undefined || d[i].gdiscount === undefined) ? '' : d[i].gdiscount;
        var prize = (rewardIndex > 0 && d[i] != undefined && d[i].prize != undefined) ? d[i].prize : [];
        html += productPriceHtml({"name": products[i], "sku": sku, "discount": discount, "price": price, "gid": i, "prize": prize}, index, rewardIndex);
    }
    html += '</div></div></div>';
    return html;
}

//活动商品配置
function productPriceHtml(data, index, rewardIndex = 0) {
    html = '<div class="form-group priceSkuGroup">';
    html += '<label class="col-sm-1 control-label m-b">' + data.name + '价格</label>';
    html += '<div class="col-sm-1">' +
        '<select type="text" class="form-control priceSelector" onchange="priceChanged(this)" name="reward_conf[' + index + '][' + data.gid + '][gprice]" value="' + data.price + '">';
    html += '<option value="-1" hidden >选择价格</option>'
    for (var priceI in priceSkuMap) {
        console.log(priceI, data.price)
        var selectedStr = ''
        if (data.price == priceI) {
            selectedStr = 'selected'
        }
        html += '<option value="' + priceI + '"  ' + selectedStr + '>' + priceI + '</option>'
    }
    html += '</select>' +
        '</div>';
    html += '<label class="col-sm-1 control-label m-b">' + data.name + 'sku</label>';
    html += '<div class="col-sm-2"><input type="text" readonly class="form-control skuInput" name="reward_conf[' + index + '][' + data.gid + '][gsku]" value="' + data.sku + '"></div>';
    html += '<label class="col-sm-2 control-label m-b">' + data.name + '折扣（显示1-当前值）</label>';
    html += '<div class="col-sm-1"><input type="text" class="form-control" name="reward_conf[' + index + '][' + data.gid + '][gdiscount]" value="' + data.discount + '"></div>';
    // console.log(3965)
    // console.log(data.prize)
    // console.log(chestPropsHtml(data.prize[0]))
    html += '<div class="col-sm-3 prizesSpan">'
    $.each(data.prize, function (i, o) {
        html += chestPropsHtml(o)
    })
    html += '</div>'
    if (rewardIndex > 0) {
        html += '<input type="hidden" name="reward[' + index + '][' + data.gid + '][prize]" value="' + escape(JSON.stringify(data.prize)) + '">';
        html += '<button type="button" class="btn btn-outline btn-success" onclick="setPrize(' + data.gid + ',7,' + index + ')">奖励配置</button>';
    }
    html += '</div>';
    return html;
}

function priceChanged(obj) {
    var price = $(obj).val();
    console.log(price)
    $(obj).parents('.priceSkuGroup').find('.skuInput').val(priceSkuMap[price])
}

function FundHtml(data) {
    for (var i = 0; i < data.length; i++) {
        $("#table_body_Fund").append(FundTR(data[i]));
    }
}

//奖励阶段行数据html
function FundTR(data) {
    var id = data['id'];
    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_' + id + '">';
    html += '<td style="width: 10%"><input readonly type="text" class="form-control" name="fund[' + id + '][id]" value="' + data['id'] + '"></td>';
    html += '<td class="fundPrize_' + id + '">';
    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="fund[' + id + '][prize]" value="' + prize + '">';
    html += '<td style="width: 10%"><button type="button" class="btn btn-outline btn-success" onclick="setPrize(' + id + ',8)">奖励配置</button></td>';
    html += '</tr>';
    return html;
}

//--------------四选一 star------------------

//复活礼包table

//复活礼包行tr

//-----------------end------------------------

//********************** 好友召回活动 *******************/
function callBackCfg(data) {
    var html = '';
    html += '<div class="form-group"><label class="col-sm-2 control-label m-b">召回固定积分<span style="color: #ff0000;">注：必填</span></label><div class="col-sm-3 input-group">';
    html += '<input type="text" style="text-align: center" class="form-control" name="extra_reward[score]" value="' + data.score + '">';
    html += '</div></div>';
    html += '<div class="form-group"><label class="col-sm-2 control-label m-b">被召回可任务天数<span style="color: #ff0000;">注：默认配置需要>=1天,且小于结束时间-领奖时间(天数)</span></label><div class="col-sm-3 input-group">';
    html += '<input type="text" style="text-align: center" class="form-control" name="extra_reward[days]" value="' + data.days + '">';
    html += '</div></div>';
    return html;
}

//创建表格式html
function callbackCondTb() {
    var html = '';
    var cols = 4;
    index = $('#callback_cond_body').find('table').length + 1;
    html += '<table class="table table-bordered spinRankTable">';
    html += '<tbody id="callback_cond_body">';
    html += '</tbody><tr><td colspan="' + cols + '"><div class="text-center"><botton class="btn btn-primary" onclick="addCallbackCondNum(' + index + ')">添加</botton><botton class="btn btn-danger del-tr" onclick="delCallbackCondNum()">删除</botton>';
    html += '</div></td></tr></table></div>';
    return html;
}

function addCallbackCondNum(index = 0) {
    var condition = {
        level: {'start': '', 'end': ''}, //等级区间
        lastDays: 1, //不在线时间范围
        score: 0, //召回成功一个奖励积分数
        gid: [], //已选的rfm分组
        extraScore: 2,
    };
    index = $('#callback_cond_body').find('table.spinRankTable').length + 1;
    var html = friendCallbackCond(condition, index);
    $('#callback_cond_body').append(html);
}

function delCallbackCondNum(index) {
    index = $('#callback_cond_body').find('table').length;
    if (index > 0) {
        $('#callback_cond_body').children("table.spinRankTable:last-child").remove();
    }
}

//可找回玩家条件赛选
function friendCallbackCond(data, index = 0) {
    data['lastDays'] = data['lastDays'] == undefined ? 1 : data['lastDays'];
    var html = '';
    var str = '对象分组' + index;
    html += '<table class="table table-bordered spinRankTable">';

    html += '<thead><tr><td colspan="4">';
    html += '<div class="form-group" id="callbackCond_table">';
    html += '<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">' + str + '</h5></div>';
    html += '</div></div></td></tr>';
    html += ChooseRFMGroup(data, index); //rfm分组
    html += '<thead><tr><td colspan="4">';
    html += '<input type="hidden"  class="form-control" name="cond[' + index + '][id]" value="' + index + '">';
    html += '<div class="form-group"><label class="col-sm-2 control-label m-b">等级区间 <span style="color: #ff0000;">注:必填</span></label><div class="col-sm-3 input-group">';
    html += '<input type="text" style="text-align: center" class="form-control" name="cond[' + index + '][level][start]" value="' + data.level['start'] + '">';
    html += '<span class="input-group-addon">-</span>';
    html += '<input type="text" style="text-align: center" class="form-control" name="cond[' + index + '][level][end]" value="' + data.level['end'] + '">';
    html += '</div></div></td></tr>';

    html += '<tr><td colspan="4">';
    html += '<div class="form-group"><label class="col-sm-2 control-label m-b">不在线天数 <span style="color: #ff0000;">注：默认配置需要>=1天</span></label><div class="col-sm-3 input-group">';
    html += '<input type="text" style="text-align: center" class="form-control" name="cond[' + index + '][lastDays]" value="' + data['lastDays'] + '"></div>';
    //<label class="col-sm-2 control-label m-b" style="color:red">注：默认配置需要>=1天</label>

    // html +='<tr><td colspan="4">';
    // 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="cond['+index+'][score]" value="'+data.score+'">';
    // html +='</div></div></td></tr>';

    html += '<tr><td colspan="4">';
    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="cond[' + index + '][extraScore]" value="' + data.extraScore + '">';
    html += '</div></div></td></tr></thead>';
    html += '<tbody>';
    html += callbackCondSignTb(index);
    html += '</tbody></div></td></tr></table>';
    return html;
}

function callbackCondSignTb(index = 0) {
    var html = '';
    html += '<tr><td colspan="4">';
    html += '<div class="col-sm-12"><div class="form-group">';
    html += '<table class="table table-bordered">';
    html += '<thead><tr><th>编号</th><th>累计签到天数</th><th>对应积分</th></thead>';
    html += '<tbody id="table_callback_sign_cond_' + index + '">';
    html += '</tbody><tr><td colspan="6"><div class="text-center"><botton class="btn btn-primary" onclick="addCallbackSign(' + index + ')">添加</botton><botton class="btn btn-danger del-tr" onclick="delCallbackSign(' + index + ')">删除</botton>';
    html += '</div></td></tr></table></div>';
    html += '</td></tr>';
    return html;
}

//累计签到天数积分奖励配置
function callbackSignTR(data, index) {
    var day = data['day'] == undefined ? 1 : data['day'];
    var score = data['score'] == undefined ? 1 : data['score'];
    var stage = $('#table_callback_sign_cond_' + index).find('tr').length + 1;
    var html = '';
    html += '<tr>';
    html += '<td style="width: 5%;"><input type="text" class="form-control" name="cond[' + index + '][sign][' + stage + '][id]" value="' + stage + '"></td>';
    html += '</select></td>';
    html += '<td><input type="text" class="form-control" name="cond[' + index + '][sign][' + stage + '][day]" value="' + day + '"></td>';
    html += '<td><input type="text" class="form-control" name="cond[' + index + '][sign][' + stage + '][score]" value="' + score + '"></td>';
    html += '</tr>';
    $('#table_callback_sign_cond_' + index).append(html);
}

//添加召回活动任务列
function addCallbackSign(index = 0) {
    var stage = $('#table_callback_sign_cond_' + index).find('tr').length + 1;
    var html = '';
    html += '<tr>';
    html += '<td style="width: 5%;"><input type="text" class="form-control" name="cond[' + index + '][sign][' + stage + '][id]" value="' + stage + '"></td>';
    html += '</select></td>';
    html += '<td><input type="text" class="form-control" name="cond[' + index + '][sign][' + stage + '][day]" value="1"></td>';
    html += '<td><input type="text" class="form-control" name="cond[' + index + '][sign][' + stage + '][score]" value="1"></td>';
    html += '</tr>';
    $('#table_callback_sign_cond_' + index).append(html);
}

//删除召回活动每日签到列表
function delCallbackSign(index = 0) {
    var length = $('#table_callback_sign_cond_' + index).find('tr').length;
    if (length > 0) {
        $('#table_callback_sign_cond_' + index).children("tr:last-child").remove();
    }
}

//删除召回任务列
function delFriendCallbackTask() {
    if (callbackTask_limit > 0) {
        $("#callback_task").children("tr:last-child").remove();
        callbackTask_limit--;
    }
}

function friendCallbackTaskTb() {
    var html = '';
    html += '<div class="col-sm-12"><div class="form-group">';
    html += '<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">活动任务配置<span style="color: #ff0000;">注：每个类型只能配一个</span></h5></div>';
    html += '<table class="table table-bordered">';
    //html +='<thead><tr><th>任务ID</th><th>任务类型</th><th>任务次数</th><th>任务参数</th><th>可获得积分</th></thead>';
    html += '<thead><tr><th>任务ID</th><th>任务类型</th><th>任务次数/数量</th><th>可获得积分</th></thead>';
    html += '<tbody id="callback_task">';
    html += '</tbody><tr><td colspan="6"><div class="text-center"><botton class="btn btn-primary" onclick="addFriendCallbackTask()">添加</botton><botton class="btn btn-danger del-tr" onclick="delFriendCallbackTask()">删除</botton>';
    html += '</div></td></tr></table></div>';
    return html;
}

//添加召回玩家任务列表
function addFriendCallbackTask() {
    callbackTask_limit++;
    var data = {"id": callbackTask_limit, "score": 1, "num": 1};
    var html = callbackTaskTR(data);
    $("#callback_task").append(html);
}

//添加召回活动任务列
function callbackTaskTR(data) {
    var stage = data['id'];
    var html = '';
    html += '<tr id="treasureInfo_' + stage + '">';
    html += '<td style="width: 5%;"><input type="text" class="form-control" name="callback_task[' + stage + '][id]" value="' + stage + '"></td>';
    var taskTypeArr = {1: "偷金币", 2: "攻击岛", 3: "消耗体力", 4: "签到", 5: "分享", 6: "fb邀请", 7: "召回分享", 8: "建造完成", 9: "赠送体力", 10: "赠送金币", 11: "赠送卡片"};
    html += '<td style="width: 15%;"><select class="form-control seltask" name="callback_task[' + stage + '][type]">';
    for (var j = 1; j <= 11; j++) {
        var tStr = "";
        if (j == data['type']) {
            tStr = "selected";
        }
        html += '<option ' + tStr + ' value="' + j + '">' + taskTypeArr[j] + '</option>';
    }
    html += '</select></td>';
    html += '<td><input type="text" class="form-control" name="callback_task[' + stage + '][num]" value="' + data['num'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="callback_task[' + stage + '][score]" value="' + data['score'] + '"></td>';
    html += '</tr>';
    return html;
}

//删除召回任务列
function delFriendCallbackTask() {
    if (callbackTask_limit > 0) {
        $("#callback_task").children("tr:last-child").remove();
        callbackTask_limit--;
    }
}

//奖励阶段行数据html
function callbackRewardTableTR(data) {
    // console.log(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'] + '">';
    html += '<td><input type="text" class="form-control" name="reward[' + data['stage'] + '][stage]" value="' + data['stage'] + '"></td>';
    html += '<td><input type="text" class="form-control" name="reward[' + data['stage'] + '][stepnum]" value="' + data['stepnum'] + '"></td>';

    html += '<td class="showStagePrize_' + 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 type="hidden" name="reward[' + data['stage'] + '][prize]" value="' + prize + '">';
    html += '<td><button type="button" class="btn btn-outline btn-success" onclick="setPrize(' + stage + ',1)">奖励配置</button></td>';// data-toggle="modal"
    html += '</tr>';
    return html;
}

//-----------------end------------------------
//---------------小玩法收集 star---------------
var collectChangeItem = [{"name": "地雷", "value": 1}];//{"name":"金矿钩子","value":2}
function collectChangeSel(data) {
    console.log(collectChangeItem.length, collectChangeItem[1]);
    var html = '';
    html += '<div class="form-group" ><label class="col-sm-2 control-label m-b">收集物:</label><div class="col-sm-3 input-group">';
    html += '<select class="form-control" name="reward_conf[item]">';
    for (var j = 0; j < collectChangeItem.length; j++) {
        var tStr = "";
        if (collectChangeItem[j]['value'] == data['item']) {
            tStr = "selected";
        }
        html += '<option ' + tStr + ' value="' + collectChangeItem[j]['value'] + '">' + collectChangeItem[j]['name'] + '</option>';
    }
    html += '</select></div></div>';
    return html;
}

//----------------- end ---------------------
//======================超级气球==star========================
//添加气球bet_table
$(document).on('click', '#addBalloonBetBtn', function (e) {
    betStage++;
    var d = {"star": 0, "end": 0};
    html2 = balloonBetTable(betStage, d);
    $("#balloon_table").append(html2);
});
//删除气球bet_table
$(document).on('click', '#delBalloonBetBtn', function (e) {
    if (betStage > 1) {
        $("#balloon_table").children(".balloonBetTable:last-child").remove();
        betStage--;
    }
});

function addBalloonTR(index) {
    if (!balloon_bet_limit[index]) {
        balloon_bet_limit[index] = 1;
    } else {
        balloon_bet_limit[index]++;
    }
    console.log('分组：阶段-', index, balloon_bet_limit[index]);
    var data = {"stage": balloon_bet_limit[index], "weight": 100, "imgType": 1, "limit": 0};
    var html = balloonTableTRHtml(index, data);
    $("#table_body3_" + index).append(html);
}

//删除排行奖励行
function delBalloonTR(index) {
    if (balloon_bet_limit[index] > 0) {
        $("#table_body3_" + index).children("tr:last-child").remove();
        balloon_bet_limit[index]--;
    }
}

function setBalloonStyleHtml(data) {
    var html = '';
    html += '<div class="form-group"><label class="col-sm-2 control-label">移动方式：</label>';
    html += '<div class="col-sm-4"><select class="form-control m-b" name="moveType">';
    var arr = {1: "向上飘", 2: "向下落"};
    for (let i in arr) {
        var tStr = "";
        if (i == data['moveType']) {
            tStr = "selected";
        }
        html += '<option ' + tStr + ' value="' + i + '">' + arr[i] + '</option>';
    }
    html += '</select></div></div>';
    html += '<div class="form-group"><label class="col-sm-2 control-label">移动速度：</label>';
    html += '<div class="col-sm-4"><input type="text"  name="speed" value="' + data['speed'] + '" class="form-control"></div>';
    html += '</div>';
    html += '<div class="form-group"><label class="col-sm-2 control-label">转到金币出现概率：</label>';
    html += '<div class="col-sm-4"><input type="text"  name="showPv" value="' + data['showPv'] + '" class="form-control"></div>';
    html += '</div>';
    html += '<div class="form-group"><label class="col-sm-2 control-label">气球产出权重：</label>';
    html += '<label class="col-xs-1 control-label">1个:</label><div class="col-sm-1"><input type="text"  name="outPut[1]" value="' + data['outPut'][1] + '" class="form-control"></div>';
    html += '<label class="col-xs-1 control-label">2-3个:</label><div class="col-sm-1"><input type="text"  name="outPut[2]" value="' + data['outPut'][2] + '" class="form-control"></div>';
    html += '<label class="col-xs-1 control-label">4-6个:</label><div class="col-sm-1"><input type="text"  name="outPut[3]" value="' + data['outPut'][3] + '" class="form-control"></div>';
    html += '</div>';
    return html;
}

function balloonTable() {
    var html = '';
    html += '<hr style=" height:2px;border:none;border-top:2px dotted #0b0;"><div class="form-group" id="balloon_table">';
    html += '<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">气球bet区间掉落配置</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="addBalloonBetBtn" type="button">添加</button>';
    html += '<button class="btn btn-white"   id="delBalloonBetBtn" type="button">删除</button>';
    html += '</div></div><hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    return html;
}

function balloonBetTable(index, data) {
    var html = '';
    html += '<table class="table table-bordered balloonBetTable">';
    html += '<thead><tr><td colspan="6">';
    html += '<div class="form-group"><label class="col-sm-2 control-label m-b">Bet区间 </label><div class="col-sm-3 input-group">';
    html += '<input type="text" style="text-align: center" class="form-control" name="spinStage[' + index + '][star]" value="' + data['star'] + '">';
    html += '<span class="input-group-addon">-</span>';
    html += '<input type="text" style="text-align: center" class="form-control" name="spinStage[' + index + '][end]" value="' + data['end'] + '">';
    html += '</div></div></td></tr>';
    html += '<tr>' +
        '<th>stage</th>' +
        '<th>飘落物品</th>' +
        '<th>权重</th>' +
        '<th>奖励</th>' +
        '<th>领取次数</th>' +
        '<th>奖励配置</th>' +
        '</tr></thead>';
    html += '<tbody id="table_body3_' + index + '">';

    html += '</tbody><tr><td colspan="6"><div class="text-center"><botton class="btn btn-primary"  onclick="addBalloonTR(' + index + ')">添加</botton><botton class="btn btn-danger del-tr" onclick="delBalloonTR(' + index + ')">删除</botton>';
    html += '</div></td></tr></table>';
    return html;
}

function balloonTableTRHtml(index, data) {
    if (!data['limit']) data['limit'] = 0;
    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'] + '">';
    html += '<td><input type="text" class="form-control" name="rewardnew[' + index + '][' + data['stage'] + '][stage]" value="' + data['stage'] + '"></td>';
    var arr = {1: "物品1", 2: "物品2", 3: "物品3", 4: "物品4"};
    html += '<td><select class="form-control" name="rewardnew[' + index + '][' + data['stage'] + '][imgType]">';
    for (let i in arr) {
        var tStr = "";
        if (i == data['imgType']) {
            tStr = "selected";
        }
        html += '<option ' + tStr + ' value="' + i + '">' + arr[i] + '</option>';
    }
    html += '</select></td>';
    html += '<td><input type="text" class="form-control" name="rewardnew[' + index + '][' + data['stage'] + '][weight]" value="' + data['weight'] + '"></td>';
    html += '<td class="showStagePrize_' + index + '_' + 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 type="hidden" name="rewardnew[' + index + '][' + data['stage'] + '][prize]" value="' + prize + '">';
    html += '<td><input type="text" class="form-control" name="rewardnew[' + index + '][' + data['stage'] + '][limit]" value="' + data['limit'] + '"></td>';
    html += '<td><button type="button" class="btn btn-outline btn-success" onclick="setPrize(' + stage + ',1,' + index + ')">奖励配置</button></td>';// data-toggle="modal"
    html += '</tr>';

    return html;
}

//========================= end ==============================
var commonLineTitles = {};
var commonLineNum = 0;

function addCommonLine() {
    var html = '';
    var d;
    commonLineNum++;
    if (act_type == 'treasure') {
        d = {"id": commonLineNum, "pro": 1, "fix": 1,};
    }
    html += commonLine(d);
    $('#commonLine').append(html);
}

function delCommonLine() {
    if (commonLineNum > 1) {
        $("#commonLine").children(".row")[commonLineNum - 1].remove();
        commonLineNum--;
    }
}

function commonInput(data) {
    var html = '';
    html += '<div class="row" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;"><div class="form-group" >';
    var zs = '';
    if (act_type == 'speed_spins') {
        zs = '<span style="color: #ff0000;">*(只能取2,3,4,5)</span>';
    }
    $.each(commonLineTitles, function (key, val) {
        html += '<label class="col-sm-2 control-label">' + val['tname'] + zs + '</label><div class="col-sm-1"><input type="text" class="form-control"  name="reward_conf[' + val['vname'] + ']" value="' + data[val['vname']] + '"></div>';
    });
    html += '</div></div>';
    return html;
}

function commonTable(title) {
    var html = '';
    html += '<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">' + title + '</h5></div>';
    // html+='<div class="col-sm-8"></div>';
    // html+='</div>';
    html += '<div class="text-center" id="commonLine">';
    html += '</div><botton class="btn btn-primary" id="addCommonLine" onclick="addCommonLine()">添加</botton><botton class="btn btn-danger del-tr" onclick="delCommonLine()">删除</botton></div>';
    // html +='<hr style=" height:2px;border:none;border-top:2px dotted #0b0;"><div class="form-group" id="balloon_table">';
    return html;
}

function commonLine(data) {
    var html = '';
    var i = data["id"];
    html += '<div class="row" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;"><div class="form-group" >';
    html += '<input type="hidden" class="form-control" readonly name="common_conf[' + i + '][id]" value="' + data["id"] + '">';
    $.each(commonLineTitles, function (key, val) {
        html += '<label class="col-sm-1 control-label">' + val['tname'] + '</label><div class="col-sm-1"><input type="text" class="form-control"  name="common_conf[' + i + '][' + val['vname'] + ']" value="' + data[val['vname']] + '"></div>';
    });
    html += '</div></div>';
    return html;
}

function commIboxTable(title) {
    return '<div class="ibox-title" style="border-top: 0;"><h5 style="font-weight: bold">' + title + '</h5></div>';
}

var prize_num = 0;//奖品行数
var prize_stage = 0;//奖品所属奖励类id
var prize_type = 0;//奖品所属奖励类
//保持进度行奖品配置
//奖品行html
// var skinsArr = {
//     19: chestArr,
//     41: easterEggSkin
//     , 43: treasureSkin
//     , 46: crazyCardGroup
//     // , 44: jigsawSkin
// }
for (var rtype in skinsArrKeys) {
    skinsArrKeys[rtype] = parseInt(skinsArrKeys[rtype])
}
var hasInvalidActProp = false;

function prizeListHtml(prizeList) {
    var prizeHtml = '';
    $.each(prizeList, function (i, prize) {
        prizeHtml += chestPropsHtml(prize)
    })
    return prizeHtml;
}

function chestPropsHtml(data) {
    if (!data || !data['type'] || isNaN(data['type'])) return ''
    if ($.inArray(parseInt(data['type']), actPropArr) != -1) {
        var dv = "分钟";
        var dc = "btn-danger";
    } else {
        if (
            data['type'] == 13//随机金卡
            || data['type'] == 48//随机黑金卡
            || data['type'] == 49//随机限时金卡
            || data['type'] == 50//随机限时黑金卡
        ) {
            var dv = data['rtype'] == 1 ? ' 固定' : (data['rtype'] == 2 ? '随机' : '固定金卡反面');
        } else {
            var dv = data['rtype'] == 1 ? '个' : '倍';
        }
        var dc = data['rtype'] == 1 ? 'btn-primary' : 'btn-danger';
    }
    if ("is_ts" in data) {
        data['is_ts'] == 1 ? dv += '(限)' : true;
        data['is_ts'] == 1 ? dc = 'btn-warning' : true;
    }
    data['type'] = parseInt(data['type'])
    if (skinsArrKeys.indexOf(data['type']) >= 0) {
        if ('skin' in data) {
            var skin = data['skin'];
        } else {
            var defArr = {19: 1};
            var skin = defArr[data['type']]
        }
        console.log(skin)
        if (skinsArr[data['type']][skin] == undefined) {
            var skName = reward_type_arr[data['type']]['name'] + '(ID:' + skin + ')' + '(已失效)';
            hasInvalidActProp = true;
        } else {
            var skName = skinsArr[data['type']][skin];
            if (skName.indexOf(skin) < 0) {
                skName += '(ID:' + skin + ')'
            }
        }
        var html = '<span class="btn btn-outline ' + dc + '">' + skName + ':' + data['num'] + dv + '</span>';
    } else {
        var html = '<span class="btn btn-outline ' + dc + '">' + reward_type_arr[data['type']]['name'] + ':' + data['num'] + dv + '</span>';
    }
    return html + ' ';
}

function prizeInfoTR(data, index = 0) {
    var w = '';
    if (index > 0) {
        var w = 'style="width: 100%"';
    }
    var html = '';
    var sel2 = '';
    var sel3 = '';
    var sel4 = '';
    var sel5 = '';
    html += '<tr id="prize_' + prize_num + '">';
    html += '<td><select class="form-control select2" style="width: 300px" onchange="prizeInfoTRChange(this,this.value)" name="type">';//prize['+data['prize']['id']+']
    $.each(reward_type, function (k, v) {
        if (act_type == "daily_chest" && v.id != 19) {
            return true;
        }
        if (data["prize"]['type'] == v["id"]) {
            sel = "selected";
        } else {
            sel = "";
        }
        html += '<option value="' + v["id"] + '" ' + sel + '>' + v["name"] + '</option>';
    });
    html += '</select></td>';
    html += '<td><select class="form-control  select2" name="rtype">';
    if (data["prize"]['rtype'] == 1) {
        sel2 = "selected";
    } else if (data["prize"]['rtype'] == 2) {
        sel3 = "selected";
    } else {
        sel4 = "selected";
    }
    if (
        data["prize"]['type'] == 13 //随机金卡
        || data["prize"]['type'] == 48//随机黑金卡
        || data["prize"]['type'] == 49//随机限时金卡
        || data["prize"]['type'] == 50//随机限时黑金卡
    ) {
        html += '<option value="1" ' + sel2 + '>固定</option>';
        html += '<option value="2" ' + sel3 + '>随机</option>';
        if (act_type == 'rank' || act_type == 'rank2') {
            html += '<option value="3" ' + sel4 + '>固定金卡反面</option>';
        }
    } else {
        html += '<option value="1" ' + sel2 + '>固定值</option>';
        html += '<option value="2" ' + sel3 + '>等级取值</option>';
    }
    html += '</select></td>';
    html += '<td><input type="text" class="form-control" name="num" value="' + data["prize"]['num'] + '" ' + w + '></td>';
    if ((act_type == 'collect' || act_type == 'collect_only' || act_type == 'super_collect') && index > 0) {
        html += '<td><select class="form-control" name="is_ts">';
        if (data["prize"]['is_ts'] == 1) {
            sel5 = "selected";
        } else {
            sel4 = "selected";
        }
        html += '<option value="0" ' + sel4 + '>否</option>';
        html += '<option value="1" ' + sel5 + '>是</option>';
        html += '</select></td>';
        html += '<td><input type="text" class="form-control" name="ts" value="' + data["prize"]['ts'] + '" ' + w + '></td>';
    } else if (act_type == 'super_balloon') {
        // html +='<td><input type="text" class="form-control" name="weight" value="'+data["prize"]['weight']+'" '+w+'></td>';
    }
    html += '<td><select class="form-control select2" name="skin">';
    console.log("==================", skinsArr)
    var skinArr = {}
    var prizeType = data["prize"]['type'] * 1
    if (chestPropsArr.indexOf(prizeType) >= 0
        || act_type == "daily_chest"
        || skinsArrKeys.indexOf(prizeType) >= 0
        || data["prize"]['type'] == 23
        // || prizeType == 43
        // || prizeType == 44
        // || prizeType == 46
    ) {
        if (skinsArr[prizeType]) {
            skinArr = skinsArr[prizeType]
        } else {
            skinArr = chestArr
        }
    }
    console.log("------------------", data["prize"]['type'], skinArr)
    if (skinArr != {}) {
        $.each(skinArr, function (k, v) {
            if (data["prize"]['skin'] == k) {
                var sel = "selected";
            } else {
                var sel = "";
            }
            if (data["prize"]['type'] * 1 == 41) {
                html += '<option ' + sel + ' value="' + k + '">' + v + "(活动ID：" + k + ")" + '</option>';
            } else {
                html += '<option ' + sel + ' value="' + k + '">' + v + '</option>';
            }
        });
    }

    html += '</select></td>';

    html += '</tr>';
    return html;
}

function prizeInfoTRChange(obj, value) {
    var selObj = $(obj).parent().next().children();
    selObj[0].options.length = 0;
    if (value == 14) {
        $(selObj).append('<option value="1" selected>固定值</option>');
        $(selObj).append('<option value="2">等级取值</option>');
    } else if (
        value == 13//随机金卡
        || value == 48//随机黑金卡
        || value == 49//随机限时金卡
        || value == 50//随机限时黑金卡
    ) {
        $(selObj).append('<option value="1" selected>固定</option>');
        $(selObj).append('<option value="2">随机</option>');
        if (act_type == 'rank' || act_type == 'rank2') {
            $(selObj).append('<option value="3">固定金卡反面</option>');
        }
    } else {
        $(selObj).append('<option value="1" selected>固定值</option>');
    }
    var selObj2 = $(obj).parent().next().next();
    value = parseInt(value);
    if (skinsArrKeys.indexOf(value) >= 0 && skinsArr[value]) {
        //选择四选一活动道具
        var html = '<select class="form-control select2" name="skin">';
        $.each(skinsArr[value], function (k, v) {
            var sel = "";
            html += '<option ' + sel + ' value="' + k + '">' + v + "(ID：" + k + ")" + '</option>';
        });
        html += '</select>';
        $(obj).parent().parent().children("td:last-child").html(html)
    } else {
        selObj2.html('<input type="text" class="form-control" name="num" value="1">')
        $(obj).parent().parent().children("td:last-child").html('<select class="form-control" name="skin"></select>')
    }
    $('.select2').select2({})
}

function scheduleSubmit() {
    var str = '';
    $.each($('#prize_body').find('tr'), function (i, o) {
        data = serializeForm($(o).attr('id'));
        str += data + ",";
    })
    str = "[" + str.slice(0, str.length - 1) + "]";

    var prize_show_arr = JSON.parse(str);
    var htmls = '';
    var nums = 0;
    if ('chooseYouWant' == prize_type) {
        prize_show_arr = [prize_show_arr[0]];
        str = JSON.stringify(prize_show_arr)
    }
    for (var j = 0; j < prize_show_arr.length; j++) {
        if (prize_show_arr[j]['is_ts'] == 0) {
            nums++;
        }
        res = propSelVersion(prize_show_arr[j]['type']);
        if (!res) {
            return false;
        }
        // if(prize_show_arr[j]['num']<1){
        //     alert('数量必须大于1');
        //     return false;
        // }
        console.log('道具类型:', prize_show_arr[j]['type']);
        if (prize_show_arr[j]['rtype'] == 2) {
            if ((prize_show_arr[j]['type'] == 14 && prize_type == 2 && act_type == 'rank') || (prize_show_arr[j]['type'] == 14 && prize_type == 2 && act_type == 'rank2')) {
                alert('排名奖励金币只能配固定金币值');
                return false;
            } else if (prize_show_arr[j]['num'] > 100) {
                var ret = window.confirm('当前倍率取值超过100倍,确定这么操作么');
                if (!ret) {
                    return false;
                }
            }
        }
        if ($.inArray(parseInt(prize_show_arr[j]['type']), [1, 2, 3, 4.10, 11, 12, 13, 18, 19, 20, 21, 29, 30]) !== -1 && prize_show_arr[j]['num'] > 1) {
            alert('宝箱,金卡等只支持一条一个');
            return false;
        }
        if (parseInt(prize_show_arr[j]['type']) === 13) {
            alert('金卡配置需谨慎操作,看清楚再配');
        }

        prize_show_arr[j].skin = Number(prize_show_arr[j].skin)
        htmls += chestPropsHtml(prize_show_arr[j]);
    }
    // console.log(nums,act_type);
    if (nums > 1 && act_type === 'super_collect') {
        $('input[name="act_version[]"]:checked').each(function () {
            var selVersion = $(this).val();
            console.log(selVersion);
            // if(toNum(selVersion)<toNum("1.9")){
            //     alert('只有1.9及之后的版本才支持配两个物品');
            //     return false;
            // }
        });
    }
    str = escape(JSON.stringify(prize_show_arr));
    console.log({"prize_type": prize_type, "this_index": this_index, "this_shushuIdx": this_shushuIdx, "prize_stage": prize_stage});

    switch (prize_type) {
        case 'treasure':
            $('input[name="treasure[' + prize_stage + '][' + this_index + '][prize]"]').val(str);
            $(".showTreasurePrize_" + prize_stage + '_' + this_index).html(htmls);
            break;
        case 'timelimitInvite':
            $('input[name="timelimitInvite[' + prize_stage + '][' + this_index + '][prize]"]').val(str);
            $(".showStagePrize_" + prize_stage + '_' + this_index).html(htmls);
            break;
        case 'mayaWheel':
            console.log($('input[name="mayaWheelReward[' + this_index + '][prize]"]'))
            console.log($(".showStagePrize_" + this_index))
            $('input[name="mayaWheelReward[' + this_index + '][prize]"]').val(str);
            $(".showStagePrize_" + this_index).html(htmls);
            break;
        case 'chooseYouWant':
            console.log($(".showStagePrize_" + prize_stage + '_' + this_index))
            console.log(htmls)
            $('input[name="chooseYouWantRewardConfig[' + prize_stage + '][' + this_index + '][prize]"]').val(str);
            $(".showStagePrize_" + prize_stage + '_' + this_index).html(htmls);
            break;
        case 'rank':
            $('input[name="rewardnew[' + this_index + '][' + this_shushuIdx + '][' + prize_stage + '][prize]"]').val(str);
            $(".showStagePrize_" + this_index + '_' + this_shushuIdx + '_' + prize_stage).html(htmls);
            break;
        case 'jigsaw':
        case 'superCollect':
        case 'spinsMaster':
        case 'driftTreasure':
        case 'superGashapon':
        case 'superSerialProgress':
            $(prize_stage).parents('tr').find('.prizeInput').val(str);
            $(prize_stage).parents('tr').find('.prizeShow').html(htmls);
            break;
        case 'easterEgg':
            $(prize_stage).parents('.easterRewardTr').find('.prizeInput').val(str);
            $(prize_stage).parents('.easterRewardTr').find('.prizeShow').html(htmls);
            break;
        case 'superSerial':
            $(prize_stage).parents('.serialRewardInfoTr').find('.prizeInput').val(str);
            $(prize_stage).parents('.serialRewardInfoTr').find('.prizeShow').html(htmls);
            break;
        case 'setCommonPrize':
            $(prize_stage).parents('.commonStageRewardTr').find('.prizeInput').val(str);
            $(prize_stage).parents('.commonStageRewardTr').find('.prizeShow').html(htmls);
            break;
        case 'setCommonPrize2':
            $(prize_stage).parents('.commonStageRewardTr').find(`.${setCommonPrizeClass}Input`).val(str);
            $(prize_stage).parents('.commonStageRewardTr').find(`.${setCommonPrizeClass}`).html(htmls);
            break;
        case 'luckyFox':
            $(prize_stage).parents('td').find('.prizeInput').val(str)
            $(prize_stage).parents('td').parents('tr').find('.prizeShow').html(htmls);
            break;
        case 'crazyBuild_basic':
            $(prize_stage).parents('td').find('.basicPrizeInput').val(str)
            $(prize_stage).parents('td').parents('tr').find('.basicRewardShow').html(htmls);
            break;
        case 'crazyBuild_final':
            $(prize_stage).parents('td').find('.finalPrizeInput').val(str)
            $(prize_stage).parents('td').parents('tr').find('.finalRewardShow').html(htmls);
            break;
    }

    if (this_index > 0) {
        if (prize_type == 1) {
            $('input[name="rewardnew[' + this_index + '][' + prize_stage + '][prize]"]').val(str);
            $(".showStagePrize_" + this_index + '_' + prize_stage).html(htmls);
        } else if (prize_type == 2) {
            $('input[name="rank[' + this_index + '][' + prize_stage + '][prize]"]').val(str);
            $(".showRankStagePrize_" + this_index + '_' + prize_stage).html(htmls);
        } else if (prize_type == 15) {
            $('input[name="reward' + this_index + '[' + prize_stage + '][prize]"]').val(str);
            $(".showStagePrize_" + this_index + '_' + prize_stage).html(htmls);
        } else if (prize_type == 7) {
            console.log($(".chooseOnePrize_" + prize_stage))
            $('input[name="reward[' + this_index + '][' + prize_stage + '][prize]"]').val(str);
            $(".chooseOnePrize_" + prize_stage).html(htmls);
            $('input[name="reward[' + this_index + '][' + prize_stage + '][prize]"]').prev('.prizesSpan').html(htmls)
        }
    } else {
        if (prize_type == 1) {
            $('input[name="reward[' + prize_stage + '][prize]"]').val(str);
            $(".showStagePrize_" + prize_stage).html(htmls);
        } else if (prize_type == 2) {
            // $('input[name="rank['+prize_stage+'][prize]"]').val(str);
            // $(".showRankStagePrize_"+prize_stage).html(htmls);
        } else if (prize_type == 3) {
            $('input[name="treasure[' + prize_stage + '][prize]"]').val(str);
            $(".showTreasurePrize_" + prize_stage).html(htmls);
        } else if (prize_type == 4) {
            $('input[name="trafficPermit[' + prize_stage + '][prize]"]').val(str);
            $(".showTrafficPermitPrize_" + prize_stage).html(htmls);
        } else if (prize_type == 5) {
            $('input[name="trafficPermit[' + prize_stage + '][specialPrize]"]').val(str);
            $(".showTrafficPermitSpecial_" + prize_stage).html(htmls);
        } else if (prize_type == 6) {
            $('input[name="safeLimit[' + prize_stage + '][prize]"]').val(str);
            $(".showSafeLimitPrize_" + prize_stage).html(htmls);
        } else if (prize_type == 7) {
            $('input[name="reward[' + this_index + '][' + prize_stage + '][prize]"]').val(str);
            $('input[name="reward[' + this_index + '][' + prize_stage + '][prize]"]').prev('.prizesSpan').html(htmls)
            // $(".chooseOnePrize_"+prize_stage).html(htmls);
        } else if (prize_type == 8) {
            $('input[name="fund[' + prize_stage + '][prize]"]').val(str);
            $(".fundPrize_" + prize_stage).html(htmls);
        }
    }


    closePrize();
    // console.log(JSON.stringify(data));
    // console.log(getElements("prize_from"));
}

function closePrize() {
    $('#myModal5').removeClass('in');
    $('#myModal5').hide();
}

function setPrize(stage, t, index = 0, shushuIdx = 1) {
    this_index = index;
    this_shushuIdx = shushuIdx;
    console.log(stage, t, index);
    prize_type = t;
    prize_stage = stage;
    var prize = [];
    prize_num = 0;
    if (index > 0 && (act_type == 'collect' || act_type == 'collect_only' || act_type == 'super_collect')) {
        var ht = '<th>奖励类型</th><th>是否固定</th><th>奖励值</th><th>是否是限时奖励</th><th>限时长（分钟）</th><th>皮肤</th>';
        $('#tds').attr('colspan', 6);
    }
        // else if(act_type=='super_balloon'){
        //     var ht ='<th>奖励类型</th><th>是否固定</th><th>奖励值</th><th>权重值</th>';
        //     $('#tds').attr('colspan',4);
    // }
    else {
        var ht = '<th>奖励类型</th><th>是否固定</th><th>奖励值</th><th>皮肤</th>';
        $('#tds').attr('colspan', 4);
    }
    $('.ths').html(ht);
    $('#myModal5').addClass('in');
    $('#myModal5').show();
    $('#prize_body').children("tr").remove();//清空行

    let str = "";
    if (index > 0) {
        if (t == 1) {
            str = $('input[name="rewardnew[' + index + '][' + prize_stage + '][prize]"]').val();
        } else if (t == 2) {
            str = $('input[name="rank[' + index + '][' + prize_stage + '][prize]"]').val();
        } else if (t == 15) {
            str = $('input[name="reward' + index + '[' + prize_stage + '][prize]"]').val();
        } else if (t == 7) {
            str = $('input[name="reward[' + index + '][' + prize_stage + '][prize]"]').val();
        } else if (t == 'treasure') {
            str = $('input[name="treasure[' + stage + '][' + index + '][prize]"]').val();
        } else if (t == 'timelimitInvite') {
            str = $('input[name="timelimitInvite[' + stage + '][' + index + '][prize]"]').val();
        } else if (t == 'mayaWheel') {
            str = $('input[name="mayaWheelReward[' + index + '][prize]"]').val();
        } else if (t == 'chooseYouWant') {
            str = $('input[name="chooseYouWantRewardConfig[' + stage + '][' + index + '][prize]"]').val();
        } else if (t == 'rank') {
            str = $('input[name="rewardnew[' + index + '][' + this_shushuIdx + '][' + prize_stage + '][prize]"]').val();
        } else if (['spinsMaster', 'superCollect', 'jigsaw', 'driftTreasure', 'superGashapon', 'superSerialProgress'].includes(t)) {
            str = $(stage).parents('tr').find('.prizeInput').val();
        } else if (t == 'easterEgg') {
            str = $(stage).parents('.easterRewardTr').find('.prizeInput').val();
        } else if (t == 'superSerial') {
            str = $(stage).parents('.serialRewardInfoTr').find('.prizeInput').val();
        } else if (t == 'setCommonPrize') {
            str = $(stage).parents('.commonStageRewardTr').find('.prizeInput').val();
        } else if (t === 'luckyFox') {
            str = $(stage).parents('td').find('.prizeInput').val();
        } else if (t === 'crazyBuild_basic') {
            str = $(stage).parents('td').find('.basicPrizeInput').val();
        } else if (t === 'crazyBuild_final') {
            str = $(stage).parents('td').find('.finalPrizeInput').val();
        } else if (t === 'setCommonPrize2') {
            setCommonPrizeClass = shushuIdx
            str = $(stage).parents('.commonStageRewardTr').find(`.${setCommonPrizeClass}Input`).val();
        }
    } else {
        if (t == 1) {
            str = $('input[name="reward[' + prize_stage + '][prize]"]').val();
        } else if (t == 2) {
            // var str = $('input[name="rank['+prize_stage+'][prize]"]').val();
        } else if (t == 3) {
            str = $('input[name="treasure[' + prize_stage + '][prize]"]').val();
        } else if (t == 4) {
            str = $('input[name="trafficPermit[' + prize_stage + '][prize]"]').val();
        } else if (t == 5) {
            str = $('input[name="trafficPermit[' + prize_stage + '][specialPrize]"]').val();
        } else if (t == 6) {
            str = $('input[name="safeLimit[' + prize_stage + '][prize]"]').val();
        } else if (t == 7) {
            str = $('input[name="reward[' + index + '][' + prize_stage + '][prize]"]').val();
        } else if (t == 8) {
            str = $('input[name="fund[' + prize_stage + '][prize]"]').val();
        } else if (t == 15) {
            str = $('input[name="reward' + index + '[' + prize_stage + '][prize]"]').val();
        }
    }
    str = unescape(str);
    console.log(str);
    if (str.length > 0 && str != "undefined") {
        prize = JSON.parse(str);
        // console.log(prize);
    }
    if (prize.length > 0) {
        for (var i = 0; i < prize.length; i++) {
            prize_num++;
            d = {"stage": stage, "prize": prize[i]};
            // console.log(prize[i]);
            var html = prizeInfoTR(d, index);
            $("#prize_body").append(html);
        }
    }
    $('.select2').select2({})
}

function addPrize() {
    stage = prize_type == 1 ? reward_limit : rank_limit;
    prize_num++;
    if ((act_type == 'collect' || act_type == 'collect_only' || act_type == 'super_collect') && this_index > 0) {
        var data = {"stage": stage, "prize": {"type": 0, "num": 1, "rtype": 1, "ts": 0, "ts_type": 0, "ts_rtype": 1, "ts_num": 0}};
    }
        // else if(act_type=='super_balloon'){
        //     var data ={"stage":stage,"prize":{"id":prize_num,"type":0,"num":0,"rtype":1,"weight":1}};
    // }
    else {
        var data = {"stage": stage, "prize": {"type": 0, "num": 1, "rtype": 1}};
    }
    console.log(stage);
    var html = prizeInfoTR(data, this_index);
    $("#prize_body").append(html);
    $('.select2').select2({})
}

function delPrize() {
    if (prize_num > 0) {
        // console.log(prize_num);
        $("#prize_body").children("tr:last-child").remove();
        prize_num--;
    }
}

var userGroups = {
    "2": "RFM分组",
    "5": "数数分组"
}

//添加奖励html
function addGroupSelect(groupRid = 0) {
    var html = '';
    html += '<div aria-hidden="true">';
    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-sm-1 control-label">分组类型*: </label><div class="col-sm-4"><select id="selectConfigGroup" class="form-control m-b" name="extra_reward[groupRid]">';
    $.each(userGroups, function (k, v) {
        var sel = groupRid == k ? 'selected' : '';
        html += '<option  value="' + k + '"' + sel + '>' + v + '</option>'
    });
    html += '</select></div>';
    html += '</div>';
    html += '</div>';
    if (act_type == 'one_plus_gift') {
        var maxNum = 1;
        if (reward_conf != undefined && Object.prototype.toString.call(reward_conf) === '[object Object]') {
            maxNum = ('maxNum' in reward_conf) ? reward_conf.maxNum : 1;
        }
        html += '<div class="form-group">';
        html += '<label class="col-xs-1 control-label">最大购买次数:</label><div class="col-sm-1"><input type="text"  name="maxNum" value="' + maxNum + '" class="form-control"></div>';
        html += '</div>';
    }
    html += '<hr style=" height:2px;border:none;border-top:2px dotted #0b0;">';
    $("#reward_info").prepend(html);
}

//获取指定form中的所有的<input>对象
function getElements(formId) {
    var form = document.getElementById(formId);
    var elements = new Array();
    var tagElements = form.getElementsByTagName('input');
    var tagElements2 = form.getElementsByTagName('select');
    for (var j = 0; j < tagElements.length; j++) {
        elements.push(tagElements[j]);
    }
    for (var i = 0; i < tagElements2.length; i++) {
        elements.push(tagElements2[i]);
    }
    return elements;
}

//获取单个input中的【name,value】数组
function inputSelector(element) {
    if (element.checked)
        return [element.name, element.value];
}

function input(element) {
    switch (element.type.toLowerCase()) {
        case 'submit':
        case 'hidden':
        case 'password':
        case 'text':
            return [element.name, element.value];
        case 'checkbox':
        case 'select-one':
            return [element.name, element.value];
        case 'radio':
            return inputSelector(element);
    }
    return false;
}

//组合URL
function serializeElement(element) {
    var parameter = input(element);

    if (parameter) {
        var key = encodeURIComponent(parameter[0]);
        if (key.length == 0) return;

        if (parameter[1].constructor != Array)
            parameter[1] = [parameter[1]];

        var values = parameter[1];
        var results = '';
        for (var i = 0; i < values.length; i++) {
            results += '"' + parameter[0] + '":"' + encodeURIComponent(values[i]) + '",';
            // results[parameter[0]] = encodeURIComponent(values[i]);
        }
        return results;

    }
}

//调用方法
function serializeForm(formId) {
    var elements = getElements(formId);
    // var queryComponents = new Array();
    var queryComponents = '';
    for (var i = 0; i < elements.length; i++) {
        var queryComponent = serializeElement(elements[i]);
        if (queryComponent)
            queryComponents += queryComponent;
        // queryComponents.push(queryComponent);
    }
    queryComponents = queryComponents.slice(0, queryComponents.length - 1);
    queryComponents = '{' + queryComponents + '}';
    return queryComponents;
}

//判别版本
function toNum(a) {
    var a = a.toString();
    //也可以这样写 var c=a.split(/\./);
    var c = a.split('.');
    var num_place = ["", "0", "00", "000", "0000"], r = num_place.reverse();
    for (var i = 0; i < c.length; i++) {
        var len = c[i].length;
        c[i] = r[len] + c[i];
    }
    var res = c.join('');
    return res;
}

//收集活动 数数分组 体力修正系数 添加
function addssGroupBox(obj, index, stage) {
    var html = '';
    var num = $(obj).parents('td').find("select").size();
    var arr = JSON.parse($hideSSGroup);
    html += '<div class="row">';
    html += '<label class="col-sm-1 control-label m-b">数数分组</label><div class="col-sm-6">';
    html += '<select class="form-control" name="rewardnew[' + index + '][' + stage + '][stagePro][' + num + '][groupId]">';
    for (let i in arr) {
        html += '<option value="' + i + '">' + arr[i] + '</option>';
    }
    html += '</select></div>';
    html += '<label class="col-sm-1 control-label m-b">预设消耗体力</label><div class="col-sm-3">';
    html += '<input type="text" class="form-control" name="rewardnew[' + index + '][' + stage + '][stagePro][' + num + '][stagePro]" value="1">';
    html += '</div></div>';
    $(obj).parents('td').find(".ssGroupBox").append(html);
}

//收集活动 数数分组 体力修正系数 添加
function delssGroupBox(obj) {
    $(obj).parents('td').find(".row:last").remove();
}

//初始化时间选择框
function initLayDate() {
    lay('.laydate-item').each(function () {
        laydate.render({
            elem: this,
            trigger: 'click',
            type: 'datetime',
            range: '~',
            fontmat: 'yyyy-MM-dd HH:mm ~ yyyy-MM-dd HH:mm'
        });
    });
}

//时间加 hours 小时。不填默认24
function addOneDays(dateStr, hours) {
    hours = (hours == undefined) ? 24 : parseInt(hours)
    hours = isNaN(hours) ? 24 : parseInt(hours)
    let t = new Date(dateStr).getTime() + hours * 60 * 60 * 1000;   //24小时 * 60分钟 * 60秒 * 1000
    let d = new Date(t);
    let theMonth = d.getMonth() + 1;
    let theDate = d.getDate();
    let theHours = d.getHours();
    let theMinutes = d.getMinutes();
    if (theMonth < 10) {
        theMonth = '0' + theMonth
    }
    if (theDate < 10) {
        theDate = '0' + theDate
    }
    if (theHours < 10) {
        theHours = '0' + theHours
    }
    if (theMinutes < 10) {
        theMinutes = '0' + theMinutes
    }
    let date = d.getFullYear() + '-' + theMonth + '-' + theDate
    let time = theHours + ':' + theMinutes
    let Spare = date + ' ' + time + ":00"
    return Spare;
}

//按钮事件
$(document).on("dblclick", ".laydate-item", function () {
    $(this).parent(".ttss").remove();
    // $(this).remove();
});

function slotWeightGroupsSelector(name, id) {
    id = parseInt(id)
    name = name ? name : 'extraData[slotWeightGroup]'
    var selected = '';
    var selecterHtml = `<select name="${name}" class="form-control">`
    slotGroups && $.each(slotGroups, function (i, o) {
        var oid = parseInt(o.id)
        console.log(oid);
        selected = (oid == id) ? 'selected' : '';
        selecterHtml += `<option value="${o.id}"  ${selected}>${o.name}</option>`
    })
    selecterHtml += `</select>`
    var html = `
        <div class="form-group" id="slotWeightGroupSelector">
            <div class="form-group">
                <label class="col-sm-2 control-label">老虎机概率组:</label>
                <div class="col-sm-4">
                    ${selecterHtml}
                </div>
            </div>
        </div>
        <hr style=" height:2px;border:none;border-top:2px dotted #0b0;">`
    return html;
}


function priceSelectorHtml(name = '', price = 0) {
    var html = `<select class="form-control  priceSelector" name="${name}" onchange="priceChanged(this)" >`;
    var sel = '';
    $.each(goodSku, function (k, v) {
        if (price == v["price"]) {
            sel = "selected";
        } else {
            sel = "";
        }
        html += `<option value="${v["price"]}" ${sel}>${v["price"]}</option>`;
    });
    html += '</select>';
    return html;
}

function getShushuSelectorOptions() {
    let html = ''
    $.each(shushuGroups, function (i, o) {
        html += '<option value="' + i + '">' + o + '</option>'
    });
    return html
}

function noTokenAlert(stageKey, gType) {
    console.log(act_type + ' 需要配置代币不足弹窗');

    let i = 0
    let gid = 0
    let tokenGoodsHtml = ''
    let priceSelector = ''
    while (i < 3) {
        priceSelector = priceSelectorHtml(`tokenGoods[${stageKey}][goods][${i}][price]`)
        gid = gType * 10000 + i
        tokenGoodsHtml += `
            <tr>
                <td >
                    <input type="text" style="text-align: center" class="form-control" name="tokenGoods[${stageKey}][goods][${i}][id]" value="${i + 1}">
                    <input type="hidden" style="text-align: center" class="form-control" name="tokenGoods[${stageKey}][goods][${i}][gid]" value="${gid}">
                </td>
                <td  class="priceSkuGroup">
                    ${priceSelector}
                    <input type="hidden" style="text-align: center" class="form-control skuInput" name="tokenGoods[${stageKey}][goods][${i}][sku]" value="">
                    <input type="hidden" style="text-align: center" class="form-control" name="tokenGoods[${stageKey}][goods][${i}][gtype]" value="${gType}">
                </td>
                <td  class="">
                    <input type="text" style="text-align: center" class="form-control" name="tokenGoods[${stageKey}][goods][${i}][discount]" value="0">
                </td>
                <td  class="">
                    <input type="text" style="text-align: center" class="form-control" name="tokenGoods[${stageKey}][goods][${i}][tokenNum]" value="0">
                </td>
            </tr>
`
        i++
    }

    return `
            <table class="table table-bordered" > 
                <thead>
                    <tr>
                        <td colspan="4"> 
                            <div class="form-group">
                                <label class="col-sm-6 control-label m-b">代币不足弹窗限购次数: </label>
                                <div class="col-sm-3 input-group">
                                    <input type="text" style="text-align: center" class="form-control" name="tokenGoods[${stageKey}][exceed]" value="0">
                                </div>
                            </div> 
                        </td>
                    </tr> 
                    <tr>
                        <th width="120">付费项</th> 
                        <th>价格</th> 
                        <th>折扣</th> 
                        <th>奖励</th> 
                    </tr>
                </thead> 
                <tbody id="tokenGoods_${stageKey}"> 
                    ${tokenGoodsHtml}
                </tbody>
            </table>
`;

}

function renderNotokenAlert(stageKey, data) {
    if (!data || !data[stageKey]) return;
    $(`input[name="tokenGoods[${stageKey}][exceed]"]`).val(data[stageKey].exceed);

    data[stageKey].goods && $.each(data[stageKey].goods, function (i, o) {
        console.log($(`select[name="tokenGoods[${stageKey}][goods][${i}][price]"]`));
        $(`select[name="tokenGoods[${stageKey}][goods][${i}][price]"]`).val(o.price);
        $(`input[name="tokenGoods[${stageKey}][goods][${i}][discount]"]`).val(o.discount);
        $(`input[name="tokenGoods[${stageKey}][goods][${i}][sku]"]`).val(o.sku);
        $(`input[name="tokenGoods[${stageKey}][goods][${i}][tokenNum]"]`).val(o.tokenNum);
    })
}