<div class="content-wrapper">

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

        <h1 class="pull-right">
            <a href="<?php echo $this->url('extend');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回已安装插件列表'); ?></a>
            <?php echo $this->HelpUrl('pluginList'); ?>
        </h1>

    </section>

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

        <div class="row">
            <?php
            if (isset($this->result['result']['pluginList']) && !empty($this->result['result']['pluginList'])) foreach ($this->result['result']['pluginList'] as $pluginValue) {
                //插件是否安装
                $installState = false;
                if (!empty($this->pluginCodeArray) && in_array($pluginValue['pluginCode'], $this->pluginCodeArray)) $installState = true;
                ?>
            <div class="col-lg-4 col-xs-6">
                <table class="box <?php if ($installState) echo 'box-primary'; ?> table table-responsive no-padding">
                    <tr>
                        <td width="25%">
                            <img src="<?php echo $this->serviceUrl . $pluginValue['pluginImage']; ?>" class="img-thumbnail">
                            <p style="margin-top: 5px;height: 36px;">
                                <span class="text-bold"><?php echo $this->translate('价格'); ?>:</span><?php echo $pluginValue['pluginPrice'] > 0 ? '￥'.$pluginValue['pluginPrice'] : $this->translate('免费'); ?>
                            <?php if ($pluginValue['pluginPrice'] > 0 && !$installState) { ?>
                                <a href="<?php echo $pluginValue['pluginBuyUrl']; ?>" target="_blank" class="btn btn-xs btn-primary"><i class="fa fa-shopping-cart" aria-hidden="true"></i> <?php echo $this->translate('点击购买'); ?></a>
                            <?php } ?>
                            </p>
                        </td>
                        <td>
                            <p class="text-bold"><?php echo $this->escapeHtml($pluginValue['pluginName']); ?></p>
                            <p style="font-size:10px;height:82px;max-height: 82px;overflow: hidden;"><?php echo nl2br($this->escapeHtml($pluginValue['pluginInfo'])); ?></p>
                            <small><a href="<?php echo $this->escapeHtml($pluginValue['pluginAuthorUrl']); ?>" target="_blank"><?php echo $this->escapeHtml($pluginValue['pluginAuthor']); ?></a> <?php echo $this->translate('开发'); ?> | <a href="<?php echo $this->escapeHtml($pluginValue['pluginSupportUrl']); ?>" target="_blank"><?php echo $this->translate('点击查看教程'); ?></a></small>
                        </td>
                        <td width="18%">
                            <?php if ($installState) { ?>
                                <a href="javascript:;" class="btn btn-sm btn-success"><?php echo $this->translate('已经安装'); ?></a>
                            <?php } else { ?>
                                <button type="button" onclick="installShopPlugin('<?php echo $pluginValue['pluginCode']; ?>');" class="btn btn-sm btn-primary"><i class="fa fa-plus" aria-hidden="true"></i> <?php echo $this->translate('点击安装'); ?></button>
                            <?php } ?>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3"><span class="text-bold"><?php echo $this->translate('支持系统最低版本'); ?></span>：<?php echo $this->escapeHtml($pluginValue['pluginSupportVersion']); ?></td>
                    </tr>
                </table>
            </div>
            <?php } else { ?>
                <div class="box-body"><h4 class="text-red"><?php echo $this->result['message']; ?></h4></div>
            <?php } ?>
        </div>

    </section>
</div>
<script type="text/javascript">
    function installShopPlugin(pluginCode) {
        layer.msg('<?php echo $this->translate('正在安装插件……，请不要关闭页面'); ?>', {
            icon: 16
            ,shade: 0.01
            ,time: 300000
        });
        $.post("<?php echo $this->url('extend', ['action' => 'startInstallPlugin']); ?>", {pluginCode:pluginCode}, function (data) {
            if (data.state == 'false') {
                layer.alert(data.message, {title: '<?php echo $this->translate('错误提示'); ?>', area:['50%', '70%']});
                return false;
            }
            shopMessage(data.message);
            window.location.reload();
        }, 'json');
    }
</script>