<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<div class="content_wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>更新编辑</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-horizontal J_ajaxForm" role="form" method="post" action="systemCompensation/actionEdit">
                                        <input type="hidden" name="id" value="<?php echo $id;?>">
                                        <div class="modal-body">
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">开始时间:</label>
                                                <div class="col-sm-6">
                                                    <input type="text" class="form-control" id="startTime" value="<?php echo date("Y-m-d H:i:s",$list['startTime']) ?>" placeholder="开始时间" name="startTime" />
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">结束时间:</label>
                                                <div class="col-sm-6">
                                                    <input type="text" class="form-control" id="endTime" value="<?php echo date("Y-m-d H:i:s",$list['endTime']) ?>" placeholder="结束时间" name="endTime" />
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">登录时间:</label>
                                                <div class="col-sm-1">
                                                    <input class='mySwitch' type="checkbox" name="loginTimeSwitch" aid="1" <?php echo $list['loginTime'] != 0 ? "checked" : ""; ?> value="<?php echo $list['loginTime'] != 0 ? 1 : 0; ?>">
                                                </div>
                                                <div class="col-sm-5">
                                                    <input type="text" class="form-control" id="loginTime" value="<?php echo date("Y-m-d H:i:s",$list['loginTime'][0]??time()) ?> - <?php echo date("Y-m-d 23:59:59",$list['loginTime'][1]??time()) ?>" placeholder="结束时间" name="loginTime" />
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">补偿等级(等级范围):</label>
                                                <div class="col-sm-1">
                                                    <input class='mySwitch' type="checkbox" name="levelIdSwitch" aid="1" <?php echo $list['levelId'] != 0 ? "checked" : ""; ?> value="<?php echo $list['levelId'] != 0 ? 1 : 0; ?>">
                                                </div>
                                                <div class="col-sm-2">
                                                    <input type="number" class="form-control" value="<?php echo $list['levelId'][0]??0;?>" min="1" name="levelIdMin">
                                                </div>
                                                <div class="col-sm-3">
                                                    <input type="number" class="form-control" value="<?php echo $list['levelId'][1]??0;?>" min="1" name="levelIdMax">
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">充值金额(金额范围):</label>
                                                <div class="col-sm-1">
                                                    <input class='mySwitch' type="checkbox" name="paySwitch" aid="1" <?php echo $list['payNum'] != 0 ? "checked" : ""; ?> value="<?php echo $list['payNum'] != 0 ? 1 : 0; ?>">
                                                </div>
                                                <div class="col-sm-2">
                                                    <input type="number" class="form-control" value="<?php echo $list['payNum'][0]??0;?>" min="1" name="payMin">
                                                </div>
                                                <div class="col-sm-3">
                                                    <input type="number" class="form-control" value="<?php echo $list['payNum'][1]??0;?>" min="1" name="payMax">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">版本(版本范围):</label>
                                                <div class="col-sm-2">
                                                    <select class="form-control m-b" name="versionDevice" style="border-radius: 4px;">
                                                        <option value="0">全部</option>
                                                        <?php foreach ($device as $k => $v) { ?>
                                                            <option <?php echo $list['device'] == $k ? "selected" : ""; ?> value="<?php echo $k?>"><?php echo $v?></option>
                                                        <?php }?>
                                                    </select>
                                                </div>
                                                <div class="col-sm-2">
                                                    <select class="form-control m-b" name="versionMin" style="border-radius: 4px;">
                                                        <option value="0">全部</option>
                                                        <?php foreach ($version as $k => $v) { ?>
                                                            <option <?php echo $list['version'][0] == $v ? "selected" : ""; ?> value="<?php echo $v?>"><?php echo $v?></option>
                                                        <?php }?>
                                                    </select>
                                                </div>
                                                <div class="col-sm-2">
                                                    <select class="form-control m-b" name="versionMax" style="border-radius: 4px;">
                                                        <option value="0">全部</option>
                                                        <?php foreach ($version as $k => $v) { ?>
                                                            <option <?php echo $list['version'][1] == $v ? "selected" : ""; ?> value="<?php echo $v?>"><?php echo $v?></option>
                                                        <?php }?>
                                                    </select>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">地区:</label>
                                                <div class="col-sm-1">
                                                    <input class='mySwitch' type="checkbox" name="countrySwitch" <?php echo !empty($list['country']) ? "checked" : ""; ?> aid="1" value="<?php echo !empty($list['country']) ? 1 : 0; ?>">
                                                </div>
                                                <div class="col-sm-6">
                                                    <?php $i=0; foreach ($country as $k => $v) { ?>
                                                        <label class="checkbox-inline" <?php if($i == 0){ echo 'style="margin-left: 10px"';} $k;?> >
                                                            <input type="checkbox" name="country[]" <?php if(in_array($k,$list['country'])){ echo "checked";} ?>  value="<?php echo $k;?>"><?php echo $v;?>
                                                        </label>
                                                        <?php $i++; }?>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">补偿奖励:</label>
                                                <div class="col-sm-9">
                                                    <label class="col-sm-2 control-label">体力:</label>
                                                    <div class="col-sm-4">
                                                        <input type="number" class="form-control" value="<?php echo $list['reward']['spins'];?>" name="reward[spins]">
                                                    </div>
                                                    <label class="col-sm-2 control-label">金币:</label>
                                                    <div class="col-sm-4">
                                                        <input type="number" class="form-control" value="<?php echo $list['reward']['money'];?>" name="reward[money]">
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="langContent2 form-group">
                                                <label class="col-sm-3 control-label">补偿内容:</label>
                                                <div class="col-sm-9">
                                                    <textarea cols="50" rows="7" class="form-control" placeholder="更新提示语言:th,zh,en,tw &#10;格式：&#10;<th></th>&#10;<zh-CN></zh-CN>&#10; <en-US></en-US>&#10;<zh-TW></zh-TW>&#10;<hi></hi>" name="langContentPri" id="langContentPri"></textarea>
                                                </div>
                                            </div>
                                            <div id="langDiv" >
                                                <?php foreach ($langList as $v) { ?>
                                                    <div class="form-group">
                                                        <label class="col-sm-3 control-label"><?php echo $v;?></label>
                                                        <div class="col-sm-9">
                                                            <textarea  rows="7" cols="50" class="form-control <?php echo $v.'_content';?>" name="content_<?php echo $v;?>"><?php echo $list['content'][strtoupper($v)];?></textarea>
                                                        </div>
                                                    </div>
                                                <?php }?>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">更新备注:</label>
                                                <div class="col-sm-9">
                                                    <textarea class="form-control gucontent remark" rows="5" placeholder="更新备注,必填" name="remark"><?php echo $list['remark'];?></textarea>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default goback" data-dismiss="modal">返回</button>
                                            <button type="button" class="btn btn-primary J_ajaxSubmitBtn">更新</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>
