<?php defined('InShopNC') or exit('Access Invalid!');?>

<div class="page">
    <!-- 页面导航 -->
    <div class="fixed-bar">
        <div class="item-title">
            <h3>红包管理</h3>
            <ul class="tab-base">
                <?php   foreach($output['menu'] as $menu) {  if($menu['menu_key'] == $output['menu_key']) { ?>
                    <li><a href="JavaScript:void(0);" class="current"><span><?php echo $menu['menu_name'];?></span></a></li>
                <?php }  else { ?>
                    <li><a href="<?php echo $menu['menu_url'];?>" ><span><?php echo $menu['menu_name'];?></span></a></li>
                <?php  } }  ?>
            </ul>
            </ul>
        </div>
    </div>

    <div class="fixed-empty"></div>
    <form id="type_form" method="post" enctype="multipart/form-data" action="index.php?act=bonus&op=bonus_type_save">
        <input type="hidden" name="type_id" value="<?php echo $output['id'];?>"/>
        <table class="table tb-type2">
            <tbody>

            <tr class="noborder">
                <td class="required" colspan="2"><label class="validation" for="sender">红包名称</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="sender" name="sender" class="txt" value="<?php echo  isset($output['data'])? $output['data']['sender'] : '';?>"></td>
                <td class="vatop tips"></td>
            </tr>

            <tr class="noborder">
                <td class="required" colspan="2"><label class="validation" for="hb_words">祝福语</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="hb_words" name="hb_words" class="txt" value="<?php echo  isset($output['data'])? $output['data']['hb_words'] : '';?>"></td>
                <td class="vatop tips"></td>
            </tr>

            <tr class="noborder">
                <td class="required" colspan="2"><label class="validation" for="h5_link">H5链接</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="h5_link" name="h5_link" class="txt" value="<?php echo  isset($output['data'])? $output['data']['h5_link'] : '';?>"></td>
                <td class="vatop tips"></td>
            </tr>

            <tr class="noborder">
                <td class="required" colspan="2"><label class="validation" for="link_param">链接参数</label></td>
            </tr>


            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="link_param" name="link_param" class="txt" value="<?php echo  isset($output['data'])? $output['data']['link_param'] : '';?>"></td>
                <td class="vatop tips"></td>
            </tr>

            <tr class="noborder">
                <td class="required" colspan="2"><label>上传CSV文件</label></td>
            </tr>

            <tr class="noborder">
                <td class="vatop rowform">
                    <span class="type-file-box">
                        <input type="file" class="type-file-file" id="bonus_file" name="bonus_file" size="30" hidefocus="true" nc_type="upload_bonus_file" title="选择文件">
                    </span>
                </td>
                <td class="vatop tips"></td>
            </tr>


            <tr class="noborder">
                <td class="required" colspan="2"><label class="validation" for="send_start_date">开始发放时间</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="send_start_date" name="send_start_date"  class="txt date" readonly="readonly" value="<?php echo  isset($output['data'])? date('Y-m-d', $output['data']['send_start_date']) : '';?>"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required" colspan="2"><label class="validation" for="send_end_date">结束发放时间</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="send_end_date" name="send_end_date"  class="txt date" readonly="readonly" value="<?php echo  isset($output['data'])? date('Y-m-d', $output['data']['send_end_date']) : '';?>"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required" colspan="2"><label class="validation" for="use_start_date">开始使用时间</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="use_start_date" name="use_start_date"  class="txt date" readonly="readonly" value="<?php echo  isset($output['data'])? date('Y-m-d', $output['data']['use_start_date']) : '';?>"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required" colspan="2"><label class="validation" for="use_end_date">结束使用时间</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="use_end_date" name="use_end_date"  class="txt date" readonly="readonly" value="<?php echo  isset($output['data'])? date('Y-m-d', $output['data']['use_end_date']) : '';?>"></td>
                <td class="vatop tips"></td>
            </tr>
            </tbody>
            <tfoot>
            <tr class="tfoot">
                <td colspan="15"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
            </tr>
            </tfoot>
        </table>
    </form>
</div>
<link type="text/css" rel="stylesheet" href="<?php echo RESOURCE_SITE_URL."/js/jquery-ui/themes/ui-lightness/jquery.ui.css";?>"/>
<script src="<?php echo RESOURCE_SITE_URL."/js/jquery-ui/jquery.ui.js";?>"></script>
<script src="<?php echo RESOURCE_SITE_URL."/js/jquery-ui/i18n/zh-CN.js";?>" charset="utf-8"></script>
<script>
    //按钮先执行验证再提交表单
    $(function(){$("#submitBtn").click(function(){
        if($("#type_form").valid()){
            $("#type_form").submit();
        }
    });
    });
    $(document).ready(function(){
        $("#send_start_date").datepicker();
        $("#send_end_date").datepicker();
        $("#use_start_date").datepicker();
        $("#use_end_date").datepicker();
        $("#pass_name").datepicker();
        $("#h5").datepicker();
        $("#h5_url").datepicker();

        $("#type_form").validate({
            errorPlacement: function(error, element){
                error.appendTo(element.parent().parent().prev().find('td:first'));
            },
            rules : {
                sender: {
                    required : true
                },
                hb_words: {
                    required : true
                },
                h5_link: {
                    required : true
                },
                link_param: {
                    required : true
                },
                type_name: {
                    required : true
                },
                send_start_date: {
                    required : true,
                    date      : false
                },
                send_end_date: {
                    required : true,
                    date      : false
                },
                use_start_date: {
                    required : true,
                    date      : false
                },
                use_end_date: {
                    required : true,
                    date      : false
                },
                _name: {
                    required : true,
                    date      : false
                },
                h5: {
                    required : true,
                    date      : false
                },
                h5_url: {
                    required : true,
                    date      : false
                }
            },
            messages : {
                sender: {
                    required : '发送者名称不能为空'
                },
                hb_words: {
                    required : '祝福语不能为空'
                },
                h5_link: {
                    required : 'H5链接不能为空'
                },
                link_param: {
                    required : '链接参数不能为空'
                },
                type_name: {
                    required : '红包名称不能为空'
                },
                send_start_date: {
                    required : '开始发放时间不能为空'
                },
                send_end_date: {
                    required : '结束发放时间不能为空>'
                },
                use_start_date: {
                    required : '开始使用时间不能为空'
                },
                use_end_date: {
                    required : '结束使用时间不能为空'
                },
                pass_name: {
                    required : '发送者不能为空'
                },
                h5: {
                    required : 'h5链接不能为空'
                },
                h5_url: {
                    required : '链接参数不能为空'
                }
            }
        });
    });

    $(function(){
        var textButton="<input type='text' name='textfield' id='textfield1' class='type-file-text' /><input type='button' name='button' id='button1' value='' class='type-file-button' />"
        $(textButton).insertBefore("#bonus_file");
        $("#bonus_file").change(function(){
            $("#textfield1").val($("#bonus_file").val());
        });
    });
</script>