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

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

    $form->get('appAccessId')->setAttributes([
        'placeholder' => $this->translate('appId')
    ]);

    $form->get('appAccessSecret')->setAttributes([
        'placeholder' => $this->translate('appSecret')
    ]);

    $form->get('appUrl')->setAttributes([
        'placeholder' => $this->translate('以https://或http://开头')
    ]);

    $form->get('appUrlPort')->setAttributes([
        'placeholder' => $this->translate('端口')
    ]);

    $form->get('appType')->setEmptyOption('选择商城类别');
    ?>
    <?= $this->form()->openTag($form); ?>
    <section class="content-header">
        <?=$this->partial('layout/breadcrumb')?>

        <h1 class="pull-right">
            <a href="<?=$this->url('app');?>" 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>
            <?=$this->HelpUrl('appAdd')?>
        </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($this->appInfo) ? $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-2">
                                <?= $this->formElement($form->get('appType')); ?>
                                <?= $this->formElementErrors($form->get('appType'), ['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('appName')); ?>
                                <?= $this->formElementErrors($form->get('appName'), ['class'=>'error-message']); ?>
                            </div>
                        </div>

                        <div class="form-group">
                            <label  class="col-sm-2 control-label"><?=$this->translate('appId')?><span class="must_add_value">*</span></label>
                            <div class="col-sm-6">
                                <div class="col-xs-9" style="padding-left: 0px;padding-right: 3px;">
                                    <?= $this->formElement($form->get('appAccessId')); ?>
                                    <?= $this->formElementErrors($form->get('appAccessId'), ['class'=>'error-message']); ?>
                                </div>
                                <div class="col-xs-3" style="padding-right: 0px;">
                                    <button type="button" onclick="createAccessId();" class="btn btn-sm bg-olive"><i class="fa fa-home"></i> <?=$this->translate('点击系统生成')?></button>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label  class="col-sm-2 control-label"><?=$this->translate('appSecret')?><span class="must_add_value">*</span></label>
                            <div class="col-sm-6">
                                <div class="col-xs-9" style="padding-left: 0px;padding-right: 3px;">
                                    <?= $this->formElement($form->get('appAccessSecret')); ?>
                                    <?= $this->formElementErrors($form->get('appAccessSecret'), ['class'=>'error-message']); ?>
                                </div>
                                <div class="col-xs-3" style="padding-right: 0px;">
                                    <button type="button" onclick="createAccessSecret();" class="btn btn-sm bg-olive"><i class="fa fa-key"></i> <?=$this->translate('点击系统生成')?></button>
                                </div>
                            </div>
                        </div>

                        <div class="form-group" style="padding-right: ">
                            <label  class="col-sm-2 control-label"><?=$this->translate('商城地址')?><span class="must_add_value">*</span></label>
                            <div class="col-sm-6">
                                <div class="col-xs-10" style="padding-left: 0px;padding-right: 3px;">
                                    <?= $this->formElement($form->get('appUrl')); ?>
                                    <?= $this->formElementErrors($form->get('appUrl'), ['class'=>'error-message']); ?>
                                </div>
                                <div class="col-xs-2" style="padding-left: 3px;padding-right: 0px;">
                                    <?= $this->formElement($form->get('appUrlPort')); ?>
                                    <?= $this->formElementErrors($form->get('appUrlPort'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                        </div>

                        <div class="form-group" style="padding-right: ">
                            <label  class="col-sm-2 control-label"><?=$this->translate('商品绑定')?></label>
                            <div class="col-sm-6">
                                <div class="col-xs-3" style="padding-left: 0px;padding-right: 3px;">
                                    <?= $this->formElement($form->get('appGoodsBindType')); ?>
                                    <?= $this->formElementErrors($form->get('appGoodsBindType'), ['class'=>'error-message']); ?>
                                </div>
                                <div class="col-xs-2" style="padding-left: 3px;padding-right: 0px;">
                                    <div class="checkbox">
                                        <label>
                                            <?= $this->formElement($form->get('appGoodsBind')); ?> <?=$this->translate('启用绑定')?>
                                            <?= $this->formElementErrors($form->get('appGoodsBind'), ['class'=>'error-message']); ?>
                                        </label>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?=$this->translate('状态')?></label>
                            <div class="col-sm-6">
                                <div class="checkbox">
                                    <label>
                                        <?= $this->formElement($form->get('appState')); ?> <?=$this->translate('启用')?>
                                        <?= $this->formElementErrors($form->get('appState'), ['class'=>'error-message']); ?>
                                    </label>
                                </div>
                            </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: {
                appName: {
                    required: true
                },
                appAccessId: {
                    required: true
                },
                appAccessSecret: {
                    required: true
                },
                appUrl: {
                    required: true
                },
                appUrlPort: {
                    required: true,
                    number: true,
                    min: 1
                },
                appType: {
                    required: true
                }
            },
            messages: {
                appName: {
                    required: "<?=$this->translate('商城名称不能为空！')?>"
                },
                appAccessId: {
                    required: "<?=$this->translate('appId不能为空！')?>"
                },
                appAccessSecret: {
                    required: "<?=$this->translate('APPSecret不能为空！')?>"
                },
                appUrl: {
                    required: "<?=$this->translate('商城url地址不能为空！')?>"
                },
                appUrlPort: {
                    required: "<?=$this->translate('端口不能为空！')?>",
                    number: "<?=$this->translate('必须为数字！')?>",
                    min: "<?=$this->translate('最小为1！')?>"
                },
                appType: {
                    required: "<?=$this->translate('商城类别不能为空！')?>"
                }
            }
        });
    });
    
    function createAccessId() {
        $.get('<?php echo $this->url('app', array('action'=>'createAccessId')); ?>',{}, function(data){
            if(data.content != '') {
                $('#appAccessId').val(data.content);
            }
        }, 'json');
    }
    function createAccessSecret() {
        $.get('<?php echo $this->url('app', array('action'=>'createAccessSecret')); ?>',{}, function(data){
            if(data.content != '') {
                $('#appAccessSecret').val(data.content);
            }
        }, 'json');
    }
</script>