<script type="text/javascript">
    laydate.render({
        elem: '#startTime',
        type: 'datetime'
    });
    laydate.render({
        elem: '#endTime',
        type: 'datetime'
    });
    laydate.render({
        elem: '#loginTime',
        type: 'datetime',
        range: true
    });
    $(".mySwitch").bootstrapSwitch({
        onSwitchChange:function(event, state){
            var aid = $(this).attr('aid');
            state = state ? 1 : 0;
            $(this).val(state)
        }
    });
    $('.goback').click(function(){
        history.go(-1);
    });

    $("input[name='gu_device']").click(function(){
        var device = $(this).val(),
            androidPackage = $('.android-package'),
            iosPackage = $('.ios-package');

        if ( device == 1 ) {
//            $("textarea[name='gu_updateurl']").text("<?php //echo $init_gu_updateurl[1];?>//");
//            $("textarea[name='gu_commonurl']").text("<?php //echo $init_gu_commonurl[1];?>//");
            iosPackage.addClass('hide');
            androidPackage.removeClass('hide');
        }else{
//            $("textarea[name='gu_updateurl']").text("<?php //echo $init_gu_updateurl[2];?>//");
//            $("textarea[name='gu_commonurl']").text("<?php //echo $init_gu_commonurl[2];?>//");
            androidPackage.addClass('hide');
            iosPackage.removeClass('hide');
        }
    });

    //全选/全不选
    $('#android-checkall').change(function () {
        if($(this).is(':checked')) {//已经是全选的状态
            $('.android-check').attr('checked', true);
        }else {
            $('.android-check').attr('checked', false);
        }
    });
    //全选/全不选
    $('#ios-checkall').change(function () {
        if($(this).is(':checked')) {//已经是全选的状态
            $('.ios-check').attr('checked', true);
        }else {
            $('.ios-check').attr('checked', false);
        }
    });

    //添加更新内容
    $('#langContentPri').change(function () {
        var langContent, contentMatch;
        langContent = $('#langContentPri').val();

        //英文更新
        contentMatch = langContent.match(/<en-US>([\s\S]*?)<\/en-US>/);
        showContent(contentMatch, $('#langDiv .en_title'), $('#langDiv  .en_content'));

        //德語更新
        contentMatch = langContent.match(/<de-DE>([\s\S]*?)<\/de-DE>/);
        showContent(contentMatch, $('#langDiv .de_title'), $('#langDiv  .de_content'));

        //西班牙更新
        contentMatch = langContent.match(/<es-ES>([\s\S]*?)<\/es-ES>/);
        showContent(contentMatch, $('#langDiv .es_title'), $('#langDiv  .es_content'));

        //法語更新
        contentMatch = langContent.match(/<fr-FR>([\s\S]*?)<\/fr-FR>/);
        showContent(contentMatch, $('#langDiv .fr_title'), $('#langDiv  .fr_content'));

        //法語更新
        contentMatch = langContent.match(/<pt-PT>([\s\S]*?)<\/pt-PT>/);
        showContent(contentMatch, $('#langDiv .pt_title'), $('#langDiv  .pt_content'));

        //泰文更新
        contentMatch = langContent.match(/<th>([\s\S]*?)<\/th>/);
        showContent(contentMatch, $('#langDiv .th_title'), $('#langDiv  .th_content'));

        //中文更新
        contentMatch = langContent.match(/<zh-CN>([\s\S]*?)<\/zh-CN>/);
        showContent(contentMatch, $('#langDiv .zh_title'), $('#langDiv  .zh_content'));

        //台湾更新
        contentMatch = langContent.match(/<zh-TW>([\s\S]*?)<\/zh-TW>/);
        showContent(contentMatch, $('#langDiv .tw_title'), $('#langDiv  .tw_content'));

        //印地语更新
        contentMatch = langContent.match(/<hi>([\s\S]*?)<\/hi>/);
        showContent(contentMatch, $('#langDiv .hi_title'), $('#langDiv  .hi_content'));

        //俄语更新
        contentMatch = langContent.match(/<ru>([\s\S]*?)<\/ru>/);
        showContent(contentMatch, $('#langDiv .ru_title'), $('#langDiv  .ru_content'));

    });

    /**
     * 更加输入内容截取显示标题和内容
     * @param contentMatch
     * @param titleElement
     * @param contentElement
     */
    function showContent(contentMatch, titleElement, contentElement) {
        var head = '', content = '', contentArr = [];
        if(!isEmpty(contentMatch)) {
            content = contentMatch[1];
            contentArr = content.trim().split(/[\n]/);
            if(contentArr.length > 0) {//如果截取的数组不为空，则取第一个为标题，其他的为内容
                head = contentArr[0];
                contentArr.splice(0, 1);
                content = contentArr.join('\n');
            }
        }
        titleElement.val(head);
        contentElement.val(content);
    }

    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        zIndexOffset:906  //控制z-index
    });

    <?php echo "var list = '".json_encode($langList,32)."'"; ?>

</script>
