{extend name="base/detail"}

{block name="content"}
<div class="main">
    <div class="content">
        <ul class="nav nav-tabs">
            <li>&nbsp;&nbsp;&nbsp;&nbsp;</li>
            <li role="presentation" class="active"><a href="javascript:;">添加商品</a></li>
        </ul><br>

        <form class="form-horizontal" role="form" action="" method="post">
            <input type="hidden" name="cate_id" value="{$goods.id|default=''}">
            <div class="form-group">
                <label class="col-md-2 control-label">商品分类</label>
                <div class="col-md-4">
                    <select name="cate_id" class="form-control" required>
                        {foreach $categorys as $v}
                        <option value="{$v.id}" {if isset($goods) && $goods.cate_id==$v.id}selected{/if}>{$v.name}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">请选择商品分类</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">页面风格</label>
                <div class="col-md-4">
                    <select name="theme" class="form-control" required>
                        {foreach :config('pay_themes') as $theme}
                        <option value="{$theme.alias}" {if isset($goods) && $goods.theme==$theme.alias}selected{/if}>{$theme.name}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">请选择购买时的页面风格</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">商品排序</label>
                <div class="col-md-4">
                    <input name="sort" type="number" class="form-control" placeholder="商品排序" value="{$goods.sort|default=0}" min=0>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">	数字越大越靠前！</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">商品名称</label>
                <div class="col-md-4">
                    <input name="name" type="text" class="form-control" placeholder="商品名称" value="{$goods.name|default=''}" maxlength="20" required>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">好的名字有利于销售哦！</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">商品价格</label>
                <div class="col-md-4">
                    <input name="price" type="text" class="form-control" placeholder="商品价格" value="{$goods.price|default=''}" required>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">商品对外出售的价格即零售价格！</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">批发优惠</label>
                <div class="col-md-4">
                    <div class="radio-inline">
                        <input type="radio" name="wholesale_discount" id="wholesale_discount1" value="1" {if isset($goods) && $goods.wholesale_discount==1}checked{/if}>
                        <label for="wholesale_discount1">
                            使用
                        </label>
                    </div>
                    <div class="radio-inline">
                        <input type="radio" name="wholesale_discount" id="wholesale_discount2" value="0" {if isset($goods)}{if $goods.wholesale_discount==0}checked{/if}{else/}checked{/if} >
                        <label for="wholesale_discount2">
                            不使用
                        </label>
                    </div>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">是否设置批发购买时使用批发价格！</p>
                </div>
            </div>
            <div class="form-group block-wholesale_discount" {if !isset($goods) || $goods.wholesale_discount==0}style="display:none"{/if}>
                <label class="col-md-2 control-label"></label>
                <div class="col-md-4">
                    <div class="block-discount_list">
                        <table>
                            <tr>
                                <th>购买数量</th>
                                <th>优惠价格</th>
                                <th></th>
                            </tr>
                            {if isset($goods)}
                            {foreach $goods.wholesale_discount_list as $v}
                            <tr class="discount_item">
                                <td style="padding-bottom:10px">
                                    <input name="wholesale_discount_list[num][]" type="number" class="form-control" value="{$v.num}" min=0 style="width:60%;display:inline-block">
                                    张
                                </td>
                                <td>
                                    <input name="wholesale_discount_list[price][]" type="text" class="form-control" value="{$v.price}" style="width:60%;display:inline-block">
                                    元
                                </td>
                                <td>
                                    <button type="button" class="btn btn-danger waves-effect waves-light" onclick="del_discount_item(this)">删除</button>
                                </td>
                            </tr>
                            {/foreach}
                            {/if}
                        </table>
                        <button type="button" class="btn btn-primary waves-effect waves-light" onclick="add_discount_item()"><i class="zmdi zmdi-plus-circle"></i> 添加优惠</button>
                    </div>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">优惠价格为单价，并不是商品总价哦！</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">成本价格</label>
                <div class="col-md-4">
                    <input name="cost_price" type="text" class="form-control" placeholder="单位（元）" value="{$goods.cost_price|default=''}">
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">商品进货价,可以不填,填写有利于商户系统的利润统计分析！</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">起购数量</label>
                <div class="col-md-4">
                    <input name="limit_quantity" type="number" class="form-control" placeholder="起购数量" value="{$goods.limit_quantity|default=1}" min=1>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">每次购买 最少购买多少件！</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">库存预警</label>
                <div class="col-md-4">
                    <input name="inventory_notify" type="number" class="form-control" placeholder="库存预警" value="{$goods.inventory_notify|default=0}" min=0>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">为0表示不报警,设置后请确保邮箱正确，否则无法接收邮件</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">通知方式</label>
                <div class="col-md-4">
                    <div class="radio-inline">
                        <input type="radio" name="inventory_notify_type" id="inventory_notify_type1" value="1" {if isset($goods)}{if $goods.inventory_notify_type==1}checked{/if}{else/}checked{/if}>
                        <label for="inventory_notify_type1">
                            站内信
                        </label>
                    </div>
                    <div class="radio-inline">
                        <input type="radio" name="inventory_notify_type" id="inventory_notify_type2" value="2" {if isset($goods) && $goods.inventory_notify_type==2}checked{/if}>
                        <label for="inventory_notify_type2">
                            邮件
                        </label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">优惠券</label>
                <div class="col-md-4">
                    <div class="radio-inline">
                        <input type="radio" name="coupon_type" id="coupon_type1" value="1" {if isset($goods) && $goods.coupon_type==1}checked{/if}>
                        <label for="coupon_type1">
                            支持
                        </label>
                    </div>
                    <div class="radio-inline">
                        <input type="radio" name="coupon_type" id="coupon_type2" value="0" {if isset($goods)}{if $goods.coupon_type==0}checked{/if}{else/}checked{/if}>
                        <label for="coupon_type2">
                            不支持
                        </label>
                    </div>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">是否支持优惠券</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">售出通知</label>
                <div class="col-md-4">
                    <div class="radio-inline">
                        <input type="radio" name="sold_notify" id="sold_notify1" value="1" {if isset($goods) && $goods.sold_notify==1}checked{/if}>
                        <label for="sold_notify1">
                            开启
                        </label>
                    </div>
                    <div class="radio-inline">
                        <input type="radio" name="sold_notify" id="sold_notify2" value="0" {if isset($goods)}{if $goods.sold_notify==0}checked{/if}{else/}checked{/if}>
                        <label for="sold_notify2">
                            关闭
                        </label>
                    </div>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">开启后，成功售卡将会发送邮件通知</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">提卡密码</label>
                <div class="col-md-4">
                    <div class="radio-inline">
                        <input type="radio" name="take_card_type" id="take_card_type1" value="1" {if isset($goods) && $goods.take_card_type==1}checked{/if}>
                        <label for="take_card_type1">
                            必填
                        </label>
                    </div>
                    <div class="radio-inline">
                        <input type="radio" name="take_card_type" id="take_card_type2" value="2" {if isset($goods) && $goods.take_card_type==2}checked{/if}>
                        <label for="take_card_type2">
                            选填
                        </label>
                    </div>
                    <div class="radio-inline">
                        <input type="radio" name="take_card_type" id="take_card_type3" value="0" {if isset($goods)}{if $goods.take_card_type==0}checked{/if}{else/}checked{/if}>
                        <label for="take_card_type3">
                            关闭
                        </label>
                    </div>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">开启后，购买页面会提示买家填写取卡密码</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">访问密码</label>
                <div class="col-md-4">
                    <div class="radio-inline">
                        <input type="radio" name="visit_type" id="visit_type1" value="1" {if isset($goods) && $goods.visit_type==1}checked{/if}>
                        <label for="visit_type1">
                            开启
                        </label>
                    </div>
                    <div class="radio-inline">
                        <input type="radio" name="visit_type" id="visit_type2" value="0" {if isset($goods)}{if $goods.visit_type==0}checked{/if}{else/}checked{/if}>
                        <label for="visit_type2">
                            关闭
                        </label>
                    </div>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">留空为不开启，若开启后商品购买页面将提示输入设置的密码才能继续访问</p>
                </div>
            </div>
            <div class="form-group block-visit_password" {if !isset($goods) || $goods.visit_type==0}style="display:none"{/if}>
                <label class="col-md-2 control-label">设置密码</label>
                <div class="col-md-4">
                    <input name="visit_password" type="text" class="form-control" placeholder="" value="{$goods.visit_password|default=''}">
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">设置密码后，请牢记该密码！</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">客户信息</label>
                <div class="col-md-4">
                    <select name="contact_limit" class="form-control" required>
                        <option value="default" {if isset($goods) && $goods.contact_limit==='default'}selected{/if}>默认</option>
                        <option value="any" {if isset($goods) && $goods.contact_limit==='any'}selected{/if}>任意字符</option>
                        <option value="qq" {if isset($goods) && $goods.contact_limit==='qq'}selected{/if}>QQ号码</option>
                        <option value="email" {if isset($goods) && $goods.contact_limit==='email'}selected{/if}>邮箱账号</option>
                        <option value="mobile" {if isset($goods) && $goods.contact_limit==='mobile'}selected{/if}>手机号码</option>
                    </select>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">客户下单时输入的联系方式或充值账号格式限制</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">商品说明</label>
                <div class="col-md-4">
                    <textarea name="content" placeholder="建议填写该商品的使用方法，文字不超过200字" class="form-control" rows="5" maxlength="200">{$goods.content|default=''}</textarea>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">商品说明将显示在商品购买页面</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">使用说明</label>
                <div class="col-md-4">
                    <textarea name="remark" placeholder="建议填写该商品的使用方法，文字不超过200字" class="form-control" rows="5" maxlength="200">{$goods.remark|default=''}</textarea>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static">使用说明将显示在订单查询结果中，一般设置售后QQ群，或者下载地址类</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label"></label>
                <div class="col-md-4">
                    <button type="submit" class="btn btn-primary btn-block"><span class="glyphicon glyphicon-send"></span>&nbsp;确认提交</button>
                </div>
                <div class="col-md-6">
                    <p class="form-control-static"></p>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}

{block name="appendJS"}

<script>
$('[name="visit_type"]').change(function(){
	var status=$(this).val();
	if(status==1){
		$('.block-visit_password').slideDown();
	}else{
		$('.block-visit_password').slideUp();
	}
});
$('[name="wholesale_discount"]').change(function(){
	var status=$(this).val();
	if(status==1){
		$('.block-wholesale_discount').slideDown();
	}else{
		$('.block-wholesale_discount').slideUp();
	}
});
function del_discount_item(obj){
	$(obj).parents('.discount_item').remove();
}
function add_discount_item(){
	var html='<tr class="discount_item"><td style="padding-bottom:10px"><input name="wholesale_discount_list[num][]" type="number" class="form-control" value="" min=0 style="width:60%;display:inline-block">张</td><td>    <input name="wholesale_discount_list[price][]" type="text" class="form-control" value="" style="width:60%;display:inline-block">元</td><td>    <button type="button" class="btn btn-danger waves-effect waves-light" onclick="del_discount_item(this)">删除</button></td></tr>';
	$('.block-discount_list table').append($(html));
}
</script>
{/block}
