<link rel="stylesheet" href="<?php echo base_url();?>public/js/bootstrap/bootstrap.min.css" >
<!-- Select2 -->
<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/select2/select2.min.css">
<div id="msg-tip">

</div>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-12">
            <aside>
                <header><i class="fa fa-fw fa-file"></i>编辑链接</header>
                <hr/>
                <section>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <form class="form-horizontal J_ajaxForm" role="form" method="post" action="Config/actionEditShareLink" data-callBack="message">
                                    <input type="hidden" readonly class="form-control"  name="id" value="<?php echo $info['id'];?>">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">名称*: </label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control"  name="name" value="<?php echo $info['name'];?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">链接类型*: </label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="action" id="action" onchange="selectChange()">
                                                <option value="1" <?php if($info['action'] == 1){ echo 'selected';} ?>>奖励</option>
                                                <option value="2" <?php if($info['action'] == 2){ echo 'selected';} ?>>兑换码</option>
                                                <option value="3" <?php if($info['action'] == 3){ echo 'selected';} ?>>开启页面</option>
                                                <option value="4" <?php if($info['action'] == 4){ echo 'selected';} ?>>开启活动</option>
                                                <option value="5" <?php if($info['action'] == 5){ echo 'selected';} ?>>邮件验证奖励</option>
                                            </select>
                                        </div>
                                    </div>

                                    <?php if(!empty($info['longUrl'])){?>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">原始链接*: </label>
                                            <div class="col-sm-3">
                                                <input type="text" class="form-control" readonly  name="longUrl" value="<?php echo $info['longUrl'];?>">
                                            </div>
                                        </div>
                                    <?php } ?>

                                    <?php if(!empty($info['shortUrl'])){?>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">短链*: </label>
                                            <div class="col-sm-3">
                                                <input type="text" class="form-control" readonly name="shortUrl" value="<?php echo $info['shortUrl'];?>">
                                            </div>
                                        </div>
                                    <?php } ?>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">有效点击数*: </label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control"  name="num" value="<?php echo $info['num']??1;?>">
                                        </div>
                                        <label class="col-sm-2 control-label">有效期*: </label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control" id="test" placeholder="yyyy-mm-dd hh:ii:ss" name="expireTime" value="<?php echo date("Y-m-d H:i:s",$info['expireTime']??strtotime("00:00:00"));?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">数据*: </label>
                                        <div class="col-sm-8" id="contentID">
                                            <?php if(in_array($info['action'],[1,5]) || empty($info['id'])){?>
                                                <div class="col-sm-9">
                                                    <label class="select-inline">
                                                        <table class="col-sm-12">
                                                            <tr>
                                                                <td class="formPropsRewardsTag" data-value='<?php echo json_encode($info['data']['props'])??"[]";?>' data-name="data[props]"></td>
                                                                <td class="text-right">
                                                                    <button type="button"
                                                                            class="btn btn-outline btn-success"
                                                                            onclick="propsJs.initEdit(this, 'formPropsRewardsTag')">
                                                                        奖励配置
                                                                    </button>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </label>
                                                </div>

                                            <?php } ?>
                                            <?php if($info['action'] == 2){?>
                                                <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                                    <div class="form-group">
                                                        <label class="col-sm-1 control-label">兑换码*: </label>
                                                        <div class="col-sm-4">
                                                            <input type="text" class="form-control"  name="data[content]" value="<?php echo $info['data']['content'];?>">
                                                        </div>
                                                    </div>
                                                </div>
                                            <?php } ?>
                                            <?php if($info['action'] == 3){?>
                                                <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                                    <div class="form-group"><label class="col-sm-1 control-label">页面*: </label>
                                                        <div class="col-sm-4">
                                                            <select class="form-control typeControl" name="data[jumpId]">
                                                                <option value="12" <?php if($info['data']['jumpId'] == 12) echo 'selected'; ?>>个人信息</option>
                                                                <option value="16" <?php if($info['data']['jumpId'] == 16) echo 'selected'; ?>>邀请好友</option>
                                                                <option value="14" <?php if($info['data']['jumpId'] == 14) echo 'selected'; ?>>礼物</option>
                                                                <option value="18" <?php if($info['data']['jumpId'] == 18) echo 'selected'; ?>>地图</option>
                                                                <option value="15" <?php if($info['data']['jumpId'] == 15) echo 'selected'; ?>>排行榜</option>
                                                                <!--                                                                <option value="6" --><?php //if($info['data']['jumpId']  == 6) echo 'selected'; ?><!--每日奖励</option>-->
                                                                <option value="19" <?php if($info['data']['jumpId'] == 19) echo 'selected'; ?>>设置</option>
                                                                <option value="23" <?php if($info['data']['jumpId'] == 23) echo 'selected'; ?>>帮助反馈</option>
                                                                <option value="22" <?php if($info['data']['jumpId'] == 22) echo 'selected'; ?>>兑换码</option>
                                                                <option value="21" <?php if($info['data']['jumpId'] == 21) echo 'selected'; ?>>评分</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                            <?php } ?>
                                            <?php if($info['action'] == 4){?>
                                                <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                                    <div class="form-group"><label class="col-sm-1 control-label">活动*: </label>
                                                        <div class="col-sm-4">
                                                            <select class="form-control typeControl" name="data[activityId]">
                                                                <option value="1" <?php if($info['data']['activityId'] == 1) echo 'selected'; ?>>建筑大师</option>
                                                                <option value="2" <?php if($info['data']['activityId'] == 2) echo 'selected'; ?>>加倍活动</option>
                                                            </select>
                                                        </div>
                                                        <label class="col-sm-1 control-label">活动时长(分)*: </label>
                                                        <div class="col-sm-4">
                                                            <input type="text" class="form-control"  name="data[time]" value="<?php echo $info['data']['time']??30;?>">
                                                        </div>
                                                    </div>
                                                </div>
                                            <?php } ?>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">用户限定*: </label>
                                        <div class="col-sm-8">
                                            <textarea id="textareaId" rows="8" onchange="checkExport()" class="form-control" placeholder="使用逗号 , 分割" name='userLimit'><?php echo $info['userLimit']??'';?></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-3">
                                            <?php if(!empty($info['id'])){?>
                                                <span style="display: block">仅有效时间与限定用户更新有效</span>
                                            <?php } ?>
                                            <button type="button" class="btn btn-info goback">返回</button>
                                            <button type="button" class="btn btn-primary J_ajaxSubmitBtn">提交</button>

                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </section>
            </aside>
        </div>
    </div>
