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

    $form->get('goodsNumber')->setAttributes([
        'placeholder' => $this->translate('商品编码')
    ]);

    $form->get('goodsName')->setAttributes([
        'placeholder' => $this->translate('商品名称')
    ]);

    $form->get('goodsBarcode')->setAttributes([
        'placeholder' => $this->translate('商品条形码')
    ]);

    $form->get('goodsRecommendPrice')->setAttributes([
        'placeholder' => $this->translate('建议售价'),
        'value' => $this->erpCurrencyFormat($form->get('goodsRecommendPrice')->getValue(), '')
    ]);

    $form->get('goodsSpec')->setAttributes([
        'placeholder' => $this->translate('商品规格')
    ]);

    $form->get('goodsInfo')->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');?>" 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($goods) ? $this->HelpUrl('goodsEdit') : $this->HelpUrl('goodsAdd'))?>
        </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($goods) && $goods->getGoodsId()) ? $this->translate('编辑商品') : $this->translate('添加商品'))?></h3>
                    </div>

                    <div class="box-body">
                        <?=$this->formElementErrors($form->get('dberp_csrf'), ['class'=>'error-message']); ?>
                        <div class="row">
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('商品名称')?><span class="must_add_value">*</span>
                                    <?= $this->formElement($form->get('goodsName')); ?>
                                    <?= $this->formElementErrors($form->get('goodsName'), ['class'=>'error-message']); ?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('商品编码')?><span class="must_add_value">*</span>
                                    <?= $this->formElement($form->get('goodsNumber')); ?>
                                    <?= $this->formElementErrors($form->get('goodsNumber'), ['class'=>'error-message']); ?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('商品条形码')?>
                                    <?= $this->formElement($form->get('goodsBarcode')); ?>
                                    <?= $this->formElementErrors($form->get('goodsBarcode'), ['class'=>'error-message']); ?>
                                </div>
                            </div>

                        </div>

                        <div class="row">
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('商品分类')?><span class="must_add_value">*</span>
                                    <?= $this->formElement($form->get('goodsCategoryId')); ?>
                                    <?= $this->formElementErrors($form->get('goodsCategoryId'), ['class'=>'error-message']); ?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('商品单位')?><span class="must_add_value">*</span>
                                    <?= $this->formElement($form->get('unitId')); ?>
                                    <?= $this->formElementErrors($form->get('unitId'), ['class'=>'error-message']); ?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('商品品牌')?>
                                    <?= $this->formElement($form->get('brandId')); ?>
                                    <?= $this->formElementErrors($form->get('brandId'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('建议售价')?><span class="must_add_value">*</span>
                                    <?= $this->formElement($form->get('goodsRecommendPrice')); ?>
                                    <?= $this->formElementErrors($form->get('goodsRecommendPrice'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('商品库存')?>
                                    <?= $this->formElement($form->get('goodsStock')); ?>
                                    <?= $this->formElementErrors($form->get('goodsStock'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('商品规格')?>
                                    <?= $this->formElement($form->get('goodsSpec')); ?>
                                    <?= $this->formElementErrors($form->get('goodsSpec'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                        </div>


                        <div class="row">
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('排序')?>
                                    <?= $this->formElement($form->get('goodsSort')); ?>
                                    <?= $this->formElementErrors($form->get('goodsSort'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-8 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('备注')?>
                                    <?= $this->formElement($form->get('goodsInfo')); ?>
                                    <?= $this->formElementErrors($form->get('goodsInfo'), ['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-4"><i class="fa fa-check"></i> <?=$this->translate('保存商品')?></button>
                    </div>
                </div>


            </div>
        </div>

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

</div>
<script>
    $(document).ready(function() {
        $("#<?=$form->getName()?>").validate({
            rules: {
                goodsName: {
                    required: true
                },
                goodsNumber: {
                    required: true
                },
                goodsCategoryId: {
                    required: true,
                    min: 1
                },
                unitId: {
                    required: true,
                    min: 1
                },
                goodsSort: {
                    number: true,
                    min: 1
                }
            },
            messages: {
                goodsName: {
                    required: "<?=$this->translate('商品名称不能为空！')?>"
                },
                goodsNumber: {
                    required: "<?=$this->translate('商品编码不能为空！')?>"
                },
                goodsCategoryId: {
                    required: "<?=$this->translate('请选择商品分类！')?>",
                    min: "<?=$this->translate('请选择商品分类！')?>"
                },
                unitId: {
                    required: "<?=$this->translate('请选择商品单位！')?>",
                    min: "<?=$this->translate('请选择商品单位！')?>"
                },
                goodsSort: {
                    number: "<?=$this->translate('排序必须为数字！')?>",
                    min: "<?=$this->translate('排序最小为1！')?>"
                }
            }
        });
    });
</script>