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

    $form->get('attributeName')->setAttributes([
        'placeholder' => $this->translate('属性名称')
    ]);
    if(isset($this->attributeInfo)) {
        $form->get('attributeGroupId')->setAttributes([
            'disabled' => true
        ]);
        $form->get('attributeType')->setAttributes([
            'disabled' => true
        ]);
    }
    ?>
    <?php echo $this->form()->openTag($form); ?>
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right" id="dbshop-menu-top">
            <a href="<?php echo $this->url('goods-attribute');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回属性列表'); ?></a>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('保存属性'); ?></button>
            <?php echo $this->HelpUrl('goodsAttribute'); ?>
        </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"><?php echo (isset($this->attributeInfo) ? $this->translate('编辑属性') : $this->translate('添加属性')); ?></h3>
                    </div>

                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('属性分组'); ?><span class="must_add_value">*</span></label>
                            <div class="col-sm-3">
                                <?php echo $this->formElement($form->get('attributeGroupId')); ?>
                                <?php echo $this->formElementErrors($form->get('attributeGroupId'), ['class'=>'error-message']); ?>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('属性类型'); ?><span class="must_add_value">*</span></label>
                            <div class="col-sm-3">
                                <?php echo $this->formElement($form->get('attributeType')); ?>
                                <?php echo $this->formElementErrors($form->get('attributeType'), ['class'=>'error-message']); ?>
                            </div>
                        </div>

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

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

                    </div>

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

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

</div>
<script type="text/javascript">
    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                attributeGroupId: {
                    required: true,
                    min: 1
                },
                attributeName: {
                    required: true
                },
                attributeSort: {
                    required: true,
                    number: true,
                    min: 1
                }
            },
            messages: {
                attributeGroupId: {
                    required: "<?php echo $this->translate('请选择属性分组!'); ?>",
                    min: "<?php echo $this->translate('请选择属性分组!'); ?>"
                },
                attributeName: {
                    required: "<?php echo $this->translate('属性名称不能为空!'); ?>"
                },
                attributeSort: {
                    required: "<?php echo $this->translate('排序不能为空!'); ?>",
                    number: "<?php echo $this->translate('排序必须为数字!'); ?>",
                    min: "<?php echo $this->translate('排序最小为1!'); ?>"
                }
            }
        });
    });
</script>
