{extend name="default/base/base_seller" /}
{block name="seller_main"}
<div class="dssc-form-default">
    <form id="add_form" method="post">
            <dl>
                <dt><i class="required">*</i>{$Think.lang.bargain_name}{$Think.lang.ds_colon}
                </dt>
                <dd>
                    <input id="bargain_name" name="bargain_name" type="text" maxlength="25" class="text w400" value="{present name='bargain_info'}{$bargain_info.bargain_name}{/present}"/>
                    <span></span>
                    <p class="hint">{$Think.lang.bargain_name_explain}</p>
                </dd>
            </dl>
            {empty name="bargain_info"}
            <dl>
                <dt><i class="required">*</i>{$Think.lang.bargain_begintime}{$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_bargain_quota.bargainquota_starttime > 1}
                        {$Think.lang.bargain_add_start_time_explain}{$current_bargain_quota.bargainquota_starttime|date="Y-m-d H:i:s"}
                        {/if}
                        {/notpresent}
                        <br/><span class="red">{$Think.lang.start_time_group_not_modified}</span>
                    </p>
                </dd>
            </dl>
            <dl>
                <dt><i class="required">*</i>{$Think.lang.bargain_endtime}{$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.bargain_add_end_time_explain}{$current_bargain_quota.bargainquota_endtime|date="Y-m-d H:i:s"}
                        {/notpresent}
                        <br/><span class="red">{$Think.lang.end_time_group_not_modifiable}</span>
                        
                    </p>
                </dd>
            </dl>
            {/empty}
            
            {empty name="bargain_info"}
            <dl>
                <dt><i class="required">*</i>{$Think.lang.bargain_goods}{$Think.lang.ds_colon}</dt>
                <dd>
                    <div dstype="bargain_goods_info" class="selected-group-goods " style="display:none;">
                        <div class="goods-thumb"><img id="bargain_goods_image" src=""/></div>
                        <div class="goods-name">
                            <a dstype="bargain_goods_href" id="bargain_goods_name" href="" target="_blank"></a>
                        </div>
                        <div class="goods-price">{$Think.lang.mall_price}：￥<span dstype="bargain_goods_price"></span></div>
                    </div>
                    <a href="javascript:void(0);" id="btn_show_search_goods" class="dssc-btn dssc-btn-acidblue">{$Think.lang.select_goods}</a>
                    <input id="bargain_goods_id" name="bargain_goods_id" type="hidden" value=""/>
                    <span></span>
                    <div id="div_search_goods" class="div-goods-select mt10" style="display: none;">
                        <table class="search-form">
                            <tr>
                                <th class="w150">
                                    <strong>{$Think.lang.search_store_goods}</strong>
                                </th>
                                <td class="w160">
                                    <input id="search_goods_name" type="text w150" class="text" name="goods_name" value=""/>
                                </td>
                                <td class="w70 tc">
                                    <a href="javascript:void(0);" id="btn_search_goods" class="dssc-btn"/><i class="iconfont">&#xe718;</i>{$Think.lang.ds_search}</a></td>
                                <td class="w10"></td>
                                <td>
                                    <p class="hint">{$Think.lang.group_information1}</p>
                                </td>
                            </tr>
                        </table>
                        <div id="div_goods_search_result" class="search-result" style="width:739px;"></div>
                        <a id="btn_hide_search_goods" class="close" href="javascript:void(0);">X</a>
                    </div>
                    <p class="hint">{$Think.lang.bargain_goods_explain}</p>
                </dd>
            </dl>
            {else/}
            <dl>
                <dt>{$Think.lang.bargain_goods_name}</dt>
                <dd>
                    {$bargain_info.bargain_goods_name}
                </dd>
            </dl>
            {/empty}
            <dl>
                <dt><i class="required">*</i>{$Think.lang.sellerpromotionbargain_floorprice}{$Think.lang.ds_colon}</dt>
                <dd>
                    <input id="bargain_limit_number" name="bargain_floorprice" type="text" class="text w130" value="{$bargain_info.bargain_floorprice|default=''}"/>{$Think.lang.ds_yuan}<span></span>
                    <p class="hint">{$Think.lang.sellerpromotionbargain_floorprice_explain}</p>
                </dd>
            </dl>
            <dl>
                <dt><i class="required">*</i>{$Think.lang.sellerpromotionbargain_limit}{$Think.lang.ds_colon}</dt>
                <dd>
                    <input id="bargain_zhe" name="bargain_limit" type="text" class="text w130" value="{$bargain_info.bargain_limit|default='1'}"/><span></span>
                    <p class="hint">{$Think.lang.sellerpromotionbargain_limit_explain}</p>
                </dd>
            </dl>
            
            <dl>
                <dt><i class="required">*</i>{$Think.lang.sellerpromotionbargain_time}{$Think.lang.ds_colon}</dt>
                <dd>
                    <input id="bargain_limit_hour" name="bargain_time" type="text" class="text w130" value="{$bargain_info.bargain_time|default='2'}"/>{$Think.lang.hour}<span></span>
                    <p class="hint">{$Think.lang.sellerpromotionbargain_time_explain}</p>
                </dd>
            </dl>
            <dl>
                <dt><i class="required">*</i>{$Think.lang.sellerpromotionbargain_total}{$Think.lang.ds_colon}</dt>
                <dd>
                    <input id="bargain_limit_quantity" name="bargain_total" type="text" class="text w130" value="{$bargain_info.bargain_total|default='20'}"/><span></span>
                    <p class="hint">{$Think.lang.sellerpromotionbargain_total_explain}</p>
                </dd>
            </dl>
            <dl>
                <dt><i class="required">*</i>{$Think.lang.sellerpromotionbargain_max}{$Think.lang.ds_colon}</dt>
                <dd>
                    <input id="bargain_limit_quantity" name="bargain_max" type="text" class="text w130" value="{$bargain_info.bargain_max|default='1'}"/>{$Think.lang.ds_yuan}<span></span>
                    <p class="hint">{$Think.lang.sellerpromotionbargain_max_explain}</p>
                </dd>
            </dl>
            <dl>
                <dt>{$Think.lang.sellerpromotionbargain_remark}{$Think.lang.ds_colon}
                </dt>
                <dd>
                    <input id="bargain_name" name="bargain_remark" type="text" maxlength="25" class="text w400" value="{present name='bargain_info'}{$bargain_info.bargain_remark}{/present}"/>
                    <span></span>
                    <p class="hint"></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 () {
        
        $('#btn_show_search_goods').on('click', function() {
            $('#div_search_goods').show();
        });

        $('#btn_hide_search_goods').on('click', function() {
            $('#div_search_goods').hide();
        });
        //搜索商品
        $('#btn_search_goods').on('click', function() {
            var url = "{:url('Sellerpromotionbargain/search_goods')}";
             var  datas  =  $.param({goods_name: $('#search_goods_name').val()});
            $('#div_goods_search_result').load(url,datas);
        });

        $('#div_goods_search_result').on('click', '.pagination li a', function() {
            $('#div_goods_search_result').load($(this).attr('href'));
            return false;
        });

        //选择商品
        $('#div_goods_search_result').on('click', '[dstype="btn_add_bargain_goods"]', function() {
            var goods_id = $(this).attr('data-goods-id');
            $.get("{:url('Sellerpromotionbargain/bargain_goods_info')}", {goods_id: goods_id}, function(data) {
                if(data.result) {
                    $('#bargain_goods_id').val(data.goods_id);
                    $('#bargain_goods_image').attr('src', data.goods_image);
                    $('#bargain_goods_name').text(data.goods_name);
                    $('[dstype="bargain_goods_price"]').text(data.goods_price);
                    $('[dstype="bargain_goods_href"]').attr('href', data.goods_href);
                    $('[dstype="bargain_goods_info"]').show();
                    $('#div_search_goods').hide();
                } else {
                    layer.msg(data.message);
                }
            }, 'json');
        });
        
    {empty name = "bargain_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;
        };

        jQuery.validator.methods.lessThanGoodsPrice= function(value, element) {
            var goods_price = $("#input_groupbuy_goods_price").val();
            return Number(value) < Number(goods_price);
        };
        
    //页面输入内容验证
    $("#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('Sellerpromotionbargain/index')}", 1000);
            },
                rules: {
                    bargain_name: {
                        required: true
                    },
                    bargain_zhe: {
                        required: true,
                        digits:true,
                        range : [1,9]
                    },
                    bargain_limit_number: {
                        required: true,
                        digits:true,
                        min:2
                    },
                    start_time: {
                        required: true,
                        greaterThanDate: "{:date('Y-m-d H:i',@$current_bargain_quota['bargainquota_starttime'])}"
                    },
                    end_time: {
                        required: true,
                        {if !$isPlatformStore}
                        lessThanDate : "{present name='current_bargain_quota.bargainquota_starttime'}{$current_bargain_quota.bargainquota_endtime|date='Y-m-d H:i'}{/present}",
                        {/if}
                        greaterThanStartDate: true
                    },
                },
                messages : {
                    bargain_name : {
                        required : '<i class="iconfont">&#xe64c;</i>{$Think.lang.bargain_name_error}'
                    },
                    bargain_zhe: {
                        required : '<i class="iconfont">&#xe64c;</i>{$Think.lang.discount_cannot_empty}',
                        digits: '<i class="iconfont">&#xe64c;</i>{$Think.lang.discount_must_figures}',
                        range: '<i class="iconfont">&#xe64c;</i>{$Think.lang.please_fill_figure}'
                    },
                    bargain_limit_number: {
                        required : '<i class="iconfont">&#xe64c;</i>{$Think.lang.group_must_not_empty}',
                        digits: '<i class="iconfont">&#xe64c;</i>{$Think.lang.number_groups_must_number}',
                        min: '<i class="iconfont">&#xe64c;</i>{$Think.lang.number_groups_cannot_less_than}'
                    },
                    start_time : {
                        required : '<i class="iconfont">&#xe64c;</i>' + "<?php echo sprintf(lang('bargain_add_start_time_explain'),@date('Y-m-d H:i',$current_bargain_quota['bargainquota_starttime']));?>",
                        greaterThanDate : '<i class="iconfont">&#xe64c;</i>' + "<?php echo sprintf(lang('bargain_add_start_time_explain'),@date('Y-m-d H:i',$current_bargain_quota['bargainquota_starttime']));?>"
                    },
                    end_time : {
                        required : '<i class="iconfont">&#xe64c;</i>' + "<?php echo sprintf(lang('bargain_add_end_time_explain'),@date('Y-m-d H:i',$current_bargain_quota['bargainquota_endtime']));?>",
                        {if !$isPlatformStore}
                        lessThanDate : '<i class="iconfont">&#xe64c;</i>' +
                        "<?php echo sprintf(lang('bargain_add_end_time_explain'),@date('Y-m-d H:i',$current_bargain_quota['bargainquota_endtime']));?>",
                        {/if}
                        greaterThanStartDate : '<i class="iconfont">&#xe64c;</i>{$Think.lang.greater_than_start_time}'
                    },
                    
            }
    });
    });
</script>

{/block}

