{extend name="default/base/base_seller" /}
{block name="seller_main"}
<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.activity_title}{$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|raw}</p>
                </dd>
            </dl>
            <dl>
                <dt>{$Think.lang.activity_description}{$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|raw}</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="iconfont">&#xe8d6;</i></em><span></span>
                    <p class="hint">
                        {notpresent name="isPlatformStore"}{if $current_xianshi_quota.xianshiquota_starttime > 1}
                        {$Think.lang.xianshi_add_start_time_explain}{$current_xianshi_quota.xianshiquota_starttime|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="iconfont">&#xe8d6;</i></em><span></span>
                    <p class="hint">
                        {notpresent name="isPlatformStore"}
                        {$Think.lang.xianshi_add_end_time_explain}{$current_xianshi_quota.xianshiquota_endtime|date="Y-m-d H:i:s"}
                        {/notpresent}
                    </p>
                </dd>
            </dl>
            {/empty}
            <dl>
                <dt><i class="required">*</i>{$Think.lang.buy_lower_limit}{$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.xianshi_lower_limit}{/empty}"/><span></span>
                    <p class="hint">{$Think.lang.minimum_purchase_quantity}</p>
                </dd>
            </dl>
            <div class="bottom">
                <input id="submit_button" type="submit" class="submit" value="{$Think.lang.ds_submit}">
            </div>
        </form>
</div>
<link rel="stylesheet" href="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.css">
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.js"></script>
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/i18n/jquery-ui-timepicker-zh-CN.js"></script>
<script>
    $(function () {
        {empty name = "xianshi_info"}
        $('#start_time').datetimepicker({dateFormat: 'yy-mm-dd'});
        $('#end_time').datetimepicker({dateFormat: 'yy-mm-dd'});
        {/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) {
            ds_ajaxpost('add_form', 'url', "{:url('Sellerpromotionxianshi/index')}",1000);
            },
                    rules: {
                     xianshi_name: {
                    required: true
                    },
                    start_time: {
                        required: true,
                        greaterThanDate: "{:date('Y-m-d H:i',@$current_xianshi_quota['xianshiquota_starttime'])}"
                    },
                    end_time: {
                    required: true,
                    {if !$isPlatformStore}
                            lessThanDate : "{present name='current_xianshi_quota.xianshiquota_starttime'}{$current_xianshi_quota.xianshiquota_endtime|date='Y-m-d H:i'}{/present}",
                    {/if}
                            greaterThanStartDate : true
                    },
                    lower_limit: {
                    required: true,
                            digits:true,
                            min:1
                    }
            },
            messages : {
                    xianshi_name : {
                    required : '<i class="iconfont">&#xe64c;</i>{$Think.lang.xianshi_name_error}'
                    },
                    start_time : {
                    required : '<i class="iconfont">&#xe64c;</i>' +
                            '<?php echo sprintf(lang('xianshi_add_start_time_explain'),@date('Y-m-d H:i',$current_xianshi_quota['xianshiquota_starttime']));?>',
                            greaterThanDate : '<i class="iconfont">&#xe64c;</i>' +
                            '<?php echo sprintf(lang('xianshi_add_start_time_explain'),@date('Y-m-d H:i',$current_xianshi_quota['xianshiquota_starttime']));?>'

                    },
                    end_time : {
                    required : '<i class="iconfont">&#xe64c;</i>' +
                            '<?php echo sprintf(lang('xianshi_add_end_time_explain'),@date('Y-m-d H:i',$current_xianshi_quota['xianshiquota_endtime']));?>',
                            {if !$isPlatformStore}
                            lessThanDate : '<i class="iconfont">&#xe64c;</i>' +
                            '<?php echo sprintf(lang('xianshi_add_end_time_explain'),@date('Y-m-d H:i',$current_xianshi_quota['xianshiquota_endtime']));?>',
                            {/if}
                            greaterThanStartDate : '<i class="iconfont">&#xe64c;</i>{$Think.lang.greater_than_start_time}'
                    },
                    lower_limit: {
                    required : '<i class="iconfont">&#xe64c;</i>{$Think.lang.purchase_limits_cannot_empty}',
                            digits: '<i class="iconfont">&#xe64c;</i>{$Think.lang.minimum_purchase_must_figure}',
                            min: '<i class="iconfont">&#xe64c;</i>{$Think.lang.buy_lower_limit_minimum}'
                    }
            }
    });
    });
</script>

{/block}

