{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="alert"> <strong>{$Think.lang.ds_explain}{$Think.lang.ds_colon}</strong>
            <ul>
                <?php if(intval(config('promotion_bundling_sum')) != 0){?>
                <li><?php printf(lang('bundling_add_explain1'), config('promotion_bundling_sum'), config('promotion_bundling_goods_sum'));?></li>
                <?php }else{?>
                <li><?php printf(lang('bundling_add_explain2'), config('promotion_bundling_goods_sum'));?></li>
                <?php }?>
                <li>凡选择指定优惠的商品，在这个商品的详细页将出现发布的优惠套装。</li>
                <li>特殊商品不能参加该活动。</li>
            </ul>
        </div>
        <div class="dssc-form-default">
            <!-- 说明 -->

            <form id="add_form" method="post" action="{:url('Sellerpromotionbundling/bundling_add')}">
                {notempty name="bundling_info"}
                <input type="hidden" name="bundling_id" value="{$bundling_info.bl_id}" />
                {/notempty}
                <dl>
                    <dt><i class="required">*</i>{$Think.lang.bundling_name}{$Think.lang.ds_colon}</dt>
                    <dd>
                        <p>
                            <input id="bundling_name" name="bundling_name" type="text" maxlength="25" class="w400 text" value="{present name="bundling_info"}{$bundling_info.bl_name}{/present}" />
                            <span></span> </p>
                        <p class="hint">{$Think.lang.bundling_name_explain}</p>
                    </dd>
                </dl>
                <dl>
                    <dt><i class="required">*</i>{$Think.lang.bundling_add_price}{$Think.lang.ds_colon}</dt>
                    <dd>
                        <input id="discount_price" name="discount_price" type="text" readonly style="background:#E7E7E7 none;" class="text w60 mr5" value="{present name="bundling_info"}{$bundling_info.bl_discount_price}{/present}"/>
                        {$Think.lang.currency_zh}
                        <span></span>
                        <p class="hint mt10">{$Think.lang.bundling_cost_price}<span nctype="cost_price" class="price mr5 ml5">{present name="bundling_info"}{$bundling_info.bl_discount_price}{/present}</span>{$Think.lang.currency_zh}{$Think.lang.bundling_cost_price_note}</p>
                    </dd>
                </dl>
                <dl>
                    <dt><i class="required">*</i>{$Think.lang.bundling_goods}{$Think.lang.ds_colon}</dt>
                    <dd>
                        <p>
                            <input id="bundling_goods" type="hidden" value="" name="bundling_goods">
                            <span></span></p>
                        <table class="dssc-default-table mb15">
                            <thead>
                            <tr>
                                <th class="w70">指定优惠</th>
                                <th class="tl" colspan="2">商品名称</th>
                                <th class="w90">{$Think.lang.bundling_cost_price}</th>
                                <th class="w90">优惠价格</th>
                                <th class="w90">{$Think.lang.ds_common_button_operate}</th>
                            </tr>
                            </thead>
                            <tbody nctype="bundling_data"  class="bd-line tip" title="{$Think.lang.bundling_add_goods_explain}">
                            <tr style="display:none;">
                                <td colspan="20" class="norecord"><div class="no-promotion"><i class="zh"></i><span>优惠套装还未选择添加商品。</span></div></td>
                            </tr>
                            {notempty name="b_goods_list"}
                            {volist name="b_goods_list" id="val"}
                           {present name="goods_list[$val.goods_id]"}
                            <tr id="bundling_tr_{$val.goods_id}" class="off-shelf">
                                <input type="hidden" value="{$val.bl_goods_id}" name="goods[{$val.goods_id}][bundling_goods_id]" />
                                <input type="hidden" value="{$val.goods_id}" name="goods[{$val.goods_id}][gid]" nctype="goods_id">
                                <td class="w70"><input type="checkbox" name="goods[{$val.goods_id}][appoint]" value="1" {if $val.bl_appoint == 1}checked="checked"{/if}></td>
                                <td class="w50"><div class="shelf-state"><div class="pic-thumb"><img src="{:cthumb($goods_list[$val.goods_id]['goods_image'],60,session('store_id'))}" ncname="{$goods_list[$val.goods_id]['goods_image']}" nctype="bundling_data_img">
                                </div></div>
                                </td>
                                <td class="tl"><dl class="goods-name">
                                    <dt style="width: 300px;">{$goods_list[$val.goods_id]['goods_name']}</dt>
                                </dl></td>
                                <td class="goods-price w90" nctype="bundling_data_price">{$goods_list[$val.goods_id]['goods_price']}</td>
                                <td class="w90">
                                    <input nctype="price" type="text" value="{$val.bl_goods_price}" name="goods[{$val.goods_id}][price]" class="text w70"></td>
                                <td class="nscs-table-handle w90"><span><a onclick="bundling_operate_delete($('#bundling_tr_{$val.goods_id}'), {$val.goods_id})" href="JavaScript:void(0);" class="btn-orange"><i class="icon-ban-circle"></i>
                  <p>{$Think.lang.bundling_goods_remove}</p>
                  </a></span></td>
                            </tr>
                           {/present}
                            {/volist}
                            {/notempty}
                            </tbody>
                        </table>
                        <a id="bundling_add_goods" href="{:url('Sellerpromotionbundling/bundling_add_goods')}" class="dssc-btn dssc-btn-acidblue">{$Think.lang.bundling_goods_add}</a>
                        <div class="div-goods-select-box">
                            <div id="bundling_add_goods_ajaxContent"></div>
                            <a id="bundling_add_goods_delete" class="close" href="javascript:void(0);" style="display: none; right: -10px;">X</a></div>
                    </dd>
                </dl>
                <dl>
                    <dt>{$Think.lang.bundling_add_freight_method}{$Think.lang.ds_colon}</dt>
                    <dd>
                        <ul class="dssc-form-radio-list">
                            <li><label for="whops_seller"><input id="whops_seller" type="radio" name="bundling_freight_choose" <?php if(!isset($bundling_info) || $bundling_info['bl_freight_choose'] == '1'){ ?>checked="checked"<?php }?> value="1" />{$Think.lang.bundling_add_freight_method_seller}</label></li>
                            <li><label for="whops_buyer"><input id="whops_buyer" type="radio" name="bundling_freight_choose" <?php if(isset($bundling_info) && $bundling_info['bl_freight_choose'] == '0'){ ?>checked="checked"<?php }?> value="0" />{$Think.lang.bundling_add_freight_method_buyer}</label>
                                <div id="whops_buyer_box" class="transport_tpl"
                                     style="<?php if(!isset($bundling_info) || $bundling_info['bl_freight_choose'] == '1'){ ?>display:none;<?php }?>">
                                    <input class="w50 text" type="text" name="bundling_freight" value="{present name='bundling_info'}{$bundling_info.bl_freight}{/present}" /><em class="add-on"><i class="icon-renminbi"></i></em>
                                </div>
                            </li>
                        </ul>
                    </dd>
                </dl>
                <dl>
                    <dt>{$Think.lang.bundling_status}{$Think.lang.ds_colon}</dt>
                    <dd>
                        <ul class="dssc-form-radio-list">
                            <li><label for="bundling_status_1">
                                <input type="radio" name="state" value="1" id="bundling_status_1" <?php if(!isset($bundling_info) || $bundling_info['bl_state'] == 1) echo 'checked="checked"'; ?> />
                                {$Think.lang.bundling_status_1}</label></li>
                            <li><label for="bundling_status_0">
                                <input type="radio" name="state" value="0" id="bundling_status_0" <?php if(isset($bundling_info) && $bundling_info['bl_state'] == 0) echo 'checked="checked"'; ?> />
                                {$Think.lang.bundling_status_0}</label></li>
                        </ul>
                    </dd>
                </dl>
                <div class="bottom">
                    <label class="submit-border"><input id="submit_button" type="submit" value="{$Think.lang.ds_submit}"  class="submit"></label>
                </div>
            </form>
        </div>
    </div>
    </div>
</div>
<script src="{$Think.config.url_domain_root}static/plugins/jquery.ajaxContent.pack.js"></script>
<script>
    jQuery.browser={};(function(){jQuery.browser.msie=false; jQuery.browser.version=0;if(navigator.userAgent.match(/MSIE ([0-9]+)./)){ jQuery.browser.msie=true;jQuery.browser.version=RegExp.$1;}})();
</script>
<script>

    $(document).ready(function(){
        /* ajax添加商品  */
        $('#bundling_add_goods').ajaxContent({
            event:'click', //mouseover
            loaderType:"img",
            loadingMsg:"{$Think.config.url_domain_root}static/home/images/loading.gif",
            target:'#bundling_add_goods_ajaxContent'
        }).click(function(){
            $(this).hide();
            $('#bundling_add_goods_delete').show();
        });

        $('#bundling_add_goods_delete').click(function(){
            $(this).hide();
            $('#bundling_add_goods_ajaxContent').html('');
            $('#bundling_add_goods').show();
        });
        // 退拽效果
        $('tbody[nctype="bundling_data"]').sortable({ items: 'tr' });
        $('#goods_images').sortable({ items: 'li' });
    });


    /* 计算商品原价 */
    function count_cost_price_sum(){
        data_price = $('td[nctype="bundling_data_price"]');
        if(typeof(data_price) != 'undefined'){
            var S_price = 0;
            data_price.each(function(){
                S_price += parseFloat($(this).html());
            });
            $('span[nctype="cost_price"]').html(S_price.toFixed(2));
        }else{
            $('span[nctype="cost_price"]').html('');
        }
    }

    /* 计算商品售价 */
    function count_price_sum(){
        data_price = $('input[nctype="price"]');
        if(typeof(data_price) != 'undefined'){
            var S_price = 0;
            data_price.each(function(){
                S_price += parseFloat($(this).val());
            });
            $('#discount_price').val(S_price.toFixed(2));
        }else{
            $('#discount_price').val('');
        }
    }
</script>
<script src="{$Think.config.url_domain_root}static/plugins/jquery.poshytip.min.js"></script>
<style>
    .pic_list .small_pic ul li {
        height: 100px;
    }
    .ui-sortable-helper {
        border: dashed 1px #F93;
        box-shadow: 2px 2px 2px rgba(153,153,153, 0.25);
        filter: alpha(opacity=75);
        -moz-opacity: 0.75;
        opacity: .75;
        cursor: ns-resize;
    }
    .ui-sortable-helper td {
        background-color: #FFC !important;
    }
    .ajaxload {
        display: block;
        width: 16px;
        height: 16px;
        margin: 100px 300px;
    }
</style>
<script type="text/javascript">
    var DEFAULT_GOODS_IMAGE = '{:defaultGoodsImage(60)}';
    $(function(){
        jQuery.validator.addMethod('bundling_goods', function(value, element){
            return $('tbody[nctype="bundling_data"] > tr').length >2?true:false;
        });
        //Ajax提示
        $('.tip').poshytip({
            className: 'tip-yellowsimple',
            showTimeout: 1,
            alignTo: 'target',
            alignX: 'left',
            alignY: 'top',
            offsetX: 5,
            offsetY: -78,
            allowTipHover: false
        });
        $('.tip2').poshytip({
            className: 'tip-yellowsimple',
            showTimeout: 1,
            alignTo: 'target',
            alignX: 'right',
            alignY: 'center',
            offsetX: 5,
            offsetY: 0,
            allowTipHover: false
        });
        //页面输入内容验证
        $("#add_form").validate({
            errorPlacement: function(error, element){
                var error_td = element.nextAll('span:first');
                error_td.append(error);
            },
            submitHandler:function(form){
                ajaxpost('add_form', '', '', 'onerror')
            },
            rules : {
                bundling_name : {
                    required : true
                },
                bundling_goods : {
                    bundling_goods : true
                },
                discount_price : {
                    required : true,
                    number : true
                }
            },
            messages : {
                bundling_name : {
                    required : '<i class="icon-exclamation-sign"></i>{$Think.lang.bundling_add_name_error}'
                },
                bundling_goods : {
                    bundling_goods : '<i class="icon-exclamation-sign"></i>{$Think.lang.bundling_add_goods_error}'
                },
                discount_price : {
                    required : '<i class="icon-exclamation-sign"></i>{$Think.lang.bundling_add_price_error_null}',
                    number : '<i class="icon-exclamation-sign"></i>{$Think.lang.bundling_add_price_error_not_num}'
                }

            }
        });

        $('input[name="bundling_freight_choose"]').click(function(){
            if($(this).val() == '0'){
                $('#whops_buyer_box').show();
            }else{
                $('#whops_buyer_box').hide();
            }
        });

        check_bundling_data_length();
        {notempty name='bundling_info'}
            count_cost_price_sum(); // 计算商品原价
            count_price_sum();
        {/notempty}

        $('tbody[nctype="bundling_data"]').on('change', 'input[nctype="price"]', function(){
            count_price_sum();
        });
    });


    /* 删除商品 */
    function bundling_operate_delete(o, id){
        o.remove();
        check_bundling_data_length();
        $('li[nctype="'+id+'"]').children(':last').html('<a href="JavaScript:void(0);" onclick="bundling_goods_add($(this))" class="dssc-btn-mini dssc-btn-green"><i class="icon-plus"></i>{$Think.lang.bundling_goods_add_bundling}</a>');
        count_cost_price_sum();
    }

    function check_bundling_data_length(){
        if ($('tbody[nctype="bundling_data"] tr').length == 1) {
            $('tbody[nctype="bundling_data"]').children(':first').show();
        }
    }
</script>
