{include file="public/seller_top" /}
<div class="seller_main w1200">
    {include file="public/seller_left" /}
    <div class="seller_right">
        <div class="seller_items">
            {include file="public/seller_items" /}
        </div>

        <div class="dssc-form-default">
            {empty name="xianshi_info"}
            <form id="add_form" action="{:url('Sellerpromotionxianshi/xianshi_save')}" method="post">
                {else /}
                <form id="add_form" action="{:url('Sellerpromotionxianshi/xianshi_edit_save')}" method="post">
                    <input type="hidden" name="xianshi_id" value="{$xianshi_info.xianshi_id}">
                    {/empty}
                    <dl>
                        <dt><i class="required">*</i>{$Think.lang.xianshi_name}{$Think.lang.ds_colon}
                        </dt>
                        <dd>
                            <input id="xianshi_name" name="xianshi_name" type="text" maxlength="25" class="text w400"
                                   value="{present name='xianshi_info'}{$xianshi_info.xianshi_name}{/present}"/>
                            <span></span>
                            <p class="hint">{$Think.lang.xianshi_name_explain}</p>
                        </dd>
                    </dl>
                    <dl>
                        <dt>活动标题{$Think.lang.ds_colon}</dt>
                        <dd>
                            <input id="xianshi_title" name="xianshi_title" type="text" maxlength="10" class="text w200"
                                   value="{present name='xianshi_info'}{$xianshi_info.xianshi_title}{/present}"/>
                            <span></span>
                            <p class="hint">{$Think.lang.xianshi_title_explain}</p>
                        </dd>
                    </dl>
                    <dl>
                        <dt>活动描述{$Think.lang.ds_colon}</dt>
                        <dd>
                            <input id="xianshi_explain" name="xianshi_explain" type="text" maxlength="30"
                                   class="text w400"
                                   value="{present name='xianshi_info'}{$xianshi_info.xianshi_explain}{/present}"/>
                            <span></span>
                            <p class="hint">{$Think.lang.xianshi_explain_explain}</p>
                        </dd>
                    </dl>
                    {empty name="xianshi_info"}
                    <dl>
                        <dt><i class="required">*</i>{$Think.lang.start_time}{$Think.lang.ds_colon}
                        </dt>
                        <dd>
                            <input id="start_time" name="start_time" type="text" class="text w130"/><em
                                class="add-on"><i class="icon-calendar"></i></em><span></span>
                            <p class="hint">
                                {notpresent name="isOwnShop"}{if $current_xianshi_quota.start_time > 1}
                                {$Think.lang.xianshi_add_start_time_explain}{$current_xianshi_quota.start_time|date="Y-m-d H:i:s",###}
                               {/if}{/notpresent}
                            </p>
                        </dd>
                    </dl>
                    <dl>
                        <dt><i class="required">*</i>{$Think.lang.end_time}{$Think.lang.ds_colon}</dt>
                        <dd>
                            <input id="end_time" name="end_time" type="text" class="text w130"/><em class="add-on"><i
                                class="icon-calendar"></i></em><span></span>
                            <p class="hint">
                                {notpresent name="isOwnShop"}
                                {$Think.lang.xianshi_add_end_time_explain}{$current_xianshi_quota.end_time|date="Y-m-d H:i:s",###}
                                {/notpresent}
                            </p>
                        </dd>
                    </dl>
                    {/empty}
                    <dl>
                        <dt><i class="required">*</i>购买下限{$Think.lang.ds_colon}</dt>
                        <dd>
                            <input id="lower_limit" name="lower_limit" type="text" class="text w130"
                                   value="{empty name='xianshi_info'}1{else}{$xianshi_info.lower_limit}{/empty}"/><span></span>
                            <p class="hint">参加活动的最低购买数量，默认为1</p>
                        </dd>
                    </dl>
                    <div class="bottom">
                        <label class="submit-border">
                            <input id="submit_button" type="submit" class="submit" value="{$Think.lang.ds_submit}">
                        </label>
                    </div>
                </form>
        </div>
    </div>
</div>
<script>
    $(function () {
        {empty name="xianshi_info"}
            $('#start_time').datepicker({
                controlType: 'select'
            });
            $('#end_time').datepicker({
                controlType: 'select'
            });
        {/empty}

        jQuery.validator.methods.greaterThanDate = function (value, element, param) {
            var date1 = new Date(Date.parse(param.replace(/-/g, "/")));
            var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
            return date1 < date2;
        };
        jQuery.validator.methods.lessThanDate = function (value, element, param) {
            var date1 = new Date(Date.parse(param.replace(/-/g, "/")));
            var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
            return date1 > date2;
        };
        jQuery.validator.methods.greaterThanStartDate = function (value, element) {
            var start_date = $("#start_time").val();
            var date1 = new Date(Date.parse(start_date.replace(/-/g, "/")));
            var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
            return date1 < date2;
        };

        //页面输入内容验证
        $("#add_form").validate({
            errorPlacement: function (error, element) {
                var error_td = element.parent('dd').children('span');
                error_td.append(error);
            },
            onfocusout: false,
            submitHandler: function (form) {
                ajaxpost('add_form', '', '', 'onerror');
            },
            rules: {
                xianshi_name: {
                    required: true
                },
                start_time: {
                    required: true,
                    greaterThanDate: "<?php echo date('Y-m-d H:i',@$current_xianshi_quota['start_time']);?>"
                },
                end_time: {
                    required: true,
                <?php if (!$isOwnShop) { ?>
                    lessThanDate : "{present name='current_xianshi_quota.start_time'}{$current_xianshi_quota.end_time|date='Y-m-d H:i',###}{/present}",
        <?php } ?>
                    greaterThanStartDate : true
                },
        lower_limit: {
            required: true,
            digits:true,
             min:1
        }
    },
            messages : {
                xianshi_name : {
                    required : '<i class="icon-exclamation-sign"></i><?php echo lang('xianshi_name_error');?>'
                },
                start_time : {
                    required : '<i class="icon-exclamation-sign"></i>' +
                    '<?php echo sprintf(lang('xianshi_add_start_time_explain'),@date('Y-m-d H:i',$current_xianshi_quota['start_time']));?>',
                        greaterThanDate : '<i class="icon-exclamation-sign"></i>'+
                    '<?php echo sprintf(lang('xianshi_add_start_time_explain'),@date('Y-m-d H:i',$current_xianshi_quota['start_time']));?>'

                },
                end_time : {
                    required : '<i class="icon-exclamation-sign"></i>' +
                    '<?php echo sprintf(lang('xianshi_add_end_time_explain'),@date('Y-m-d H:i',$current_xianshi_quota['end_time']));?>',
                <?php if (!$isOwnShop) { ?>
                        lessThanDate : '<i class="icon-exclamation-sign"></i>' +
                        '<?php echo sprintf(lang('xianshi_add_end_time_explain'),@date('Y-m-d H:i',$current_xianshi_quota['end_time']));?>',
                    <?php } ?>
                    greaterThanStartDate : '<i class="icon-exclamation-sign"></i><?php echo lang('greater_than_start_time');?>'
                },
                lower_limit: {
                        required : '<i class="icon-exclamation-sign"></i>购买下限不能为空',
                        digits: '<i class="icon-exclamation-sign"></i>购买下限必须为数字',
                        min: '<i class="icon-exclamation-sign"></i>购买下限不能小于1'
                }
            }
       });
    });
</script>