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

    if(isset($this->userInfo) && $this->userInfo->getUserId()) {
        $form->get('userName')->setAttributes([
            'disabled' => 'disabled'
        ]);
    }
    ?>
    <?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('user', [], ['query' => $this->queryData]);?>" 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('userAdd'); ?>
        </h1>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab"><?php echo $this->translate('基本信息'); ?></a></li>
                        <?php if($this->userInfo) { ?>
                            <li><a href="#tab_2" data-toggle="tab"><?php echo $this->translate('地址信息'); ?></a></li>
                            <li><a href="#tab_3" data-toggle="tab"><?php echo $this->translate('收藏商品'); ?></a></li>
                            <li><a href="#tab_4" data-toggle="tab"><?php echo $this->translate('购物车信息'); ?></a></li>
                            <li><a href="#tab_5" data-toggle="tab"><?php echo $this->translate('已绑定登录'); ?></a></li>
                        <?php } ?>
                    </ul>
                    <div class="tab-content">
                        <?php echo $this->partial('layout/messages'); ?>
                        <div class="tab-pane active" id="tab_1">
                            <div class="box-body">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('客户头像'); ?></label>
                                    <div class="col-sm-3">
                                        <img src="<?php echo $this->basePath($form->get('userAvatar')->getValue()); ?>" style="max-width: 100px;padding-bottom: 5px;">
                                        <?php echo $this->formElement($form->get('userAvatar')); ?>
                                        <?php echo $this->formElementErrors($form->get('userAvatar'), ['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-5">
                                        <?php echo $this->formElement($form->get('userName')); ?>
                                        <?php echo $this->formElementErrors($form->get('userName'), ['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('userGroupId')); ?>
                                        <?php echo $this->formElementErrors($form->get('userGroupId'), ['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('userSex')); ?>
                                        <?php echo $this->formElementErrors($form->get('userSex'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <?php if(!isset($this->userInfo)) { ?>
                                    <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('userPassword')); ?>
                                            <?php echo $this->formElementErrors($form->get('userPassword'), ['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('payPassword')); ?>
                                            <?php echo $this->formElementErrors($form->get('payPassword'), ['class'=>'error-message']); ?>
                                        </div>
                                    </div>
                                <?php } ?>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('电子邮箱'); ?></label>
                                    <div class="col-sm-4">
                                        <?php echo $this->formElement($form->get('userEmail')); ?>
                                        <?php echo $this->formElementErrors($form->get('userEmail'), ['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-3">
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <?php echo $this->formElement($form->get('userBirthday')); ?>
                                        </div>
                                        <?php echo $this->formElementErrors($form->get('userBirthday'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('手机号码'); ?></label>
                                    <?php if(count($this->phoneArea) == 1) { ?>
                                        <div class="col-sm-3">
                                            <?php echo $this->formElement($form->get('areaCode')); ?>
                                            <?php echo $this->formElementErrors($form->get('areaCode'), ['class'=>'error-message']); ?>
                                            <?php echo $this->formElement($form->get('userPhone')); ?>
                                            <?php echo $this->formElementErrors($form->get('userPhone'), ['class'=>'error-message']); ?>
                                        </div>
                                    <?php } else { ?>
                                        <div class="col-sm-2">
                                            <?php echo $this->formElement($form->get('areaCode')); ?>
                                            <?php echo $this->formElementErrors($form->get('areaCode'), ['class'=>'error-message']); ?>
                                        </div>
                                        <div class="col-sm-3">
                                            <?php echo $this->formElement($form->get('userPhone')); ?>
                                            <?php echo $this->formElementErrors($form->get('userPhone'), ['class'=>'error-message']); ?>
                                        </div>
                                    <?php } ?>
                                </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('userStatus')); ?>
                                        <?php echo $this->formElementErrors($form->get('userStatus'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php if($this->userInfo) { ?>
                            <div class="tab-pane" id="tab_2">
                                <div class="box-body table-responsive no-padding">
                                    <table class="table shop-table table-hover">
                                        <thead>
                                        <tr class="shop-bg-thead">
                                            <th><?php echo $this->translate('收货人'); ?></th>
                                            <th><?php echo $this->translate('联系电话'); ?></th>
                                            <th><?php echo $this->translate('收货地址'); ?></th>
                                            <th><?php echo $this->translate('邮政编码'); ?></th>
                                            <th><?php echo $this->translate('默认地址'); ?></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php
                                        $phoneAreaCodeCount = count($this->phoneAreaCode);
                                        if ($this->userAddress) foreach ($this->userAddress as $addressValue) {
                                            ?>
                                        <tr>
                                            <td><?php echo $this->escapeHtml($addressValue->getTrueName()); ?></td>
                                            <td><?php echo ($phoneAreaCodeCount > 1 ? '+'.$this->phoneAreaCode[$addressValue->getAreaCode()]['areaPhoneCode'] : '') . ' ' . $this->escapeHtml($addressValue->getPhone()); ?></td>
                                            <td><?php echo $this->escapeHtml($addressValue->getRegionValue().$addressValue->getAddressInfo()); ?></td>
                                            <td><?php echo $this->escapeHtml($addressValue->getPostCode()); ?></td>
                                            <td><?php echo $addressValue->getAddrDefault() == 1 ? $this->translate('是') : $this->translate('否'); ?></td>
                                        </tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                            <div class="tab-pane" id="tab_3">
                                <div class="box-body table-responsive no-padding">
                                    <table class="table shop-table table-hover">
                                        <thead>
                                        <tr class="shop-bg-thead">
                                            <th width="5%"><?php echo $this->translate('图片'); ?></th>
                                            <th><?php echo $this->translate('商品名称'); ?></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php if ($this->userGoodsFavorites) foreach ($this->userGoodsFavorites AS $favoritesValue) { ?>
                                            <tr>
                                                <td>
                                                    <img src="<?php echo $this->shopHelper()->baseGoodsImagePath($favoritesValue['goodsThumbnailImage']); ?>" class="img-thumbnail">
                                                </td>
                                                <td>
                                                    <?php echo $this->escapeHtml($favoritesValue['goodsName']); ?>
                                                </td>
                                            </tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                            <div class="tab-pane" id="tab_4">
                                <div class="box-body table-responsive no-padding">
                                    <table class="table shop-table table-hover">
                                        <thead>
                                        <tr class="shop-bg-thead">
                                            <th width="5%"><?php echo $this->translate('图片'); ?></th>
                                            <th><?php echo $this->translate('商品名称'); ?></th>
                                            <th><?php echo $this->translate('规格'); ?></th>
                                            <th><?php echo $this->translate('单价'); ?></th>
                                            <th><?php echo $this->translate('数量'); ?></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php if ($this->userCart['cartGoodsList']) foreach ($this->userCart['cartGoodsList'] AS $cartGoodsValue) { ?>
                                            <tr>
                                                <td>
                                                    <img src="<?php echo $this->shopHelper()->baseGoodsImagePath($cartGoodsValue['goodsThumbnailImage']); ?>" class="img-thumbnail">
                                                </td>
                                                <td>
                                                    <?php echo $this->escapeHtml($cartGoodsValue['goodsName']); ?>
                                                </td>
                                                <td>
                                                    <?php if(isset($cartGoodsValue['specGoodsTagInfo'])) { ?>
                                                        <?php foreach ($cartGoodsValue['specGoodsTagInfo'] as $specInfo) { ?>
                                                            <small><?php echo $this->escapeHtml($specInfo['tagGroupName']); ?>：<?php echo $this->escapeHtml($specInfo[0]->getTagName()); ?></small>
                                                        <?php } ?>
                                                    <?php } ?>
                                                </td>
                                                <td>
                                                    <?php echo $this->escapeHtml($cartGoodsValue['goodsPrice']); ?>
                                                </td>
                                                <td><?php echo $cartGoodsValue[0]->getBuyNum(); ?></td>
                                            </tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                            <div class="tab-pane" id="tab_5">
                                <div class="box-body table-responsive no-padding">
                                    <table class="table shop-table table-hover">
                                        <thead>
                                        <tr class="shop-bg-thead">
                                            <th width="100%"><?php echo $this->translate('绑定登录应用'); ?></th>
                                        </tr>
                                        </thead>
                                        <?php if ($this->otherLoginList) { ?>
                                        <tbody>
                                            <?php foreach ($this->otherLoginList AS $loginValue) { ?>
                                            <tr>
                                                <td><?php echo $this->otherLoginTextName[$loginValue->getLoginType()]; ?></td>
                                            </tr>
                                            <?php } ?>
                                        </tbody>
                                        <?php } ?>
                                    </table>
                                </div>
                            </div>
                        <?php } ?>

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

    </section>
    <?php echo $this->form()->closeTag(); ?>
</div>
<script type="text/javascript">
    laydate.render({elem: '#userBirthday'});

    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                userGroupId: {
                    required: true
                }
                <?php if(!isset($this->userInfo)) { ?>
                ,
                userName: {
                    required: true
                },
                userPassword: {
                    required: true
                },
                payPassword: {
                    required: true
                }
                <?php } ?>
            },
            messages: {
                userGroupId: {
                    required: "<?php echo $this->translate('请选择客户组!'); ?>"
                }
                <?php if(!isset($this->userInfo)) { ?>
                ,
                userName: {
                    required: "<?php echo $this->translate('客户名称不能为空!'); ?>"
                },
                userPassword: {
                    required: "<?php echo $this->translate('登录密码不能为空!'); ?>"
                },
                payPassword: {
                    required: "<?php echo $this->translate('余额支付密码不能为空!'); ?>"
                }
                <?php } ?>
            }
        });
    });
</script>