</div>


<!--<script src="--><?php //echo base_url();?><!--public/h5/js/jquery.min.js"></script>-->
<!--<script src="--><?php //echo base_url();?><!--public/h5/js/bootstrap.min.js"></script>-->
<script src="<?php echo base_url(); ?>public/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?php echo base_url(); ?>public/plugins/datatables/extensions/Responsive/js/dataTables.responsive.min.js"></script>
<!--<script src="--><?php //echo base_url();?><!--public/js/common.js"></script>-->
<script>
    $(function () {
        //var idData = JSON.parse('<?php //echo json_encode($idData); ?>//');
        propsJs.initTag('formPropsRewardsTag')
        // $('#contentID').on("click", '.deleteParent', function () {
        //     $(this).parent().remove();
        // });
        //
        // $('#contentID').on("click",'.addParent', function () {
        //     var str = "";
        //     str += '<div class="form-group"><label class="col-sm-1 control-label">道具*: </label><div class="col-sm-4"><select class="form-control" name="data[props][propsId][]"">';
        //     for (var x in idData) {
        //         str += '<option value="' + x + '">' + idData[x]['msg'] + '</option>';
        //     }
        //     str += '</select></div><label class="col-sm-1 control-label">数量*: </label><div class="col-sm-4"><input type="text" class="form-control"  name="data[props][num][]" value="1">' +
        //         '</div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
        //     $(this).before(str);
        // });

    });

    function selectChange(){
        var action = $('#action').val();
        var str = "";
        if(action == 1||action == 5){
            // str = '<div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">'+
            //       '<div class="form-group"><label class="col-sm-1 control-label">金币*: </label><div class="col-sm-4"><select class="form-control typeControl" name="data[coins][coins]">'+
            //       '<option value="coins01">coins01</option><option value="coins02">coins02</option><option value="coins03">coins03</option><option value="coins04">coins04</option><option value="coins05">coins05</option><option value="coins06">coins06</option>'+
            //       '</select></div><label class="col-sm-1 control-label">倍率*: </label><div class="col-sm-4"><input type="text" class="form-control"  name="data[coins][bet]" value="1"></div></div><div class="form-group"><label class="col-sm-1 control-label">体力*: </label>' +
            //       '<div class="col-sm-4"><input type="text" class="form-control"  name="data[spins]" value="1"></div></div><button type="button" class="btn btn-success addParent" style="margin-left: 12px;margin-bottom: 10px;">增加</button></div>'
        }else if(action == 2){
            str = '<div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;"><div class="form-group"><label class="col-sm-1 control-label">兑换码*: </label>'
                + '<div class="col-sm-4"><input type="text" class="form-control"  name="data[content]" value=""></div></div></div>'
        }else if(action == 3){
            str = '<div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">' +
                '<div class="form-group"><label class="col-sm-1 control-label">页面*: </label>' +
                '<div class="col-sm-4"><select class="form-control typeControl" name="data[jumpId]">' +
                '<option value="12">个人信息</option>' +
                '<option value="16">邀请好友</option>' +
                '<option value="14">礼物</option>' +
                '<option value="18">地图</option>' +
                '<option value="15">排行榜</option>' +
                // '<option value="6">每日奖励</option>' +
                '<option value="19">设置</option>' +
                '<option value="23">帮助反馈</option>' +
                '<option value="22">兑换码</option>' +
                '<option value="21">评分</option>' +
                '</select></div></div></div>'
        }else if(action == 4){
            str = '<div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">' +
                '<div class="form-group"><label class="col-sm-1 control-label">活动*: </label>' +
                '<div class="col-sm-4"><select class="form-control typeControl" name="data[activityId]">' +
                '<option value="1">建筑大师</option>' +
                '<option value="2">加倍活动</option>' +
                '</select></div><label class="col-sm-1 control-label">活动时长(分)*: </label>'+
                '<div class="col-sm-4"><input type="text" class="form-control"  name="data[time]" value="30"></div></div></div>';
        }
        $('#contentID').html(str);
    }



    $('.goback').click(function(){
        history.go(-1);
    });

    function message(returnData, $from) {
        if(returnData.state!= 'success'){
            alert(returnData.msg);
        }else{
            // console.log(returnData)
            window.location.href = "/#config/shareLink";
        }
    }

    laydate.render({
        elem: '#test'
        ,type: 'datetime'
        , range: false
        ,done:function(value, date, endDate){
            console.log(date);
            console.log(endDate);
        }
    });

    function checkExport() {
        var textarea = $('#textareaId').val();
        $('#textareaId').val(textarea.replace(/，/g,","));
    }
</script>
