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

    $form->get('customerCode')->setAttributes([
        'placeholder' => $this->translate('客户编码')
    ]);

    $form->get('customerName')->setAttributes([
        'placeholder' => $this->translate('客户名称')
    ]);

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

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

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

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

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

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

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

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

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

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

        <h1 class="pull-right">
            <a href="<?=$this->url('customer');?>" 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($customer) ? $this->HelpUrl('customerEdit') : $this->HelpUrl('customerAdd'))?>
        </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($customer) && $customer->getcustomerId()) ? $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('customerCategoryId')); ?>
                                    <?= $this->formElementErrors($form->get('customerCategoryId'), ['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('customerName')); ?>
                                    <?= $this->formElementErrors($form->get('customerName'), ['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('customerCode')); ?>
                                    <?= $this->formElementErrors($form->get('customerCode'), ['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('customerContacts')); ?>
                                    <?= $this->formElementErrors($form->get('customerContacts'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('手机号码')?>
                                    <?= $this->formElement($form->get('customerPhone')); ?>
                                    <?= $this->formElementErrors($form->get('customerPhone'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('座机号码')?>
                                    <?= $this->formElement($form->get('customerTelephone')); ?>
                                    <?= $this->formElementErrors($form->get('customerTelephone'), ['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('customerEmail')); ?>
                                    <?= $this->formElementErrors($form->get('customerEmail'), ['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($customer)) { ?>
                                            <span class="show_region_value"><?=$customer->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 id="show_address_area" name="show_address_area" style="height:30px;line-height: 30px;<?=isset($customer) ? '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('customerAddress')); ?>
                                    <?= $this->formElementErrors($form->get('customerAddress'), ['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('customerBank')); ?>
                                    <?= $this->formElementErrors($form->get('customerBank'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('开户账号')?>
                                    <?= $this->formElement($form->get('customerBankAccount')); ?>
                                    <?= $this->formElementErrors($form->get('customerBankAccount'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('税号')?>
                                    <?= $this->formElement($form->get('customerTax')); ?>
                                    <?= $this->formElementErrors($form->get('customerTax'), ['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('customerSort')); ?>
                                    <?= $this->formElementErrors($form->get('customerSort'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="col-xs-8 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('备注')?>
                                    <?= $this->formElement($form->get('customerInfo')); ?>
                                    <?= $this->formElementErrors($form->get('customerInfo'), ['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: {
                customerCategoryId: {
                    required: true,
                    min: 1
                },
                customerName: {
                    required: true
                },
                customerCode: {
                    required: true
                },
                show_address_area: {
                    required: true
                }
            },
            messages: {
                customerCategoryId: {
                    required: "<?=$this->translate('请选择客户分类！')?>",
                    min: "<?=$this->translate('请选择客户分类！')?>"
                },
                customerName: {
                    required: "<?=$this->translate('请填写客户名称！')?>"
                },
                customerCode: {
                    required: "<?=$this->translate('请填写客户编码！')?>"
                },
                show_address_area: {
                    required: "<?=$this->translate('请选择地区！')?>"
                }
            }
        });
    });
</script>