search.matchWords.Index.js 7.08 KB
webpackJsonp([154],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/*
	 *@time: 2016-11-09 11:09:56
	 *@author: LiQZ
	 * App.template
	 */
	var $ = __webpack_require__(1), common = __webpack_require__(2);

	var artTemplate = common.artTemplate;

	var categoryList = [];

	// 下拉框
	new common.dropDown({
	    el: "#status"
	});
	new common.dropDown({
	    el: "#time_status"
	});

	$.timepicker.datetimeRange($('#start_time'), $('#end_time'));

	var tableGird = new common.grid({

	    el: "#table-box",
	    parms: function() {
	      return {
	            matchWordName: $("#matchWordName").val(),
	            status: $("#status").val(),
	            timeStatus: $("#time_status").val(),
	            startTime: timeToSeconds($("#start_time").val()),
	            endTime: timeToSeconds($("#end_time").val()),
	        }  
	    },
	    columns: [
	    { display: "ID", name: "id" },
	    { display: "匹配词", name: "matchWordName"},
	    { display: "PC链接", name: "matchPcUrl"},
	    { display: "移动端链接", name:"matchAppUrl"},
	    { display: "频道", name:"channelIds", render: function(item) {
	        var channelId = parseInt(item.channelIds);
	        var categoryName = '默认';
	        for(var i=0; i<categoryList.length; i++){
	            if(channelId==0){
	                break;
	            }else if(channelId == categoryList[i].categoryId){
	                categoryName = categoryList[i].categoryName;
	                break;
	            }
	        }
	        return categoryName;
	    }},
	    { display: "开启状态", name:"status", render: function(item) {
	        if (item.status == 0) {return "开启"; } else { return "关闭"; }
	    }},
	    { display: "时间状态", name:"status", render: function(item) {
	        var now = Date.parse(new Date())/1000;
	        // 未开始
	        if (item.startTime > now) {
	            return "未开始";
	        }
	        // 进行中
	        if (item.startTime <= now && item.endTime >= now) {
	            return "进行中";
	        }
	        // 已结束
	        if (item.endTime < now) {
	            return "已结束";
	        }
	        return "时间设置错误";
	    }},
	    { display: "开始时间", name:"startTime", render: function(item) {
	            return common.util.__secondsFormat(item.startTime);
	    }},
	    { display: "结束时间", name:"endTime", render: function(item) {
	        return common.util.__secondsFormat(item.endTime);
	    }},
	    { display: "操作", render: function(items) {
	            var HtmArr = [];
	            HtmArr.push('<a href="javascript:void(0);" data-index="' + items.__index + '" class="btn btn-primary btn-xs btn_edit">编辑</a>');
	            if (items.status == 0) {
	                HtmArr.push('<a href="javascript:;" data-id="' + items.id + '" class="btn btn-danger btn-xs close-btn">关闭</a>');
	            } else {
	                HtmArr.push('<a href="javascript:;" data-id="' + items.id + '" class="btn btn-success btn-xs open-btn">开启</a>');
	            }
	            HtmArr.push('<a href="javascript:;" data-id="' + items.id + '" class="btn btn-danger btn-xs delete-btn">删除</a>');
	            return HtmArr.join('');
	        }
	    }]
	});

	tableGird.init('/search/matchWords/list');

	$(document).on("click", "#filter-btn", function () {
	    tableGird.reload();
	});

	//开启
	$('#table-box').on('click', '.open-btn', function() {
	    var param = {
	        id: $(this).data('id'),
	        status: '0'
	    }
	    common.util.__ajax({
	        url: '/search/matchWords/triggerStatus',
	        data: param

	    }, function(res) {
	        tableGird.reload();
	    });
	});

	//关闭
	$('#table-box').on('click', '.close-btn', function() {
	    var param = {
	        id: $(this).data('id'),
	        status: '1'
	    }
	    common.util.__ajax({
	        url: '/search/matchWords/triggerStatus',
	        data: param

	    }, function(res) {
	        tableGird.reload();
	    });
	});

	//删除
	$('#table-box').on('click', '.delete-btn', function() {
	    var param = {
	        id: $(this).data('id')
	    }
	    common.util.__ajax({
	        url: '/search/matchWords/delete',
	        data: param

	    }, function(res) {
	        tableGird.reload();
	    });
	});

	function timeToSeconds(time) {
	    if (time) {
	        time = time.replace(/-/g,'/'); // 通用性好一点
	        return new Date(time).getTime() / 1000;
	    }
	}

	/**************************************
	 * 添加编辑
	 **************************************/

	 var Bll = {

	        toast:function(url, item, hint) {

	            var e = new common.edit("#baseform");

	            var dialog = common.dialog.confirm(hint, artTemplate("template", item),  function() {

	                    e.submit(url, function (option) {

	                        console.log(option.data);

	                        option.data.startTime = new Date(option.data.startTime).getTime() / 1000;
	                        option.data.endTime = new Date(option.data.endTime).getTime() / 1000;

	                        option.success=function() {
	                            dialog.close();
	                            tableGird.reload();
	                        };
	                        option.error=function(){};
	                    });

	                    return false;
	            });
	            common.util.__ajax({
	                async:false,
	                url: "/salesCategory/querySCListByLevel",
	                data: {levelNumber:1}
	            }, function (res) {
	                categoryList = res.data;
	                for(var i=0; i<categoryList.length; i++){
	                    var categoryName = categoryList[i].categoryName;
	                    var categoryId = categoryList[i].categoryId;
	                    html = '<div style="float:left;margin-right: 5px"><input type="checkbox" name="channelIds" class="observe" data-field="channelIds" value="'+categoryId+'">'+categoryName+'</div>';
	                    $("#channelCheckBox").append(html);
	                }
	            },true);

	            e.on("validate", function() {
	                var matchWordName = $("#baseform").find("#matchWordName").val();
	                if (matchWordName.indexOf(",") >= 0) {
	                    return "请使用英文 , 分割";
	                }
	            });

	            e.init();


	        }
	    };

	    $('#btn_add').on('click', function() {
	        var item = { "status": 0 }; // 默认开启
	        Bll.toast('/search/matchWords/save', item, "创建匹配词");
	    });

	    $(document).on('click', '.btn_edit', function() {
	        var item = tableGird.rows[$(this).data("index")];
	        console.log(item);
	        Bll.toast('/search/matchWords/save', item, "编辑匹配词");
	        $(":checkbox").attr("disabled", true);
	    });

	$(function(){
	    $.ajax({
	        type: 'POST',
	        dataType: 'json',
	        url: "/salesCategory/querySCListByLevel",
	        data: {levelNumber: '1'},
	        async: false
	    }).then(function (data) {
	        console.log(data);
	        if (data.code === 200) {
	            categoryList = data.data;
	        }
	    });
	});


/***/ }
]);