limitcode-edit.js 2.38 KB
var $ = require('jquery');
var edit=require('../common/edit');


	var e=new edit("#basicForm");
    var type=$("#basicForm").attr("role");


    e.on("render",function(){
        if($("#reqDepartment").val()){
            var departmentArr = String.prototype.split.call($("#reqDepartment").val(), '/'),
            $department1 = $("#department1"),
            $department2 = $("#department2");

            $department1.val(departmentArr[0]);
            if (departmentArr[1]) {
                $department2.val(departmentArr[1]).show();
            } else {
                $department2.hide();
            }
        }
    });

    e.on("bind",function(){
        if($("#reqDepartment").val()){
            var departmentArr = String.prototype.split.call($("#reqDepartment").val(), '/'),
            $department1 = $("#department1"),
            $department2 = $("#department2");

            $("select").change(function() {
                if ($(this).is($department1)) {
                    departmentArr.length = 0;
                    departmentArr[0] = $(this).val();
                    if ($(this).val() === "零售运营部") {
                        $department2.show();
                        departmentArr[1] = $department2.val();
                    } else {
                        $department2.hide();
                    }
                } else {
                    departmentArr[1] = $(this).val();
                }
                $("#reqDepartment").val(departmentArr.join('/'));
            });
        }
    });

    e.init();

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

    $("#save_brand").click(function(){
        submit(function(data){
            //  限购码状态0:待审核 1:审核通过 2:驳回 3:过期 4:作废
            data.status=0;
        });
        return false;
    });