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

    $form->get('supplierCode')->setAttributes([
        'placeholder' => $this->translate('供应商编码')
    ]);

    $form->get('supplierName')->setAttributes([
        'placeholder' => $this->translate('供应商名称')
    ]);

    $form->get('supplierSort')->setAttributes([
        'placeholder' => $this->translate('供应商排序')
    ]);

    $form->get('supplierAddress')->setAttributes([
        'placeholder' => $this->translate('详细地址')
    ]);

    $form->get('supplierEmail')->setAttributes([
        'placeholder' => $this->translate('电子邮箱')
    ]);

    $form->get('supplierContacts')->setAttributes([
        'placeholder' => $this->translate('联系人')
    ]);

    $form->get('supplierPhone')->setAttributes([
        'placeholder' => $this->translate('手机')
    ]);

    $form->get('supplierTelephone')->setAttributes([
        'placeholder' => $this->translate('座机')
    ]);

    $form->get('supplierBank')->setAttributes([
        'placeholder' => $this->translate('开户银行')
    ]);

    $form->get('supplierBankAccount')->setAttributes([
        'placeholder' => $this->translate('开户行账号')
    ]);

    $form->get('supplierTax')->setAttributes([
        'placeholder' => $this->translate('税号')
    ]);

    $form->get('supplierInfo')->setAttributes([
        'placeholder' => $this->translate('备注')
    ]);
    ?>
    <?= $this->form()->openTag($form); ?>
    <section class="content-header">
        <?=$this->partial('layout/breadcrumb')?>

        <h1 class="pull-right">
            <a href="<?=$this->url('supplier');?>" 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($supplier) ? $this->HelpUrl('supplierEdit') : $this->HelpUrl('supplierAdd'))?>
        </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($supplier) && $supplier->getSupplierId()) ? $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('supplierCategoryId')); ?>
                                    <?= $this->formElementErrors($form->get('supplierCategoryId'), ['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('supplierName')); ?>
                                    <?= $this->formElementErrors($form->get('supplierName'), ['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('supplierCode')); ?>
                                    <?= $this->formElementErrors($form->get('supplierCode'), ['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('supplierContacts')); ?>
                                    <?= $this->formElementErrors($form->get('supplierContacts'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('手机号码')?>
                                    <?= $this->formElement($form->get('supplierPhone')); ?>
                                    <?= $this->formElementErrors($form->get('supplierPhone'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('座机号码')?>
                                    <?= $this->formElement($form->get('supplierTelephone')); ?>
                                    <?= $this->formElementErrors($form->get('supplierTelephone'), ['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('supplierEmail')); ?>
                                    <?= $this->formElementErrors($form->get('supplierEmail'), ['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>
                                    <div class="controls" id="region">
                                        <?php if(isset($supplier)) { ?>
                                            <span class="show_region_value"><?=$supplier->getRegionValues();?></span>
                                            <button type="button" onclick="regionEdit();" class="btn btn-success btn-xs show_region_value"><i class="fa fa-pencil"></i> <?=$this->translate('修改')?></button>
                                        <?php } ?>
                                        <select name="show_address_area" id="show_address_area" style="height:30px;line-height: 30px;<?=isset($supplier) ? 'display: none' : '';?>">
                                            <option value=""><?php echo $this->translate('请选择'); ?></option>
                                            <?php if ($this->region and !empty($this->region)) {
                                                foreach ($this->region as $value) {
                                                    ?>
                                                    <option
                                                            value="<?=$value->getRegionId(); ?>"><?=$value->getRegionName(); ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                        <?= $this->formElement($form->get('regionId')); ?>
                                        <?= $this->formElementErrors($form->get('regionId'), ['class'=>'error-message']); ?>

                                        <?= $this->formElement($form->get('regionValues')); ?>
                                        <?= $this->formElementErrors($form->get('regionValues'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('详细地址')?>
                                    <?= $this->formElement($form->get('supplierAddress')); ?>
                                    <?= $this->formElementErrors($form->get('supplierAddress'), ['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('supplierBank')); ?>
                                    <?= $this->formElementErrors($form->get('supplierBank'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('开户账号')?>
                                    <?= $this->formElement($form->get('supplierBankAccount')); ?>
                                    <?= $this->formElementErrors($form->get('supplierBankAccount'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('税号')?>
                                    <?= $this->formElement($form->get('supplierTax')); ?>
                                    <?= $this->formElementErrors($form->get('supplierTax'), ['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('supplierSort')); ?>
                                    <?= $this->formElementErrors($form->get('supplierSort'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-8 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('备注')?>
                                    <?= $this->formElement($form->get('supplierInfo')); ?>
                                    <?= $this->formElementErrors($form->get('supplierInfo'), ['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>
    var SITE_REGION_URL = '<?=$this->url('region', ['action' => 'ajaxRegion']);?>';
    var AREA_SELECT_LANG = '<?php echo $this->translate('请选择'); ?>';

    regionInit("region");

    $(document).ready(function() {
        $("#<?=$form->getName()?>").validate({
            rules: {
                supplierCategoryId: {
                    required: true,
                    min: 1
                },
                supplierName: {
                    required: true
                },
                supplierCode: {
                    required: true
                },
                show_address_area: {
                    required: true
                }
            },
            messages: {
                supplierCategoryId: {
                    required: "<?=$this->translate('请选择供应商分类！')?>",
                    min: "<?=$this->translate('请选择供应商分类！')?>"
                },
                supplierName: {
                    required: "<?=$this->translate('请填写供应商名称！')?>"
                },
                supplierCode: {
                    required: "<?=$this->translate('请填写供应商编码！')?>"
                },
                show_address_area: {
                    required: "<?=$this->translate('请选择地区！')?>"
                }
            }
        });
    });
</script>