Edit.js 1.2 KB
var $ = require('jquery'), common = require('../../../common/common');

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

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

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

    if (!/^[1-9]\d*$/.test(minCount) || minCount < 2) {
        return "起购件数格式不正确";    
    }

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

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

});

e.init();

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

        var data = option.data;

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

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

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