<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();

    $form->get('goodsCategoryName')->setAttributes([
        'placeholder' => $this->translate('分类名称')
    ]);

    $form->get('goodsCategoryCode')->setAttributes([
        'placeholder' => $this->translate('分类编码')
    ]);

    $form->get('goodsCategorySort')->setAttributes([
        'placeholder' => $this->translate('排序')
    ]);

    ?>
    <?= $this->form()->openTag($form); ?>
    <section class="content-header">
        <?=$this->partial('layout/breadcrumb')?>

        <h1 class="pull-right">
            <a href="<?=$this->url('goods-category');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?=$this->translate('返回商品分类列表')?></a>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?=$this->translate('保存商品分类')?></button>
            <?=(isset($category) ? $this->HelpUrl('goodsCategoryEdit') : $this->HelpUrl('goodsCategoryAdd'))?>
        </h1>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><?=((isset($category) && $category->getGoodsCategoryId()) ? $this->translate('编辑商品分类') : $this->translate('添加商品分类'))?></h3>
                    </div>

                    <div class="box-body">
                        <?=$this->formElementErrors($form->get('dberp_csrf'), ['class'=>'error-message']); ?>
                        <div class="form-group">
                            <label  class="col-sm-2 control-label"><?=$this->translate('分类编码')?><span class="must_add_value">*</span></label>
                            <div class="col-sm-3">
                                <?= $this->formElement($form->get('goodsCategoryCode')); ?>
                                <?= $this->formElementErrors($form->get('goodsCategoryCode'), ['class'=>'error-message']); ?>
                            </div>
                        </div>

                        <div class="form-group">
                            <label  class="col-sm-2 control-label"><?=$this->translate('分类名称')?><span class="must_add_value">*</span></label>
                            <div class="col-sm-6">
                                <?= $this->formElement($form->get('goodsCategoryName')); ?>
                                <?= $this->formElementErrors($form->get('goodsCategoryName'), ['class'=>'error-message']); ?>
                            </div>
                        </div>

                        <div class="form-group">
                            <label  class="col-sm-2 control-label"><?=$this->translate('上级分类')?></label>
                            <div class="col-sm-3">
                                <?= $this->formElement($form->get('goodsCategoryTopId')); ?>
                                <?= $this->formElementErrors($form->get('goodsCategoryTopId'), ['class'=>'error-message']); ?>
                            </div>
                        </div>

                        <div class="form-group">
                            <label  class="col-sm-2 control-label"><?=$this->translate('排序')?><span class="must_add_value">*</span></label>
                            <div class="col-sm-3">
                                <?= $this->formElement($form->get('goodsCategorySort')); ?>
                                <?= $this->formElementErrors($form->get('goodsCategorySort'), ['class'=>'error-message']); ?>
                            </div>
                        </div>

                    </div>

                    <div>
                        <div class="box-footer">
                            <?=$this->formElement($form->get('dberp_csrf')); ?>
                            <button type="submit" class="btn btn-primary col-md-offset-2"><i class="fa fa-check"></i> <?=$this->translate('保存商品分类')?></button>
                        </div>
                    </div>

                </div>
            </div>
        </div>

    </section>
    <?= $this->form()->closeTag(); ?>

</div>
<script>
    $(document).ready(function() {
        $("#<?=$form->getName()?>").validate({
            rules: {
                goodsCategoryCode: {
                    required: true
                },
                goodsCategoryName: {
                    required: true
                },
                goodsCategorySort: {
                    required: true,
                    number: true,
                    min: 1
                }
            },
            messages: {
                goodsCategoryCode: {
                    required: "<?=$this->translate('分类编码不能为空！')?>"
                },
                goodsCategoryName: {
                    required: "<?=$this->translate('分类名称不能为空！')?>"
                },
                goodsCategorySort: {
                    required: "<?=$this->translate('排序不能为空！')?>",
                    number: "<?=$this->translate('排序必须为数字！')?>",
                    min: "<?=$this->translate('排序最小为1！')?>"
                }
            }
        });
    });
</script>
