Index.js 5.9 KB
/**
 * Created by zw on 2016/11/3.
 * 视频管理
 */
var $ = require('jquery');
var common = require('../../common/common');


/**
 * 列表显示数据
 * @type {common.grid}
 */
var g = new common.grid({
    el: '#content-list',
    hash: false,
    complete: function () {
        $('#content-list').poptrox({
            usePopupCaption: true
        });
    },
    parms: function () {
        return {
            skn: common.util.__input('content-filter1'),
            videoName: common.util.__input('content-filter2')           
        };
    },
//列表显示
    columns: [
        {display: "视频名称", name: "videoName"},
        {display: "关联SKN", name: "skn"},    
        {
        display: '视频',
        name: 'url',
        render: function (item) {
            if (item.url) {
                return '<img height="140" width="80" src="' + item.url +'?vframe/jpg/offset/0'+ '">';
                } else {
                    return '';
                }

            }
        },
        {display: "视频大小", name: "videoSize",render:function(item) { return item.videoSize+"M"}}, 
        {display: "备注", name: "note"},          
        {
            display: "操作", name: "", render: function (item) {
                var arr = [];
                arr.push('<a class="btn btn-xs btn-info update" data-index="' + item.__index + '">编辑</a>');
                arr.push('<a class="btn btn-xs btn-danger delete" data-index="' + item.__index + '">删除</a>');
                return arr.join('');
            }
        }
    ]
});
g.init("/video/queryVideosList");



//  
var Bll = {
    newVideo: {},
    rendBoList: function (obj) {    
        $("#imgTag").attr("src",obj.url+"?vframe/jpg/offset/0");    
        $("#imgTag").show();
        $("#imgATag").hide();
    },
    toast: function (url, item, datacall) {
        $("#imgTag").hide();
        if(item.__state == "edit" ){
            Bll.newVideo.url=item.url;
            Bll.newVideo.fileName=item.fileName;
            Bll.newVideo.videoSize=item.fileSize;
            Bll.newVideo.id=item.id;           
            item.url = item.url+"?vframe/jpg/offset/0"     
        }

        var a = new common.dialog({
            title: "视频",
            width: '50%',
            content: common.util.__template2($("#template").html(), item),
            button: [
                {
                    value: "提交", callback: function () {
                    if($.trim($("#videoName").val()) == ""){
                        common.util.__tip("视频名称不能为空", 'warning');
                        return false;
                    }

                    var data = {};                
                                                    
                    Bll.newVideo.videoName = $.trim($("#videoName").val());
                    Bll.newVideo.skn = $.trim($("#skn").val());
                    Bll.newVideo.note = $.trim($("#note").val());

                    console.log("提交的参数:"+JSON.stringify(Bll.newVideo));  
                    common.util.__ajax({
                        url: url,
                        data: Bll.newVideo
                    }, function (res) {
                        if (res.code == '200') {
                            /*common.util.__tip("上传成功", 'success');*/
                            g.reload();
                            a.close();
                        }
                    });
                    return false;
                }, css: "btn-primary"
                },
                {
                    "value": "取消",
                    css: "btn-info"
                }
            ]
        });
        //Bll.rendBoList(Bll.pictureBoList);
        // var loadModal = null;
        common.edit.ajaxfileupload(".picfile", {
            params: {
                __type: "import-video",
                bucket: "goodsvideo"
            },
            valid_extensions: ['mp4'],
            // onStart: function(params) {                
            //     loadModal = common.dialog.load();                
            // },
            onComplete: function (response) {
                console.log("批量接口返回数据",response);
                if (response.status && response.code == 200) {                
                    Bll.newVideo.url=response.data.url;
                    Bll.newVideo.fileName=response.data.fileName;
                    Bll.newVideo.videoSize=response.data.fileSize;
                   // if (loadModal) {
                   //      loadModal.close();
                   //  }
                    Bll.rendBoList(Bll.newVideo);
                }
                else {
                    common.util.__tip(response.message, 'warning');
                }
            }
        });
    }
};




//添加
$('#addVideo').on('click', function () {
    var item = {
        "__state":"add",
        "videoName": "",
        'skn': "",
        'url': "",
        'note': ""
    };
    
    Bll.toast('/video/editVideo', item, function(){
        return {
            productPhotoAddStrList: ""
        }
    });
});


//查询按钮--点击事件
$(document).on('click', '#filter-btn', function () {
    g.reload(1);
});

//删除--点击事件
$(document).on('click', '.delete', function () {
    var item = g.rows[$(this).data("index")];
    common.dialog.confirm("警告",
        "确认删除?",
        function () {
            common.util.__ajax({
                url: '/video/delVideo',
                data: {
                    id: item.id
                }
            }, function () {
                g.reload(1);
            });
        });
});

//修改--点击事件
$(document).on('click', '.update', function () {
    var item = g.rows[$(this).data("index")];
    item.__state="edit";
    if(item.url.indexOf("?") > 0){
        item.url = item.url.substring(0,item.url.indexOf("?"));    
    }
    console.log("修改"+ item.url);

    Bll.toast('/video/editVideo', item, "修改视频");
});