<?php
$form = $this->form;
$form->prepare();
?>
<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title"><?php echo $this->translate('商品咨询回复')?></h4>
    </div>
    <div class="modal-body box-body table-responsive no-padding">
        <?php echo $this->form()->openTag($form); ?>
            <div class="box-body">
                <div class="form-group">
                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品名称'); ?></label>
                    <div class="col-sm-8">
                        <p class="form-control-static"><?php echo $this->escapeHtml($this->goodsInfo->getGoodsName()); ?></p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><?php echo $this->translate('咨询人'); ?></label>
                    <div class="col-sm-8">
                        <p class="form-control-static"><?php echo $this->escapeHtml($this->consultInfo->getConsultUser()); ?></p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><?php echo $this->translate('咨询内容'); ?></label>
                    <div class="col-sm-8">
                        <p class="form-control-static"><?php echo nl2br($this->escapeHtml($this->consultInfo->getConsultContent())); ?></p>
                    </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-8">
                        <?php echo $this->formElement($form->get('replyContent')); ?>
                        <?php echo $this->formElementErrors($form->get('replyContent'), ['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">
                        <?php echo $this->formElement($form->get('consultShowStatus')); ?>
                        <?php echo $this->formElementErrors($form->get('consultShowStatus'), ['class'=>'error-message']); ?>
                    </div>
                </div>
            </div>
            <div class="box-footer">
                <button type="submit" class="btn btn-primary col-md-offset-3"><i class="fa fa-check"></i> <?php echo $this->translate('点击回复')?></button>
            </div>
        <?php echo $this->form()->closeTag(); ?>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                replyContent: {
                    required: true
                }
            },
            messages: {
                replyContent: {
                    required: "<?php echo $this->translate('回复内容不能为空!'); ?>"
                }
            },
            submitHandler: function() {
                ajaxSubmit();
            }
        });
    });
    function ajaxSubmit() {
        $.post("<?php echo $this->url('goods-consult', ['action' => 'replyConsult', 'id' => $this->consultInfo->getConsultId()]); ?>", {replyContent:$('#replyContent').val(), consultShowStatus:$('#consultShowStatus').val()}, function (data) {
            if(data.status == 'true') {
                window.location.reload();
            } else {
                shopMessage(data.message);
            }
        }, 'json');
    }
</script>