product.productBundle.Index.js 4.88 KB
webpackJsonp([118],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/*
	 *@time: 2016.10.10
	 *@author: LiQZ
	 */
	var $ = __webpack_require__(1), common = __webpack_require__(2);
	__webpack_require__(9);


	//日期插件
	$('.hasDatepicker').fdatepicker({
	    format: 'yyyy-mm-dd hh:ii:ss',
	    pickTime: true
	});

	new common.dropDown({el: "#brand-name", ajax: "brand"});
	new common.dropDown({ el: "#time_status" });


	var tableGird = new common.grid({
	    el: "#table-box",
	    size: 30,
	    parms: function() {
	        return {
	            // "id": common.util.__input('id'),
	            "bundleName": common.util.__input('bundleName'),
	            "productSkn": common.util.__input('productSkn'),
	            "status": $("#time_status").val(),
	            "brand": common.util.__input("brand-name")
	        };
	    },
	    columns: [
	    { display: "组合套餐号", name: "id" },
	    { display: "套餐名称", name: "bundleName" },
	    { display: "SKN", render: function(items) {
	        return items.productSkn.replace(/,/g, '/');
	    }},
	    { display: "品牌", render: function(items) {
	        return items.brand;
	    }},
	    { display: "有效期", render: function(items) {
	        // return common.util.__secondsFormat(items.startTime)
	        //  + " ~ "
	        // + common.util.__secondsFormat(items.endTime);
	        return toDate(items.startTime) + " ~ " + toDate(items.endTime);
	    }},
	    { display: "折扣", render: function(items) {
	        return items.discount;
	    }},
	    { display: "状态", render: function(items) {
	        if (items.status != 1) {
	            return "已终止";
	        }
	        var now = Date.parse(new Date())/1000;
	        // 未开始
	        if (items.startTime > now) {
	            return "未开始";
	        }
	        // 进行中
	        if (items.startTime <= now && items.endTime >= now) {
	            return "进行中";
	        }
	        // 已结束
	        if (items.endTime < now) {
	            return "已结束";
	        }
	        return "时间设置错误";
	    }},
	    { display: "操作信息", render: function(items) {
	        return items.operator + " " + common.util.__secondsFormat(items.updateTime);
	    }},
	    { display: "操作", render: function(items) {
	            var now = Date.parse(new Date())/1000;
	            var HtmArr = [];
	            if (items.status == 1 && items.startTime > now) {
	                HtmArr.push('<a href="/product/bundle/' + items.id + '" data-id="' + items.id + '" class="btn btn-primary btn-xs">编辑</a>');
	            }
	            if (items.status == 1 && items.endTime >= now) {
	                HtmArr.push('<a href="javascript:void(0);" data-id="' + items.id + '" class="btn btn-danger btn-xs delete">终止</a>');
	            }
	            HtmArr.push('<a href="javascript:void(0);" data-id="' + items.id + '" class="btn btn-warning btn-xs sync">同步</a>');
	            return HtmArr.join('');
	        }
	    }]
	});

	tableGird.init('/product/bundle/list');

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

	function toSeconds(strDate) {
	    var seconds = new Date(strDate).getTime() / 1000;
	    return seconds;
	}

	function toDate(seconds) {
	    if (!$.isNumeric(seconds) || seconds <= 0) { return ''; }
	    var date = new Date(seconds * 1000);
	    return fixTwo(date.getFullYear()) + '-' + fixTwo((date.getMonth() + 1)) + '-' + fixTwo(date.getDate()) + ' ' + fixTwo(date.getHours()) + ':' + fixTwo(date.getMinutes()) + ':' + fixTwo(date.getSeconds());
	}

	function fixTwo(number) {
	    return number < 10? "0" + number: number;
	}

	/**
	 * 删除--点击事件
	 */
	$(document).on('click', '.delete', function () {
	    var id = $(this).attr("data-id");
	    common.dialog.confirm("警告",
	        "确认终止?",
	        function () {
	            common.util.__ajax({
	                url: '/product/bundle/stop',
	                data: { id: id }
	            }, function () {
	                tableGird.reload();
	            });
	        });
	});

	// 导出
	$(document).on("click", "#exportsearch", function () {
	    var temp = $.extend(true, tableGird.__getparams(), {"size": 10000} );
	    window.open("/ajax/down?queryConf=" + JSON.stringify(temp) + "&type=productBundleServiceExport");
	});

	// 同步
	$(document).on('click', '.sync', function () {
	    var id = $(this).attr("data-id");
	    common.util.__ajax({
	        url: '/product/bundle/sync',
	        data: { id: id }
	    }, function (resp) {
	        // common.util.__tip(resp.message, resp.code == 200 ? 'success' : 'warning');
	    });
	});

	function toDate(seconds) {
	    if (!seconds || seconds <= 0) { return ''; }
	    var date = new Date(seconds * 1000);
	    return fixTwo(date.getFullYear()) + '-' + fixTwo((date.getMonth() + 1)) + '-' + fixTwo(date.getDate());
	}

	function fixTwo(number) {
	    return number < 10? "0" + number: number;
	}


/***/ }
]);