product.productBundle.Edit.js 2.47 KB
webpackJsonp([123],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	var $ = __webpack_require__(1), common = __webpack_require__(2);

	var e = new common.edit('#editor-group');

	e.on("validate", function () {

	    var discount = $("#discount").val();

	    if (!/^1|0\.[0-9]{0,2}$/.test(discount) || discount > 1.0 || discount <= 0.0) {
	        return "折扣格式不正确";
	    }

	    var skns = '';

	    var iptSkns = $("input[name='productSkn']");

	    for (var i = 0, l = iptSkns.length; i < l; i++) {
	        var $thiz = $(iptSkns[i]);
	        var skn = $.trim($thiz.val());
	        if (/^[1-9][0-9]{4,10}$/.test(skn)) {
	            skns = skns + skn + ",";
	        } else if(skn.length != 0) {
	            return "第 " + (i + 1) + " 个 SKN 格式错误";
	        }
	    }

	    var lio = skns.lastIndexOf(",");

	    if (lio == -1) {
	        return "请填写商品 SKN";
	    }

	    $("#productSkn").val(skns.substring(0, lio));

	});

	e.init();

	// submit
	$('#add-btn').click(function(option) {
	    e.submit($('#add-form').attr('action'), function(option) {

	        var data = option.data;

	        // convert date
	        data.startTime = toSeconds(data.beginTimeStr);
	        data.endTime = toSeconds(data.endTimeStr);

	        option.beforeSend = function() {
	            $('#add-btn').addClass('disabled');
	        };

	        option.success = function(res) {
	            if (res.code == "200") {
	                e.$tip('提交成功', function() {
	                    location.href = "/product/bundle/index";
	                }, 'growl-success');
	            } else {
	                $('#add-btn').removeClass('disabled');
	                e.$tip(res.message);
	            }

	            return false;
	        }
	        option.error = function(res) {
	            e.$tip("提交失败");
	        };
	    });
	});

	$(".btn-up").click(function() {
	    var tr = $(this).parents("tr");
	    var ipt = tr.find("input[name='productSkn']");
	    var prev = tr.prev().find("input[name='productSkn']");
	    var val = ipt.val();
	    ipt.val(prev.val());
	    prev.val(val);
	});

	$(".btn-down").click(function() {
	    var tr = $(this).parents("tr");
	    var ipt = tr.find("input[name='productSkn']");
	    var next = tr.next().find("input[name='productSkn']");
	    var val = ipt.val();
	    ipt.val(next.val());
	    next.val(val);
	});

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


/***/ }
]);