product_cache.hbs 4.47 KB
<div class="pageheader">
    <div class="media">
        <div class="pageicon pull-left">
            <i class="fa fa-th-list"></i>
        </div>
        <div class="media-body">
            <ul class="breadcrumb">
                <li><a href="/"><i class="glyphicon glyphicon-home"></i></a></li>
                <li><a href="/servers">缓存管理</a></li>
            </ul>
            <h4>清理商品缓存</h4>
        </div>
    </div>
    <!-- media -->
</div>

<div class="contentpanel">
    <div class="row cache-panel">
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="col-sm-6">
                    <div class="operations mb20">
                        <label class="control-label">导入文件:</label>
                        <div class="file-upload"></div>
                        <p class="skn-count"></p>
                        <select id="selectType" class="form-control input-sm selcet-auto pull-left mr20">
                            <option value="1">批量变价</option>
                            <option value="2">其它批量</option>
                        </select>
                        <button class="btn btn-warning btn-clear ">执行清理</button>
                        
                    </div>
                    <div class="download">
                        <a href="/template/product_cache_template.xlsx" class="block">模板文件下载</a>
                        &nbsp;
                        <a href="javascript:;" class="block product-url">生成商品url</a>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="panel">
                        <div class="panel-heading">
                            <h4 class="panel-title">日志</h4>
                        </div><!-- panel-heading -->
                        <div class="panel-body yoho-log-dark">
                            <div class="results-list ">

                            </div><!-- results-list -->
                        </div><!-- panel-body -->
                    </div><!-- panel -->
                </div>
            </div>
            <div class="panel-footer">
                
                <div class="result pull-left ml20"></div>
            </div>
        </div>
    </div>
</div>

<script>
    var posing = false;
    $(document).on('ready pjax:success', function() {

        var fileUpload = $('.file-upload').uploadFile({
            url: '/product_cache/import',
            method: 'POST',
            uploadStr: '浏览',
            multiple: false,
            maxFileCount: 1,
            fileName: 'excelFile',
            allowedTypes: 'xlsx,xls',
            dynamicFormData: function() {
                return {type: $('#selectType').val()}
            },
            onSuccess: function(files, data, xhr, pd) {
                console.log('success')
                if(data.code === 200) {
                    $('.skn-count').text('导入数量:' + data.count).data('count', data.count);
                }
                fileUpload.reset();
            },
            onError: function(files, data, xhr, pd) {
                console.log('onError')
                fileUpload.reset();
            }
        })
        $('.btn-clear').click(function() {
            var count = $('.skn-count').data('count');
            var selectType = $('#selectType').val();
            if(count > 0 && selectType) {
                $.post('/product_cache/clear', {
                    type: selectType,
                }); 
            }
        })
        $('.product-url').click(function() {
            var count = $('.skn-count').data('count');
            if(count > 0) {
                window.location.href = '/product_cache/product_url';
            }
        })
        
        function layoutResize() {
            $('.yoho-log-dark').height($('body').height() - 450);
        }

        $(window).resize(function() {
            layoutResize();
        });

        layoutResize();
        var $logs = $('.yoho-log-dark .results-list');
        var $dark = $('.yoho-log-dark');
        function appendLog(message) {
            var html = '<p><span class="message">- ' + message + '</span></p>';
            $logs.append(html);
            $dark.scrollTop($logs[0].scrollHeight);
        }

        var ws = io();
        ws.on('connect', function() {
            ws.on('/product_cache/log', function(data) {
                appendLog(data.message)
            });
        });

    });
</script>