<div class="content-wrapper">

    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right">
            <?php echo $this->HelpUrl('consultList'); ?>
        </h1>

    </section>

    <section class="content">
        <?php echo $this->partial('layout/messages'); ?>

        <div class="row">
            <div class="col-xs-12">
                <div class="box shop-box">

                    <div class="box-body table-responsive no-padding">
                        <table class="table shop-table table-hover">
                            <thead>
                            <tr class="shop-bg-thead">
                                <th width="20%"><?php echo $this->translate('商品名称'); ?></th>
                                <th width="30%"><?php echo $this->translate('咨询内容'); ?></th>
                                <th width="10%"><?php echo $this->translate('咨询人'); ?></th>
                                <th width="5%"><?php echo $this->translate('显示'); ?></th>
                                <th width="5%"><?php echo $this->translate('回复'); ?></th>
                                <th width="15%"><?php echo $this->translate('咨询时间'); ?></th>
                                <th width="15%"><?php echo $this->translate('操作'); ?></th>
                            </tr>
                            <?php
                            $sForm = $this->searchForm;
                            $sForm->prepare();
                            ?>
                            <?php echo $this->form()->openTag($sForm); ?>
                            <tr>
                                <td>
                                    <?php echo $this->formElement($sForm->get('goods_name')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('goods_name'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('consult_content')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('consult_content'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('consult_user')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('consult_user'), ['class'=>'error-message']);?>
                                </td>
                                <td></td>
                                <td></td>
                                <td>
                                    <p>
                                        <?php echo $this->formElement($sForm->get('start_time')); ?>
                                    </p>
                                    <div>
                                        <?php echo $this->formElement($sForm->get('end_time')); ?>
                                    </div>
                                    <?php echo $this->formElementErrors($sForm->get('start_time'), ['class'=>'error-message']);?>
                                    <?php echo $this->formElementErrors($sForm->get('end_time'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <button type="submit" class="btn btn-info btn-sm"><i class="fa fa-search"></i></button>
                                    <?php
                                    $formData = $sForm->getData();
                                    if(!empty(array_filter($formData))) { ?>
                                        &nbsp;&nbsp;<a href="<?php echo $this->url('goods-consult');?>" class="btn btn-default btn-sm"><i class="fa fa-reply"></i></a>
                                    <?php } ?>
                                </td>
                            </tr>
                            <?php echo $this->form()->closeTag(); ?>
                            </thead>
                            <tbody>
                            <?php if($this->consultList->getCurrentItemCount() > 0) foreach ($this->consultList as $consultValue) { ?>
                                <tr>
                                    <td><?php echo $this->escapeHtml($consultValue['goodsName']); ?></td>
                                    <td><?php echo $this->escapeHtml($consultValue[0]->getConsultContent()); ?></td>
                                    <td><?php echo $this->escapeHtml($consultValue[0]->getConsultUser()); ?></td>
                                    <td>
                                        <?php if($consultValue[0]->getConsultShowStatus() == 2) { ?>
                                            <i class="fa fa-times text-red"></i>
                                        <?php } else { ?>
                                            <i class="fa fa-check text-green"></i>
                                        <?php } ?>
                                    </td>
                                    <td>
                                        <?php echo !empty($consultValue[0]->getReplyTime()) ? '<span class="text-green">'.$this->translate('已回复').'</span>' : '<span class="text-red">'.$this->translate('未回复').'</span>'; ?>
                                    </td>
                                    <td><?php echo $this->shopDateFormat()->goodsConsultTime($consultValue[0]->getConsultTime()); ?></td>
                                    <td>
                                        <a href="javascript:;" onclick="replyGoodsConsult(<?php echo $consultValue[0]->getConsultId(); ?>);" class="btn btn-xs btn-success"><i class="fa fa-reply"></i> <?php echo $this->translate('回复'); ?></a>
                                        <a href="javascript:;" onclick="deleteConfirm('<?php echo $this->translate('您确实要删除该咨询信息吗?'); ?>', '<?php echo $this->url('goods-consult', ['action'=>'delete', 'id' => $consultValue[0]->getConsultId()], ['query' => ['qToken' => $this->adminHelper()->getCsrfValue()]]); ?>');" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i> <?php echo $this->translate('删除'); ?></a>
                                    </td>
                                </tr>
                                <?php if(!empty($consultValue[0]->getReplyTime())) { ?>
                                    <tr>
                                        <td colspan="7" style="border-top:1px solid #fff;">
                                            <strong><?php echo $this->translate('回复时间'); ?>：</strong><?php echo $this->shopDateFormat()->goodsConsultTime($consultValue[0]->getReplyTime()); ?> <strong><?php echo $this->translate('回复人'); ?>：</strong><?php echo $consultValue[0]->getReplyUser(); ?><br>
                                            <strong><?php echo $this->translate('回复内容'); ?>：</strong><?php echo $this->escapeHtml($consultValue[0]->getReplyContent()); ?>
                                        </td>
                                    </tr>
                                <?php } ?>
                            <?php } ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <?php echo $this->paginationControl($this->consultList, 'Sliding', 'layout/page', ['route' => 'goods-consult']); ?>
                    </div>
                </div>

            </div>
        </div>

    </section>
</div>

<div class="modal fade" id="modalDefault">
    <div class="modal-dialog" style="width: 800px;" id="replyConsult">

    </div>
</div>

<script>
    laydate.render({elem: '#start_time'});
    laydate.render({elem: '#end_time'});

    function replyGoodsConsult(consultId) {
        $.get('<?php echo $this->url('goods-consult', ['action' => 'replyConsult']); ?>/'+consultId, {}, function (html) {
            if(html.length > 0) {
                $('#replyConsult').html(html);
                $('#modalDefault').modal('show');
            }
        })
    }
</script>