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

var e = new edit("#basicForm", {bucket: "yhb-img02"});
e.on("validate", function () {
    var contactPhone = $.trim($("#contactPhone").val());
    if (contactPhone) {
        if (!(/^[0-9-()]*$/.test(contactPhone))) {
            return "请输入正确的公司联系电话";
        }
    }
    //phone
    var phone = $.trim($("#phone").val());
    var legalPerson = $.trim($("#legalPerson").val());
    if(legalPerson.length>250){
         return "法人代表长度不能超过250!";
    }
    if (phone) {
        if (!(/^[0-9-()]*$/.test(phone))) {
            return "请输入正确的联系人电话";
        }
    }
    if (!phone && !contactPhone) {
        return "请在公司联系电话,联系人电话至少填一个";
    }

    return true;
});
e.init();

var submit = function (callback, config) {
    e.submit($("#basicForm").attr("action"), function (option) {
        option.success = function (res) {
            if (res.code == "200") {
                e.$tip(config.msg || "提交成功", function () {
                    if (+option.data.operations == 1) {
                        location.href = "/supplier/supplier/index";
                    } else {
                        location.href = "/supplier/supplier/managelist";
                    }
                }, 'growl-success');
            } else {
                e.$tip(res.message);
            }
            return false;
        },
            option.error = function (res) {
                e.$tip("提交失败");
            }
        callback && callback(option.data);
    });
};

//添加暂存,提交审核
$(document).on('click','#btnTemporary',function () {
    submit(function (data) {
        data.operations = 1;
        data.status = 100;
    }, {msg: "暂存成功"});
    return false;
});

//到审核表
$(document).on('click','#btnReview',function () {
    submit(function (data) {
        data.operations ? data.operations : data.operations = 1;
        if (+data.status == 300) {
            data.operations = 2;
        }
        data.status = 200;
    }, {msg: "提交成功"});
    return false;
});

//供应商列表
$(document).on('click','#updatecheck',function () {
    submit(function (data) {
        data.operations = 2;
        data.status = 200;
    }, {msg: "提交成功"});
    return false;
});